MOAB: Mesh Oriented datABase  (version 5.5.0)
commgraph_test.cpp File Reference
#include "moab/Core.hpp"
#include "moab_mpi.h"
#include "moab/ParallelComm.hpp"
#include "MBParallelConventions.h"
#include "moab/iMOAB.h"
#include "TestUtil.hpp"
#include "moab/CpuTimer.hpp"
#include "moab/ProgOptions.hpp"
#include <iostream>
#include <sstream>
+ Include dependency graph for commgraph_test.cpp:

Go to the source code of this file.

Macros

#define CHECKIERR(rc, message)
 

Functions

std::string readopts ("PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS")
 
std::string readoptsPC ("PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION")
 
std::string fileWriteOptions ("PARALLEL=WRITE_PART")
 
std::string tagT ("a2oTbot")
 
std::string tagU ("a2oUbot")
 
std::string tagV ("a2oVbot")
 
std::string separ (":")
 
std::string tagT1 ("a2oTbot_1")
 
std::string tagU1 ("a2oUbot_1")
 
std::string tagV1 ("a2oVbot_1")
 
std::string tagT2 ("a2oTbot_2")
 
int commgraphtest ()
 
void testspectral_phys ()
 
void testspectral_lnd ()
 
void testphysatm_lnd ()
 
int main (int argc, char *argv[])
 

Variables

int ierr
 
int rankInGlobalComm
 
int numProcesses
 
MPI_Group jgroup
 
std::string atmFilename = TestDir + "unittest/wholeATM_T.h5m"
 
int rankInAtmComm = -1
 
int cmpatm = 605
 
std::string atmPhysFilename = TestDir + "unittest/AtmPhys.h5m"
 
std::string atmPhysOutFilename = "outPhys.h5m"
 
std::string atmFilename2 = "wholeATM_new.h5m"
 
int rankInPhysComm = -1
 
int physatm = 5
 
int nghlay = 0
 
std::vector< int > groupTasks
 
int startG1 = 0
 
int startG2 = 0
 
int endG1 = numProcesses - 1
 
int endG2 = numProcesses - 1
 
int typeA = 1
 
int typeB = 2
 

Macro Definition Documentation

◆ CHECKIERR

#define CHECKIERR (   rc,
  message 
)
Value:
if( 0 != ( rc ) ) \
{ \
printf( "%s. ErrorCode = %d.\n", message, rc ); \
CHECK( 0 ); \
}

Definition at line 50 of file commgraph_test.cpp.

Function Documentation

◆ commgraphtest()

int commgraphtest ( )

Definition at line 136 of file commgraph_test.cpp.

