MOAB: Mesh Oriented datABase  (version 5.5.0)
migrate_nontrivial.cpp File Reference
#include "moab/ParallelComm.hpp"
#include "moab/Core.hpp"
#include "moab_mpi.h"
#include "moab/iMOAB.h"
#include "TestUtil.hpp"
#include "moab/ProgOptions.hpp"
+ Include dependency graph for migrate_nontrivial.cpp:

Go to the source code of this file.

Macros

#define RUN_TEST_ARG2(A, B)   run_test( &( A ), #A, B )
 
#define CHECKRC(rc, message)
 

Functions

int is_any_proc_error (int is_my_error)
 
int run_test (ErrorCode(*func)(const char *), const char *func_name, const char *file_name)
 
ErrorCode migrate_graph (const char *filename)
 
ErrorCode migrate_geom (const char *filename)
 
ErrorCode migrate_trivial (const char *filename)
 
ErrorCode migrate_smart (const char *filename, const char *outfile, int partMethod)
 
int main (int argc, char *argv[])
 

Variables

int rank
 
int size
 
int ierr
 
int compid1
 
int compid2
 
int nghlay
 
std::vector< int > groupTasks
 
int startG1
 
int startG2
 
int endG1
 
int endG2
 
MPI_Comm jcomm
 
MPI_Group jgroup
 

Macro Definition Documentation

◆ CHECKRC

#define CHECKRC (   rc,
  message 
)
Value:
if( 0 != ( rc ) ) \
{ \
printf( "Error: %s\n", message ); \
return MB_FAILURE; \
}

Definition at line 30 of file migrate_nontrivial.cpp.

◆ RUN_TEST_ARG2

