Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
moab::gs_data Class Reference

#include <gs.hpp>

Classes

class  crystal_data
 

Public Member Functions

 gs_data (uint n, const long *label, const Ulong *ulabel, uint maxv, const unsigned int nlabels, const unsigned int nulabels, crystal_data *crystal, ErrorCode &Init_Result)
 
 gs_data ()
 
 ~gs_data ()
 
ErrorCode initialize (uint n, const long *label, const Ulong *ulabel, uint maxv, const unsigned int nlabels, const unsigned int nulabels, crystal_data *crystal)
 
void reset ()
 
void gs_data_op (realType *u, int op)
 
void gs_data_op_vec (realType *u, uint n, int op)
 
void gs_data_op_many (realType **u, uint n, int op)
 

Public Attributes

sintlocal_cm
 

Detailed Description

Definition at line 15 of file gs.hpp.

Constructor & Destructor Documentation

◆ gs_data() [1/2]

moab::gs_data::gs_data ( uint  n,
const long *  label,
const Ulong ulabel,
uint  maxv,
const unsigned int  nlabels,
const unsigned int  nulabels,
crystal_data crystal,
ErrorCode Init_Result 
)
inline

Constructor for moab_gs_data: takes all arguments and initializes moab_gs_data. If needs_reset is false after calling constructor, initialization has failed.

param n number of tuples in tuple list param label pointer to signed labels param ulabel pointer to unsigned labels param maxv max vector size param nlabels number of signed long labels (not including gid) param nulabels number of unsigned long labels param crystal moab_crystal_data contains MPI_Comm and is used for message passing

Definition at line 199 of file gs.hpp.

207  {
208  Init_Result = this->initialize( n, label, ulabel, maxv, nlabels, nulabels, crystal );
209  };

References initialize().

◆ gs_data() [2/2]

moab::gs_data::gs_data ( )
inline

Default constructor (Note: moab_gs_data must be initialized before use!)

Definition at line 214 of file gs.hpp.

214 {};

◆ ~gs_data()

moab::gs_data::~gs_data ( )
inline

Definition at line 216 of file gs.hpp.

217  {
218  reset();
219  }

References reset().

Member Function Documentation

◆ gs_data_op()

void moab::gs_data::gs_data_op ( realType u,
int  op 
)

Definition at line 751 of file gs.cpp.

752 {
753  local_condense( u, op, this->local_cm );
754 #ifdef MOAB_HAVE_MPI
755  this->nlinfo->nonlocal( u, op, _comm );
756 #endif
758 }

References local_cm, moab::local_condense(), and moab::local_uncondense().

◆ gs_data_op_many()

void moab::gs_data::gs_data_op_many ( realType **  u,
uint  n,
int  op 
)

Definition at line 775 of file gs.cpp.

776 {
777  uint i;
778 #ifdef MOAB_HAVE_MPI
779  if( n > nlinfo->_maxv )
780  moab::fail( "%s: initialized with max vec size = %d,"
781  " but called with vec size = %d\n",
782  __FILE__, nlinfo->_maxv, n );
783 #endif
784  for( i = 0; i < n; ++i )
785  local_condense( u[i], op, local_cm );
786 
787  moab::fail( "%s: initialized with max vec size = %d,"
788  " but called with vec size = %d\n",
789  __FILE__, 6, n );
790 
791 #ifdef MOAB_HAVE_MPI
792  this->nlinfo->nonlocal_many( u, n, op, _comm );
793 #endif
794  for( i = 0; i < n; ++i )
795  local_uncondense( u[i], local_cm );
796 }

References moab::fail(), local_cm, moab::local_condense(), and moab::local_uncondense().

◆ gs_data_op_vec()

void moab::gs_data::gs_data_op_vec ( realType u,
uint  n,
int  op 
)

Definition at line 760 of file gs.cpp.

761 {
762 #ifdef MOAB_HAVE_MPI
763  if( n > nlinfo->_maxv )
764  moab::fail( "%s: initialized with max vec size = %d,"
765  " but called with vec size = %d\n",
766  __FILE__, nlinfo->_maxv, n );
767 #endif
768  local_condense_vec( u, n, op, local_cm );
769 #ifdef MOAB_HAVE_MPI
770  this->nlinfo->nonlocal_vec( u, n, op, _comm );
771 #endif
773 }

