38 int IFACE_START, IFACE_END;
39 int GHOST_START, GHOST_END;
40 int SHAREDV_START, SHAREDV_END;
41 int RESOLVE_START, RESOLVE_END;
42 int ENTITIES_START, ENTITIES_END;
43 int RHANDLES_START, RHANDLES_END;
44 int OWNED_START, OWNED_END;
54 std::vector< ParallelComm::Buffer* >
msgs;
58 #ifdef DEBUG_PACKING_TIMES
61 if( __PACK_num == (unsigned int)n && __PACK_string == m ) \
65 if( __PACK_count > 1 ) std::cerr << " (" << __PACK_count << "x)"; \
69 std::cerr << std::endl << "PACK: " << n << m; \
74 if( __UNPACK_num == (unsigned int)n && __UNPACK_string == m ) \
78 if( __UNPACK_count > 1 ) std::cerr << "(" << __UNPACK_count << "x)"; \
80 __UNPACK_string = m; \
82 std::cerr << std::endl << "UNPACK: " << n << m; \
90 template <
typename T >
91 static inline void UNPACK(
unsigned char*& buff, T* val,
size_t count )
93 memcpy( val, buff, count *
sizeof( T ) );
94 buff += count *
sizeof( T );
97 template <
typename T >
98 static inline void PACK(
unsigned char*& buff,
const T* val,
size_t count )
100 memcpy( buff, val, count *
sizeof( T ) );
101 buff += count *
sizeof( T );
104 static inline void PACK_INTS(
unsigned char*& buff,
const int* int_val,
size_t num )
106 PACK( buff, int_val, num );
110 static inline void PACK_INT(
unsigned char*& buff,
int int_val )
115 static inline void PACK_DBLS(
unsigned char*& buff,
const double* dbl_val,
size_t num )
117 PACK( buff, dbl_val, num );
118 PC( num,
" doubles" );
127 PACK( buff, eh_val, num );
128 PC( num,
" handles" );
139 static inline void PACK_VOID(
unsigned char*& buff,
const void* val,
size_t num )
141 PACK( buff,
reinterpret_cast< const unsigned char*
>( val ), num );
145 static inline void PACK_BYTES(
unsigned char*& buff,
const void* val,
int num )
160 PC( rng.
psize(),
"-subranged range" );
163 static inline void UNPACK_INTS(
unsigned char*& buff,
int* int_val,
size_t num )
165 UNPACK( buff, int_val, num );
169 static inline void UNPACK_INT(
unsigned char*& buff,
int& int_val )
174 static inline void UNPACK_DBLS(
unsigned char*& buff,
double* dbl_val,
size_t num )
176 UNPACK( buff, dbl_val, num );
177 UPC( num,
" doubles" );
180 static inline void UNPACK_DBL(
unsigned char*& buff,
double& dbl_val )
187 UNPACK( buff, eh_val, num );
188 UPC( num,
" handles" );
199 static inline void UNPACK_VOID(
unsigned char*& buff,
void* val,
size_t num )
201 UNPACK( buff,
reinterpret_cast< unsigned char*
>( val ), num );
205 static inline void UNPACK_TYPE(
unsigned char*& buff, EntityType& type )
209 type =
static_cast< EntityType
>( int_type );
218 for(
int i = 0; i < num_subs; i++ )
220 UPC( num_subs,
"-subranged range" );
222 rng.
insert( eh[0], eh[1] );
245 #define PRINT_DEBUG_ISEND( A, B, C, D, E ) print_debug_isend( ( A ), ( B ), ( C ), ( D ), ( E ) )
246 #define PRINT_DEBUG_IRECV( A, B, C, D, E, F ) print_debug_irecv( ( A ), ( B ), ( C ), ( D ), ( E ), ( F ) )
247 #define PRINT_DEBUG_RECD( A ) print_debug_recd( ( A ) )
248 #define PRINT_DEBUG_WAITANY( A, B, C ) print_debug_waitany( ( A ), ( B ), ( C ) )
252 myDebug->
tprintf( 3,
"Isend, %d->%d, buffer ptr = %p, tag=%d, size=%d\n", from, to, (
void*)buff, tag, sz );
257 myDebug->
tprintf( 3,
"Irecv, %d<-%d, buffer ptr = %p, tag=%d, size=%d", to, from, (
void*)buff, tag, sz );
271 int success = MPI_Get_count( &status, MPI_UNSIGNED_CHAR, &this_count );
272 if( MPI_SUCCESS != success ) this_count = -1;
273 myDebug->
tprintf( 3,
"Received from %d, count = %d, tag = %d\n", status.MPI_SOURCE, this_count,
289 for(
unsigned int i = 0; i < reqs.size(); i++ )
311 #define PARALLEL_COMM_TAG_NAME "__PARALLEL_COMM"
314 : mbImpl( impl ), procConfig( cm ), sharedpTag( 0 ), sharedpsTag( 0 ), sharedhTag( 0 ), sharedhsTag( 0 ),
315 pstatusTag( 0 ), ifaceSetsTag( 0 ), partitionTag( 0 ), globalPartCount( -1 ), partitioningSet( 0 ),
324 : mbImpl( impl ), procConfig( cm ), sharedpTag( 0 ), sharedpsTag( 0 ), sharedhTag( 0 ), sharedhsTag( 0 ),
325 pstatusTag( 0 ), ifaceSetsTag( 0 ), partitionTag( 0 ), globalPartCount( -1 ), partitioningSet( 0 ),
349 int retval = MPI_Initialized( &flag );
350 if( MPI_SUCCESS != retval || !flag )
356 retval = MPI_Init( &argc, &argv );
357 assert( MPI_SUCCESS == retval );
379 assert( 0 != pc_tag );
394 pc_array[index] = pc;
408 std::vector< ParallelComm* >::iterator pc_it = std::find( pc_array.begin(), pc_array.end(), pc );
409 assert(
MB_SUCCESS == result && pc_it != pc_array.end() );
424 const bool largest_dim_only,
426 const bool owned_only )
430 std::vector< unsigned char > pstatus;
431 for(
int dim = 0;
dim <= dimension;
dim++ )
433 if(
dim == 0 || !largest_dim_only ||
dim == dimension )
459 const bool owned_only )
461 int local_num_elements[4];
463 for(
int dim = 0;
dim <= dimension;
dim++ )
474 MPI_Allgather( local_num_elements, 4, MPI_INT, &num_elements[0], 4, MPI_INT,
procConfig.
proc_comm() );
475 if( 0 != retval )
return MB_FAILURE;
480 num_elements[
dim] = local_num_elements[
dim];
483 int total_elems[4] = { start_id, start_id, start_id, start_id };
488 total_elems[
dim] += num_elements[4 * proc +
dim];
500 num_elements[i++] = total_elems[
dim]++;
517 std::vector< unsigned int >::iterator vit = std::find(
buffProcs.begin(),
buffProcs.end(), to_proc );
522 buffProcs.push_back( (
unsigned int)to_proc );
525 if( is_new ) *is_new =
true;
530 if( is_new ) *is_new =
false;
538 const bool adjacencies,
541 #ifndef MOAB_HAVE_MPI
562 if( MPI_SUCCESS != success )
564 MB_SET_ERR( MB_FAILURE,
"MPI_Bcast of buffer size failed" );
577 if( MPI_SUCCESS != success )
579 MB_SET_ERR( MB_FAILURE,
"MPI_Bcast of buffer failed" );
588 std::vector< std::vector< EntityHandle > > dum1a, dum1b;
589 std::vector< std::vector< int > > dum1p;
590 std::vector< EntityHandle > dum2, dum4;
591 std::vector< unsigned int > dum3;
593 result =
unpack_buffer( buff.
buff_ptr,
false, from_proc, -1, dum1a, dum1b, dum1p, dum2, dum2, dum3, dum4 );
MB_CHK_SET_ERR( result,
"Failed to unpack buffer in broadcast_entities" );
603 const bool adjacencies,
606 #ifndef MOAB_HAVE_MPI
610 int i, success, buff_size, prev_size;
612 int* sendCounts =
new int[nProcs];
613 int* displacements =
new int[nProcs];
614 sendCounts[0] =
sizeof( int );
615 displacements[0] = 0;
622 if( my_proc == (
unsigned int)from_proc )
624 for( i = 1; i < nProcs; i++ )
627 buff.
reset_ptr( prev_size +
sizeof(
int ) );
634 delete[] displacements;
635 MB_SET_ERR( result,
"Failed to pack buffer in scatter_entities" );
639 *( (
int*)( buff.
mem_ptr + prev_size ) ) = buff_size;
640 sendCounts[i] = buff_size;
646 if( MPI_SUCCESS != success )
649 delete[] displacements;
650 MB_SET_ERR( MB_FAILURE,
"MPI_Bcast of buffer size failed" );
653 for( i = 1; i < nProcs; i++ )
655 displacements[i] = displacements[i - 1] + sendCounts[i - 1];
659 rec_buff.
reserve( sendCounts[my_proc] );
662 success = MPI_Scatterv( buff.
mem_ptr, sendCounts, displacements, MPI_UNSIGNED_CHAR, rec_buff.
mem_ptr,
665 if( MPI_SUCCESS != success )
668 delete[] displacements;
669 MB_SET_ERR( MB_FAILURE,
"MPI_Scatterv of buffer failed" );
673 if( my_proc != (
unsigned int)from_proc )
675 std::vector< std::vector< EntityHandle > > dum1a, dum1b;
676 std::vector< std::vector< int > > dum1p;
677 std::vector< EntityHandle > dum2, dum4;
678 std::vector< unsigned int > dum3;
680 result =
unpack_buffer( rec_buff.
buff_ptr,
false, from_proc, -1, dum1a, dum1b, dum1p, dum2, dum2, dum3, dum4 );
684 delete[] displacements;
685 MB_SET_ERR( result,
"Failed to unpack buffer in scatter_entities" );
692 delete[] displacements;
702 const bool store_remote_handles,
708 std::vector< MPI_Request >& recv_remoteh_reqs,
711 #ifndef MOAB_HAVE_MPI
724 if( !tmp_range.
empty() )
726 orig_ents =
subtract( orig_ents, tmp_range );
737 &recv_remoteh_reqs[2 * ind], &incoming2 );
MB_CHK_SET_ERR( result,
"Failed to send buffer" );
744 std::vector< Range* >& send_ents,
747 const bool store_remote_handles )
767 unsigned int n_proc = send_procs.size();
768 for( i = 0; i < n_proc; i++ )
776 if( !tmp_range.
empty() )
778 *send_ents[i] =
subtract( *send_ents[i], tmp_range );
786 Range allsent, tmp_range;
789 for( i = 0; i < n_proc; i++ )
791 int n_ents = send_ents[i]->size();
795 allsent.
merge( *send_ents[i] );
804 for( i = 0; i < n_proc; i++ )
806 for(
Range::iterator rit = send_ents[i]->begin(); rit != send_ents[i]->end(); ++rit )
808 entprocs.
vi_wr[entprocs.
get_n()] = send_procs[i];
816 sort_buffer.buffer_init( npairs );
817 entprocs.
sort( 1, &sort_buffer );
822 (
unsigned long)allsent.
size() );
827 for( i = 0; i < n_proc; i++ )
829 if( send_ents[i]->
size() > 0 )
832 myDebug->
tprintf( 1,
"Sent ents compactness (size) = %f (%lu)\n", send_ents[i]->compactness(),
833 (
unsigned long)send_ents[i]->
size() );
849 &incoming2 );
MB_CHK_SET_ERR( result,
"Failed to Isend in ghost send" );
869 for(
int i = 0; i <
size; i++ )
874 std::vector< std::vector< int > >& msgsizes,
875 std::vector< std::vector< EntityHandle > >& senddata,
876 std::vector< std::vector< EntityHandle > >& recvdata )
903 std::vector< MPI_Request > recv_ent_reqs( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
907 std::vector< unsigned int >::iterator sit;
917 if( success != MPI_SUCCESS )
919 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in send_recv_entities" );
924 for( i = 0; i < (int)send_procs.size(); i++ )
930 int buff_size = msgsizes[i].size() *
sizeof( int ) + senddata[i].
size() *
sizeof(
EntityHandle );
934 std::vector< int > msg;
935 msg.insert( msg.end(), msgsizes[i].begin(), msgsizes[i].end() );
938 std::vector< EntityHandle >
entities;
951 recv_ent_reqs[3 * ind + 2], &ack_buff, incoming );
MB_CHK_SET_ERR(
error,
"Failed to Isend in send_recv_entities" );
962 int index_in_recv_requests;
965 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_ent_reqs[0], &index_in_recv_requests, &status );
966 if( MPI_SUCCESS != success )
968 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in send_recv_entities" );
972 ind = index_in_recv_requests / 3;
982 recv_ent_reqs[3 * ind + 1],
983 recv_ent_reqs[3 * ind + 2],
994 int from_proc = status.MPI_SOURCE;
995 int idx = std::find( send_procs.begin(), send_procs.end(), from_proc ) - send_procs.begin();
997 int msg = msgsizes[idx].size();
998 std::vector< int > recvmsg( msg );
999 int ndata = senddata[idx].size();
1000 std::vector< EntityHandle > dum_vec( ndata );
1005 recvdata[idx].insert( recvdata[idx].end(), dum_vec.begin(), dum_vec.end() );
1020 std::vector< int >& procs,
1021 std::vector< EntityHandle >& handles )
1026 int procmin = *std::min_element( procs.begin(), procs.end() );
1028 if( (
int)
rank() > procmin )
1039 if( (
int)procs.size() > 1 )
1041 procs.push_back(
rank() );
1042 handles.push_back( entity );
1044 int idx = std::find( procs.begin(), procs.end(), procmin ) - procs.begin();
1046 std::iter_swap( procs.begin(), procs.begin() + idx );
1047 std::iter_swap( handles.begin(), handles.begin() + idx );
1067 std::vector< EntityHandle > newents;
1076 const bool store_remote_handles,
1077 const bool is_iface,
1081 std::vector< std::vector< EntityHandle > >& L1hloc,
1082 std::vector< std::vector< EntityHandle > >& L1hrem,
1083 std::vector< std::vector< int > >& L1p,
1084 std::vector< EntityHandle >& L2hloc,
1085 std::vector< EntityHandle >& L2hrem,
1086 std::vector< unsigned int >& L2p,
1087 std::vector< MPI_Request >& recv_remoteh_reqs,
1090 #ifndef MOAB_HAVE_MPI
1100 if( success != MPI_SUCCESS )
1102 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in ghost exchange" );
1106 return recv_messages( from_proc, store_remote_handles, is_iface, final_ents, incoming1, incoming2, L1hloc, L1hrem,
1107 L1p, L2hloc, L2hrem, L2p, recv_remoteh_reqs );
1114 const bool store_remote_handles,
1115 const bool migrate )
1121 int success, ind, i;
1124 std::vector< std::vector< EntityHandle > > recd_ents(
buffProcs.size() );
1125 std::vector< std::vector< EntityHandle > > L1hloc(
buffProcs.size() ), L1hrem(
buffProcs.size() );
1126 std::vector< std::vector< int > > L1p(
buffProcs.size() );
1127 std::vector< EntityHandle > L2hloc, L2hrem;
1128 std::vector< unsigned int > L2p;
1129 std::vector< EntityHandle > new_ents;
1138 if( MPI_SUCCESS != success )
1140 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in owned entity exchange" );
1150 unsigned int base_ind = 2 * ( ind / 2 );
1167 ind / 2, L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents,
true );
1170 std::cout <<
"Failed to unpack entities. Buffer contents:" << std::endl;
1188 if( success != MPI_SUCCESS )
1190 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv for remote handles in ghost exchange" );
1211 MB_SET_ERR( MB_FAILURE,
"Requests length doesn't match proc count in entity exchange" );
1214 #ifdef MOAB_HAVE_MPE
1224 std::set< unsigned int >::iterator it = recv_procs.begin();
1225 std::set< unsigned int >::iterator eit = recv_procs.end();
1226 for( ; it != eit; ++it )
1251 if( MPI_SUCCESS != success )
1253 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in owned entity exchange" );
1261 unsigned int base_ind = 2 * ( ind / 2 );
1280 #ifdef MOAB_HAVE_MPE
1293 const bool store_remote_handles,
1294 const bool is_iface,
1298 std::vector< std::vector< EntityHandle > >& L1hloc,
1299 std::vector< std::vector< EntityHandle > >& L1hrem,
1300 std::vector< std::vector< int > >& L1p,
1301 std::vector< EntityHandle >& L2hloc,
1302 std::vector< EntityHandle >& L2hrem,
1303 std::vector< unsigned int >& L2p,
1304 std::vector< MPI_Request >& recv_remoteh_reqs )
1306 #ifndef MOAB_HAVE_MPI
1313 std::vector< EntityHandle > new_ents;
1319 success = MPI_Waitany( 2, &
recvReqs[2 * ind1], &ind2, &status );
1320 if( MPI_SUCCESS != success )
1322 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in recv_messages" );
1333 unsigned int base_ind = 2 * ( ind2 / 2 );
1339 ( !is_iface && store_remote_handles ?
localOwnedBuffs[ind2 / 2] : NULL ),
1347 L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents );
MB_CHK_SET_ERR( result,
"Failed to unpack buffer in recev_messages" );
1349 std::copy( new_ents.begin(), new_ents.end(),
range_inserter( final_ents ) );
1355 result =
pack_remote_handles( L1hloc[ind2 / 2], L1hrem[ind2 / 2], L1p[ind2 / 2], from_proc,
1360 recv_remoteh_reqs[ind2 + 1], (
int*)(
localOwnedBuffs[ind2 / 2]->mem_ptr ),
1362 incoming2 );
MB_CHK_SET_ERR( result,
"Failed to send remote handles" );
1372 std::vector< EntityHandle >& L2hloc,
1373 std::vector< EntityHandle >& L2hrem,
1374 std::vector< unsigned int >& L2p,
1375 std::vector< MPI_Request >& recv_remoteh_reqs )
1377 #ifndef MOAB_HAVE_MPI
1388 success = MPI_Waitany( 2, &recv_remoteh_reqs[2 * ind1], &ind2, &status );
1389 if( MPI_SUCCESS != success )
1391 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in recv_remote_handle_messages" );
1401 unsigned int base_ind = 2 * ( ind2 / 2 );
1421 const bool store_remote_handles,
1435 std::vector< Tag > all_tags;
1436 std::vector< Range > tag_ranges;
1441 result =
pack_entities( orig_ents, buff, store_remote_handles, to_proc,
false, entprocs, allsent );
MB_CHK_SET_ERR( result,
"Packing entities failed" );
1444 result =
pack_sets( orig_ents, buff, store_remote_handles, to_proc );
MB_CHK_SET_ERR( result,
"Packing sets (count) failed" );
1451 result =
pack_tags( orig_ents, all_tags, all_tags, tag_ranges, buff, store_remote_handles, to_proc );
MB_CHK_SET_ERR( result,
"Packing tags (count) failed" );
1464 const bool store_remote_handles,
1465 const int from_proc,
1467 std::vector< std::vector< EntityHandle > >& L1hloc,
1468 std::vector< std::vector< EntityHandle > >& L1hrem,
1469 std::vector< std::vector< int > >& L1p,
1470 std::vector< EntityHandle >& L2hloc,
1471 std::vector< EntityHandle >& L2hrem,
1472 std::vector< unsigned int >& L2p,
1473 std::vector< EntityHandle >& new_ents,
1474 const bool created_iface )
1476 unsigned char* tmp_buff = buff_ptr;
1478 result =
unpack_entities( buff_ptr, store_remote_handles, ind,
false, L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p,
1479 new_ents, created_iface );
MB_CHK_SET_ERR( result,
"Unpacking entities failed" );
1482 myDebug->
tprintf( 4,
"unpack_entities buffer space: %ld bytes.\n", (
long int)( buff_ptr - tmp_buff ) );
1483 tmp_buff = buff_ptr;
1485 result =
unpack_sets( buff_ptr, new_ents, store_remote_handles, from_proc );
MB_CHK_SET_ERR( result,
"Unpacking sets failed" );
1488 myDebug->
tprintf( 4,
"unpack_sets buffer space: %ld bytes.\n", (
long int)( buff_ptr - tmp_buff ) );
1489 tmp_buff = buff_ptr;
1491 result =
unpack_tags( buff_ptr, new_ents, store_remote_handles, from_proc );
MB_CHK_SET_ERR( result,
"Unpacking tags failed" );
1494 myDebug->
tprintf( 4,
"unpack_tags buffer space: %ld bytes.\n", (
long int)( buff_ptr - tmp_buff ) );
1506 std::vector< EntityHandle > dum_connect_vec;
1512 buff_size += 2 *
sizeof( int ) + 3 *
sizeof(
double ) * num_verts;
1513 if( store_remote_handles ) buff_size +=
sizeof(
EntityHandle ) * num_verts;
1524 buff_size += 3 *
sizeof( int );
1525 int num_ents =
entities.num_of_type( t );
1527 buff_size += ( num_connect + 1 ) *
sizeof(
EntityHandle ) * num_ents;
1531 buff_size +=
sizeof( int );
1539 int buff_size =
sizeof( int );
1545 for( ; rit !=
entities.end(); ++rit )
1547 unsigned int options;
1550 buff_size +=
sizeof( int );
1561 else if( options & MESHSET_ORDERED )
1568 buff_size +=
sizeof(
EntityHandle ) * num_ents +
sizeof(
int );
1572 int num_par, num_ch;
1576 buff_size += ( num_ch + num_par ) *
sizeof(
EntityHandle ) + 2 *
sizeof( int );
1584 const bool store_remote_handles,
1600 if( buff_size < 0 )
MB_SET_ERR( MB_FAILURE,
"Failed to estimate ents buffer size" );
1604 unsigned int num_ents;
1607 std::vector< EntityHandle > entities_vec(
entities.size() );
1612 if( store_remote_handles )
1624 std::vector< int > sharedp_vals(
entities.size() );
1626 std::vector< char > pstatus_vals(
entities.size() );
1632 std::set< unsigned int > dumprocs;
1639 assert( ind < entprocs->get_n() );
1641 while( ind < entprocs->get_n() && entprocs->
vul_rd[ind] == *rit )
1642 dumprocs.insert( entprocs->
vi_rd[ind++] );
1644 result =
build_sharedhps_list( *rit, pstatus_vals[i], sharedp_vals[i], dumprocs, num_ents, tmp_procs,
1645 tmp_handles );
MB_CHK_SET_ERR( result,
"Failed to build sharedhps" );
1657 unsigned int dp = 0;
1659 dumprocs.insert( tmp_procs[dp] );
1660 assert( dumprocs.size() == dp );
1668 num_ents = these_ents.
size();
1672 buff_size = 2 *
sizeof( int ) + 3 * num_ents *
sizeof(
double );
1679 std::vector< double > tmp_coords( 3 * num_ents );
1683 myDebug->
tprintf( 4,
"Packed %lu ents of type %s\n", (
unsigned long)these_ents.
size(),
1690 int last_nodes = -1;
1710 if( NULL == seq )
return MB_FAILURE;
1715 if( !these_ents.
empty() &&
1718 result =
pack_entity_seq( last_nodes, store_remote_handles, to_proc, these_ents, entities_vec, buff );
MB_CHK_SET_ERR( result,
"Failed to pack entities from a sequence" );
1731 last_type = eseq->
type();
1737 start_rit = end_rit;
1749 const unsigned char pstatus,
1755 const std::set< unsigned int >& procs,
1756 unsigned int& num_ents,
1761 unsigned char pstat;
1763 assert( pstat == pstatus );
1774 assert(
"If not owned, I should be shared too" && pstatus &
PSTATUS_SHARED && 1 == num_ents );
1776 tmp_handles[1] = entity;
1782 assert(
"shared and owned, should be only 1 sharing proc" && 1 == num_ents );
1783 tmp_procs[1] = tmp_procs[0];
1785 tmp_handles[1] = tmp_handles[0];
1786 tmp_handles[0] = entity;
1793 tmp_handles[0] = entity;
1798 int tmp_ps = num_ents;
1802 for( std::set< unsigned int >::iterator sit = procs.begin(); sit != procs.end(); ++sit )
1805 if( tmp_ps && std::find( tmp_procs, tmp_procs + tmp_ps, *sit ) != tmp_procs + tmp_ps )
1807 std::cerr <<
"Trouble with something already in shared list on proc " <<
procConfig.
proc_rank()
1808 <<
". Entity:" << std::endl;
1810 std::cerr <<
"pstatus = " << (int)pstatus <<
", sharedp = " << sharedp << std::endl;
1811 std::cerr <<
"tmp_ps = ";
1812 for(
int i = 0; i < tmp_ps; i++ )
1813 std::cerr << tmp_procs[i] <<
" ";
1814 std::cerr << std::endl;
1815 std::cerr <<
"procs = ";
1816 for( std::set< unsigned int >::iterator sit2 = procs.begin(); sit2 != procs.end(); ++sit2 )
1817 std::cerr << *sit2 <<
" ";
1821 tmp_procs[num_ents] = *sit;
1822 tmp_handles[num_ents] = 0;
1829 tmp_procs[num_ents] = -1;
1830 tmp_handles[num_ents] = 0;
1837 const bool store_remote_handles,
1840 std::vector< EntityHandle >& entities_vec,
1843 int tmp_space = 3 *
sizeof( int ) + nodes_per_entity * these_ents.
size() *
sizeof(
EntityHandle );
1857 std::vector< EntityHandle > connect;
1863 assert( (
int)connect.size() == nodes_per_entity );
1865 get_remote_handles( store_remote_handles, &connect[0], &connect[0], connect.size(), to_proc, entities_vec );
MB_CHK_SET_ERR( result,
"Failed in get_remote_handles" );
1869 myDebug->
tprintf( 3,
"Packed %lu ents of type %s\n", (
unsigned long)these_ents.
size(),
1880 const std::vector< EntityHandle >& new_ents )
1888 std::vector< EntityHandle > tmp_vector;
1890 if( to_vec == from_vec )
1892 tmp_vector.resize( num_ents );
1893 to_vec = &tmp_vector[0];
1896 if( !store_remote_handles )
1900 for(
int i = 0; i < num_ents; i++ )
1902 int ind = std::lower_bound( new_ents.begin(), new_ents.end(), from_vec[i] ) - new_ents.begin();
1903 assert( new_ents[ind] == from_vec[i] );
1905 assert( to_vec[i] != 0 && !err && -1 != ind );
1910 Tag shp_tag, shps_tag, shh_tag, shhs_tag, pstat_tag;
1914 std::vector< int > sharing_procs( num_ents );
1916 result =
mbImpl->
tag_get_data( shp_tag, from_vec, num_ents, &sharing_procs[0] );
MB_CHK_SET_ERR( result,
"Failed to get sharing proc tag in remote_handles" );
1917 for(
int j = 0; j < num_ents; j++ )
1919 if( to_vec[j] && sharing_procs[j] != to_proc ) to_vec[j] = 0;
1926 for( i = 0; i < num_ents; i++ )
1935 if( -1 == tmp_procs[j] )
1937 else if( tmp_procs[j] == to_proc )
1940 to_vec[i] = tmp_handles[j];
1941 assert( to_vec[i] );
1948 int j = std::lower_bound( new_ents.begin(), new_ents.end(), from_vec[i] ) - new_ents.begin();
1949 if( (
int)new_ents.size() == j )
1953 for(
int k = 0; k <= num_ents; k++ )
1954 std::cout << k <<
": " << from_vec[k] <<
" " << to_vec[k] << std::endl;
1955 MB_SET_ERR( MB_FAILURE,
"Failed to find new entity in send list" );
1961 MB_SET_ERR( MB_FAILURE,
"Failed to create handle in remote_handles" );
1969 if( to_vec_tmp == from_vec ) memcpy( from_vec, to_vec, num_ents *
sizeof(
EntityHandle ) );
1975 const Range& from_range,
1978 const std::vector< EntityHandle >& new_ents )
1985 if( !store_remote_handles )
1991 for( rit = from_range.
begin(), i = 0; rit != from_range.
end(); ++rit, i++ )
1993 int ind = std::lower_bound( new_ents.begin(), new_ents.end(), *rit ) - new_ents.begin();
1994 assert( new_ents[ind] == *rit );
1996 assert( to_vec[i] != 0 && !err && -1 != ind );
2001 Tag shp_tag, shps_tag, shh_tag, shhs_tag, pstat_tag;
2005 std::vector< int > sharing_procs( from_range.
size() );
2008 for(
unsigned int j = 0; j < from_range.
size(); j++ )
2010 if( to_vec[j] && sharing_procs[j] != to_proc ) to_vec[j] = 0;
2018 for( rit = from_range.
begin(), i = 0; rit != from_range.
end(); ++rit, i++ )
2027 if( tmp_procs[j] == to_proc )
2029 to_vec[i] = tmp_handles[j];
2036 int j = std::lower_bound( new_ents.begin(), new_ents.end(), *rit ) - new_ents.begin();
2037 if( (
int)new_ents.size() == j )
2039 MB_SET_ERR( MB_FAILURE,
"Failed to find new entity in send list" );
2045 MB_SET_ERR( MB_FAILURE,
"Failed to create handle in remote_handles" );
2056 const Range& from_range,
2059 const std::vector< EntityHandle >& new_ents )
2061 std::vector< EntityHandle > to_vector( from_range.
size() );
2064 std::copy( to_vector.begin(), to_vector.end(),
range_inserter( to_range ) );
2069 const bool store_remote_handles,
2071 const bool is_iface,
2072 std::vector< std::vector< EntityHandle > >& L1hloc,
2073 std::vector< std::vector< EntityHandle > >& L1hrem,
2074 std::vector< std::vector< int > >& L1p,
2075 std::vector< EntityHandle >& L2hloc,
2076 std::vector< EntityHandle >& L2hrem,
2077 std::vector< unsigned int >& L2p,
2078 std::vector< EntityHandle >& new_ents,
2079 const bool created_iface )
2116 unsigned char* buff_save = buff_ptr;
2119 if( store_remote_handles )
2123 buff_save = buff_ptr;
2126 for( i = 0; i < num_ents; i++ )
2131 std::cout <<
"Should be non-negative # proc/handles.";
2135 buff_ptr += j * (
sizeof( int ) +
sizeof(
EntityHandle ) );
2139 std::vector< EntityHandle > msg_ents;
2151 int num_ents2, verts_per_entity = 0;
2155 if(
MBVERTEX != this_type && num_ents2 )
2162 for(
int e = 0; e < num_ents2; e++ )
2174 if( store_remote_handles )
2180 std::cout <<
"Shouldn't ever be fewer than 1 procs here." << std::endl;
2195 UNPACK_EH( buff_ptr, connect, verts_per_entity );
2205 if( store_remote_handles )
2207 result =
find_existing_entity( is_iface, ps[0], hs[0], num_ps, connect, verts_per_entity, this_type,
2208 L2hloc, L2hrem, L2p, new_h );
MB_CHK_SET_ERR( result,
"Failed to get existing entity" );
2214 bool created_here =
false;
2215 if( !new_h && !is_iface )
2234 created_here =
true;
2246 msg_ents.push_back( new_h );
2249 if( created_here ) new_ents.push_back( new_h );
2251 if( new_h && store_remote_handles )
2253 unsigned char new_pstat = 0x0;
2258 int idx = std::min_element( &ps[0], &ps[0] + num_ps ) - &ps[0];
2261 std::swap( ps[0], ps[idx] );
2262 std::swap( hs[0], hs[idx] );
2268 else if( created_here )
2280 if( store_remote_handles && !is_iface && num_ps > 2 )
2282 L2hrem.push_back( hs[0] );
2283 L2hloc.push_back( new_h );
2284 L2p.push_back( ps[0] );
2290 for( j = 0; j < num_ps; j++ )
2294 if( idx == (
int)L1hloc.size() )
2296 L1hloc.resize( idx + 1 );
2297 L1hrem.resize( idx + 1 );
2298 L1p.resize( idx + 1 );
2302 std::vector< EntityHandle >::iterator vit =
2303 std::find( L1hloc[idx].begin(), L1hloc[idx].end(), new_h );
2304 if( vit != L1hloc[idx].end() )
2308 if( L1p[idx][vit - L1hloc[idx].begin()] != -1 && hs[j] )
2310 L1hrem[idx][vit - L1hloc[idx].begin()] = hs[j];
2311 L1p[idx][vit - L1hloc[idx].begin()] = -1;
2320 assert( -1 != ps[0] && num_ps > 2 );
2321 L1p[idx].push_back( ps[0] );
2322 L1hrem[idx].push_back( hs[0] );
2327 "either this remote handle isn't in the remote list, or "
2328 "it's for another proc" &&
2329 ( std::find( L1hrem[idx].begin(), L1hrem[idx].end(), hs[j] ) == L1hrem[idx].end() ||
2330 L1p[idx][std::find( L1hrem[idx].begin(), L1hrem[idx].end(), hs[j] ) -
2331 L1hrem[idx].begin()] != -1 ) );
2332 L1p[idx].push_back( -1 );
2333 L1hrem[idx].push_back( hs[j] );
2335 L1hloc[idx].push_back( new_h );
2340 assert(
"Shouldn't be here for non-shared entities" && -1 != num_ps );
2341 std::fill( &ps[0], &ps[num_ps], -1 );
2342 std::fill( &hs[0], &hs[num_ps], 0 );
2352 std::sort( new_ents.begin(), new_ents.end() );
2361 std::cerr <<
" sent";
2363 std::cerr <<
" received";
2364 std::cerr <<
" message type " << mesg_tag <<
" to/from proc " << from_proc <<
"; contents:" << std::endl;
2366 int msg_length, num_ents;
2367 unsigned char* orig_ptr = buff_ptr;
2369 std::cerr << msg_length <<
" bytes..." << std::endl;
2375 std::vector< int > ps;
2376 std::vector< EntityHandle > hs;
2379 std::cerr << num_ents <<
" entities..." << std::endl;
2382 for( i = 0; i < num_ents; i++ )
2385 if( 0 > j )
return MB_FAILURE;
2388 std::cerr <<
"Entity " << i <<
", # procs = " << j << std::endl;
2391 std::cerr <<
" Procs: ";
2392 for( k = 0; k < j; k++ )
2393 std::cerr << ps[k] <<
" ";
2394 std::cerr << std::endl;
2395 std::cerr <<
" Handles: ";
2396 for( k = 0; k < j; k++ )
2397 std::cerr << hs[k] <<
" ";
2398 std::cerr << std::endl;
2400 if( buff_ptr - orig_ptr > msg_length )
2402 std::cerr <<
"End of buffer..." << std::endl;
2418 int num_ents2, verts_per_entity = 0;
2422 if(
MBVERTEX != this_type && num_ents2 )
2427 std::cerr <<
"Type: " <<
CN::EntityTypeName( this_type ) <<
"; num_ents = " << num_ents2;
2428 if(
MBVERTEX != this_type ) std::cerr <<
"; verts_per_ent = " << verts_per_entity;
2429 std::cerr << std::endl;
2430 if( num_ents2 < 0 || num_ents2 > msg_length )
2432 std::cerr <<
"Wrong number of entities, returning." << std::endl;
2436 for(
int e = 0; e < num_ents2; e++ )
2443 std::cerr <<
"xyz = " << coords[0] <<
", " << coords[1] <<
", " << coords[2] << std::endl;
2449 UNPACK_EH( buff_ptr, connect, verts_per_entity );
2452 std::cerr <<
"Connectivity: ";
2453 for( k = 0; k < verts_per_entity; k++ )
2454 std::cerr << connect[k] <<
" ";
2455 std::cerr << std::endl;
2458 if( buff_ptr - orig_ptr > msg_length )
2460 std::cerr <<
"End of buffer..." << std::endl;
2470 std::cerr << num_ents <<
" entities..." << std::endl;
2471 if( 0 > num_ents || num_ents > msg_length )
2473 std::cerr <<
"Wrong number of entities, returning." << std::endl;
2476 std::vector< EntityHandle > L1hloc( num_ents ), L1hrem( num_ents );
2477 std::vector< int > L1p( num_ents );
2479 UNPACK_EH( buff_ptr, &L1hrem[0], num_ents );
2480 UNPACK_EH( buff_ptr, &L1hloc[0], num_ents );
2481 std::cerr << num_ents <<
" Entity pairs; hremote/hlocal/proc: " << std::endl;
2482 for(
int i = 0; i < num_ents; i++ )
2489 if( buff_ptr - orig_ptr > msg_length )
2491 std::cerr <<
"End of buffer..." << std::endl;
2498 int num_tags, dum1, data_type, tag_size;
2500 std::cerr <<
"Number of tags = " << num_tags << std::endl;
2501 for(
int i = 0; i < num_tags; i++ )
2503 std::cerr <<
"Tag " << i <<
":" << std::endl;
2507 std::cerr <<
"Tag size, type, data type = " << tag_size <<
", " << dum1 <<
", " << data_type << std::endl;
2509 std::cerr <<
"Default value size = " << dum1 << std::endl;
2512 std::string name( (
char*)buff_ptr, dum1 );
2513 std::cerr <<
"Tag name = " << name.c_str() << std::endl;
2516 std::cerr <<
"Number of ents = " << num_ents << std::endl;
2517 std::vector< EntityHandle > tmp_buff( num_ents );
2518 UNPACK_EH( buff_ptr, &tmp_buff[0], num_ents );
2520 for(
int j = 0; j < num_ents; j++ )
2528 std::cerr <<
"(variable, length = " << dum1 <<
")" << std::endl;
2534 std::cerr << dum_dbl << std::endl;
2540 std::cerr << dum_int << std::endl;
2544 std::cerr <<
"(opaque)" << std::endl;
2545 buff_ptr += tag_size;
2551 std::cerr << dum_eh << std::endl;
2555 std::cerr <<
"(bit)" << std::endl;
2556 buff_ptr += tag_size;
2579 shared_ents.
print(
"Shared entities:\n" );
2583 unsigned char pstat;
2586 unsigned int num_ps;
2589 for(
int i = 0; i < num_ents; i++ )
2594 std::cout <<
" coords: " << coords[0] <<
" " << coords[1] <<
" " << coords[2] <<
"\n";
2598 std::cout <<
"Pstatus: ";
2600 std::cout <<
"local " << std::endl;
2608 std::cout << std::endl;
2609 for(
unsigned int j = 0; j < num_ps; j++ )
2611 std::cout <<
" proc " << tmp_procs[j] <<
" id (handle) " <<
mbImpl->
id_from_handle( tmp_handles[j] )
2612 <<
"(" << tmp_handles[j] <<
")" << std::endl;
2615 std::cout << std::endl;
2630 Range& remote_range,
2632 const unsigned char add_pstat )
2638 for( rit = local_range.
begin(), rit2 = remote_range.
begin(); rit != local_range.
end(); ++rit, ++rit2 )
2650 const unsigned char add_pstat
2665 unsigned char new_pstat;
2671 int num_exist = new_numps;
2674 new_pstat |= add_pstat;
2698 std::set< unsigned int > dumprocs;
2699 unsigned int dp = 0;
2700 for( ; (int)dp < num_ps && -1 != ps[dp]; dp++ )
2701 dumprocs.insert( ps[dp] );
2702 assert( dp == dumprocs.size() );
2710 new_hs[1] = new_hs[0];
2711 new_ps[1] = new_ps[0];
2719 for(
int i = 0; i < num_ps; i++ )
2721 idx = std::find( &new_ps[0], &new_ps[0] + new_numps, ps[i] ) - &new_ps[0];
2722 if( idx < new_numps )
2724 if( !new_hs[idx] && hs[i] )
2726 new_hs[idx] = hs[i];
2728 assert( !hs[i] || new_hs[idx] == hs[i] );
2734 MB_SET_ERR( MB_FAILURE,
"Exceeded MAX_SHARING_PROCS for "
2738 new_ps[new_numps] = ps[i];
2739 new_hs[new_numps] = hs[i];
2745 idx = std::find( &new_ps[0], &new_ps[0] + new_numps,
rank() ) - &new_ps[0];
2746 if( idx == new_numps )
2748 new_ps[new_numps] =
rank();
2749 new_hs[new_numps] = new_h;
2752 else if( !new_hs[idx] && new_numps > 2 )
2753 new_hs[idx] = new_h;
2770 result =
set_sharing_data( new_h, new_pstat, num_exist, new_numps, &new_ps[0], &new_hs[0] );
MB_CHK_SET_ERR( result,
"Failed to set sharing data in update_remote_data" );
2781 const unsigned char add_pstat )
2785 unsigned char pstat;
2788 unsigned int num_exist;
2794 std::set< unsigned int > dumprocs;
2795 unsigned int dp = 0;
2796 for( ; (int)dp < num_ps && -1 != ps[dp]; dp++ )
2797 dumprocs.insert( ps[dp] );
2798 assert( dp == dumprocs.size() );
2803 bool changed =
false;
2808 memcpy( tag_ps, ps, num_ps *
sizeof(
int ) );
2812 assert(
"I shouldn't be the only proc there." && ( 1 != num_exist || ps[0] != (
int)
procConfig.
proc_rank() ) );
2817 for(
int i = 0; i < num_ps; i++ )
2819 idx = std::find( tag_ps, tag_ps + num_exist, ps[i] ) - tag_ps;
2820 if( idx == (
int)num_exist )
2839 tag_ps[1] = tag_ps[0];
2840 tag_hs[1] = tag_hs[0];
2848 tag_ps[num_exist] = ps[i];
2849 tag_hs[num_exist] = hs[i];
2853 else if( 0 == tag_hs[idx] )
2855 tag_hs[idx] = hs[i];
2858 else if( 0 != hs[i] )
2860 assert( hs[i] == tag_hs[idx] );
2868 idx = std::min_element( tag_ps, tag_ps + num_exist ) - tag_ps;
2871 int tag_proc = tag_ps[idx];
2872 tag_ps[idx] = tag_ps[0];
2873 tag_ps[0] = tag_proc;
2875 tag_hs[idx] = tag_hs[0];
2884 assert(
"interface entities should have > 1 proc" && ( !( add_pstat &
PSTATUS_INTERFACE ) || num_exist > 1 ) );
2885 assert(
"ghost entities should have > 1 proc" && ( !( add_pstat &
PSTATUS_GHOST ) || num_exist > 1 ) );
2892 assert( idx < (
int)num_exist );
2893 if( !tag_hs[idx] ) tag_hs[idx] = new_h;
2904 else if( num_exist > 0 )
2931 std::set< unsigned int > dumprocs;
2932 unsigned int dp = 0;
2933 for( ; dp < num_exist && -1 != tag_ps[dp]; dp++ )
2934 dumprocs.insert( tag_ps[dp] );
2935 assert( dp == dumprocs.size() );
2939 else if( num_exist == 2 || num_exist == 1 )
2944 tag_ps[0] = tag_ps[1];
2945 tag_hs[0] = tag_hs[1];
2947 assert( tag_ps[0] != -1 && tag_hs[0] != 0 );
2966 unsigned char pstat;
2967 std::set< int > tmp_procs;
2982 std::copy( sp2, sp2 + num_ps, std::inserter( procs, procs.begin() ) );
2986 std::sort( sp2, sp2 + num_ps );
2989 std::set_union( procs.begin(), procs.end(), sp2, sp2 + num_ps,
2990 std::inserter( tmp_procs, tmp_procs.end() ) );
2992 std::set_intersection( procs.begin(), procs.end(), sp2, sp2 + num_ps,
2993 std::inserter( tmp_procs, tmp_procs.end() ) );
2996 assert(
"Unknown operation." &&
false );
2999 procs.swap( tmp_procs );
3010 unsigned char& pstat,
3011 unsigned int& num_ps )
3052 const int num_connect,
3053 const EntityType this_type,
3054 std::vector< EntityHandle >& L2hloc,
3055 std::vector< EntityHandle >& L2hrem,
3056 std::vector< unsigned int >& L2p,
3060 if( !is_iface && num_ps > 2 )
3062 for(
unsigned int i = 0; i < L2hrem.size(); i++ )
3064 if( L2hrem[i] == owner_h && owner_p == (
int)L2p[i] )
3077 if( !tmp_range.
empty() )
3080 new_h = *tmp_range.
begin();
3091 Range& local_handles,
3092 const std::vector< EntityHandle >& new_ents )
3094 std::vector< EntityHandle > rh_vec;
3095 rh_vec.reserve( remote_handles.
size() );
3096 std::copy( remote_handles.
begin(), remote_handles.
end(), std::back_inserter( rh_vec ) );
3098 std::copy( rh_vec.begin(), rh_vec.end(),
range_inserter( local_handles ) );
3104 std::vector< EntityHandle > tmp_ents;
3105 std::copy( new_ents.
begin(), new_ents.
end(), std::back_inserter( tmp_ents ) );
3111 const std::vector< EntityHandle >& new_ents )
3113 for(
int i = 0; i < num_ents; i++ )
3141 int tmp_num = ( *key_it ).second - ( *key_it ).first + 1;
3142 handle_map.
insert( ( *key_it ).first, val_start, tmp_num );
3143 val_start += tmp_num;
3169 if( buff_size < 0 )
MB_SET_ERR( MB_FAILURE,
"Failed to estimate sets buffer size" );
3176 std::vector< unsigned int > options( all_sets.
size() );
3178 std::vector< EntityHandle > members;
3180 for( rit = all_sets.
begin(), i = 0; rit != all_sets.
end(); ++rit, i++ )
3188 if( !all_sets.
empty() )
3191 int n_sets = all_sets.
size();
3192 bool b_pack =
false;
3193 std::vector< int > id_data( n_sets );
3201 for( i = 0; i < n_sets; i++ )
3203 if( id_data[i] != 0 )
3213 buff->
check_space( ( n_sets + 1 ) *
sizeof(
int ) );
3225 std::vector< EntityHandle > entities_vec(
entities.size() );
3227 for( rit = all_sets.
begin(), i = 0; rit != all_sets.
end(); ++rit, i++ )
3232 get_remote_handles( store_remote_handles, &members[0], &members[0], members.size(), to_proc, entities_vec );
MB_CHK_SET_ERR( result,
"Failed in get_remote_handles" );
3239 if( !store_remote_handles )
3242 unsigned int tot_pch = 0;
3245 for( rit = all_sets.
begin(), i = 0; rit != all_sets.
end(); ++rit, i++ )
3258 members.reserve( tot_pch );
3259 std::vector< EntityHandle > tmp_pch;
3260 for( rit = all_sets.
begin(), i = 0; rit != all_sets.
end(); ++rit, i++ )
3263 std::copy( tmp_pch.begin(), tmp_pch.end(), std::back_inserter( members ) );
3266 std::copy( tmp_pch.begin(), tmp_pch.end(), std::back_inserter( members ) );
3269 assert( members.size() == tot_pch );
3270 if( !members.empty() )
3272 result =
get_remote_handles( store_remote_handles, &members[0], &members[0], members.size(), to_proc,
3273 entities_vec );
MB_CHK_SET_ERR( result,
"Failed to get remote handles for set parent/child sets" );
3276 for(
unsigned int __j = 0; __j < members.size(); __j++ )
3288 for( rit = all_sets.
begin(); rit != all_sets.
end(); ++rit )
3296 if( store_remote_handles && !all_sets.
empty() )
3311 std::vector< EntityHandle >&
entities,
3312 const bool store_remote_handles,
3313 const int from_proc )
3328 std::vector< EntityHandle > members;
3330 std::vector< unsigned int > options_vec( num_sets );
3332 if( num_sets )
UNPACK_VOID( buff_ptr, &options_vec[0], num_sets *
sizeof(
unsigned int ) );
3337 if( n_uid > 0 && n_uid != num_sets )
3339 std::cerr <<
"The number of Parallel geometry unique ids should be same." << std::endl;
3344 std::vector< int > uids( n_uid );
3352 for( i = 0; i < n_uid; i++ )
3356 void* tag_vals[] = { &uids[i] };
3361 if( !temp_sets.
empty() )
3363 set_handle = *temp_sets.
begin();
3370 new_sets.
insert( set_handle );
3376 for( i = 0; i < num_sets; i++ )
3382 assert( set_handle > *new_sets.
rbegin() );
3383 new_sets.
insert( set_handle );
3387 std::copy( new_sets.
begin(), new_sets.
end(), std::back_inserter(
entities ) );
3391 for( rit = new_sets.
begin(), i = 0; rit != new_sets.
end(); ++rit, i++ )
3395 members.resize( num_ents );
3396 if( num_ents )
UNPACK_EH( buff_ptr, &members[0], num_ents );
3401 std::vector< int > num_pch( 2 * new_sets.
size() );
3402 std::vector< int >::iterator vit;
3404 for( vit = num_pch.begin(); vit != num_pch.end(); ++vit )
3410 members.resize( tot_pch );
3411 UNPACK_EH( buff_ptr, &members[0], tot_pch );
3416 for( rit = new_sets.
begin(); rit != new_sets.
end(); ++rit )
3419 int num_par = num_pch[num++], num_child = num_pch[num++];
3420 if( num_par + num_child )
3422 for( i = 0; i < num_par; i++ )
3424 assert( 0 != mem_ptr[i] );
3428 for( i = 0; i < num_child; i++ )
3430 assert( 0 != mem_ptr[i] );
3433 mem_ptr += num_child;
3439 if( store_remote_handles && !new_sets.
empty() )
3471 const std::vector< Tag >& src_tags,
3472 const std::vector< Tag >& dst_tags,
3473 const std::vector< Range >& tag_ranges,
3475 const bool store_remote_handles,
3479 std::vector< Tag >::const_iterator tag_it, dst_it;
3480 std::vector< Range >::const_iterator rit;
3483 for( tag_it = src_tags.begin(), rit = tag_ranges.begin(); tag_it != src_tags.end(); ++tag_it, ++rit )
3490 count +=
sizeof( int );
3496 std::vector< EntityHandle > entities_vec(
entities.size() );
3499 for( tag_it = src_tags.begin(), dst_it = dst_tags.begin(), rit = tag_ranges.begin(); tag_it != src_tags.end();
3500 ++tag_it, ++dst_it, ++rit )
3502 result =
pack_tag( *tag_it, *dst_it, *rit, entities_vec, buff, store_remote_handles, to_proc );
3518 std::vector< int > var_len_sizes;
3519 std::vector< const void* > var_len_values;
3522 count +=
sizeof( int );
3526 count += 3 *
sizeof( int );
3529 count +=
sizeof( int );
3537 const int num_ent = tagged_entities.
size();
3539 count += num_ent *
sizeof( int );
3541 var_len_sizes.resize( num_ent );
3542 var_len_values.resize( num_ent );
3545 count += std::accumulate( var_len_sizes.begin(), var_len_sizes.end(), 0 );
3558 const Range& tagged_entities,
3559 const std::vector< EntityHandle >& whole_vec,
3561 const bool store_remote_handles,
3565 std::vector< int > var_len_sizes;
3566 std::vector< const void* > var_len_values;
3568 if( src_tag != dst_tag )
3609 std::vector< EntityHandle > dum_tagged_entities( tagged_entities.
size() );
3610 result =
get_remote_handles( store_remote_handles, tagged_entities, &dum_tagged_entities[0], to_proc, whole_vec );
3615 std::cerr <<
"Failed to get remote handles for tagged entities:" << std::endl;
3616 tagged_entities.
print(
" " );
3618 MB_SET_ERR( result,
"Failed to get remote handles for tagged entities" );
3621 PACK_EH( buff->
buff_ptr, &dum_tagged_entities[0], dum_tagged_entities.size() );
3623 const size_t num_ent = tagged_entities.
size();
3626 var_len_sizes.resize( num_ent, 0 );
3627 var_len_values.resize( num_ent, 0 );
3628 result =
mbImpl->
tag_get_by_ptr( src_tag, tagged_entities, &var_len_values[0], &var_len_sizes[0] );
MB_CHK_SET_ERR( result,
"Failed to get variable-length tag data in pack_tags" );
3631 for(
unsigned int i = 0; i < num_ent; i++ )
3644 PC( num_ent * src_tag->
get_size(),
" void" );
3651 std::vector< Tag >& all_tags,
3652 std::vector< Range >& tag_ranges )
3654 std::vector< Tag > tmp_tags;
3657 std::vector< Tag >::iterator tag_it;
3658 for( tag_it = tmp_tags.begin(); tag_it != tmp_tags.end(); ++tag_it )
3660 std::string tag_name;
3662 if( tag_name.c_str()[0] ==
'_' && tag_name.c_str()[1] ==
'_' )
continue;
3665 result = ( *tag_it )->get_tagged_entities(
sequenceManager, tmp_range );
MB_CHK_SET_ERR( result,
"Failed to get entities for tag in pack_tags" );
3666 tmp_range =
intersect( tmp_range, whole_range );
3668 if( tmp_range.
empty() )
continue;
3671 all_tags.push_back( *tag_it );
3672 tag_ranges.push_back(
Range() );
3673 tag_ranges.back().swap( tmp_range );
3680 std::vector< EntityHandle >&
entities,
3683 const MPI_Op*
const mpi_op )
3694 std::vector< const void* > var_len_vals;
3695 std::vector< unsigned char > dum_vals;
3696 std::vector< EntityHandle > dum_ehvals;
3698 for(
int i = 0; i < num_tags; i++ )
3704 int tag_size, tag_data_type, tag_type;
3712 void* def_val_ptr = NULL;
3715 def_val_ptr = buff_ptr;
3716 buff_ptr += def_val_size;
3717 UPC( tag_size,
" void" );
3723 std::string tag_name(
reinterpret_cast< char*
>( buff_ptr ), name_len );
3724 buff_ptr += name_len;
3725 UPC( 64,
" chars" );
3741 std::vector< EntityHandle > dum_ents( num_ents );
3742 UNPACK_EH( buff_ptr, &dum_ents[0], num_ents );
3751 dum_ehvals.resize( num_ents );
3752 UNPACK_EH( buff_ptr, &dum_ehvals[0], num_ents );
3760 if( !dum_ents.empty() )
3767 std::vector< int > var_lengths( num_ents );
3768 UNPACK_INTS( buff_ptr, &var_lengths[0], num_ents );
3769 UPC(
sizeof(
int ) * num_ents,
" void" );
3772 var_len_vals.resize( num_ents );
3773 for( std::vector< EntityHandle >::size_type j = 0; j < (std::vector< EntityHandle >::size_type)num_ents;
3776 var_len_vals[j] = buff_ptr;
3777 buff_ptr += var_lengths[j] * type_size;
3778 UPC( var_lengths[j],
" void" );
3781 mbImpl->
tag_set_by_ptr( tag_handle, &dum_ents[0], num_ents, &var_len_vals[0], &var_lengths[0] );
MB_CHK_SET_ERR( result,
"Failed to set tag data when unpacking variable-length tag" );
3786 dum_vals.resize( tag_size * num_ents );
3791 result =
mbImpl->
tag_get_data( tag_handle, &dum_ents[0], num_ents, &dum_vals[0] );
MB_CHK_SET_ERR( result,
"Failed to get existing value of dst tag on entities" );
3792 result =
reduce_void( tag_data_type, *mpi_op, tag_length * num_ents, &dum_vals[0], buff_ptr );
MB_CHK_SET_ERR( result,
"Failed to perform mpi op on dst tags" );
3794 result =
mbImpl->
tag_set_data( tag_handle, &dum_ents[0], num_ents, buff_ptr );
MB_CHK_SET_ERR( result,
"Failed to set range-based tag data when unpacking tag" );
3795 buff_ptr += num_ents * tag_size;
3796 UPC( num_ents * tag_size,
" void" );
3806 template <
class T >
3807 T
LAND(
const T& arg1,
const T& arg2 )
3809 return arg1 && arg2;
3811 template <
class T >
3812 T
LOR(
const T& arg1,
const T& arg2 )
3814 return arg1 || arg2;
3816 template <
class T >
3817 T
LXOR(
const T& arg1,
const T& arg2 )
3819 return ( ( arg1 && !arg2 ) || ( !arg1 && arg2 ) );
3821 template <
class T >
3822 T
MAX(
const T& arg1,
const T& arg2 )
3824 return ( arg1 > arg2 ? arg1 : arg2 );
3826 template <
class T >
3827 T
MIN(
const T& arg1,
const T& arg2 )
3829 return ( arg1 < arg2 ? arg1 : arg2 );
3831 template <
class T >
3832 T
ADD(
const T& arg1,
const T& arg2 )
3836 template <
class T >
3837 T
MULT(
const T& arg1,
const T& arg2 )
3842 template <
class T >
3845 T* old_tmp =
reinterpret_cast< T*
>( old_vals );
3849 std::vector< T > new_values;
3850 new_values.resize( num_ents );
3851 memcpy( &new_values[0], new_vals, num_ents *
sizeof( T ) );
3852 T* new_tmp = &new_values[0];
3854 if( mpi_op == MPI_SUM )
3855 std::transform( old_tmp, old_tmp + num_ents, new_tmp, new_tmp, ADD< T > );
3856 else if( mpi_op == MPI_PROD )
3857 std::transform( old_tmp, old_tmp + num_ents, new_tmp, new_tmp, MULT< T > );
3858 else if( mpi_op == MPI_MAX )
3859 std::transform( old_tmp, old_tmp + num_ents, new_tmp, new_tmp, MAX< T > );
3860 else if( mpi_op == MPI_MIN )
3861 std::transform( old_tmp, old_tmp + num_ents, new_tmp, new_tmp, MIN< T > );
3862 else if( mpi_op == MPI_LAND )
3863 std::transform( old_tmp, old_tmp + num_ents, new_tmp, new_tmp, LAND< T > );
3864 else if( mpi_op == MPI_LOR )
3865 std::transform( old_tmp, old_tmp + num_ents, new_tmp, new_tmp, LOR< T > );
3866 else if( mpi_op == MPI_LXOR )
3867 std::transform( old_tmp, old_tmp + num_ents, new_tmp, new_tmp, LXOR< T > );
3868 else if( mpi_op == MPI_BAND || mpi_op == MPI_BOR || mpi_op == MPI_BXOR )
3870 std::cerr <<
"Bitwise operations not allowed in tag reductions." << std::endl;
3873 else if( mpi_op != MPI_OP_NULL )
3875 std::cerr <<
"Unknown MPI operation type." << std::endl;
3880 memcpy( new_vals, new_tmp, num_ents *
sizeof( T ) );
3881 std::vector< T >().swap( new_values );
3887 const MPI_Op mpi_op,
3893 switch( tag_data_type )
3896 result = reduce< int >( mpi_op, num_ents, old_vals, new_vals );
3899 result = reduce< double >( mpi_op, num_ents, old_vals, new_vals );
3902 result = reduce< unsigned char >( mpi_op, num_ents, old_vals, new_vals );
3938 proc_ents.
merge( tmp_ents );
3948 if( -1 == resolve_dim )
3954 if( resolve_dim > shared_dim &&
3959 proc_ents.
erase( lower, upper );
3974 #ifdef MOAB_HAVE_MPE
3985 if( resolve_dim < shared_dim )
3987 MB_SET_ERR( MB_FAILURE,
"MOAB does not support vertex-based partitions, only element-based ones" );
3990 if( -1 == shared_dim )
3992 if( !proc_ents.
empty() )
3994 else if( resolve_dim == 3 )
3997 int max_global_resolve_dim = -1;
3998 int err = MPI_Allreduce( &resolve_dim, &max_global_resolve_dim, 1, MPI_INT, MPI_MAX,
proc_config().proc_comm() );
3999 if( MPI_SUCCESS != err )
4001 MB_SET_ERR( MB_FAILURE,
"Unable to guess global resolve_dim" );
4003 if( shared_dim < 0 || resolve_dim < 0 )
4006 resolve_dim = max_global_resolve_dim;
4007 shared_dim = resolve_dim - 1;
4010 if( resolve_dim < 0 || shared_dim < 0 )
return MB_SUCCESS;
4014 Range tmp_skin_ents[4];
4018 int skin_dim = resolve_dim - 1;
4021 skin_ents = tmp_skin_ents;
4022 skin_ents[resolve_dim] = proc_ents;
4025 skinner.
find_skin( this_set, skin_ents[skin_dim + 1],
false, skin_ents[skin_dim], NULL,
true,
true,
true );
MB_CHK_SET_ERR( result,
"Failed to find skin" );
4026 myDebug->
tprintf( 1,
"Found skin: skin_dim: %d resolve_dim: %d , now resolving.\n", skin_dim, resolve_dim );
4027 myDebug->
tprintf( 3,
"skin_ents[0].size(): %d skin_ents[1].size(): %d \n", (
int)skin_ents[0].
size(),
4028 (
int)skin_ents[1].
size() );
4030 for(
int this_dim = skin_dim - 1; this_dim >= 0; this_dim-- )
4035 if( this_set && skin_dim == 2 && this_dim == 1 )
4041 else if( skin_ents[resolve_dim].empty() )
4042 skin_ents[resolve_dim] = proc_ents;
4050 bool tag_created =
false;
4053 &def_val, &tag_created );
4056 MB_SET_ERR( result,
"Failed to create/get gid tag handle" );
4058 else if( tag_created )
4073 std::vector< long > lgid_data( skin_ents[0].
size() );
4080 else if( 4 == bytes_per_tag )
4082 std::vector< int > gid_data( lgid_data.size() );
4084 std::copy( gid_data.begin(), gid_data.end(), lgid_data.begin() );
4089 MB_SET_ERR( MB_FAILURE,
"Unsupported id tag" );
4093 std::vector< Ulong > handle_vec;
4094 std::copy( skin_ents[0].begin(), skin_ents[0].end(), std::back_inserter( handle_vec ) );
4096 #ifdef MOAB_HAVE_MPE
4121 result = gsd->
initialize( skin_ents[0].
size(), &lgid_data[0], &handle_vec[0], 2, 1, 1, cd );
MB_CHK_SET_ERR( result,
"Failed to create gs data" );
4124 Tag shp_tag, shps_tag, shh_tag, shhs_tag, pstat_tag;
4132 unsigned int i = 0, j = 0;
4133 for(
unsigned int p = 0; p < gsd->nlinfo->_np; p++ )
4134 for(
unsigned int np = 0; np < gsd->nlinfo->_nshared[p]; np++ )
4136 shared_verts.
vi_wr[i++] = gsd->nlinfo->_sh_ind[j];
4137 shared_verts.
vi_wr[i++] = gsd->nlinfo->_target[p];
4138 shared_verts.
vul_wr[j] = gsd->nlinfo->_ulabels[j];
4140 shared_verts.
inc_n();
4147 sort_buffer.buffer_init( max_size );
4148 shared_verts.
sort( 0, &sort_buffer );
4149 sort_buffer.
reset();
4154 std::fill( sharing_procs.begin(), sharing_procs.end(), maxp );
4159 std::map< std::vector< int >, std::vector< EntityHandle > > proc_nvecs;
4163 myDebug->
print( 3,
" resolve shared ents: proc verts ", proc_verts );
4166 #ifdef MOAB_HAVE_MPE
4176 shared_verts.
reset();
4180 for( std::map< std::vector< int >, std::vector< EntityHandle > >::const_iterator mit = proc_nvecs.begin();
4181 mit != proc_nvecs.end(); ++mit )
4184 for( std::vector< int >::const_iterator vit = ( mit->first ).begin(); vit != ( mit->first ).end(); ++vit )
4196 std::set< unsigned int > procs;
4213 #ifdef MOAB_HAVE_MPE
4230 #ifdef MOAB_HAVE_MPE
4235 MPE_Log_get_state_eventIDs( &IFACE_START, &IFACE_END );
4236 MPE_Log_get_state_eventIDs( &GHOST_START, &GHOST_END );
4237 MPE_Log_get_state_eventIDs( &SHAREDV_START, &SHAREDV_END );
4238 MPE_Log_get_state_eventIDs( &RESOLVE_START, &RESOLVE_END );
4239 MPE_Log_get_state_eventIDs( &ENTITIES_START, &ENTITIES_END );
4240 MPE_Log_get_state_eventIDs( &RHANDLES_START, &RHANDLES_END );
4241 MPE_Log_get_state_eventIDs( &OWNED_START, &OWNED_END );
4242 success =
MPE_Describe_state( IFACE_START, IFACE_END,
"Resolve interface ents",
"green" );
4244 success =
MPE_Describe_state( GHOST_START, GHOST_END,
"Exchange ghost ents",
"red" );
4246 success =
MPE_Describe_state( SHAREDV_START, SHAREDV_END,
"Resolve interface vertices",
"blue" );
4248 success =
MPE_Describe_state( RESOLVE_START, RESOLVE_END,
"Resolve shared ents",
"purple" );
4250 success =
MPE_Describe_state( ENTITIES_START, ENTITIES_END,
"Exchange shared ents",
"yellow" );
4252 success =
MPE_Describe_state( RHANDLES_START, RHANDLES_END,
"Remote handles",
"cyan" );
4254 success =
MPE_Describe_state( OWNED_START, OWNED_END,
"Exchange owned ents",
"black" );
4261 const unsigned int np,
4263 const int part_dim )
4265 std::vector< Range > verts( np );
4267 unsigned int p, i, j, v;
4269 for( p = 0; p < np; p++ )
4272 Range part_ents, skin_ents;
4275 rval = skinner.
find_skin( this_set, part_ents,
false, skin_ents, 0,
true,
true,
true );
4279 tot_verts += verts[p].size();
4283 shared_ents.
initialize( 2, 0, 1, 0, tot_verts );
4288 std::vector< int > gids;
4291 for( p = 0; p < np; p++ )
4295 gids.resize( verts[p].
size() );
4299 for( v = 0, rit = verts[p].begin(); v < gids.size(); v++, ++rit )
4301 shared_ents.
vi_wr[i++] = gids[v];
4302 shared_ents.
vi_wr[i++] = p;
4303 shared_ents.
vul_wr[j] = *rit;
4305 shared_ents.
inc_n();
4310 sort_buffer.buffer_init( tot_verts );
4311 shared_ents.
sort( 0, &sort_buffer );
4312 sort_buffer.
reset();
4316 std::vector< EntityHandle > handles;
4317 std::vector< int > procs;
4319 while( i < shared_ents.
get_n() )
4325 int this_gid = shared_ents.
vi_rd[j];
4326 while( i < shared_ents.
get_n() && shared_ents.
vi_rd[j] == this_gid )
4329 procs.push_back( shared_ents.
vi_rd[j++] );
4330 handles.push_back( shared_ents.
vul_rd[i++] );
4332 if( 1 == procs.size() )
continue;
4334 for( v = 0; v < procs.size(); v++ )
4336 rval = pc[procs[v]]->
update_remote_data( handles[v], &procs[0], &handles[0], procs.size(),
4337 ( procs[0] == (
int)pc[procs[v]]->
rank()
4344 std::set< unsigned int > psets;
4345 for( p = 0; p < np; p++ )
4355 shared_ents.
reset();
4363 Range iface_ents, tmp_ents, rmv_ents;
4364 std::vector< unsigned char > pstat;
4365 unsigned char set_pstat;
4374 pstat.resize( iface_ents.
size() );
4378 for( rit2 = iface_ents.
begin(), i = 0; rit2 != iface_ents.
end(); ++rit2, i++ )
4382 rmv_ents.
insert( *rit2 );
4392 iface_ents =
subtract( iface_ents, rmv_ents );
4394 std::remove_if( pstat.begin(), pstat.end(),
4395 std::bind( std::equal_to< unsigned char >(), std::placeholders::_1, 0x0 ) );
4399 unsigned int sz = iface_ents.
size();
4400 for( i = 0; i < sz; i++ )
4411 unsigned char pstatus_val,
4412 bool lower_dim_ents,
4416 std::vector< unsigned char > pstatus_vals( pstatus_ents.
size() );
4417 Range all_ents, *range_ptr = &pstatus_ents;
4419 if( lower_dim_ents || verts_too )
4421 all_ents = pstatus_ents;
4422 range_ptr = &all_ents;
4424 for( ; start_dim >= 0; start_dim-- )
4432 for(
unsigned int i = 0; i < pstatus_vals.size(); i++ )
4433 pstatus_vals[i] |= pstatus_val;
4437 for(
unsigned int i = 0; i < pstatus_vals.size(); i++ )
4438 pstatus_vals[i] = pstatus_val;
4447 unsigned char pstatus_val,
4448 bool lower_dim_ents,
4452 std::vector< unsigned char > pstatus_vals( num_ents );
4454 if( lower_dim_ents || verts_too )
4458 std::copy( pstatus_ents, pstatus_ents + num_ents,
range_inserter( tmp_range ) );
4465 for(
unsigned int i = 0; i < (
unsigned int)num_ents; i++ )
4466 pstatus_vals[i] |= pstatus_val;
4470 for(
unsigned int i = 0; i < (
unsigned int)num_ents; i++ )
4471 pstatus_vals[i] = pstatus_val;
4483 for(
size_t i = 0; i < proc_list.size(); i++ )
4484 val ^= proc_list[i];
4485 srand( (
int)( val ) );
4486 return rand() % proc_list.size();
4505 int num_tags =
sizeof( shared_set_tag_names ) /
sizeof( shared_set_tag_names[0] );
4506 Range candidate_sets;
4518 for(
int d = 0; d < 4; d++ )
4520 candidate_sets.
clear();
4521 const void* vals[] = { &d };
4527 for(
int i = 1; i < num_tags; i++ )
4532 candidate_sets.
clear();
4541 for(
int i = 0; i < num_tags; i++ )
4554 all_sets =
subtract( all_sets, candidate_sets );
4556 while( it != all_sets.
end() )
4562 if( contents.
empty() )
4568 hint = candidate_sets.
insert( hint, *it );
4569 it = all_sets.
erase( it );
4574 Range prev_list = candidate_sets;
4575 while( !prev_list.
empty() )
4577 it = all_sets.
begin();
4579 hint = new_list.
begin();
4580 while( it != all_sets.
end() )
4584 if( !
intersect( prev_list, contents ).empty() )
4586 hint = new_list.
insert( hint, *it );
4587 it = all_sets.
erase( it );
4593 if( !
intersect( prev_list, contents ).empty() )
4595 hint = new_list.
insert( hint, *it );
4596 it = all_sets.
erase( it );
4605 candidate_sets.
merge( new_list );
4606 prev_list.
swap( new_list );
4615 for(
size_t i = 1; i < v.size(); i++ )
4616 if( v[i - 1] >= v[i] )
return false;
4630 std::vector< long > larray;
4631 std::vector< Ulong > handles;
4653 larray.push_back(
dum );
4654 handles.push_back( *rit );
4655 tmp_sets.
insert( tmp_sets.
end(), *rit );
4658 else if( 4 == bytes_per_tag )
4664 larray.push_back(
dum );
4665 handles.push_back( *rit );
4666 tmp_sets.
insert( tmp_sets.
end(), *rit );
4671 const size_t nsets = handles.size();
4680 result = gsd->
initialize( nsets, &larray[0], &handles[0], 2, 1, 1, cd );
MB_CHK_SET_ERR( result,
"Failed to create gs data" );
4687 for(
unsigned p = 0; p < gsd->nlinfo->_np; p++ )
4688 ntuple += gsd->nlinfo->_nshared[p];
4689 std::vector< set_tuple > tuples;
4690 tuples.reserve( ntuple );
4692 for(
unsigned p = 0; p < gsd->nlinfo->_np; p++ )
4694 for(
unsigned np = 0; np < gsd->nlinfo->_nshared[p]; np++ )
4697 t.
idx = gsd->nlinfo->_sh_ind[j];
4698 t.
proc = gsd->nlinfo->_target[p];
4699 t.
handle = gsd->nlinfo->_ulabels[j];
4700 tuples.push_back( t );
4704 std::sort( tuples.begin(), tuples.end() );
4713 std::vector< unsigned > procs;
4715 while( si != tmp_sets.
end() && ti < tuples.size() )
4717 assert( idx <= tuples[ti].idx );
4718 if( idx < tuples[ti].idx ) si += ( tuples[ti].idx - idx );
4719 idx = tuples[ti].idx;
4722 size_t ti_init = ti;
4723 while( ti < tuples.size() && tuples[ti].idx == idx )
4725 procs.push_back( tuples[ti].proc );
4733 std::cerr <<
"Failure at " __FILE__
":" << __LINE__ << std::endl;
4740 std::vector< unsigned >::iterator it = std::lower_bound( procs.begin(), procs.end(), rk );
4741 assert( it == procs.end() || *it > rk );
4742 procs.insert( it, rk );
4745 if( procs[owner_idx] == rk )
4747 else if( procs[owner_idx] > rk )
4748 owner_handle = tuples[ti_init + owner_idx - 1].handle;
4750 owner_handle = tuples[ti_init + owner_idx].handle;
4754 std::cerr <<
"Failure at " __FILE__
":" << __LINE__ << std::endl;
4776 int num_tags =
sizeof( shared_set_tag_names ) /
sizeof( shared_set_tag_names[0] );
4779 Tag* tags =
new Tag[num_tags + 1];
4781 int my_rank =
rank();
4782 int** tagVals =
new int*[num_tags];
4783 for(
int i = 0; i < num_tags; i++ )
4791 typedef std::map< int, EntityHandle > MVal;
4792 typedef std::map< int, EntityHandle >::iterator itMVal;
4793 MVal* localMaps =
new MVal[num_tags];
4795 for(
int i = 0; i < num_tags; i++ )
4803 if( rangeSets[i].
size() > 0 )
4805 tagVals[i] =
new int[rangeSets[i].
size()];
4809 for(
int j = 0; j < (int)rangeSets[i].
size(); j++ )
4811 localMaps[i][tagVals[i][j]] = rangeSets[i][j];
4829 remoteEnts.
initialize( 3, 0, 1, 0, initialSize );
4835 std::set< EntityHandle > own_and_sha;
4837 for( std::set< EntityHandle >::iterator vit =
sharedEnts.begin(); vit !=
sharedEnts.end(); ++vit )
4841 if( own_and_sha.find( geh ) != own_and_sha.end() )
4846 unsigned char pstat;
4850 for(
int i = 0; i < num_tags; i++ )
4851 delete[] tagVals[i];
4857 own_and_sha.insert( geh );
4858 for(
int i = 0; i < num_tags; i++ )
4860 for(
int j = 0; j < (int)rangeSets[i].
size(); j++ )
4867 for(
int k = 0; k < nprocs; k++ )
4869 if( procs[k] != my_rank )
4874 int oldSize = remoteEnts.
get_max();
4876 remoteEnts.
resize( oldSize + oldSize / 2 + 1 );
4878 remoteEnts.
vi_wr[ir++] = procs[k];
4879 remoteEnts.
vi_wr[ir++] = i;
4880 remoteEnts.
vi_wr[ir++] = tagVals[i][j];
4881 remoteEnts.
vul_wr[jr++] = handles[k];
4894 for(
int k = 0; k < nprocs; k++ )
4896 if( procs[k] != my_rank )
4901 int oldSize = remoteEnts.
get_max();
4903 remoteEnts.
resize( oldSize + oldSize / 2 + 1 );
4905 remoteEnts.
vi_wr[ir++] = procs[k];
4906 remoteEnts.
vi_wr[ir++] = num_tags;
4907 remoteEnts.
vi_wr[ir++] = gid;
4908 remoteEnts.
vul_wr[jr++] = handles[k];
4918 int sentEnts = remoteEnts.
get_n();
4919 assert( ( sentEnts == jr ) && ( 3 * sentEnts == ir ) );
4925 rval = cd->gs_transfer( 1, remoteEnts, 0 );
MB_CHK_SET_ERR( rval,
"Error in tuple transfer" );
4932 int received = remoteEnts.
get_n();
4933 for(
int i = 0; i < received; i++ )
4937 int from_proc = remoteEnts.
vi_rd[3 * i];
4938 if( my_rank == from_proc )
4939 std::cout <<
" unexpected receive from my rank " << my_rank <<
" during augmenting with ghosts\n ";
4940 int tag_type = remoteEnts.
vi_rd[3 * i + 1];
4941 assert( ( 0 <= tag_type ) && ( tag_type <= num_tags ) );
4942 int value = remoteEnts.
vi_rd[3 * i + 2];
4943 if( tag_type == num_tags )
4951 MVal& lmap = localMaps[tag_type];
4952 itMVal itm = lmap.find( value );
4953 if( itm == lmap.end() )
4958 lmap[value] = newSet;
4973 for(
int i = 0; i < num_tags; i++ )
4974 delete[] tagVals[i];
4983 std::map< std::vector< int >, std::vector< EntityHandle > > proc_nvecs;
4990 unsigned char pstat;
4991 for( std::set< EntityHandle >::iterator vit =
sharedEnts.begin(); vit !=
sharedEnts.end(); ++vit )
4995 std::sort( procs, procs + nprocs );
4996 std::vector< int > tmp_procs( procs, procs + nprocs );
4997 assert( tmp_procs.size() != 2 );
4998 proc_nvecs[tmp_procs].push_back( *vit );
5005 skinner.
find_skin( this_set, skin_ents[resolve_dim],
false, skin_ents[resolve_dim - 1], 0,
true,
true,
true );
MB_CHK_SET_ERR( result,
"Failed to find skin" );
5006 if( shared_dim > 1 )
5008 result =
mbImpl->
get_adjacencies( skin_ents[resolve_dim - 1], resolve_dim - 2,
true, skin_ents[resolve_dim - 2],
5012 result =
get_proc_nvecs( resolve_dim, shared_dim, skin_ents, proc_nvecs );
5023 Tag shp_tag, shps_tag, shh_tag, shhs_tag, pstat_tag;
5028 std::vector< unsigned char > pstatus;
5029 for( std::map< std::vector< int >, std::vector< EntityHandle > >::iterator vit = proc_nvecs.begin();
5030 vit != proc_nvecs.end(); ++vit )
5038 assert( !vit->second.empty() );
5041 if( vit->first.size() == 1 )
5045 proc_handles[0] = 0;
5060 std::copy( vit->first.begin(), vit->first.end(), proc_ids );
5063 unsigned int ind = std::find( proc_ids, proc_ids + vit->first.size(),
procConfig.
proc_rank() ) - proc_ids;
5064 assert( ind < vit->
first.size() );
5066 proc_handles[ind] = new_set;
5071 int min_proc = ( vit->first )[0];
5079 std::vector< EntityHandle > verts;
5080 for( std::vector< EntityHandle >::iterator v2it = ( vit->second ).begin(); v2it != ( vit->second ).end();
5083 pstatus.resize( verts.size(), pval );
5084 if( !verts.empty() )
5086 result =
mbImpl->
tag_set_data( pstat_tag, &verts[0], verts.size(), &pstatus[0] );
MB_CHK_SET_ERR( result,
"Failed to tag interface set vertices with pstatus" );
5105 std::vector< EntityHandle > tag_vals;
5114 if( iface_ents.
empty() )
continue;
5116 tag_vals.resize( iface_ents.
size() );
5117 std::fill( tag_vals.begin(), tag_vals.end(), *rit );