137 {
138 
139  if( !rankInGlobalComm )
140  {
141  std::cout << " first file: " << atmFilename << "\n on tasks : " << startG1 << ":" << endG1
142  << "\n second file: " << atmPhysFilename << "\n on tasks : " << startG2 << ":" << endG2 << "\n ";
143  }
144 
145  // load files on 2 different communicators, groups
146  // will create a joint comm for rendezvous
147  MPI_Group atmPEGroup;
148  groupTasks.resize( numProcesses, 0 );
149  for( int i = startG1; i <= endG1; i++ )
150  groupTasks[i - startG1] = i;
151 
152  ierr = MPI_Group_incl( jgroup, endG1 - startG1 + 1, &groupTasks[0], &atmPEGroup );
153  CHECKIERR( ierr, "Cannot create atmPEGroup" )
154 
155  groupTasks.clear();
156  groupTasks.resize( numProcesses, 0 );
157  MPI_Group atmPhysGroup;
158  for( int i = startG2; i <= endG2; i++ )
159  groupTasks[i - startG2] = i;
160 
161  ierr = MPI_Group_incl( jgroup, endG2 - startG2 + 1, &groupTasks[0], &atmPhysGroup );
162  CHECKIERR( ierr, "Cannot create atmPhysGroup" )
163 
164  // create 2 communicators, one for each group
165  int ATM_COMM_TAG = 1;
166  MPI_Comm atmComm;
167  // atmComm is for atmosphere app;
168  ierr = MPI_Comm_create_group( MPI_COMM_WORLD, atmPEGroup, ATM_COMM_TAG, &atmComm );
169  CHECKIERR( ierr, "Cannot create atmComm" )
170 
171  int PHYS_COMM_TAG = 2;
172  MPI_Comm physComm;
173  // physComm is for phys atm app
174  ierr = MPI_Comm_create_group( MPI_COMM_WORLD, atmPhysGroup, PHYS_COMM_TAG, &physComm );
175  CHECKIERR( ierr, "Cannot create physComm" )
176 
177  // now, create the joint communicator atm physatm
178 
179  //
180  MPI_Group joinAtmPhysAtmGroup;
181  ierr = MPI_Group_union( atmPEGroup, atmPhysGroup, &joinAtmPhysAtmGroup );
182  CHECKIERR( ierr, "Cannot create joint atm - phys atm group" )
183  int JOIN_COMM_TAG = 5;
184  MPI_Comm joinComm;
185  ierr = MPI_Comm_create_group( MPI_COMM_WORLD, joinAtmPhysAtmGroup, JOIN_COMM_TAG, &joinComm );
186  CHECKIERR( ierr, "Cannot create joint atm cou communicator" )
187 
188  ierr = iMOAB_Initialize( 0, NULL ); // not really needed anything from argc, argv, yet; maybe we should
189  CHECKIERR( ierr, "Cannot initialize iMOAB" )
190 
191  int cmpAtmAppID = -1;
192  iMOAB_AppID cmpAtmPID = &cmpAtmAppID; // atm
193  int physAtmAppID = -1; // -1 means it is not initialized
194  iMOAB_AppID physAtmPID = &physAtmAppID; // phys atm on phys pes
195 
196  // load atm mesh
197  if( atmComm != MPI_COMM_NULL )
198  {
199  MPI_Comm_rank( atmComm, &rankInAtmComm );
200  ierr = iMOAB_RegisterApplication( "ATM1", &atmComm, &cmpatm, cmpAtmPID );
201  CHECKIERR( ierr, "Cannot register ATM App" )
202 
203  // load first model
204  std::string rdopts = readopts;
205  if( typeA == 2 ) rdopts = readoptsPC; // point cloud
206  ierr = iMOAB_LoadMesh( cmpAtmPID, atmFilename.c_str(), rdopts.c_str(), &nghlay );
207  CHECKIERR( ierr, "Cannot load ATM mesh" )
208  }
209 
210  // load atm phys mesh
211  if( physComm != MPI_COMM_NULL )
212  {
213  MPI_Comm_rank( physComm, &rankInPhysComm );
214  ierr = iMOAB_RegisterApplication( "PhysATM", &physComm, &physatm, physAtmPID );
215  CHECKIERR( ierr, "Cannot register PHYS ATM App" )
216 
217  // load phys atm mesh all tests this is PC
218  ierr = iMOAB_LoadMesh( physAtmPID, atmPhysFilename.c_str(), readoptsPC.c_str(), &nghlay );
219  CHECKIERR( ierr, "Cannot load Phys ATM mesh" )
220  }
221 
222  if( MPI_COMM_NULL != joinComm )
223  {
224  ierr = iMOAB_ComputeCommGraph( cmpAtmPID, physAtmPID, &joinComm, &atmPEGroup, &atmPhysGroup, &typeA, &typeB,
225  &cmpatm, &physatm );
226  // it will generate parcomm graph between atm and atmPhys models
227  // 2 meshes, that are distributed in parallel
228  CHECKIERR( ierr, "Cannot compute comm graph between the two apps " )
229  }
230 
231  if( atmComm != MPI_COMM_NULL )
232  {
233  // call send tag;
234  std::string tags = tagT + separ + tagU + separ + tagV;
235  ierr = iMOAB_SendElementTag( cmpAtmPID, tags.c_str(), &joinComm, &physatm );
236  CHECKIERR( ierr, "cannot send tag values" )
237  }
238 
239  if( physComm != MPI_COMM_NULL )
240  {
241  // need to define tag storage
242  std::string tags1 = tagT1 + separ + tagU1 + separ + tagV1 + separ;
243  int tagType = DENSE_DOUBLE;
244  int ndof = 1;
245  if( typeB == 1 ) ndof = 16;
246  int tagIndex = 0;
247  ierr = iMOAB_DefineTagStorage( physAtmPID, tagT1.c_str(), &tagType, &ndof, &tagIndex );
248  CHECKIERR( ierr, "failed to define the field tag a2oTbot" );
249 
250  ierr = iMOAB_DefineTagStorage( physAtmPID, tagU1.c_str(), &tagType, &ndof, &tagIndex );
251  CHECKIERR( ierr, "failed to define the field tag a2oUbot" );
252 
253  ierr = iMOAB_DefineTagStorage( physAtmPID, tagV1.c_str(), &tagType, &ndof, &tagIndex );
254  CHECKIERR( ierr, "failed to define the field tag a2oVbot" );
255 
256  ierr = iMOAB_ReceiveElementTag( physAtmPID, tags1.c_str(), &joinComm, &cmpatm );
257  CHECKIERR( ierr, "cannot receive tag values" )
258  }
259 
260  // we can now free the sender buffers
261  if( atmComm != MPI_COMM_NULL )
262  {
263  ierr = iMOAB_FreeSenderBuffers( cmpAtmPID, &physatm );
264  CHECKIERR( ierr, "cannot free buffers" )
265  }
266 
267  if( physComm != MPI_COMM_NULL )
268  {
269  ierr = iMOAB_WriteMesh( physAtmPID, atmPhysOutFilename.c_str(), fileWriteOptions.c_str() );
270  }
271  if( physComm != MPI_COMM_NULL )
272  {
273  // send back first tag only
274  ierr = iMOAB_SendElementTag( physAtmPID, tagT1.c_str(), &joinComm, &cmpatm );
275  CHECKIERR( ierr, "cannot send tag values" )
276  }
277  // receive it in a different tag
278  if( atmComm != MPI_COMM_NULL )
279  {
280  // need to define tag storage
281  int tagType = DENSE_DOUBLE;
282  int ndof = 16;
283  if( typeA == 2 ) ndof = 1;
284  int tagIndex = 0;
285  ierr = iMOAB_DefineTagStorage( cmpAtmPID, tagT2.c_str(), &tagType, &ndof, &tagIndex );
286  CHECKIERR( ierr, "failed to define the field tag a2oTbot_2" );
287 
288  ierr = iMOAB_ReceiveElementTag( cmpAtmPID, tagT2.c_str(), &joinComm, &physatm );
289  CHECKIERR( ierr, "cannot receive tag values a2oTbot_2" )
290  }
291  // now send back one tag , into a different tag, and see if we get the same values back
292  // we can now free the sender buffers
293  if( physComm != MPI_COMM_NULL )
294  {
295  ierr = iMOAB_FreeSenderBuffers( physAtmPID, &cmpatm );
296  CHECKIERR( ierr, "cannot free buffers " )
297  }
298  if( atmComm != MPI_COMM_NULL )
299  {
300  ierr = iMOAB_WriteMesh( cmpAtmPID, atmFilename2.c_str(), fileWriteOptions.c_str() );
301  }
302 
303  // unregister in reverse order
304  if( physComm != MPI_COMM_NULL )
305  {
306  ierr = iMOAB_DeregisterApplication( physAtmPID );
307  CHECKIERR( ierr, "cannot deregister second app model" )
308  }
309 
310  if( atmComm != MPI_COMM_NULL )
311  {
312  ierr = iMOAB_DeregisterApplication( cmpAtmPID );
313  CHECKIERR( ierr, "cannot deregister first app model" )
314  }
315 
316  ierr = iMOAB_Finalize();
317  CHECKIERR( ierr, "did not finalize iMOAB" )
318 
319  // free atm group and comm
320  if( MPI_COMM_NULL != atmComm ) MPI_Comm_free( &atmComm );
321  MPI_Group_free( &atmPEGroup );
322 
323  // free atm phys group and comm
324  if( MPI_COMM_NULL != physComm ) MPI_Comm_free( &physComm );
325  MPI_Group_free( &atmPhysGroup );
326 
327  // free atm phys group and comm
328  if( MPI_COMM_NULL != joinComm ) MPI_Comm_free( &joinComm );
329  MPI_Group_free( &joinAtmPhysAtmGroup );
330 
331  return 0;
332 }