References moab::fail(), local_cm, moab::local_condense_vec(), and moab::local_uncondense_vec().

◆ initialize()

ErrorCode moab::gs_data::initialize ( uint  n,
const long *  label,
const Ulong ulabel,
uint  maxv,
const unsigned int  nlabels,
const unsigned int  nulabels,
crystal_data crystal 
)

Sets up the moab_gs_data; see constructor for parameter documentation

Definition at line 802 of file gs.cpp.

809 {
810  nlinfo = NULL;
811  unsigned int j;
812  TupleList nonzero, primary;
813  ErrorCode rval;
814 #ifdef MOAB_HAVE_MPI
815  TupleList shared;
816 #else
818 #endif
819  (void)VALGRIND_CHECK_MEM_IS_DEFINED( label, nlabels * sizeof( long ) );
820  (void)VALGRIND_CHECK_MEM_IS_DEFINED( ulabel, nlabels * sizeof( Ulong ) );
821 #ifdef MOAB_HAVE_MPI
822  MPI_Comm_dup( crystal->_comm, &this->_comm );
823 #else
824  buf.buffer_init( 1024 );
825 #endif
826 
827  /* construct list of nonzeros: (index ^, label) */
828  nonzero.initialize( 1, nlabels, nulabels, 0, n );
829  nonzero.enableWriteAccess();
830  {
831  uint i;
832  sint* nzi;
833  long* nzl;
834  Ulong* nzul;
835  nzi = nonzero.vi_wr;
836  nzl = nonzero.vl_wr;
837  nzul = nonzero.vul_wr;
838  for( i = 0; i < n; ++i )
839  if( label[nlabels * i] != 0 )
840  {
841  nzi[0] = i;
842  for( j = 0; j < nlabels; j++ )
843  nzl[j] = label[nlabels * i + j];
844  for( j = 0; j < nulabels; j++ )
845  nzul[j] = ulabel[nulabels * i + j];
846  nzi++;
847  nzl += nlabels;
848  nzul += nulabels;
849  nonzero.inc_n();
850  }
851  }
852 
853  /* sort nonzeros by label: (index ^2, label ^1) */
854 #ifndef MOAB_HAVE_MPI
855  nonzero.sort( 1, &buf );
856 #else
857  nonzero.sort( 1, &crystal->all->buf );
858 #endif
859 
860  /* build list of unique labels w/ lowest associated index:
861  (index in nonzero ^, primary (lowest) index in label, count, label(s),
862  ulabel(s)) */
863  primary.initialize( 3, nlabels, nulabels, 0, nonzero.get_n() );
864  primary.enableWriteAccess();
865  {
866  uint i;
867  sint *nzi = nonzero.vi_wr, *pi = primary.vi_wr;
868  slong *nzl = nonzero.vl_wr, *pl = primary.vl_wr;
869  Ulong *nzul = nonzero.vul_wr, *pul = primary.vul_wr;
870  slong last = -1;
871  for( i = 0; i < nonzero.get_n(); ++i, nzi += 1, nzl += nlabels, nzul += nulabels )
872  {
873  if( nzl[0] == last )
874  {
875  ++pi[-1];
876  continue;
877  }
878  last = nzl[0];
879  pi[0] = i;
880  pi[1] = nzi[0];
881  for( j = 0; j < nlabels; j++ )
882  pl[j] = nzl[j];
883  for( j = 0; j < nulabels; j++ )
884  pul[j] = nzul[j];
885  pi[2] = 1;
886  pi += 3, pl += nlabels;
887  pul += nulabels;
888  primary.inc_n();
889  }
890  }
891 
892  /* calculate size of local condense map */
893  {
894  uint i, count = 1;
895  sint* pi = primary.vi_wr;
896  for( i = primary.get_n(); i; --i, pi += 3 )
897  if( pi[2] > 1 ) count += pi[2] + 1;
898  this->local_cm = (sint*)malloc( count * sizeof( sint ) );
899  }
900 
901  /* sort unique labels by primary index:
902  (nonzero index ^2, primary index ^1, count, label ^2) */
903 #ifndef MOAB_HAVE_MPI
904  primary.sort( 0, &buf );
905  buf.reset();
906  // buffer_free(&buf);
907 #else
908  primary.sort( 0, &crystal->all->buf );
909 #endif
910 
911  /* construct local condense map */
912  {
913  uint i, ln;
914  sint* pi = primary.vi_wr;
915  sint* cm = this->local_cm;
916  for( i = primary.get_n(); i > 0; --i, pi += 3 )
917  if( ( ln = pi[2] ) > 1 )
918  {
919  sint* nzi = nonzero.vi_wr + 1 * pi[0];
920  for( j = ln; j > 0; --j, nzi += 1 )
921  *cm++ = nzi[0];
922  *cm++ = -1;
923  }
924  *cm++ = -1;
925  }
926  nonzero.reset();
927 #ifndef MOAB_HAVE_MPI
928  primary.reset();
929 #else
930  /* assign work proc by label modulo np */
931  {
932  uint i;
933  sint* pi = primary.vi_wr;
934  slong* pl = primary.vl_wr;
935  for( i = primary.get_n(); i; --i, pi += 3, pl += nlabels )
936  pi[0] = pl[0] % crystal->_num;
937  }
938  rval = crystal->gs_transfer( 1, primary, 0 ); /* transfer to work procs */
939  if( rval != MB_SUCCESS ) return rval;
940  /* primary: (source proc, index on src, useless, label) */
941  /* sort by label */
942  primary.sort( 3, &crystal->all->buf );
943  /* add sentinel to primary list */
944  if( primary.get_n() == primary.get_max() )
945  primary.resize( ( primary.get_max() ? primary.get_max() + ( primary.get_max() + 1 ) / 2 + 1 : 2 ) );
946  primary.vl_wr[nlabels * primary.get_n()] = -1;
947  /* construct shared list: (proc1, proc2, index1, label) */
948 #ifdef MOAB_HAVE_MPI
949  shared.initialize( 3, nlabels, nulabels, 0, primary.get_n() );
950  shared.enableWriteAccess();
951 #endif
952  {
953  sint *pi1 = primary.vi_wr, *si = shared.vi_wr;
954  slong lbl, *pl1 = primary.vl_wr, *sl = shared.vl_wr;
955  Ulong *pul1 = primary.vul_wr, *sul = shared.vul_wr;
956  for( ; ( lbl = pl1[0] ) != -1; pi1 += 3, pl1 += nlabels, pul1 += nulabels )
957  {
958  sint* pi2 = pi1 + 3;
959  slong* pl2 = pl1 + nlabels;
960  Ulong* pul2 = pul1 + nulabels;
961  for( ; pl2[0] == lbl; pi2 += 3, pl2 += nlabels, pul2 += nulabels )
962  {
963  if( shared.get_n() + 2 > shared.get_max() )
964  shared.resize( ( shared.get_max() ? shared.get_max() + ( shared.get_max() + 1 ) / 2 + 1 : 2 ) ),
965  si = shared.vi_wr + shared.get_n() * 3;
966  sl = shared.vl_wr + shared.get_n() * nlabels;
967  sul = shared.vul_wr + shared.get_n() * nulabels;
968  si[0] = pi1[0];
969  si[1] = pi2[0];
970  si[2] = pi1[1];
971  for( j = 0; j < nlabels; j++ )
972  sl[j] = pl2[j];
973  for( j = 0; j < nulabels; j++ )
974  sul[j] = pul2[j];
975  si += 3;
976  sl += nlabels;
977  sul += nulabels;
978  shared.inc_n();
979  si[0] = pi2[0];
980  si[1] = pi1[0];
981  si[2] = pi2[1];
982  for( j = 0; j < nlabels; j++ )
983  sl[j] = pl1[j];
984  for( j = 0; j < nulabels; j++ )
985  sul[j] = pul1[j];
986  si += 3;
987  sl += nlabels;
988  sul += nulabels;
989  shared.inc_n();
990  }
991  }
992  }
993  primary.reset();
994  rval = crystal->gs_transfer( 1, shared, 0 ); /* segfaulting transfer to dest procs */
995  if( rval != MB_SUCCESS ) return rval;
996  /* shared list: (useless, proc2, index, label) */
997  /* sort by label */
998  shared.sort( 3, &crystal->all->buf );
999  /* sort by partner proc */
1000  shared.sort( 1, &crystal->all->buf );
1001  /* count partner procs */
1002  {
1003  uint i, count = 0;
1004  sint proc = -1, *si = shared.vi_wr;
1005  for( i = shared.get_n(); i; --i, si += 3 )
1006  if( si[1] != proc )
1007  {
1008  ++count;
1009  proc = si[1];
1010  }
1011  // this->nlinfo = new nonlocal_info();
1012  // this->nlinfo->initialize(count,shared.get_n(),
1013  // nlabels, nulabels, maxv);
1014  this->nlinfo = new nonlocal_info( count, shared.get_n(), nlabels, nulabels, maxv );
1015  }
1016  /* construct non-local info */
1017  {
1018  uint i;
1019  sint proc = -1, *si = shared.vi_wr;
1020  slong* sl = shared.vl_wr;
1021  Ulong* ul = shared.vul_wr;
1022  uint* target = this->nlinfo->_target;
1023  uint* nshared = this->nlinfo->_nshared;
1024  uint* sh_ind = this->nlinfo->_sh_ind;
1025  slong* slabels = this->nlinfo->_slabels;
1026  Ulong* ulabels = this->nlinfo->_ulabels;
1027  for( i = shared.get_n(); i; --i, si += 3 )
1028  {
1029  if( si[1] != proc )
1030  {
1031  proc = si[1];
1032  *target++ = proc;
1033  *nshared++ = 0;
1034  }
1035  ++nshared[-1];
1036  *sh_ind++ = si[2];
1037  // don't store 1st slabel
1038  sl++;
1039  for( j = 0; j < nlabels - 1; j++ )
1040  slabels[j] = sl[j];
1041  for( j = 0; j < nulabels; j++ )
1042  ulabels[j] = ul[j];
1043  slabels += nlabels - 1;
1044  ulabels += nulabels;
1045  sl += nlabels - 1;
1046  ul += nulabels;
1047  }
1048  }
1049  shared.reset();
1050 #endif
1051  return MB_SUCCESS;
1052 }

