Example demonstrating parallel communication using TupleList and Crystal Router.
More...
Example demonstrating parallel communication using TupleList and Crystal Router.
This example shows how to:
- Use MOAB's TupleList for efficient data communication
- Perform sparse all-to-all communication using Crystal Router
- Handle parallel data exchange with varying communication patterns
- Verify received data integrity
- Measure communication performance
The Crystal Router is used for sparse communication patterns where each processor communicates with only a subset of other processors, avoiding the overhead of full all-to-all communication.
- Author
- MOAB Development Team
- Date
- 2024
To run: mpiexec -np n CrystalRouterExample -r [reportrank] -t [num_tuples] -n [num_comms]
- Parameters
-
| argc | Number of command line arguments |
| argv | Command line arguments array |
- Returns
- 0 on success, 1 on failure
Definition in file CrystalRouterExample.cpp.
| int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 78 of file CrystalRouterExample.cpp.
81 MPI_Init( &argc, &argv );
87 int size = pc.proc_size();
88 int rank = pc.proc_rank();
91 LONG_DESC <<
"This program does a gather scatter with a list of tuples. \n"
92 " It tries to see how much communication costs in terms of time and memory. \n"
93 <<
"It starts with creating a list of tuples to be sent from each processor, \n to a "
94 "list of other processors.\n"
95 <<
"The number of tuples and how many tasks to communicate to are controlled by "
97 <<
"After communication, we verify locally if we received what we expected. \n";
102 opts.addOpt<
int >(
"num_comms,n",
"each task will send to about num_comms other tasks some tuples (default 2)",
106 opts.addOpt<
int >(
"num_tuples,t",
"each task will send to some task about num_tuples tuples (default 4)",
109 int reportrank = size + 1;
110 opts.addOpt<
int >(
"reporting_rank,r",
111 "this rank will report the tuples sent and the tuples received; it could "
112 "be higher than num_procs, then no reporting",
115 opts.parseCommandLine( argc, argv );
117 if( rank == reportrank || ( reportrank >= size && 0 == rank ) )
119 cout <<
" There are " << size <<
" tasks in example.\n";
120 cout <<
" We will send groups of " << num_tuples <<
" from each task towards " << num_comms
121 <<
" other tasks.\n";
128 long total_n_tuples = num_comms * num_tuples;
131 if( rank < size / 2 )
136 if( rank < size / 3 )
138 else if( rank > size - size / 3 )
147 tl.
initialize( 1, 1, 0, 1, num_tuples * num_comms );
150 unsigned int n = tl.
get_n();
151 for(
int i = 0; i < num_comms; i++ )
153 int sendTo = rank + i * size / 2 + 1;
154 sendTo = sendTo % size;
155 long intToSend = 1000 * rank + 100000 * sendTo;
156 for(
int j = 0; j < num_tuples; j++ )
159 tl.
vi_wr[n] = sendTo;
160 tl.
vl_wr[n] = intToSend + j;
161 tl.
vr_wr[n] = 10000. * rank + j;
166 if( rank == reportrank )
168 cout <<
"rank " << rank <<
"\n";
169 tl.
print(
" before sending" );
172 clock_t tt = clock();
174 MB_CHK_SET_ERR( cd->gs_transfer( 1, tl, 0 ),
"Error in tuple transfer" );
177 if( rank == reportrank || ( reportrank >= size && 0 == rank ) )
179 secs = ( clock() - tt ) / (
double)CLOCKS_PER_SEC;
181 if( rank == reportrank )
183 cout <<
"rank " << rank <<
"\n";
184 tl.
print(
" after transfer" );
188 unsigned int received = tl.
get_n();
189 for(
int i = 0; i < (int)received; i++ )
191 int from = tl.
vi_rd[i];
192 long valrec = tl.
vl_rd[i];
193 int remainder = valrec - 100000 * rank - 1000 * from;
194 if( remainder < 0 || remainder >= num_tuples * 4 )
195 cout <<
" error: tuple " << i <<
" received at proc rank " << rank <<
" from proc " << from <<
" has value "
196 << valrec <<
" remainder " << remainder <<
"\n";
199 if( rank == reportrank || ( reportrank >= size && 0 == rank ) )
201 cout <<
"communication of about " << total_n_tuples <<
" tuples/per proc took " << secs <<
" seconds" <<
"\n";
210 std::cout <<
" Build with MPI for this example to work\n";
References ProgOptions::addOpt(), BRIEF_DESC, moab::ProcConfig::crystal_router(), moab::TupleList::enableWriteAccess(), moab::TupleList::get_n(), moab::TupleList::inc_n(), moab::TupleList::initialize(), LONG_DESC, MB_CHK_SET_ERR, moab::MBErrorHandler_Finalize(), moab::MBErrorHandler_Init(), ProgOptions::parseCommandLine(), moab::TupleList::print(), moab::ProcConfig::proc_rank(), moab::ProcConfig::proc_size(), moab::TupleList::vi_rd, moab::TupleList::vi_wr, moab::TupleList::vl_rd, moab::TupleList::vl_wr, and moab::TupleList::vr_wr.