It shows how to load the mesh independently, on multiple communicators (with second argument, the number of comms)
#ifdef MOAB_HAVE_MPI
#endif
#include <iostream>
using namespace std;
int main(
int argc,
char** argv )
{
#ifdef MOAB_HAVE_MPI
MPI_Init( &argc, &argv );
string options;
if( argc > 1 )
{
}
int nbComms = 1;
if( argc > 2 ) nbComms = atoi( argv[2] );
options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS";
Interface*
mb =
new( std::nothrow ) Core;
if( NULL ==
mb )
return 1;
MPI_Comm comm;
int global_rank, global_size;
MPI_Comm_rank( MPI_COMM_WORLD, &global_rank );
MPI_Comm_rank( MPI_COMM_WORLD, &global_size );
int color = global_rank % nbComms;
if( nbComms > 1 )
{
MPI_Comm_split( MPI_COMM_WORLD, color, global_rank, &comm );
}
else
comm = MPI_COMM_WORLD;
ParallelComm* pcomm =
new ParallelComm(
mb, comm );
int nprocs = pcomm->proc_config().proc_size();
int rank = pcomm->proc_config().proc_rank();
#ifndef NDEBUG
MPI_Comm rcomm = pcomm->proc_config().proc_comm();
assert( rcomm == comm );
#endif
if( 0 == global_rank )
cout << " global rank:" << global_rank << " color:" << color << " rank:" << rank << " of " << nprocs
<< " processors\n";
if( 1 == global_rank )
cout << " global rank:" << global_rank << " color:" << color << " rank:" << rank << " of " << nprocs
<< " processors\n";
MPI_Barrier( MPI_COMM_WORLD );
if( 0 == global_rank )
cout <<
"Reading file " <<
test_file_name <<
"\n with options: " << options <<
"\n on " << nprocs
<< " processors on " << nbComms << " communicator(s)\n";
Range shared_ents;
rval = pcomm->get_shared_entities( -1, shared_ents );
MB_CHK_ERR( rval );
Range owned_entities;
unsigned int nums[4] = { 0 };
for( int i = 0; i < 4; i++ )
nums[i] = (int)owned_entities.num_of_dimension( i );
vector< int > rbuf( nprocs * 4, 0 );
MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm );
if( 0 == global_rank )
{
for( int i = 0; i < nprocs; i++ )
cout << " Shared, owned entities on proc " << i << ": " << rbuf[4 * i] << " verts, " << rbuf[4 * i + 1]
<< " edges, " << rbuf[4 * i + 2] << " faces, " << rbuf[4 * i + 3] << " elements" << endl;
}
rval = pcomm->exchange_ghost_cells( 3,
0,
1,
0,
shared_ents.clear();
owned_entities.clear();
rval = pcomm->get_shared_entities( -1, shared_ents );
MB_CHK_ERR( rval );
for( int i = 0; i < 4; i++ )
nums[i] = (int)owned_entities.num_of_dimension( i );
MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm );
if( 0 == global_rank )
{
cout << " \n\n After exchanging one ghost layer: \n";
for( int i = 0; i < nprocs; i++ )
{
cout << " Shared, owned entities on proc " << i << ": " << rbuf[4 * i] << " verts, " << rbuf[4 * i + 1]
<< " edges, " << rbuf[4 * i + 2] << " faces, " << rbuf[4 * i + 3] << " elements" << endl;
}
}
MPI_Finalize();
#else
std::cout << " compile with MPI and hdf5 for this example to work\n";
#endif
return 0;
}