21 const bool debug =
false;
26 "PARALLEL DELETE NONLOCAL",
27 "PARALLEL CHECK_GIDS_SERIAL",
28 "PARALLEL GET_FILESET_ENTS",
29 "PARALLEL RESOLVE_SHARED_ENTS",
30 "PARALLEL EXCHANGE_GHOSTS",
31 "PARALLEL RESOLVE_SHARED_SETS",
32 "PARALLEL_AUGMENT_SETS_WITH_GHOSTS",
33 "PARALLEL PRINT_PARALLEL",
34 "PARALLEL_CREATE_TRIVIAL_PARTITION",
35 "PARALLEL_CORRECT_THIN_GHOST_LAYERS" };
40 : mbImpl( impl ), myPcomm( pc ), myDebug(
"ReadPara", std::cerr )
59 const Tag* file_id_tag )
72 if( MB_FAILURE == result )
74 MB_SET_ERR( MB_FAILURE,
"Unexpected value for 'PARALLEL' option" );
83 std::string partition_tag_name;
84 result = opts.
get_option(
"PARTITION", partition_tag_name );
88 partition_tag_name =
"";
103 std::vector< int > partition_tag_vals;
107 bool create_trivial_partition =
false;
108 if( partition_tag_name == std::string(
"TRIVIAL" ) )
115 bool cputime =
false;
120 bool print_parallel =
false;
122 if(
MB_SUCCESS == result ) print_parallel =
true;
125 std::string ghost_str;
126 int bridge_dim, ghost_dim = -1, num_layers, addl_ents = 0;
136 int num_fields = sscanf( ghost_str.c_str(),
"%d.%d.%d.%d", &ghost_dim, &bridge_dim, &num_layers, &addl_ents );
139 MB_SET_ERR( MB_FAILURE,
"Didn't read 3 fields from PARALLEL_GHOSTS string" );
144 std::string shared_str;
145 int resolve_dim = -2, shared_dim = -1;
146 result = opts.
get_str_option(
"PARALLEL_RESOLVE_SHARED_ENTS", shared_str );
154 int num_fields = sscanf( shared_str.c_str(),
"%d.%d", &resolve_dim, &shared_dim );
155 if( 2 != num_fields )
157 MB_SET_ERR( MB_FAILURE,
"Didn't read 2 fields from PARALLEL_RESOLVE_SHARED_ENTS string" );
162 bool skip_augment =
false;
164 if(
MB_SUCCESS == result ) skip_augment =
true;
166 bool correct_thin_ghosts =
false;
168 if(
MB_SUCCESS == result ) correct_thin_ghosts =
true;
177 MB_SET_ERR( MB_FAILURE,
"Unexpected value for 'MPI_IO_RANK' option" );
181 std::vector< int > pa_vec;
184 bool partition_by_rank =
false;
187 partition_by_rank =
true;
188 if( !partition_tag_vals.empty() )
190 MB_SET_ERR( MB_FAILURE,
"Cannot specify both PARTITION_VALS and PARTITION_BY_RANK" );
197 if( factor_seq < 1. )
MB_SET_ERR( MB_FAILURE,
"cannot have sequence factor less than 1." );
200 switch( parallel_mode )
243 MB_SET_ERR( MB_FAILURE,
"Unexpected parallel read mode" );
250 if( -2 != resolve_dim )
259 result =
load_file( file_names, num_files, file_set, parallel_mode, partition_tag_name, partition_tag_vals, distrib,
260 partition_by_rank, pa_vec, opts, subset_list, file_id_tag, reader_rank, cputime, resolve_dim,
261 shared_dim, ghost_dim, bridge_dim, num_layers, addl_ents );
MB_CHK_ERR( result );
272 std::string& partition_tag_name,
273 std::vector< int >& partition_tag_vals,
275 bool partition_by_rank,
276 std::vector< int >& pa_vec,
279 const Tag* file_id_tag,
280 const int reader_rank,
282 const int resolve_dim,
283 const int shared_dim,
285 const int bridge_dim,
286 const int num_layers,
287 const int addl_ents )
293 Tag file_set_tag = 0;
296 Range other_file_sets, file_sets;
299 std::vector< double > act_times( pa_vec.size() + 1 );
300 std::vector< int >::iterator vit;
302 act_times[0] = MPI_Wtime();
306 if( !file_set_ptr || !( *file_set_ptr ) )
311 file_set = *file_set_ptr;
315 bool use_id_tag =
false;
318 for( i = 1, vit = pa_vec.begin(); vit != pa_vec.end(); ++vit, i++ )
327 for( j = 0; j < num_files; j++ )
333 tmp_result = impl->
serial_load_file( file_names[j], &new_file_set, opts, subset_list, file_id_tag );
338 assert( 0 != new_file_set );
342 all_ents.
insert( new_file_set );
380 file_id_tag = &id_tag;
388 if( partition_by_rank )
390 assert( partition_tag_vals.empty() );
398 if( !partition_tag_vals.empty() )
404 std::vector< ReaderIface::IDTag > subset;
407 std::vector< ReaderIface::IDTag > tmplist( subset_list->
tag_list,
409 tmplist.push_back( parts );
410 subset.swap( tmplist );
419 tmp_result = impl->
serial_load_file( *file_names, &file_set, opts, &sl, file_id_tag );
422 if( !partition_tag_name.empty() )
452 myDebug.
tprint( 1,
"create trivial partition, for higher dim entities.\n" );
455 if( hi_dim_ents.
empty() ) hi_dim_ents =
entities.subset_by_dimension( 2 );
456 if( hi_dim_ents.
empty() ) hi_dim_ents =
entities.subset_by_dimension( 1 );
457 if( hi_dim_ents.
empty() )
MB_SET_ERR( MB_FAILURE,
"there are no elements of dim 1-3" );
459 size_t num_hi_ents = hi_dim_ents.
size();
469 size_t nPartEnts = num_hi_ents / num_parts;
472 int iextra = num_hi_ents % num_parts;
474 for(
int k = 0; k < (int)num_parts; k++ )
483 size_t num_ents_in_part = nPartEnts;
484 if( i < iextra ) num_ents_in_part++;
485 for(
size_t i1 = 0; i1 < num_ents_in_part; i1++, itr++ )
488 myDebug.
tprintf( 1,
"create trivial part %d with %lu entities \n", k, num_ents_in_part );
507 std::cerr <<
"Bcast done; entities:" << std::endl;
523 std::cerr <<
"Delete nonlocal done; entities:" << std::endl;
580 myDebug.
tprint( 1,
"Augmenting sets with ghost entities.\n" );
603 MB_SET_ERR( MB_FAILURE,
"Unexpected parallel action" );
611 if( cputime ) act_times[i] = MPI_Wtime();
621 for( i = pa_vec.size(); i > 0; i-- )
622 act_times[i] -= act_times[i - 1];
625 act_times[0] = MPI_Wtime() - act_times[0];
629 MPI_Reduce( &act_times[0], 0, pa_vec.size() + 1, MPI_DOUBLE, MPI_MAX, 0,
634 #if( MPI_VERSION >= 2 )
635 MPI_Reduce( MPI_IN_PLACE, &act_times[0], pa_vec.size() + 1, MPI_DOUBLE, MPI_MAX, 0,
639 std::vector< double > act_times_tmp( pa_vec.size() + 1 );
640 MPI_Reduce( &act_times[0], &act_times_tmp[0], pa_vec.size() + 1, MPI_DOUBLE, MPI_MAX, 0,
642 act_times = act_times_tmp;
644 std::cout <<
"Parallel Read times: " << std::endl;
645 for( i = 1, vit = pa_vec.begin(); vit != pa_vec.end(); ++vit, i++ )
647 std::cout <<
" " << act_times[0] <<
" PARALLEL TOTAL" << std::endl;
655 std::vector< int >& ptag_vals,
659 Range partition_sets;
669 if( !ptag_vals.empty() )
675 for( std::vector< int >::iterator pit = tag_vals.begin(); pit != tag_vals.end(); ++pit )
677 std::vector< int >::iterator pit2 = std::find( ptag_vals.begin(), ptag_vals.end(), *pit );
690 MB_SET_ERR( MB_FAILURE,
"Too few parts; P = " << proc_rk <<
", tag = " << ptag
699 if( proc_rk < (
int)num_leftover )
702 begin_set = num_sets * proc_rk;
705 begin_set = proc_rk * num_sets + num_leftover;
707 for(
unsigned int i = 0; i < num_sets; i++ )
729 bool tag_created =
false;
731 &tag_created );
MB_CHK_SET_ERR( result,
"Trouble getting PARALLEL_PARTITION tag" );
738 int* proc_rk_ptr = &proc_rk;
740 1, tagged_sets );
MB_CHK_SET_ERR( result,
"Trouble getting tagged sets" );
764 Range partition_ents, all_sets;
780 Range deletable_ents =
subtract( file_ents, partition_ents );
786 myDebug.
tprint( 2,
"Removing deletable entities from keepable sets.\n" );
803 if( !deletable_sets.
empty() )
808 deletable_ents -= deletable_sets;
812 myDebug.
print( 2,
"Deletable entities: ", deletable_ents );
815 if( !deletable_ents.
empty() )