References atmFilename, atmFilename2, atmPhysFilename, atmPhysOutFilename, CHECKIERR, cmpatm, DENSE_DOUBLE, endG1, endG2, fileWriteOptions(), groupTasks, ierr, iMOAB_AppID, iMOAB_DefineTagStorage(), iMOAB_DeregisterApplication(), iMOAB_Finalize(), iMOAB_Initialize(), iMOAB_LoadMesh(), iMOAB_RegisterApplication(), iMOAB_WriteMesh(), jgroup, MPI_COMM_WORLD, nghlay, numProcesses, physatm, rankInAtmComm, rankInGlobalComm, rankInPhysComm, readopts(), readoptsPC(), separ(), startG1, startG2, tagT(), tagT1(), tagT2(), tagU(), tagU1(), tagV(), tagV1(), typeA, and typeB.

Referenced by testphysatm_lnd(), testspectral_lnd(), and testspectral_phys().

◆ fileWriteOptions()

std::string fileWriteOptions ( )

Referenced by commgraphtest(), and main().

◆ main()

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

Definition at line 333 of file commgraph_test.cpp.

334 {
335 
336  MPI_Init( &argc, &argv );
337  MPI_Comm_rank( MPI_COMM_WORLD, &rankInGlobalComm );
338  MPI_Comm_size( MPI_COMM_WORLD, &numProcesses );
339 
340  MPI_Comm_group( MPI_COMM_WORLD, &jgroup ); // all processes in global group
341 
342  // default: load atm on 2 proc, phys grid on 2 procs, establish comm graph, then migrate
343  // data from atm pes to phys pes, and back
344  startG1 = 0, startG2 = 0, endG1 = numProcesses - 1, endG2 = numProcesses - 1;
345 
346  ProgOptions opts;
347  opts.addOpt< std::string >( "modelA,m", "first model file ", &atmFilename );
348  opts.addOpt< int >( "typeA,t", " type of first model ", &typeA );
349 
350  opts.addOpt< std::string >( "modelB,n", "second model file", &atmPhysFilename );
351  opts.addOpt< int >( "typeB,v", " type of the second model ", &typeB );
352 
353  opts.addOpt< int >( "startAtm,a", "start task for first model layout", &startG1 );
354  opts.addOpt< int >( "endAtm,b", "end task for first model layout", &endG1 );
355 
356  opts.addOpt< int >( "startPhys,c", "start task for second model layout", &startG2 );
357  opts.addOpt< int >( "endPhys,d", "end task for second model layout", &endG2 );
358 
359  opts.addOpt< std::string >( "output,o", "output filename", &atmPhysOutFilename );
360 
361  opts.addOpt< std::string >( "output,o", "output filename", &atmFilename2 );
362 
363  opts.parseCommandLine( argc, argv );
364 
365  int num_err = 0;
366  num_err += RUN_TEST( testspectral_phys );
367 
368  //
369  if( argc == 1 )
370  {
371  num_err += RUN_TEST( testspectral_lnd );
372  num_err += RUN_TEST( testphysatm_lnd );
373  }
374  MPI_Group_free( &jgroup );
375 
376  MPI_Finalize();
377 
378  return num_err;
379 }

