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 );
5123 for(
int d = 2; d >= 0; d-- )
5134 tag_vals.resize( tmp_ents2.
size() );
5139 for(
unsigned int i = 0; i < tag_vals.size(); i++ )
5141 if( tag_vals[i] && tag_vals[i] != last_set )
5144 last_set = tag_vals[i];
5159 std::map< std::vector< int >, std::vector< EntityHandle > >& proc_nvecs )
5165 std::set< int > sharing_procs;
5166 std::vector< EntityHandle > dum_connect;
5167 std::vector< int > sp_vec;
5169 for(
int d = 3; d > 0; d-- )
5171 if( resolve_dim == d )
continue;
5180 if( sharing_procs.empty() ||
5186 if( sharing_procs.size() == 2 )
5188 std::set< int >::iterator it = sharing_procs.find(
proc_config().proc_rank() );
5189 assert( it != sharing_procs.end() );
5190 sharing_procs.erase( it );
5195 std::copy( sharing_procs.begin(), sharing_procs.end(), std::back_inserter( sp_vec ) );
5196 assert( sp_vec.size() != 2 );
5197 proc_nvecs[sp_vec].push_back( *rit );
5203 for( std::map< std::vector< int >, std::vector< EntityHandle > >::iterator mit = proc_nvecs.begin();
5204 mit != proc_nvecs.end(); ++mit )
5206 std::vector< EntityHandle > tmp_vec = ( mit->second );
5207 std::sort( tmp_vec.begin(), tmp_vec.end() );
5208 std::vector< EntityHandle >::iterator vit = std::unique( tmp_vec.begin(), tmp_vec.end() );
5209 assert( vit == tmp_vec.end() );
5220 std::map< std::vector< int >, std::vector< EntityHandle > >& proc_nvecs,
5222 unsigned int i_extra )
5224 Tag shp_tag, shps_tag, shh_tag, shhs_tag, pstat_tag;
5227 unsigned int j = 0, i = 0;
5228 std::vector< int > sharing_procs, sharing_procs2, tag_procs;
5229 std::vector< EntityHandle > sharing_handles, sharing_handles2, tag_lhandles, tag_rhandles;
5230 std::vector< unsigned char > pstatus;
5233 if( i_extra ) i += i_extra;
5234 while( j < 2 * shared_ents.
get_n() )
5238 int other_proc = -1;
5239 while( j < 2 * shared_ents.
get_n() && shared_ents.
vul_rd[j] == this_ent )
5245 if( shared_ents.
vul_rd[j] != other_ent || shared_ents.
vi_rd[i] != other_proc )
5247 assert( 0 != shared_ents.
vul_rd[j] );
5248 sharing_procs.push_back( shared_ents.
vi_rd[i] );
5249 sharing_handles.push_back( shared_ents.
vul_rd[j] );
5251 other_proc = shared_ents.
vi_rd[i];
5252 other_ent = shared_ents.
vul_rd[j];
5257 if( sharing_procs.size() > 1 )
5261 sharing_handles.push_back( this_ent );
5266 sharing_procs2 = sharing_procs;
5267 std::sort( sharing_procs2.begin(), sharing_procs2.end() );
5268 sharing_handles2.resize( sharing_handles.size() );
5269 for(
size_t k = 0; k < sharing_handles.size(); k++ )
5271 size_t idx = std::lower_bound( sharing_procs2.begin(), sharing_procs2.end(), sharing_procs[k] ) -
5272 sharing_procs2.begin();
5273 sharing_handles2[idx] = sharing_handles[k];
5275 sharing_procs.swap( sharing_procs2 );
5276 sharing_handles.swap( sharing_handles2 );
5279 assert( sharing_procs.size() != 2 );
5280 proc_nvecs[sharing_procs].push_back( this_ent );
5283 if( sharing_procs.size() == 1 )
5285 tag_procs.push_back( sharing_procs[0] );
5286 tag_lhandles.push_back( this_ent );
5287 tag_rhandles.push_back( sharing_handles[0] );
5288 pstatus.push_back( share_flag );
5296 std::cerr <<
"MAX_SHARING_PROCS exceeded for vertex " << this_ent <<
" on process "
5310 sharing_procs.clear();
5311 sharing_handles.clear();
5314 if( !tag_procs.empty() )
5316 result =
mbImpl->
tag_set_data( shp_tag, &tag_lhandles[0], tag_procs.size(), &tag_procs[0] );
MB_CHK_SET_ERR( result,
"Failed to set sharedp tag on shared vertex" );
5317 result =
mbImpl->
tag_set_data( shh_tag, &tag_lhandles[0], tag_procs.size(), &tag_rhandles[0] );
MB_CHK_SET_ERR( result,
"Failed to set sharedh tag on shared vertex" );
5318 result =
mbImpl->
tag_set_data( pstat_tag, &tag_lhandles[0], tag_procs.size(), &pstatus[0] );
MB_CHK_SET_ERR( result,
"Failed to set pstatus tag on shared vertex" );
5319 for( std::vector< EntityHandle >::iterator vvt = tag_lhandles.begin(); vvt != tag_lhandles.end(); vvt++ )
5325 for( std::map< std::vector< int >, std::vector< EntityHandle > >::iterator mit = proc_nvecs.begin();
5326 mit != proc_nvecs.end(); ++mit )
5328 std::vector< EntityHandle > tmp_vec = ( mit->second );
5329 std::sort( tmp_vec.begin(), tmp_vec.end() );
5330 std::vector< EntityHandle >::iterator vit = std::unique( tmp_vec.begin(), tmp_vec.end() );
5331 assert( vit == tmp_vec.end() );
5340 std::map< std::vector< int >, std::vector< EntityHandle > >& proc_nvecs,
5343 Tag shp_tag, shps_tag, shh_tag, shhs_tag, pstat_tag;
5346 unsigned int j = 0, i = 0;
5347 std::vector< int > sharing_procs, sharing_procs2;
5348 std::vector< EntityHandle > sharing_handles, sharing_handles2, skin_verts( skin_ents[0].
size() );
5349 for(
Range::iterator rit = skin_ents[0].begin(); rit != skin_ents[0].
end(); ++rit, i++ )
5350 skin_verts[i] = *rit;
5353 while( j < 2 * shared_ents.
get_n() )
5356 int this_idx = shared_ents.
vi_rd[j];
5358 while( j < 2 * shared_ents.
get_n() && shared_ents.
vi_rd[j] == this_idx )
5363 sharing_procs.push_back( shared_ents.
vi_rd[j++] );
5364 sharing_handles.push_back( shared_ents.
vul_rd[i++] );
5367 if( sharing_procs.size() > 1 )
5371 sharing_handles.push_back( this_ent );
5377 sharing_procs2 = sharing_procs;
5378 std::sort( sharing_procs2.begin(), sharing_procs2.end() );
5379 sharing_handles2.resize( sharing_handles.size() );
5380 for(
size_t k = 0; k < sharing_handles.size(); k++ )
5382 size_t idx = std::lower_bound( sharing_procs2.begin(), sharing_procs2.end(), sharing_procs[k] ) -
5383 sharing_procs2.begin();
5384 sharing_handles2[idx] = sharing_handles[k];
5386 sharing_procs.swap( sharing_procs2 );
5387 sharing_handles.swap( sharing_handles2 );
5389 assert( sharing_procs.size() != 2 );
5390 proc_nvecs[sharing_procs].push_back( this_ent );
5393 if( sharing_procs.size() == 1 )
5406 std::cerr <<
"MAX_SHARING_PROCS exceeded for vertex " << this_ent <<
" on process "
5420 sharing_procs.clear();
5421 sharing_handles.clear();
5426 for( std::map< std::vector< int >, std::vector< EntityHandle > >::iterator mit = proc_nvecs.begin();
5427 mit != proc_nvecs.end(); ++mit )
5429 std::vector< EntityHandle > tmp_vec = ( mit->second );
5430 std::sort( tmp_vec.begin(), tmp_vec.end() );
5431 std::vector< EntityHandle >::iterator vit = std::unique( tmp_vec.begin(), tmp_vec.end() );
5432 assert( vit == tmp_vec.end() );
5457 if( -1 != iface_proc[i] )
5460 procs_set.insert( (
unsigned int)iface_proc[i] );
5469 procs_set.insert( (
unsigned int)tmp_iface_procs[j] );
5470 else if( -1 == tmp_iface_procs[j] )
5472 std::fill( tmp_iface_procs, tmp_iface_procs + j, -1 );
5481 for( std::set< unsigned int >::iterator sit = procs_set.begin(); sit != procs_set.end(); ++sit )
5508 std::vector< unsigned char > pstatus( ents.
size() );
5514 for( ; rit != ents.
end(); i++, ++rit )
5517 pstatus_ents.
insert( *rit );
5522 for( ; rit != ents.
end(); i++, ++rit )
5525 pstatus_ents.
insert( *rit );
5533 const int dimension,
5535 const bool largest_dim_only,
5536 const bool parallel,
5537 const bool owned_only )
5544 void* tag_ptr = &def_val;
5547 if( !dum_range.
empty() )
5550 result =
assign_global_ids( this_set, dimension, start_id, largest_dim_only, parallel, owned_only );
MB_CHK_SET_ERR( result,
"Failed assigning global ids" );
5561 if(
MB_SUCCESS == result && to_proc == sharing_procs[0] )
return true;
5568 if( to_proc == sharing_procs[i] )
5570 else if( -1 == sharing_procs[i] )
5578 unsigned char pstat,
5581 Range* returned_ents )
5588 if( returned_ents ) returned_ents->
clear();
5594 std::vector< unsigned char > shared_flags( ents.
size() ), shared_flags2;
5601 for( rit = ents.
begin(), i = 0; rit != ents.
end(); ++rit, i++ )
5603 if( ( ( shared_flags[i] & ~pstat ) ^ shared_flags[i] ) & pstat )
5605 hint = tmp_ents.
insert( hint, *rit );
5606 if( -1 != to_proc ) shared_flags2.push_back( shared_flags[i] );
5612 for( rit = ents.
begin(), i = 0; rit != ents.
end(); ++rit, i++ )
5614 if( ( shared_flags[i] & pstat ) == pstat )
5616 hint = tmp_ents.
insert( hint, *rit );
5617 if( -1 != to_proc ) shared_flags2.push_back( shared_flags[i] );
5623 for( rit = ents.
begin(), i = 0; rit != ents.
end(); ++rit, i++ )
5625 if( !( shared_flags[i] & pstat ) )
5627 hint = tmp_ents.
insert( hint, *rit );
5628 if( -1 != to_proc ) shared_flags2.push_back( shared_flags[i] );
5643 hint = tmp_ents2.
begin();
5645 for( rit = tmp_ents.
begin(), i = 0; rit != tmp_ents.
end(); ++rit, i++ )
5651 assert( -1 != sharing_procs[0] );
5655 if( sharing_procs[j] == to_proc )
5657 hint = tmp_ents2.
insert( hint, *rit );
5659 else if( -1 == sharing_procs[j] )
5662 sharing_procs[j] = -1;
5668 assert( -1 != sharing_procs[0] );
5669 if( sharing_procs[0] == to_proc ) hint = tmp_ents2.
insert( hint, *rit );
5670 sharing_procs[0] = -1;
5673 assert(
"should never get here" &&
false );
5676 tmp_ents.
swap( tmp_ents2 );
5680 returned_ents->
swap( tmp_ents );
5682 ents.
swap( tmp_ents );
5691 bool store_remote_handles,
5695 #ifdef MOAB_HAVE_MPE
5705 myDebug->
tprintf( 1,
"Entering exchange_ghost_cells with num_layers = %d\n", num_layers );
5714 assert( num_layers > 0 || store_remote_handles );
5716 const bool is_iface = !num_layers;
5722 int incoming1 = 0, incoming2 = 0;
5732 #ifdef MOAB_HAVE_MPE
5740 std::vector< MPI_Request > recv_ent_reqs( 3 *
buffProcs.size(), MPI_REQUEST_NULL ),
5741 recv_remoteh_reqs( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
5742 std::vector< unsigned int >::iterator proc_it;
5745 for( ind = 0, proc_it =
buffProcs.begin(); proc_it !=
buffProcs.end(); ++proc_it, ind++ )
5752 if( success != MPI_SUCCESS )
5754 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in ghost exchange" );
5764 result =
get_sent_ents( is_iface, bridge_dim, ghost_dim, num_layers, addl_ents, sent_ents, allsent, entprocs );
MB_CHK_SET_ERR( result,
"get_sent_ents failed" );
5768 if( addl_ents > 0 && file_set && !allsent.
empty() )
5773 (
unsigned long)allsent.
size() );
5778 for( p = 0, proc_it =
buffProcs.begin(); proc_it !=
buffProcs.end(); ++proc_it, p++ )
5780 myDebug->
tprintf( 1,
"Sent ents compactness (size) = %f (%lu)\n", sent_ents[p].compactness(),
5781 (
unsigned long)sent_ents[p].
size() );
5788 &entprocs, &allsent );
MB_CHK_SET_ERR( result,
"Packing entities failed" );
5799 ( !is_iface && store_remote_handles ?
5802 &recv_remoteh_reqs[3 * p], &incoming2 );
MB_CHK_SET_ERR( result,
"Failed to Isend in ghost exchange" );
5813 std::vector< std::vector< EntityHandle > > recd_ents(
buffProcs.size() );
5814 std::vector< std::vector< EntityHandle > > L1hloc(
buffProcs.size() ), L1hrem(
buffProcs.size() );
5815 std::vector< std::vector< int > > L1p(
buffProcs.size() );
5816 std::vector< EntityHandle > L2hloc, L2hrem;
5817 std::vector< unsigned int > L2p;
5818 std::vector< EntityHandle > new_ents;
5826 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_ent_reqs[0], &ind, &status );
5827 if( MPI_SUCCESS != success )
5829 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in ghost exchange" );
5839 unsigned int base_ind = 3 * ( ind / 3 );
5843 ( !is_iface && store_remote_handles ?
localOwnedBuffs[ind / 3] : NULL ),
5845 &recv_remoteh_reqs[base_ind + 1], &incoming2 );
MB_CHK_SET_ERR( result,
"Failed to receive buffer" );
5858 L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents );
5861 std::cout <<
"Failed to unpack entities. Buffer contents:" << std::endl;
5866 if( recv_ent_reqs.size() != 3 *
buffProcs.size() )
5870 assert( !is_iface );
5871 recv_remoteh_reqs.resize( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
5872 for(
unsigned int i = recv_ent_reqs.size(); i < 3 *
buffProcs.size(); i += 3 )
5880 &recv_remoteh_reqs[i] );
5881 if( success != MPI_SUCCESS )
5883 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv for remote handles in ghost exchange" );
5886 recv_ent_reqs.resize( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
5893 if( recv_ent_reqs.size() != 3 *
buffProcs.size() )
5896 MB_SET_ERR( MB_FAILURE,
"Requests length doesn't match proc count in ghost exchange" );
5899 #ifdef MOAB_HAVE_MPE
5912 if(
MB_SUCCESS != result ) std::cout <<
"Failed check." << std::endl;
5919 if(
MB_SUCCESS != result ) std::cout <<
"Failed check." << std::endl;
5921 if(
MB_SUCCESS != result ) std::cout <<
"Failed check." << std::endl;
5924 #ifdef MOAB_HAVE_MPE
5943 success = MPI_Waitall( 3 *
buffProcs.size(), &recv_ent_reqs[0], mult_status );
5944 if( MPI_SUCCESS != success )
5946 MB_SET_ERR( MB_FAILURE,
"Failed in waitall in ghost exchange" );
5949 if( MPI_SUCCESS != success )
5951 MB_SET_ERR( MB_FAILURE,
"Failed in waitall in ghost exchange" );
5961 myDebug->
tprintf( 1,
"Exiting exchange_ghost_cells for is_iface==true \n" );
5977 if( MPI_SUCCESS != success )
5979 MB_SET_ERR( MB_FAILURE,
"Failed in waitall in ghost exchange" );
5987 for( p = 0, proc_it =
buffProcs.begin(); proc_it !=
buffProcs.end(); ++proc_it, p++ )
6002 recv_remoteh_reqs[3 * p + 2], &dum_ack_buff, incoming2 );
MB_CHK_SET_ERR( result,
"Failed to send remote handles" );
6011 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_remoteh_reqs[0], &ind, &status );
6012 if( MPI_SUCCESS != success )
6014 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in ghost exchange" );
6023 unsigned int base_ind = 3 * ( ind / 3 );
6041 #ifdef MOAB_HAVE_MPE
6061 success = MPI_Waitall( 3 *
buffProcs.size(), &recv_remoteh_reqs[0], mult_status );
6062 if( MPI_SUCCESS == success ) success = MPI_Waitall( 3 *
buffProcs.size(), &
sendReqs[0], mult_status );
6064 if( MPI_SUCCESS != success )
6066 MB_SET_ERR( MB_FAILURE,
"Failed in waitall in ghost exchange" );
6075 if( file_set && !new_ents.empty() )
6081 myDebug->
tprintf( 1,
"Exiting exchange_ghost_cells for is_iface==false \n" );
6089 MPI_Request& send_req,
6090 MPI_Request& ack_req,
6095 MPI_Request* next_recv_req,
6096 int* next_incoming )
6104 ( *next_incoming )++;
6109 if( success != MPI_SUCCESS )
6111 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv for next message in ghost exchange" );
6120 success = MPI_Irecv( (
void*)ack_buff,
sizeof(
int ), MPI_UNSIGNED_CHAR, to_proc, mesg_tag - 1,
6122 if( success != MPI_SUCCESS )
6124 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv for entity ack in ghost exchange" );
6134 if( success != MPI_SUCCESS )
return MB_FAILURE;
6140 const MPI_Status& mpi_status,
6142 MPI_Request& recv_req,
6146 MPI_Request& send_req,
6147 MPI_Request& sent_ack_req,
6151 MPI_Request* next_req,
6152 int* next_incoming )
6156 int from_proc = mpi_status.MPI_SOURCE;
6177 if( success != MPI_SUCCESS )
6179 MB_SET_ERR( MB_FAILURE,
"Failed to post 2nd iRecv in ghost exchange" );
6185 success = MPI_Isend( recv_buff->
mem_ptr,
sizeof(
int ), MPI_UNSIGNED_CHAR, from_proc, mesg_tag_expected - 1,
6187 if( success != MPI_SUCCESS )
6189 MB_SET_ERR( MB_FAILURE,
"Failed to send ack in ghost exchange" );
6192 else if( mpi_status.MPI_TAG == mesg_tag_expected - 1 )
6203 ( *next_incoming )++;
6209 if( success != MPI_SUCCESS )
6211 MB_SET_ERR( MB_FAILURE,
"Failed to post next irecv in ghost exchange" );
6219 assert( send_buff->
get_stored_size() - INITIAL_BUFF_SIZE < send_buff->alloc_size &&
6223 if( success != MPI_SUCCESS )
6225 MB_SET_ERR( MB_FAILURE,
"Failed to send 2nd message in ghost exchange" );
6229 mpi_status.MPI_TAG == mesg_tag_expected + 1 )
6250 else if( a.
procs[i] < 0 )
6263 typedef std::map< ProcList, Range > procmap_t;
6264 procmap_t old_procs, new_procs;
6269 unsigned char pstatus;
6273 for( rvit = allsent.
rbegin(); rvit != allsent.
rend(); ++rvit )
6276 assert(
"Should be shared with at least one other proc" &&
6281 int idx = std::find( sharedh, sharedh + nump, (
EntityHandle)0 ) - sharedh;
6282 if( idx == nump )
continue;
6285 std::sort( old_list.
procs, old_list.
procs + nump );
6286 old_procs[old_list].insert( *rvit );
6290 bool removed_owner = !idx;
6291 for( ++idx; idx < nump; ++idx )
6295 sharedh[new_nump] = sharedh[idx];
6296 sharedp.
procs[new_nump] = sharedp.
procs[idx];
6300 sharedp.
procs[new_nump] = -1;
6302 if( removed_owner && new_nump > 1 )
6307 idx = std::min_element( sharedp.
procs, sharedp.
procs + new_nump ) - sharedp.
procs;
6308 std::swap( sharedp.
procs[0], sharedp.
procs[idx] );
6309 std::swap( sharedh[0], sharedh[idx] );
6324 sharedp.
procs[1] = -1;
6328 std::sort( sharedp.
procs, sharedp.
procs + new_nump );
6330 new_procs[sharedp].insert( *rvit );
6334 if( old_procs.empty() )
6336 assert( new_procs.empty() );
6341 procmap_t::iterator pmit;
6347 assert( nump != 2 );
6348 std::sort( sharedp.
procs, sharedp.
procs + nump );
6351 pmit = old_procs.find( sharedp );
6352 if( pmit != old_procs.end() )
6357 pmit = new_procs.find( sharedp );
6358 if( pmit == new_procs.end() )
6378 new_procs.erase( pmit );
6385 for( pmit = new_procs.begin(); pmit != new_procs.end(); ++pmit )
6394 assert( pmit->first.procs[0] >= 0 );
6396 if( pmit->first.procs[1] == -1 )
6398 int other = pmit->first.procs[0];
6423 unsigned char pstatus,
6448 assert( new_nump > 1 &&
6462 std::set< unsigned int > dumprocs;
6464 for( ; dp < old_nump && -1 != ps[dp]; dp++ )
6465 dumprocs.insert( ps[dp] );
6466 assert( dp == (
int)dumprocs.size() );
6472 if( old_nump > 2 && new_nump < 3 )
6482 else if( ( old_nump < 3 && new_nump > 2 ) || ( old_nump > 1 && new_nump == 1 ) )
6491 assert(
"check for multishared/owner I'm first proc" &&
6493 ( ps[0] == (
int)
rank() ) ) &&
6494 "interface entities should have > 1 proc" && ( !( pstatus &
PSTATUS_INTERFACE ) || new_nump > 1 ) &&
6495 "ghost entities should have > 1 proc" && ( !( pstatus &
PSTATUS_GHOST ) || new_nump > 1 ) );
6506 assert( -1 != ps[j] );
6513 if( old_nump > 1 && new_nump < 2 )
sharedEnts.erase( ent );
6519 const int bridge_dim,
6520 const int ghost_dim,
6521 const int num_layers,
6522 const int addl_ents,
6529 std::vector< unsigned int >::iterator proc_it;
6534 for( ind = 0, proc_it =
buffProcs.begin(); proc_it !=
buffProcs.end(); ++proc_it, ind++ )
6549 if( !tmp_range.
empty() ) sent_ents[ind] =
subtract( sent_ents[ind], tmp_range );
6551 allsent.
merge( sent_ents[ind] );
6560 for( ind = 0; ind <
buffProcs.size(); ind++ )
6561 npairs += sent_ents[ind].
size();
6568 for( ind = 0, proc_it =
buffProcs.begin(); proc_it !=
buffProcs.end(); ++proc_it, ind++ )
6570 for(
Range::iterator rit = sent_ents[ind].begin(); rit != sent_ents[ind].
end(); ++rit )
6579 sort_buffer.buffer_init( npairs );
6580 entprocs.
sort( 1, &sort_buffer );
6583 sort_buffer.
reset();
6589 unsigned int num_procs,
6594 bool store_remote_handles,
6602 assert( num_layers > 0 || store_remote_handles );
6604 const bool is_iface = !num_layers;
6610 std::vector< Error* > ehs( num_procs );
6611 for(
unsigned int i = 0; i < num_procs; i++ )
6632 for(
unsigned int p = 0; p < num_procs; p++ )
6635 result = pc->
get_sent_ents( is_iface, bridge_dim, ghost_dim, num_layers, addl_ents, sent_ents[p], allsent[p],
6636 entprocs[p] );
MB_CHK_SET_ERR( result,
"p = " << p <<
", get_sent_ents failed" );
6641 for( ind = 0; ind < pc->
buffProcs.size(); ind++ )
6646 pc->
buffProcs[ind], is_iface, &entprocs[p], &allsent[p] );
MB_CHK_SET_ERR( result,
"p = " << p <<
", packing entities failed" );
6649 entprocs[p].
reset();
6663 for(
unsigned int p = 0; p < num_procs; p++ )
6665 L1hloc[p].resize( pcs[p]->
buffProcs.size() );
6666 L1hrem[p].resize( pcs[p]->
buffProcs.size() );
6667 L1p[p].resize( pcs[p]->
buffProcs.size() );
6670 for(
unsigned int p = 0; p < num_procs; p++ )
6674 for( ind = 0; ind < pc->
buffProcs.size(); ind++ )
6687 is_iface, L1hloc[to_p], L1hrem[to_p], L1p[to_p], L2hloc[to_p],
6688 L2hrem[to_p], L2p[to_p], new_ents[to_p] );
MB_CHK_SET_ERR( result,
"p = " << p <<
", failed to unpack entities" );
6697 for(
unsigned int p = 0; p < num_procs; p++ )
6703 for(
unsigned int p = 0; p < num_procs; p++ )
6716 std::vector< unsigned int >::iterator proc_it;
6717 for(
unsigned int p = 0; p < num_procs; p++ )
6721 for( ind = 0, proc_it = pc->
buffProcs.begin(); proc_it != pc->
buffProcs.end(); ++proc_it, ind++ )
6733 for(
unsigned int p = 0; p < num_procs; p++ )
6737 for( ind = 0, proc_it = pc->
buffProcs.begin(); proc_it != pc->
buffProcs.end(); ++proc_it, ind++ )
6743 L2hrem[to_p], L2p[to_p] );
MB_CHK_SET_ERR( result,
"p = " << p <<
", failed to unpack remote handles" );
6748 for(
unsigned int p = 0; p < num_procs; p++ )
6758 for(
unsigned int p = 0; p < num_procs; p++ )
6760 if( new_ents[p].empty() )
continue;
6771 int n_proc = exchange_procs.size();
6772 for(
int i = 0; i < n_proc; i++ )
6784 for(
int i = 0; i < n_proc; i++ )
6792 if( success != MPI_SUCCESS )
6794 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in owned entity exchange" );
6804 int num = shared_procs.size();
6805 for(
int i = 0; i < num; i++ )
6809 for(
int i = 0; i < num; i++ )
6812 for(
int i = 0; i < num; i++ )
6823 std::set< unsigned int >::iterator it = recv_procs.begin();
6824 std::set< unsigned int >::iterator eit = recv_procs.end();
6825 for( ; it != eit; ++it )
6833 if( success != MPI_SUCCESS )
6835 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in owned entity exchange" );
6843 std::vector< Range* >& exchange_ents,
6844 std::vector< MPI_Request >& recv_ent_reqs,
6845 std::vector< MPI_Request >& recv_remoteh_reqs,
6846 bool store_remote_handles,
6854 std::vector< unsigned int > exchange_procs_sets;
6855 std::vector< Range* > exchange_sets;
6856 int n_proc = exchange_procs.size();
6857 for(
int i = 0; i < n_proc; i++ )
6860 *exchange_ents[i] =
subtract( *exchange_ents[i], set_range );
6862 exchange_sets.push_back( tmp_range );
6863 exchange_procs_sets.push_back( exchange_procs[i] );
6870 store_remote_handles, wait_all, migrate );
MB_CHK_SET_ERR( result,
"Failed to exchange owned mesh entities" );
6874 store_remote_handles, wait_all, migrate );
6879 result =
exchange_owned_mesh( exchange_procs, exchange_ents, recv_ent_reqs, recv_remoteh_reqs,
false,
6880 store_remote_handles, wait_all, migrate );
MB_CHK_SET_ERR( result,
"Failed to exchange owned mesh entities" );
6883 result =
exchange_owned_mesh( exchange_procs_sets, exchange_sets, recv_ent_reqs, recv_remoteh_reqs,
false,
6884 store_remote_handles, wait_all, migrate );
MB_CHK_SET_ERR( result,
"Failed to exchange owned mesh sets" );
6887 for(
int i = 0; i < n_proc; i++ )
6888 delete exchange_sets[i];
6891 std::map< std::vector< int >, std::vector< EntityHandle > > proc_nvecs;
6895 unsigned char pstat;
6896 for( std::set< EntityHandle >::iterator vit =
sharedEnts.begin(); vit !=
sharedEnts.end(); ++vit )
6900 std::sort( procs, procs + nprocs );
6901 std::vector< int > tmp_procs( procs, procs + nprocs );
6902 assert( tmp_procs.size() != 2 );
6903 proc_nvecs[tmp_procs].push_back( *vit );
6913 std::vector< Range* >& exchange_ents,
6914 std::vector< MPI_Request >& recv_ent_reqs,
6915 std::vector< MPI_Request >& recv_remoteh_reqs,
6916 const bool recv_posted,
6917 bool store_remote_handles,
6921 #ifdef MOAB_HAVE_MPE
6937 int incoming1 = 0, incoming2 = 0;
6940 unsigned int n_proc = exchange_procs.size();
6941 for( i = 0; i < n_proc; i++ )
6949 if( !tmp_range.
empty() )
6951 *exchange_ents[i] =
subtract( *exchange_ents[i], tmp_range );
6958 #ifdef MOAB_HAVE_MPE
6969 recv_ent_reqs.resize( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
6970 recv_remoteh_reqs.resize( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
6973 for( i = 0; i < n_proc; i++ )
6981 if( success != MPI_SUCCESS )
6983 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in owned entity exchange" );
6988 incoming1 += n_proc;
6994 Range allsent, tmp_range;
6998 for( i = 0; i < n_proc; i++ )
7000 int n_ents = exchange_ents[i]->size();
7004 allsent.
merge( *exchange_ents[i] );
7013 for( i = 0; i < n_proc; i++ )
7015 for(
Range::iterator rit = exchange_ents[i]->begin(); rit != exchange_ents[i]->end(); ++rit )
7017 entprocs.
vi_wr[entprocs.
get_n()] = exchange_procs[i];
7025 sort_buffer.buffer_init( npairs );
7026 entprocs.
sort( 1, &sort_buffer );
7027 sort_buffer.
reset();
7030 (
unsigned long)allsent.
size() );
7035 for( i = 0; i < n_proc; i++ )
7038 myDebug->
tprintf( 1,
"Sent ents compactness (size) = %f (%lu)\n", exchange_ents[i]->compactness(),
7039 (
unsigned long)exchange_ents[i]->
size() );
7054 ( store_remote_handles ?
localOwnedBuffs[ind] : NULL ), &recv_remoteh_reqs[3 * ind],
7055 &incoming2 );
MB_CHK_SET_ERR( result,
"Failed to Isend in ghost exchange" );
7065 std::vector< std::vector< EntityHandle > > recd_ents(
buffProcs.size() );
7066 std::vector< std::vector< EntityHandle > > L1hloc(
buffProcs.size() ), L1hrem(
buffProcs.size() );
7067 std::vector< std::vector< int > > L1p(
buffProcs.size() );
7068 std::vector< EntityHandle > L2hloc, L2hrem;
7069 std::vector< unsigned int > L2p;
7070 std::vector< EntityHandle > new_ents;
7078 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_ent_reqs[0], &ind, &status );
7079 if( MPI_SUCCESS != success )
7081 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in owned entity exchange" );
7091 unsigned int base_ind = 3 * ( ind / 3 );
7108 ind / 3, L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents,
true );
7111 std::cout <<
"Failed to unpack entities. Buffer contents:" << std::endl;
7116 if( recv_ent_reqs.size() != 3 *
buffProcs.size() )
7119 recv_remoteh_reqs.resize( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
7120 for( i = recv_ent_reqs.size(); i < 3 *
buffProcs.size(); i += 3 )
7128 &recv_remoteh_reqs[i] );
7129 if( success != MPI_SUCCESS )
7131 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv for remote handles in ghost exchange" );
7134 recv_ent_reqs.resize( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
7148 if( recv_ent_reqs.size() != 3 *
buffProcs.size() )
7151 MB_SET_ERR( MB_FAILURE,
"Requests length doesn't match proc count in entity exchange" );
7154 #ifdef MOAB_HAVE_MPE
7172 if( MPI_SUCCESS != success )
7174 MB_SET_ERR( MB_FAILURE,
"Failed in waitall in exchange owned mesh" );
7182 for( i = 0; i < n_proc; i++ )
7197 recv_remoteh_reqs[3 * ind + 2], &dum_ack_buff, incoming2 );
MB_CHK_SET_ERR( result,
"Failed to send remote handles" );
7206 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_remoteh_reqs[0], &ind, &status );
7207 if( MPI_SUCCESS != success )
7209 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in owned entity exchange" );
7218 unsigned int base_ind = 3 * ( ind / 3 );
7238 #ifdef MOAB_HAVE_MPE
7258 success = MPI_Waitall( 3 *
buffProcs.size(), &recv_remoteh_reqs[0], mult_status );
7259 if( MPI_SUCCESS == success ) success = MPI_Waitall( 3 *
buffProcs.size(), &
sendReqs[0], mult_status );
7261 if( MPI_SUCCESS != success )
7263 MB_SET_ERR( MB_FAILURE,
"Failed in waitall in owned entity exchange" );
7282 if( -1 != other_proc && !
is_iface_proc( *rit, other_proc ) )
continue;
7327 std::vector< unsigned char > pstat( allsent.
size() );
7329 std::vector< EntityHandle > handles( allsent.
size() );
7331 std::vector< int > procs( allsent.
size() );
7341 for( rit = allsent.
begin(), i = 0; rit != allsent.
end(); ++rit, i++ )
7343 if( -1 != procs[i] && 0 == handles[i] )
7344 bad_entities.
insert( *rit );
7352 MB_SET_ERR( result,
"Failed to get sharedps tag data" );
7357 int num_procs = ns_proc - dum_ps;
7360 EntityHandle* ns_handle = std::find( dum_hs, dum_hs + num_procs, 0 );
7361 int num_handles = ns_handle - dum_hs;
7362 assert( num_handles <= num_procs );
7363 if( num_handles != num_procs ) bad_entities.
insert( *rit );
7371 std::vector< EntityHandle >& L1hrem,
7372 std::vector< int >& L1p,
7376 assert( std::find( L1hloc.begin(), L1hloc.end(), (
EntityHandle)0 ) == L1hloc.end() );
7396 unsigned char*& buff_ptr,
7397 std::vector< EntityHandle >& L2hloc,
7398 std::vector< EntityHandle >& L2hrem,
7399 std::vector< unsigned int >& L2p )
7405 unsigned char* buff_proc = buff_ptr;
7406 buff_ptr += num_eh *
sizeof( int );
7407 unsigned char* buff_rem = buff_ptr + num_eh *
sizeof(
EntityHandle );
7411 for(
int i = 0; i < num_eh; i++ )
7423 L2hloc, L2hrem, L2p, new_h );
MB_CHK_SET_ERR( result,
"Didn't get existing entity" );
7429 if( !( hpair[0] && hpair[1] ) )
return MB_FAILURE;
7430 int this_proc = from_proc;
7431 result =
update_remote_data( hpair[0], &this_proc, hpair + 1, 1, 0 );
MB_CHK_SET_ERR( result,
"Failed to set remote data range on sent entities in ghost exchange" );
7442 Range& ghosted_ents )
7447 assert( 0 < num_layers );
7453 if( bridge_dim == -1 )
7463 if( from_ents.
empty() )
continue;
7473 Range tmp_ents, tmp_owned, tmp_notowned;
7475 if( tmp_owned.
empty() )
return result;
7477 tmp_notowned = tmp_owned;
7482 tmp_notowned -= tmp_owned;
7485 if( 1 == addl_ents || 3 == addl_ents )
7490 if( 2 == addl_ents || 3 == addl_ents )
7496 ghosted_ents.
merge( tmp_ents );
7507 std::pair< Range::const_iterator, Range::const_iterator > set_range = sent_ents.
equal_range(
MBENTITYSET );
7527 const std::vector< Tag >& dst_tags,
7528 const Range& entities_in )
7536 std::set< unsigned int > exch_procs;
7541 std::vector< MPI_Request > recv_tag_reqs( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
7543 std::vector< unsigned int >::iterator sit;
7557 if( success != MPI_SUCCESS )
7559 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in ghost exchange" );
7569 if( entities_in.
empty() )
7584 if( !tag_ents.
empty() )
7590 std::vector< Range > tag_ranges;
7591 for( std::vector< Tag >::const_iterator vit = src_tags.begin(); vit != src_tags.end(); ++vit )
7599 tag_ranges.push_back(
intersect( tag_ents, tagged_ents ) );
7603 tag_ranges.push_back( tag_ents );
7615 recv_tag_reqs[3 * ind + 2], &dum_ack_buff, incoming );
MB_CHK_SET_ERR( result,
"Failed to send buffer" );
7622 int index_in_recv_requests;
7624 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_tag_reqs[0], &index_in_recv_requests, &status );
7625 if( MPI_SUCCESS != success )
7627 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in tag exchange" );
7630 ind = index_in_recv_requests / 3;
7638 std::vector< EntityHandle > dum_vec;
7640 recv_tag_reqs[3 * ind + 1],
7641 recv_tag_reqs[3 * ind + 2],
7664 if( MPI_SUCCESS != success )
7666 MB_SET_ERR( MB_FAILURE,
"Failure in waitall in tag exchange" );
7671 assert( src_tags.size() == dst_tags.size() );
7672 if( src_tags != dst_tags )
7674 std::vector< unsigned char > data;
7676 if( entities_in.
empty() )
7679 owned_ents = entities_in;
7682 if( !owned_ents.
empty() )
7685 for(
size_t i = 0; i < src_tags.size(); i++ )
7687 if( src_tags[i] == dst_tags[i] )
continue;
7689 Range tagged_ents( owned_ents );
7698 MB_SET_ERR( MB_FAILURE,
"tag sizes don't match" );
7701 data.resize( sz * tagged_ents.
size() );
7714 const std::vector< Tag >& dst_tags,
7715 const MPI_Op mpi_op,
7716 const Range& entities_in )
7724 if( src_tags.size() != dst_tags.size() )
7726 MB_SET_ERR( MB_FAILURE,
"Source and destination tag handles must be specified for reduce_tags" );
7730 std::vector< Tag >::const_iterator vits, vitd;
7731 int tags_size, tagd_size;
7733 std::vector< unsigned char > vals;
7734 std::vector< int > tags_sizes;
7735 for( vits = src_tags.begin(), vitd = dst_tags.begin(); vits != src_tags.end(); ++vits, ++vitd )
7741 MB_SET_ERR( MB_FAILURE,
"Src/dst tags must have integer, double, or bit data type" );
7745 vals.resize( tags_size );
7748 tags_sizes.push_back( tags_size );
7751 if( *vits == *vitd )
continue;
7754 if( tags_size != tagd_size )
7756 MB_SET_ERR( MB_FAILURE,
"Sizes between src and dst tags don't match" );
7759 if( tags_type != tagd_type )
7761 MB_SET_ERR( MB_FAILURE,
"Src and dst tags must be of same data type" );
7766 std::set< unsigned int > exch_procs;
7771 std::vector< MPI_Request > recv_tag_reqs( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
7773 std::vector< unsigned int >::iterator sit;
7787 if( success != MPI_SUCCESS )
7789 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in ghost exchange" );
7799 if( entities_in.
empty() )
7805 std::vector< Tag >::const_iterator vit = src_tags.
begin(), vit2 = dst_tags.begin();
7806 std::vector< int >::const_iterator vsizes = tags_sizes.begin();
7807 for( ; vit != src_tags.end(); ++vit, ++vit2, ++vsizes )
7809 if( *vit == *vit2 )
continue;
7810 vals.resize(
entities.size() * ( *vsizes ) );
7825 std::vector< Range > tag_ranges;
7826 for( vit = src_tags.begin(); vit != src_tags.end(); ++vit )
7834 tag_ranges.push_back(
intersect( tag_ents, tagged_ents ) );
7837 tag_ranges.push_back( tag_ents );
7848 recv_tag_reqs[3 * ind + 2], &dum_ack_buff, incoming );
MB_CHK_SET_ERR( result,
"Failed to send buffer" );
7855 int index_in_recv_requests;
7857 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_tag_reqs[0], &index_in_recv_requests, &status );
7858 if( MPI_SUCCESS != success )
7860 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in ghost exchange" );
7862 ind = index_in_recv_requests / 3;
7870 std::vector< EntityHandle > dum_vec;
7872 recv_tag_reqs[3 * ind + 1],
7873 recv_tag_reqs[3 * ind + 2],
7896 if( MPI_SUCCESS != success )
7898 MB_SET_ERR( MB_FAILURE,
"Failure in waitall in tag exchange" );
7965 unsigned char tmp_pstatus = 0;
7993 if( create_if_missing )
8013 if( 0 == pc_tag )
return NULL;
8020 return pc_array[index];
8035 if( pc_array[i] ) list.push_back( pc_array[i] );
8053 rval = impl->
tag_get_data( prtn_tag, &prtn, 1, &pcomm_id );
8061 if( !result )
return 0;
8064 rval = impl->
tag_set_data( prtn_tag, &prtn, 1, &pcomm_id );
8086 if( 0 == pc_tag )
return MB_FAILURE;
8089 if(
MB_SUCCESS != result )
return MB_FAILURE;
8090 int id = std::find( pcomm_arr, pcomm_arr +
MAX_SHARING_PROCS,
this ) - pcomm_arr;
8139 ents.
merge( tmp_ents );
8149 unsigned char pstat;
8162 owner = sharing_procs[0];
8164 handle = sharing_handles[0];
8169 owner = sharing_procs[0];
8171 handle = sharing_handles[0];
8185 return count_out < 0 ? MB_FAILURE :
MB_SUCCESS;
8240 if( pSets.
index( set_out ) < 0 )
8261 if( pSets.
index( part_id ) >= 0 )
8263 pSets.
erase( part_id );
8278 int& num_neighbors_out )
8285 num_neighbors_out = 0;
8288 int* parts[2] = { neighbors_out, tmp };
8291 unsigned char pstat;
8294 std::sort( curr, curr + n );
8296 int* k = std::set_union( parts[j], parts[j] + num_neighbors_out, curr, curr + n, parts[1 - j] );
8298 num_neighbors_out = k - parts[j];
8300 if( parts[j] != neighbors_out ) std::copy( parts[j], parts[j] + num_neighbors_out, neighbors_out );
8306 num_neighbors_out = std::remove( neighbors_out, neighbors_out + num_neighbors_out,
id ) - neighbors_out;
8321 while( i != iface_sets_out.
end() )
8323 unsigned char pstat;
8327 if( std::find( part_ids, part_ids + num_parts, *adj_part_id ) - part_ids != num_parts )
8330 i = iface_sets_out.
erase( i );
8342 unsigned char pstat;
8347 if( remote_handle ) *remote_handle = handle;
8354 if( owning_part_id != -1 )
8365 const void* part_id_list = 0;
8368 owning_part_id = ( (
const int*)part_id_list )[0];
8374 const void* handle_list = 0;
8378 *remote_handle = ( (
const EntityHandle*)handle_list )[0];
8384 int& num_part_ids_out,
8390 unsigned char pstat;
8395 if( remote_handles ) remote_handles[0] = entity;
8396 num_part_ids_out = 1;
8403 if( part_ids_out[0] != -1 )
8405 num_part_ids_out = 2;
8412 remote_handles[1] = entity;
8421 for( num_part_ids_out = 0; num_part_ids_out < MAX_SHARING_PROCS && part_ids_out[num_part_ids_out] >= 0;
8422 num_part_ids_out++ )
8426 int my_idx = std::find( part_ids_out, part_ids_out + num_part_ids_out,
proc_config().proc_rank() ) - part_ids_out;
8427 assert( my_idx < num_part_ids_out );
8436 assert( remote_handles[my_idx] == entity );
8447 int num_sharing, tmp_int;
8454 tmp.
owner = tmp_int;
8457 unsigned char pstat;
8460 for(
int j = 0; j < num_sharing; j++ )
8462 if( ent_procs[j] == (
int)
proc_config().proc_rank() )
continue;
8463 tmp.
local = handles[j];
8465 assert( -1 != ind );
8466 if( (
int)send_data.size() < ind + 1 ) send_data.resize( ind + 1 );
8467 send_data[ind].push_back( tmp );
8475 std::vector< std::vector< SharedEntityData > >& result )
8482 std::vector< MPI_Request > recv_req(
buffProcs.size(), MPI_REQUEST_NULL );
8483 std::vector< MPI_Request > send_req(
buffProcs.size(), MPI_REQUEST_NULL );
8486 std::vector< int > sizes_send( num_proc ), sizes_recv( num_proc );
8487 for(
int i = 0; i < num_proc; i++ )
8489 ierr = MPI_Irecv( &sizes_recv[i], 1, MPI_INT, procs[i], tag, cm, &recv_req[i] );
8494 assert( num_proc == (
int)send_data.size() );
8496 result.resize( num_proc );
8497 for(
int i = 0; i < num_proc; i++ )
8499 sizes_send[i] = send_data[i].size();
8500 ierr = MPI_Isend( &sizes_send[i], 1, MPI_INT,
buffProcs[i], tag, cm, &send_req[i] );
8505 std::vector< MPI_Status > stat( num_proc );
8506 ierr = MPI_Waitall( num_proc, &recv_req[0], &stat[0] );
8510 ierr = MPI_Waitall( num_proc, &send_req[0], &stat[0] );
8514 for(
int i = 0; i < num_proc; i++ )
8516 result[i].resize( sizes_recv[i] );
8517 ierr = MPI_Irecv( (
void*)( &( result[i][0] ) ),
sizeof(
SharedEntityData ) * sizes_recv[i], MPI_UNSIGNED_CHAR,
8523 for(
int i = 0; i < num_proc; i++ )
8525 ierr = MPI_Isend( (
void*)( &( send_data[i][0] ) ),
sizeof(
SharedEntityData ) * sizes_send[i],
8526 MPI_UNSIGNED_CHAR,
buffProcs[i], tag, cm, &send_req[i] );
8531 ierr = MPI_Waitall( num_proc, &recv_req[0], &stat[0] );
8535 ierr = MPI_Waitall( num_proc, &send_req[0], &stat[0] );
8544 std::vector< std::vector< SharedEntityData > > shents(
buffProcs.size() ), send_data(
buffProcs.size() );
8578 #ifdef MOAB_HAVE_HDF5
8579 std::ostringstream ent_str;
8597 std::vector< EntityHandle > dum_connect;
8602 std::set< int > tmp_set, vset;
8605 unsigned char pstat;
8606 std::vector< EntityHandle > bad_ents;
8607 std::vector< std::string > errors;
8609 std::set< EntityHandle >::iterator vit;
8616 bad_ents.push_back( *vit );
8617 errors.push_back( std::string(
"Failure getting sharing data." ) );
8624 errors.push_back( std::string(
"Entity should be shared but isn't." ) ), bad =
true;
8628 errors.push_back( std::string(
"Entity not owned but is first proc." ) ), bad =
true;
8633 errors.push_back( std::string(
"Entity owned and multishared but not first proc or not first handle." ) ),
8638 bad_ents.push_back( *vit );
8646 int orig_ps = num_ps;
8648 std::copy( tmp_procs, tmp_procs + num_ps, std::inserter( vset, vset.begin() ) );
8654 bad_ents.push_back( *vit );
8655 errors.push_back( std::string(
"Failed to get connectivity." ) );
8659 for(
int i = 0; i < num_connect; i++ )
8664 bad_ents.push_back( *vit );
8672 std::sort( tmp_procs, tmp_procs + num_ps );
8674 std::set_intersection( tmp_procs, tmp_procs + num_ps, vset.begin(), vset.end(),
8675 std::inserter( tmp_set, tmp_set.end() ) );
8676 vset.swap( tmp_set );
8677 if( vset.empty() )
break;
8682 std::set_intersection( tmp_procs, tmp_procs + num_ps, vset.begin(), vset.end(),
8683 std::inserter( tmp_set, tmp_set.end() ) );
8684 if( orig_ps != (
int)tmp_set.size() )
8686 errors.push_back( std::string(
"Vertex proc set not same size as entity proc set." ) );
8687 bad_ents.push_back( *vit );
8688 for(
int i = 0; i < num_connect; i++ )
8690 bad_ents.push_back( connect[i] );
8691 errors.push_back( std::string(
"vertex in connect" ) );
8696 if( !bad_ents.empty() )
8698 std::cout <<
"Found bad entities in check_local_shared, proc rank " <<
procConfig.
proc_rank() <<
","
8700 std::vector< std::string >::iterator sit;
8701 std::vector< EntityHandle >::iterator rit;
8702 for( rit = bad_ents.begin(), sit = errors.begin(); rit != bad_ents.end(); ++rit, ++sit )
8705 std::cout <<
"Reason: " << *sit << std::endl;
8717 std::vector< std::vector< std::vector< SharedEntityData > > > shents, send_data;
8721 send_data.resize( num_pcs );
8722 for(
int p = 0; p < num_pcs; p++ )
8725 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
8730 shents.resize( num_pcs );
8731 for(
int p = 0; p < num_pcs; p++ )
8732 shents[p].resize( pcs[p]->
buffProcs.size() );
8734 for(
int p = 0; p < num_pcs; p++ )
8736 for(
unsigned int idx_p = 0; idx_p < pcs[p]->
buffProcs.size(); idx_p++ )
8741 assert( -1 != top_idx_p );
8742 shents[to_p][top_idx_p] = send_data[p][idx_p];
8746 for(
int p = 0; p < num_pcs; p++ )
8748 std::ostringstream ostr;
8749 ostr <<
"Processor " << p <<
" bad entities:";
8751 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
8758 const char* prefix )
8765 std::vector< EntityHandle > dum_vec;
8768 Range bad_ents, local_shared;
8769 std::vector< SharedEntityData >::iterator vit;
8770 unsigned char tmp_pstat;
8771 for(
unsigned int i = 0; i < shents.size(); i++ )
8776 for( vit = shents[i].begin(); vit != shents[i].end(); ++vit )
8778 EntityHandle localh = vit->local, remoteh = vit->remote, dumh;
8779 local_shared.
erase( localh );
8785 bad_ents.
insert( localh );
8788 if( !local_shared.
empty() ) bad_ents.
merge( local_shared );
8791 if( !bad_ents.
empty() )
8793 if( prefix ) std::cout << prefix << std::endl;
8805 const bool owned_filter )
8807 shared_ents.
clear();
8834 if( -1 != other_proc )
8844 for(
unsigned int i = 0; i < exchange_ents.size(); i++ )
8846 Range* ents = exchange_ents[i];
8847 int num_ents = ents->
size();
8850 for(
int n = 0; n < num_ents; n++ )
8883 unsigned& owner_rank,
8918 int root_proc_rank )
8921 int bytes_per_tag = 0;
8925 int sz_buffer =
sizeof( int ) + gather_ents.
size() * (
sizeof( int ) + bytes_per_tag );
8926 void* senddata = malloc( sz_buffer );
8927 ( (
int*)senddata )[0] = (int)gather_ents.
size();
8928 int* ptr_int = (
int*)senddata + 1;
8931 ptr_int = (
int*)( senddata ) + 1 + gather_ents.
size();
8934 std::vector< int > displs(
proc_config().proc_size(), 0 );
8935 MPI_Gather( &sz_buffer, 1, MPI_INT, &displs[0], 1, MPI_INT, root_proc_rank,
comm() );
8936 std::vector< int > recvcnts(
proc_config().proc_size(), 0 );
8937 std::copy( displs.begin(), displs.end(), recvcnts.begin() );
8938 std::partial_sum( displs.begin(), displs.end(), displs.begin() );
8939 std::vector< int >::iterator lastM1 = displs.end() - 1;
8940 std::copy_backward( displs.begin(), lastM1, displs.end() );
8944 if( (
int)
rank() != root_proc_rank )
8945 MPI_Gatherv( senddata, sz_buffer, MPI_BYTE, NULL, NULL, NULL, MPI_BYTE, root_proc_rank,
comm() );
8951 void* recvbuf = malloc( recvbuffsz );
8952 MPI_Gatherv( senddata, sz_buffer, MPI_BYTE, recvbuf, &recvcnts[0], &displs[0], MPI_BYTE, root_proc_rank,
8958 bool multiple_sequences =
false;
8959 if( gents.
psize() > 1 )
8960 multiple_sequences =
true;
8965 assert( NULL != gvals );
8966 assert( count > 0 );
8967 if( (
size_t)count != gents.
size() )
8969 multiple_sequences =
true;
8975 if( multiple_sequences )
8977 gvals = malloc( gents.
size() * bytes_per_tag );
8978 assert( NULL != gvals );
8981 for(
int i = 0; i != (int)
size(); i++ )
8983 int numents = *(
int*)( ( (
char*)recvbuf ) + displs[i] );
8984 int* id_ptr = (
int*)( ( (
char*)recvbuf ) + displs[i] +
sizeof(
int ) );
8985 char* val_ptr = (
char*)( id_ptr + numents );
8986 for(
int j = 0; j != numents; j++ )
8988 int idx = id_ptr[j];
8989 memcpy( (
char*)gvals + ( idx - 1 ) * bytes_per_tag, val_ptr + j * bytes_per_tag, bytes_per_tag );
8998 if( multiple_sequences )
9001 size_t start_idx = 0;
9002 while( iter != gents.
end() )
9007 assert( NULL != ptr );
9008 assert( count > 0 );
9009 memcpy( (
char*)ptr, (
char*)gvals + start_idx * bytes_per_tag, bytes_per_tag * count );
9014 assert( start_idx == gents.
size() );
9037 Range& shared_edges_owned,
9038 std::vector< std::vector< EntityHandle >* >& extraNodesVec,
9049 std::set< unsigned int > exch_procs;
9054 std::vector< MPI_Request > recv_intx_reqs( 3 *
buffProcs.size(), MPI_REQUEST_NULL );
9055 std::vector< unsigned int >::iterator sit;
9069 if( success != MPI_SUCCESS )
9071 MB_SET_ERR( MB_FAILURE,
"Failed to post irecv in settle intersection point" );
9103 std::vector< EntityHandle > dum_remote_edges( edges_to_send.
size() );
9113 std::vector< EntityHandle > dum_vec;
9116 count +=
sizeof( int ) * (
int)edges_to_send.
size();
9122 std::vector< EntityHandle >& intx_nodes = *( extraNodesVec[indx] );
9123 count += (int)intx_nodes.size() * 3 *
sizeof( double );
9128 PACK_EH( buff->
buff_ptr, &dum_remote_edges[0], dum_remote_edges.size() );
9134 std::vector< EntityHandle >& intx_nodes = *( extraNodesVec[indx] );
9138 buff->
buff_ptr += 3 *
sizeof( double ) * intx_nodes.size();
9146 recv_intx_reqs[3 * ind + 2], &dum_ack_buff, incoming );
MB_CHK_SET_ERR( result,
"Failed to send buffer" );
9153 int index_in_recv_requests;
9155 success = MPI_Waitany( 3 *
buffProcs.size(), &recv_intx_reqs[0], &index_in_recv_requests, &status );
9156 if( MPI_SUCCESS != success )
9158 MB_SET_ERR( MB_FAILURE,
"Failed in waitany in ghost exchange" );
9161 ind = index_in_recv_requests / 3;
9170 recv_intx_reqs[3 * ind + 1],
9171 recv_intx_reqs[3 * ind + 2],
9188 std::vector< EntityHandle > rec_edges;
9189 rec_edges.resize( num_edges );
9191 for(
int i = 0; i < num_edges; i++ )
9195 std::vector< EntityHandle >& intx_nodes = *( extraNodesVec[indx] );
9199 std::vector< double > pos_from_owner;
9200 pos_from_owner.resize( 3 * nverts );
9202 std::vector< double > current_positions( 3 * intx_nodes.size() );
9203 result =
mbImpl->
get_coords( &intx_nodes[0], intx_nodes.size(), ¤t_positions[0] );
MB_CHK_SET_ERR( result,
"Failed to get current positions" );
9205 for(
int k = 0; k < (int)intx_nodes.size(); k++ )
9207 double* pk = ¤t_positions[3 * k];
9210 for(
int j = 0; j < nverts && !found; j++ )
9212 double* pj = &pos_from_owner[3 * j];
9213 double dist2 = ( pk[0] - pj[0] ) * ( pk[0] - pj[0] ) + ( pk[1] - pj[1] ) * ( pk[1] - pj[1] ) +
9214 ( pk[2] - pj[2] ) * ( pk[2] - pj[2] );
9227 std::cout <<
" pk:" << pk[0] <<
" " << pk[1] <<
" " << pk[2] <<
" not found \n";
9229 result = MB_FAILURE;
9233 result =
mbImpl->
set_coords( &intx_nodes[0], (
int)intx_nodes.size(), ¤t_positions[0] );
MB_CHK_SET_ERR( result,
"Failed to set new current positions" );
9248 if( MPI_SUCCESS != success )
9250 MB_SET_ERR( MB_FAILURE,
"Failure in waitall in tag exchange" );
9264 unsigned char pstat;
9267 unsigned int num_ps;
9277 if( rval !=
MB_SUCCESS || num_ps == 0 )
continue;
9279 for(
unsigned int p = 0; p < num_ps; p++ )
9281 ents_to_delete.
vi_wr[i] = tmp_procs[p];
9282 ents_to_delete.
vul_wr[i] = (
unsigned long)tmp_handles[p];
9284 ents_to_delete.
inc_n();
9291 rval = cd->gs_transfer( 1, ents_to_delete, 0 );
MB_CHK_SET_ERR( rval,
"Error in tuple transfer" );
9294 unsigned int received = ents_to_delete.
get_n();
9295 for( i = 0; i < received; i++ )
9298 unsigned long valrec = ents_to_delete.
vul_rd[i];
9303 std::set< EntityHandle > good_ents;
9304 for( std::set< EntityHandle >::iterator sst =
sharedEnts.begin(); sst !=
sharedEnts.end(); sst++ )
9307 int index = to_delete.
index( eh );
9308 if( -1 == index ) good_ents.insert( eh );
9318 std::ostringstream str;
9320 #define ppstat( a, b ) \
9322 if( pstat & ( a ) ) \
9324 if( num ) str << ", "; \
9343 std::cout << str.c_str() << std::endl;
9350 std::vector< std::vector< SharedEntityData > > shents(
buffProcs.size() ), send_data(
buffProcs.size() );
9390 unsigned char pstat;
9399 for(
int j = 1; j < num_sharing; j++ )
9402 int send_to_proc = ent_procs[j];
9403 tmp.
local = handles[j];
9405 assert( -1 != ind );
9406 for(
int k = 1; k < num_sharing; k++ )
9409 if( j == k )
continue;
9411 tmp.
owner = ent_procs[k];
9412 send_data[ind].push_back( tmp );
9420 for(
size_t i = 0; i < shents.size(); i++ )
9422 std::vector< SharedEntityData >& shEnts = shents[i];
9423 for(
size_t j = 0; j < shEnts.size(); j++ )
9429 unsigned char pstat;
9434 int proc_remote = tmp.
owner;
9435 if( std::find( ent_procs, ent_procs + num_sharing, proc_remote ) == ent_procs + num_sharing )
9440 std::cout <<
"THIN GHOST: we did not find on proc " <<
rank() <<
" for shared ent " << eh
9441 <<
" the proc " << proc_remote <<
"\n";
9445 handles[num_sharing] = tmp.
remote;
9446 handles[num_sharing + 1] = 0;
9447 ent_procs[num_sharing] = tmp.
owner;
9448 ent_procs[num_sharing + 1] = -1;
9451 if( 2 == num_sharing )