#define RUN_TEST_ARG2 (   A,
 
)    run_test( &( A ), #A, B )

Definition at line 24 of file migrate_nontrivial.cpp.

Function Documentation

◆ is_any_proc_error()

int is_any_proc_error ( int  is_my_error)

Definition at line 37 of file migrate_nontrivial.cpp.

38 {
39  int result = 0;
40  int err = MPI_Allreduce( &is_my_error, &result, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD );
41  return err || result;
42 }

References MPI_COMM_WORLD.

Referenced by run_test().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 207 of file migrate_nontrivial.cpp.

208 {
209  MPI_Init( &argc, &argv );
210  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
211  MPI_Comm_size( MPI_COMM_WORLD, &size );
212 
213  MPI_Comm_dup( MPI_COMM_WORLD, &jcomm );
214  MPI_Comm_group( jcomm, &jgroup );
215 
216  ProgOptions opts;
217  int typeTest = 3;
218  // std::string inputfile, outfile("out.h5m"), netcdfFile, variable_name, sefile_name;
219  std::string filename;
220  filename = TestDir + "unittest/field1.h5m";
221  startG1 = 0;
222  startG2 = 0;
223  endG1 = 0;
224  endG2 = 1;
225 
226  opts.addOpt< std::string >( "file,f", "source file", &filename );
227 
228  opts.addOpt< int >( "startSender,a", "start task for source layout", &startG1 );
229  opts.addOpt< int >( "endSender,b", "end task for source layout", &endG1 );
230  opts.addOpt< int >( "startRecv,c", "start task for receiver layout", &startG2 );
231  opts.addOpt< int >( "endRecv,d", "end task for receiver layout", &endG2 );
232 
233  opts.addOpt< int >( "typeTest,t", "test types (0 - trivial, 1 graph, 2 geom, 3 both graph and geometry",
234  &typeTest );
235 
236  opts.parseCommandLine( argc, argv );
237 
238  if( rank == 0 )
239  {
240  std::cout << " input file : " << filename << "\n";
241  std::cout << " sender on tasks: " << startG1 << ":" << endG1 << "\n";
242  std::cout << " receiver on tasks: " << startG2 << ":" << endG2 << "\n";
243  std::cout << " type migrate: " << typeTest << " (0 - trivial, 1 graph , 2 geom, 3 both graph and geom ) \n";
244  }
245 
246  int num_errors = 0;
247 
248  if( 0 == typeTest ) num_errors += RUN_TEST_ARG2( migrate_trivial, filename.c_str() );
249  if( 3 == typeTest || 1 == typeTest ) num_errors += RUN_TEST_ARG2( migrate_graph, filename.c_str() );
250  if( 3 == typeTest || 2 == typeTest ) num_errors += RUN_TEST_ARG2( migrate_geom, filename.c_str() );
251 
252  if( rank == 0 )
253  {
254  if( !num_errors )
255  std::cout << "All tests passed" << std::endl;
256  else
257  std::cout << num_errors << " TESTS FAILED!" << std::endl;
258  }
259 
260  MPI_Group_free( &jgroup );
261  MPI_Comm_free( &jcomm );
262  MPI_Finalize();
263  return num_errors;
264 }

References ProgOptions::addOpt(), endG1, endG2, filename, jcomm, jgroup, migrate_geom(), migrate_graph(), migrate_trivial(), MPI_COMM_WORLD, ProgOptions::parseCommandLine(), rank, RUN_TEST_ARG2, size, startG1, and startG2.

◆ migrate_geom()

ErrorCode migrate_geom ( const char *  filename)

Definition at line 197 of file migrate_nontrivial.cpp.

198 {
199  return migrate_smart( filename, "migrate_geom.h5m", 2 );
200 }

References filename, and migrate_smart().

Referenced by main().

◆ migrate_graph()

ErrorCode migrate_graph ( const char *  filename)

Definition at line 192 of file migrate_nontrivial.cpp.

193 {
194  return migrate_smart( filename, "migrate_graph.h5m", 1 );
195 }

References filename, and migrate_smart().

Referenced by main().

◆ migrate_smart()

ErrorCode migrate_smart ( const char *  filename,
const char *  outfile,
int  partMethod 
)

Definition at line 76 of file migrate_nontrivial.cpp.

77 {
78  // first create MPI groups
79 
80  std::string filen( filename );
81  MPI_Group group1, group2;
82  groupTasks.resize( endG1 - startG1 + 1 );
83  for( int i = startG1; i <= endG1; i++ )
84  groupTasks[i - startG1] = i;
85 
86  ierr = MPI_Group_incl( jgroup, endG1 - startG1 + 1, &groupTasks[0], &group1 );
87  CHECKRC( ierr, "can't create group1" )
88 
89  groupTasks.resize( endG2 - startG2 + 1 );
90  for( int i = startG2; i <= endG2; i++ )
91  groupTasks[i - startG2] = i;
92 
93  ierr = MPI_Group_incl( jgroup, endG2 - startG2 + 1, &groupTasks[0], &group2 );
94  CHECKRC( ierr, "can't create group2" )
95 
96  // create 2 communicators, one for each group
97  int tagcomm1 = 1, tagcomm2 = 2;
98  int context_id = -1; // plain migrate, default context
99  MPI_Comm comm1, comm2;
100  ierr = MPI_Comm_create_group( jcomm, group1, tagcomm1, &comm1 );
101  CHECKRC( ierr, "can't create comm1" )
102 
103  ierr = MPI_Comm_create_group( jcomm, group2, tagcomm2, &comm2 );
104  CHECKRC( ierr, "can't create comm2" )
105 
106  ierr = iMOAB_Initialize( 0, 0 ); // not really needed anything from argc, argv, yet; maybe we should
107  CHECKRC( ierr, "can't initialize iMOAB" )
108 
109  // give some dummy values to component ids, just to differentiate between them
110  // the par comm graph is unique between components
111  compid1 = 4;
112  compid2 = 7;
113 
114  int appID1;
115  iMOAB_AppID pid1 = &appID1;
116  int appID2;
117  iMOAB_AppID pid2 = &appID2;
118 
119  if( comm1 != MPI_COMM_NULL )
120  {
121  ierr = iMOAB_RegisterApplication( "APP1", &comm1, &compid1, pid1 );
122  CHECKRC( ierr, "can't register app1 " )
123  }
124  if( comm2 != MPI_COMM_NULL )
125  {
126  ierr = iMOAB_RegisterApplication( "APP2", &comm2, &compid2, pid2 );
127  CHECKRC( ierr, "can't register app2 " )
128  }
129 
130  if( comm1 != MPI_COMM_NULL )
131  {
132 
133  std::string readopts( "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS" );
134 
135  nghlay = 0;
136 
137  ierr = iMOAB_LoadMesh( pid1, filen.c_str(), readopts.c_str(), &nghlay );
138  CHECKRC( ierr, "can't load mesh " )
139  ierr = iMOAB_SendMesh( pid1, &jcomm, &group2, &compid2, &partMethod ); // send to component 2
140  CHECKRC( ierr, "cannot send elements" )
141 #ifdef GRAPH_INFO
142  int is_sender = 1;
143  int context = compid2;
144  iMOAB_DumpCommGraph( pid1, &context, &is_sender, "MigrateS" );
145 #endif
146  }
147 
148  if( comm2 != MPI_COMM_NULL )
149  {
150  ierr = iMOAB_ReceiveMesh( pid2, &jcomm, &group1, &compid1 ); // receive from component 1
151  CHECKRC( ierr, "cannot receive elements" )
152  std::string wopts;
153  wopts = "PARALLEL=WRITE_PART;";
154  ierr = iMOAB_WriteMesh( pid2, outfile, wopts.c_str() );
155  CHECKRC( ierr, "cannot write received mesh" )
156 #ifdef GRAPH_INFO
157  int is_sender = 0;
158  int context = compid1;
159  iMOAB_DumpCommGraph( pid2, &context, &is_sender, "MigrateR" );
160 #endif
161  }
162 
163  MPI_Barrier( jcomm );
164 
165  // we can now free the sender buffers
166  context_id = compid2; // even for default migrate, be more explicit
167  if( comm1 != MPI_COMM_NULL ) ierr = iMOAB_FreeSenderBuffers( pid1, &context_id );
168 
169  if( comm2 != MPI_COMM_NULL )
170  {
172  CHECKRC( ierr, "cannot deregister app 2 receiver" )
173  }
174 
175  if( comm1 != MPI_COMM_NULL )
176  {
178  CHECKRC( ierr, "cannot deregister app 1 sender" )
179  }
180 
181  ierr = iMOAB_Finalize();
182  CHECKRC( ierr, "did not finalize iMOAB" )
183 
184  if( MPI_COMM_NULL != comm1 ) MPI_Comm_free( &comm1 );
185  if( MPI_COMM_NULL != comm2 ) MPI_Comm_free( &comm2 );
186 
187  MPI_Group_free( &group1 );
188  MPI_Group_free( &group2 );
189  return MB_SUCCESS;
190 }

References CHECKRC, compid1, compid2, context, endG1, endG2, filename, groupTasks, ierr, iMOAB_AppID, iMOAB_DeregisterApplication(), iMOAB_Finalize(), iMOAB_Initialize(), iMOAB_LoadMesh(), iMOAB_RegisterApplication(), iMOAB_WriteMesh(), jcomm, jgroup, MB_SUCCESS, nghlay, outfile, readopts(), startG1, and startG2.

Referenced by migrate_geom(), migrate_graph(), and migrate_trivial().

◆ migrate_trivial()

ErrorCode migrate_trivial ( const char *  filename)

Definition at line 202 of file migrate_nontrivial.cpp.

203 {
204  return migrate_smart( filename, "migrate_trivial.h5m", 0 );
205 }

References filename, and migrate_smart().

Referenced by main().

◆ run_test()

int run_test ( ErrorCode(*)(const char *)  func,
const char *  func_name,
const char *  file_name 
)

Definition at line 44 of file migrate_nontrivial.cpp.

45 {
46  ErrorCode result = ( *func )( file_name );
47  int is_err = is_any_proc_error( ( MB_SUCCESS != result ) );
48  int rank;
49  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
50  if( rank == 0 )
51  {
52  if( is_err )
53  std::cout << func_name << " : FAILED!!" << std::endl;
54  else
55  std::cout << func_name << " : success" << std::endl;
56  }
57 
58  return is_err;
59 }

References ErrorCode, is_any_proc_error(), MB_SUCCESS, MPI_COMM_WORLD, and rank.

Variable Documentation

◆ compid1

int compid1

Definition at line 68 of file migrate_nontrivial.cpp.

Referenced by migrate_smart().

◆ compid2

int compid2

Definition at line 68 of file migrate_nontrivial.cpp.

Referenced by migrate_smart().

◆ endG1

int endG1

Definition at line 71 of file migrate_nontrivial.cpp.

Referenced by main(), and migrate_smart().

◆ endG2

int endG2

Definition at line 71 of file migrate_nontrivial.cpp.

Referenced by main(), and migrate_smart().

◆ groupTasks

std::vector< int > groupTasks

Definition at line 70 of file migrate_nontrivial.cpp.

Referenced by migrate_smart().

◆ ierr

int ierr

Definition at line 66 of file migrate_nontrivial.cpp.

Referenced by migrate_smart().

◆ jcomm

◆ jgroup

MPI_Group jgroup

Definition at line 74 of file migrate_nontrivial.cpp.

Referenced by main(), and migrate_smart().

◆ nghlay

int nghlay

Definition at line 69 of file migrate_nontrivial.cpp.

Referenced by migrate_smart().

◆ rank

int rank
Examples
CrystalRouterExample.cpp, ErrorHandlingSimulation.cpp, GenLargeMesh.cpp, HelloParMOAB.cpp, ReadWriteTest.cpp, ReduceExchangeTags.cpp, and StructuredMeshSimple.cpp.

Definition at line 66 of file migrate_nontrivial.cpp.

Referenced by add_field_value(), moab::MeshGeneration::BrickInstance(), PartMap::build_map(), check_consistent_ids(), closedsurface_uref_hirec_convergence_study(), moab::NCWriteGCRM::collect_mesh_info(), moab::NCWriteHOMME::collect_mesh_info(), moab::NCWriteMPAS::collect_mesh_info(), moab::WriteHDF5Parallel::communicate_shared_set_data(), compute_tracer_case1(), compute_velocity_case1(), PartMap::count_from_rank(), create_coarse_mesh(), moab::WriteHDF5Parallel::create_dataset(), create_fine_mesh(), moab::NCHelperESMF::create_mesh(), moab::NCHelperGCRM::create_mesh(), moab::NCHelperHOMME::create_mesh(), moab::NCHelperMPAS::create_mesh(), moab::NCHelperScrip::create_mesh(), create_mesh_in_memory(), moab::WriteHDF5Parallel::create_meshset_tables(), IntxUtilsCSLAM::create_span_quads(), moab::WriteHDF5Parallel::create_tag_tables(), moab::Coupler::do_normalization(), do_rank_subst(), moab::HiReconstruction::eval_vander_bivar_cmf(), moab::HiReconstruction::eval_vander_univar_cmf(), moab::ReadHDF5::find_sets_containing(), FunctionA(), FunctionB(), FunctionC(), gather_one_cell_var(), generate_mesh(), moab::TempestOnlineMap::GenerateRemappingWeights(), GenerateTestMatrixAndVectors(), get_attrib_array_length_handle(), moab::Coupler::get_matching_entities(), get_max_id(), moab::SharedSetData::get_owner_handle(), moab::SharedSetData::get_shared_sets(), get_tag(), handle_error_code(), iMeshP_getPartsArrOnRank(), iMeshP_getRankOfPart(), iMeshP_getRankOfPartArr(), iMOAB_LoadMesh(), iMOAB_WriteLocalMesh(), moab::NCHelperDomain::init_mesh_vals(), moab::NCHelperEuler::init_mesh_vals(), moab::NCHelperFV::init_mesh_vals(), initialize_tree(), interface_verts(), moab::TempestOnlineMap::IsConservative(), moab::TempestOnlineMap::LinearRemapFVtoFV_Tempest_MOAB(), moab::TempestOnlineMap::LinearRemapSE4_Tempest_MOAB(), moab::ReadParallel::load_file(), load_meshset_hirec(), PartMap::local_id_from_rank(), main(), moab::MBTraceBackErrorHandler(), mhdf_create_table(), mhdf_create_table_with_prop(), mhdf_getTagInfo(), mhdf_open_table(), mhdf_open_table2(), MPI_swap(), multiple_loads_of_same_file(), moab::my_Gatherv(), parallel_create_mesh(), moab::ReadNC::parse_options(), moab::WriteNC::parse_options(), PartMap::part_from_coords(), PartMap::part_id_from_rank(), ZoltanPartitioner::partition_owned_cells(), print_partitioned_entities(), moab::FILEDebugStream::println(), moab::CxxDebugStream::println(), moab::FILEErrorStream::println(), moab::CxxErrorStream::println(), moab::ProcConfig::ProcConfig(), moab::DGMSolver::qr_polyfit_safeguarded(), moab::ReadHDF5::read_all_set_meta(), read_buffered_map(), read_mesh_parallel(), read_one_cell_var(), moab::TempestOnlineMap::ReadParallelMap(), ZoltanPartitioner::repartition(), report_iface_ents(), report_nsets(), report_sets(), run_test(), runner_run_tests(), moab::DebugOutput::set_rank(), moab::ErrorOutput::set_rank(), moab::ReadHDF5::set_up_read(), moab::TempestOnlineMap::SetDOFmapAssociation(), moab::SharedSetData::SharedSetData(), test_assign_global_ids(), test_correct_ghost(), test_entity_copies(), test_entity_copy_parts(), test_entity_owner(), test_entity_status(), test_eul_check_across_files(), test_eul_check_append(), test_eul_check_T(), test_eul_check_timestep(), test_exchange_ents(), test_fv_check_T(), test_gather_onevar(), test_gcrm_check_vars(), test_get_neighbors(), test_get_part_boundary(), test_get_parts(), test_ghost_tag_exchange(), test_ghosted_entity_shared_data(), test_homme_check_T(), test_interface_owners_common(), test_intx_in_parallel_elem_based(), test_intx_mpas(), test_mesh(), test_mpas_check_vars(), test_multiple_loads_of_same_file(), test_part_boundary_iter(), test_part_id_handle(), test_part_rank(), test_push_tag_data_common(), test_read_and_ghost_after(), test_read_bc_sets(), test_read_elements_common(), test_read_eul_onevar(), test_read_fv_onevar(), test_read_global_tags(), test_read_non_adjs_side(), test_read_parallel(), test_read_sets_common(), test_read_tags(), test_read_time(), test_read_with_ghost(), test_read_with_ghost_no_augment(), test_read_with_thin_ghost_layer(), test_reduce_tag_explicit_dest(), test_reduce_tag_failures(), test_reduce_tags(), test_shared_sets(), test_string_rank_subst(), test_tempest_map_bcast(), test_trivial_partition(), test_var_length_parallel(), test_write_dense_tags(), test_write_different_element_types(), test_write_different_tags(), test_write_elements(), test_write_polygons(), test_write_shared_sets(), test_write_unbalanced(), tprint(), moab::NCWriteHelper::write_set_variables(), moab::TempestOnlineMap::WriteHDF5MapFile(), and moab::TempestOnlineMap::WriteSCRIPMapFile().

◆ size

int size

Definition at line 66 of file migrate_nontrivial.cpp.

Referenced by main().

◆ startG1

int startG1

Definition at line 71 of file migrate_nontrivial.cpp.

Referenced by main(), and migrate_smart().

◆ startG2

int startG2

Definition at line 71 of file migrate_nontrivial.cpp.

Referenced by main(), and migrate_smart().