References ProgOptions::addOpt(), atmFilename, atmFilename2, atmPhysFilename, atmPhysOutFilename, endG1, endG2, jgroup, MPI_COMM_WORLD, numProcesses, ProgOptions::parseCommandLine(), rankInGlobalComm, RUN_TEST, startG1, startG2, testphysatm_lnd(), testspectral_lnd(), testspectral_phys(), typeA, and typeB.

◆ readopts()

◆ readoptsPC()

std::string readoptsPC ( )

Referenced by commgraphtest().

◆ separ()

std::string separ ( ":"  )

Referenced by commgraphtest().

◆ tagT()

std::string tagT ( "a2oTbot"  )

Referenced by commgraphtest(), and testphysatm_lnd().

◆ tagT1()

std::string tagT1 ( "a2oTbot_1"  )

Referenced by commgraphtest(), and testphysatm_lnd().

◆ tagT2()

std::string tagT2 ( "a2oTbot_2"  )

Referenced by commgraphtest(), and testphysatm_lnd().

◆ tagU()

std::string tagU ( "a2oUbot"  )

Referenced by commgraphtest(), and testphysatm_lnd().

◆ tagU1()

std::string tagU1 ( "a2oUbot_1"  )

Referenced by commgraphtest(), and testphysatm_lnd().