References moab::TupleList::enableWriteAccess(), ErrorCode, moab::TupleList::get_max(), moab::TupleList::get_n(), moab::TupleList::inc_n(), moab::TupleList::initialize(), local_cm, MB_SUCCESS, moab::TupleList::buffer::reset(), moab::TupleList::reset(), moab::TupleList::resize(), moab::TupleList::sort(), VALGRIND_CHECK_MEM_IS_DEFINED, moab::TupleList::vi_wr, moab::TupleList::vl_wr, and moab::TupleList::vul_wr.

Referenced by gs_data(), moab::ParallelComm::resolve_shared_ents(), and moab::ParallelComm::resolve_shared_sets().

◆ reset()

void moab::gs_data::reset ( )

Definition at line 1054 of file gs.cpp.

1055 {
1056  free( local_cm );
1057  local_cm = NULL;
1058 #ifdef MOAB_HAVE_MPI
1059  if( nlinfo != NULL )
1060  {
1061  nlinfo->nlinfo_free();
1062  delete this->nlinfo;
1063  MPI_Comm_free( &_comm );
1064  nlinfo = NULL;
1065  }
1066 #endif
1067 }

References local_cm.

Referenced by moab::ParallelComm::resolve_shared_ents(), moab::ParallelComm::resolve_shared_sets(), and ~gs_data().

Member Data Documentation

◆ local_cm

sint* moab::gs_data::local_cm

Definition at line 180 of file gs.hpp.

Referenced by gs_data_op(), gs_data_op_many(), gs_data_op_vec(), initialize(), and reset().


The documentation for this class was generated from the following files: