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 );
273 std::string& partition_tag_name,
274 std::vector< int >& partition_tag_vals,
276 bool partition_by_rank,
277 std::vector< int >& pa_vec,
280 const Tag* file_id_tag,
281 const int reader_rank,
283 const int resolve_dim,
284 const int shared_dim,
286 const int bridge_dim,
287 const int num_layers,
288 const int addl_ents )
294 Tag file_set_tag = 0;
297 Range other_file_sets, file_sets;
300 std::vector< double > act_times( pa_vec.size() + 1 );
301 std::vector< int >::iterator vit;
303 act_times[0] = MPI_Wtime();
307 if( !file_set_ptr || !( *file_set_ptr ) )
313 file_set = *file_set_ptr;
317 bool use_id_tag =
false;
320 for( i = 1, vit = pa_vec.begin(); vit != pa_vec.end(); ++vit, i++ )
329 for( j = 0; j < num_files; j++ )
336 tmp_result = impl->
serial_load_file( file_names[j], &new_file_set, opts, subset_list, file_id_tag );
341 assert( 0 != new_file_set );
345 all_ents.
insert( new_file_set );
383 file_id_tag = &id_tag;
391 if( partition_by_rank )
393 assert( partition_tag_vals.empty() );
401 if( !partition_tag_vals.empty() )
407 std::vector< ReaderIface::IDTag > subset;
410 std::vector< ReaderIface::IDTag > tmplist( subset_list->
tag_list,
412 tmplist.push_back( parts );
413 subset.swap( tmplist );
422 tmp_result = impl->
serial_load_file( *file_names, &file_set, opts, &sl, file_id_tag );
425 if( !partition_tag_name.empty() )
451 entities.
insert( file_set );
455 myDebug.
tprint( 1,
"create trivial partition, for higher dim entities.\n" );
460 if( hi_dim_ents.
empty() )
MB_SET_ERR( MB_FAILURE,
"there are no elements of dim 1-3" );
462 size_t num_hi_ents = hi_dim_ents.
size();
470 MB_CHK_SET_ERR( tmp_result,
"Can't create trivial partition tag" );
473 size_t nPartEnts = num_hi_ents / num_parts;
476 int iextra = num_hi_ents % num_parts;
478 for(
int k = 0; k < (int)num_parts; k++ )
484 entities.
insert( part_set );
489 size_t num_ents_in_part = nPartEnts;
490 if( i < iextra ) num_ents_in_part++;
491 for(
size_t i1 = 0; i1 < num_ents_in_part; i1++, itr++ )
494 MB_CHK_SET_ERR( tmp_result,
"Can't add entities to trivial part " << k );
495 myDebug.
tprintf( 1,
"create trivial part %d with %lu entities \n", k, num_ents_in_part );
497 MB_CHK_SET_ERR( tmp_result,
"Can't add trivial part to file set " << k );
515 std::cerr <<
"Bcast done; entities:" << std::endl;
531 std::cerr <<
"Delete nonlocal done; entities:" << std::endl;
588 myDebug.
tprint( 1,
"Augmenting sets with ghost entities.\n" );
611 MB_SET_ERR( MB_FAILURE,
"Unexpected parallel action" );
619 if( cputime ) act_times[i] = MPI_Wtime();
630 for( i = pa_vec.size(); i > 0; i-- )
631 act_times[i] -= act_times[i - 1];
634 act_times[0] = MPI_Wtime() - act_times[0];
638 MPI_Reduce( act_times.data(), 0, pa_vec.size() + 1, MPI_DOUBLE, MPI_MAX, 0,
643 #if ( MPI_VERSION >= 2 )
644 MPI_Reduce( MPI_IN_PLACE, act_times.data(), pa_vec.size() + 1, MPI_DOUBLE, MPI_MAX, 0,
648 std::vector< double > act_times_tmp( pa_vec.size() + 1 );
649 MPI_Reduce( act_times.data(), act_times_tmp.data(), pa_vec.size() + 1, MPI_DOUBLE, MPI_MAX, 0,
651 act_times = act_times_tmp;
653 std::cout <<
"Parallel Read times: " << std::endl;
654 for( i = 1, vit = pa_vec.begin(); vit != pa_vec.end(); ++vit, i++ )
656 std::cout <<
" " << act_times[0] <<
" PARALLEL TOTAL" << std::endl;
664 std::vector< int >& ptag_vals,
668 Range partition_sets;
672 MB_CHK_SET_ERR( result,
"Failed getting tag handle in delete_nonlocal_entities" );
675 MB_CHK_SET_ERR( result,
"Failed to get sets with partition-type tag" );
680 if( !ptag_vals.empty() )
686 MB_CHK_SET_ERR( result,
"Failed to get tag data for partition vals tag" );
687 for( std::vector< int >::iterator pit = tag_vals.begin(); pit != tag_vals.end(); ++pit )
689 std::vector< int >::iterator pit2 = std::find( ptag_vals.begin(), ptag_vals.end(), *pit );
702 MB_SET_ERR( MB_FAILURE,
"Too few parts; P = " << proc_rk <<
", tag = " << ptag
711 if( proc_rk < (
int)num_leftover )
714 begin_set = num_sets * proc_rk;
717 begin_set = proc_rk * num_sets + num_leftover;
719 for(
unsigned int i = 0; i < num_sets; i++ )
742 bool tag_created =
false;
745 MB_CHK_SET_ERR( result,
"Trouble getting PARALLEL_PARTITION tag" );
752 int* proc_rk_ptr = &proc_rk;
759 MB_CHK_SET_ERR( result,
"Trouble deleting data of PARALLEL_PARTITION tag" );
770 MB_CHK_SET_ERR( result,
"Trouble setting data to PARALLEL_PARTITION tag" );
781 Range partition_ents, all_sets;
799 Range deletable_ents =
subtract( file_ents, partition_ents );
805 myDebug.
tprint( 2,
"Removing deletable entities from keepable sets.\n" );
824 if( !deletable_sets.
empty() )
827 MB_CHK_SET_ERR( result,
"Failure deleting sets in delete_nonlocal_entities" );
830 deletable_ents -= deletable_sets;
834 myDebug.
print( 2,
"Deletable entities: ", deletable_ents );
837 if( !deletable_ents.
empty() )
840 MB_CHK_SET_ERR( result,
"Failure deleting entities in delete_nonlocal_entities" );