◆ tagV()

std::string tagV ( "a2oVbot"  )

Referenced by commgraphtest(), and testphysatm_lnd().

◆ tagV1()

std::string tagV1 ( "a2oVbot_1"  )

Referenced by commgraphtest(), and testphysatm_lnd().

◆ testphysatm_lnd()

void testphysatm_lnd ( )

Definition at line 121 of file commgraph_test.cpp.

122 {
123  // use for first file the output "outPhys.h5m" from first test
124  atmFilename = std::string( "outPhys.h5m" );
125  atmPhysFilename = std::string( "outLnd.h5m" );
126  atmPhysOutFilename = std::string( "physAtm_lnd.h5m" );
127  atmFilename2 = std::string( "physBack_lnd.h5m" );
128  tagT = tagT1;
129  tagU = tagU1;
130  tagV = tagV1;
131  tagT1 = std::string( "newT" );
132  tagT2 = std::string( "newT2" );
133  typeA = 2;
134  commgraphtest();
135 }

References atmFilename, atmFilename2, atmPhysFilename, atmPhysOutFilename, commgraphtest(), tagT(), tagT1(), tagT2(), tagU(), tagU1(), tagV(), tagV1(), and typeA.

Referenced by main().

◆ testspectral_lnd()

void testspectral_lnd ( )

Definition at line 112 of file commgraph_test.cpp.

113 {
114  // first model is spectral, second is land
115  atmPhysFilename = TestDir + "unittest/wholeLnd.h5m";
116  atmPhysOutFilename = std::string( "outLnd.h5m" );
117  atmFilename2 = std::string( "wholeATM_lnd.h5m" );
118  commgraphtest();
119 }

References atmFilename2, atmPhysFilename, atmPhysOutFilename, and commgraphtest().

Referenced by main().

◆ testspectral_phys()

void testspectral_phys ( )

Definition at line 106 of file commgraph_test.cpp.

107 {
108  // no changes
109  commgraphtest();
110 }

References commgraphtest().

Referenced by main().

Variable Documentation

◆ atmFilename

std::string atmFilename = TestDir + "unittest/wholeATM_T.h5m"

Definition at line 66 of file commgraph_test.cpp.

Referenced by commgraphtest(), main(), and testphysatm_lnd().

◆ atmFilename2

std::string atmFilename2 = "wholeATM_new.h5m"

Definition at line 78 of file commgraph_test.cpp.

Referenced by commgraphtest(), main(), testphysatm_lnd(), and testspectral_lnd().

◆ atmPhysFilename

std::string atmPhysFilename = TestDir + "unittest/AtmPhys.h5m"

Definition at line 76 of file commgraph_test.cpp.

Referenced by commgraphtest(), main(), testphysatm_lnd(), and testspectral_lnd().

◆ atmPhysOutFilename

std::string atmPhysOutFilename = "outPhys.h5m"

Definition at line 77 of file commgraph_test.cpp.

Referenced by commgraphtest(), main(), testphysatm_lnd(), and testspectral_lnd().

◆ cmpatm

int cmpatm = 605

Definition at line 74 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ endG1

int endG1 = numProcesses - 1

Definition at line 88 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ endG2

int endG2 = numProcesses - 1

Definition at line 88 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ groupTasks

std::vector< int > groupTasks

Definition at line 87 of file commgraph_test.cpp.

Referenced by commgraphtest(), create_group_and_comm(), and main().

◆ ierr

int ierr
Examples
ReduceExchangeTags.cpp.

Definition at line 63 of file commgraph_test.cpp.

Referenced by PartMap::build_map(), check_consistent_ids(), check_one_layer(), cleanup_after_intersection(), cleanup_after_simulation(), commgraphtest(), create_group_and_comm(), create_joint_comm_group(), create_mesh(), create_mesh_in_memory(), moab::Coupler::do_normalization(), moab::ParallelComm::exchange_all_shared_handles(), moab::ReadHDF5::find_sets_containing(), get_adj(), get_boundary_vertices(), get_coords(), get_imesh_mesh(), get_local_parts(), moab::Coupler::get_matching_entities(), get_num_adj_all(), get_num_adj_quads(), get_part_boundary_verts(), get_part_quads_and_verts(), iMeshP_getNumOfTopoAll(), iMeshP_getNumOfTypeAll(), initialize_area_and_tracer(), interface_verts(), intersection_at_level(), moab::TempestOnlineMap::IsConservative(), moab::TempestOnlineMap::IsConsistent(), moab::TempestOnlineMap::IsMonotone(), main(), PartMap::part_from_coords(), moab::ReadHDF5::read_all_set_meta(), moab::ParCommGraph::receive_comm_graph(), moab::ParCommGraph::receive_mesh(), moab::ParCommGraph::receive_tag_values(), moab::ParCommGraph::release_send_buffers(), run_global_smoother(), run_local_smoother(), run_local_smoother2(), run_quality_optimizer(), run_solution_mesh_optimizer(), run_test(), moab::ParCommGraph::send_graph(), moab::ParCommGraph::send_graph_partition(), moab::ParCommGraph::send_mesh_parts(), moab::ParCommGraph::send_tag_values(), moab::TempestOnlineMap::SetDOFmapTags(), setup_component_coupler_meshes(), test_create_ghost_ents(), test_entity_copies(), test_entity_copy_parts(), test_entity_owner(), test_entity_status(), test_exchange_ents(), test_get_by_topo(), test_get_by_type(), test_get_by_type_topo_all(), test_get_by_type_topo_local(), test_get_neighbors(), test_get_part_boundary(), test_get_partitions(), test_get_parts(), test_interface_owners_common(), test_load(), test_part_boundary_iter(), test_part_id_handle(), test_part_rank(), test_push_tag_data_common(), test_tempest_cs_create(), test_tempest_ico_create(), test_tempest_mpas_create(), test_tempest_overlap_combinations(), test_tempest_rll_create(), update_tracer(), update_tracer_test(), vertex_tag(), and moab::TempestOnlineMap::WriteSCRIPMapFile().

◆ jgroup

MPI_Group jgroup

Definition at line 65 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ nghlay

int nghlay = 0

Definition at line 85 of file commgraph_test.cpp.

Referenced by commgraphtest(), main(), and setup_component_coupler_meshes().

◆ numProcesses

int numProcesses

Definition at line 64 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ physatm

int physatm = 5

Definition at line 81 of file commgraph_test.cpp.

Referenced by commgraphtest().

◆ rankInAtmComm

int rankInAtmComm = -1

Definition at line 72 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ rankInGlobalComm

int rankInGlobalComm

Definition at line 64 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ rankInPhysComm

int rankInPhysComm = -1

Definition at line 79 of file commgraph_test.cpp.

Referenced by commgraphtest().

◆ startG1

int startG1 = 0

Definition at line 88 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ startG2

int startG2 = 0

Definition at line 88 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().

◆ typeA

int typeA = 1

Definition at line 89 of file commgraph_test.cpp.

Referenced by commgraphtest(), main(), and testphysatm_lnd().

◆ typeB

int typeB = 2

Definition at line 90 of file commgraph_test.cpp.

Referenced by commgraphtest(), and main().