|
Packit |
0848f5 |
/* -*- Mode: C++; c-basic-offset:4 ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2013 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include "mpitestconf.h"
|
|
Packit |
0848f5 |
#include "mpitestcxx.h"
|
|
Packit |
0848f5 |
#ifdef HAVE_IOSTREAM
|
|
Packit |
0848f5 |
// Not all C++ compilers have iostream instead of iostream.h
|
|
Packit |
0848f5 |
#include <iostream>
|
|
Packit |
0848f5 |
#ifdef HAVE_NAMESPACE_STD
|
|
Packit |
0848f5 |
// Those that do often need the std namespace; otherwise, a bare "cout"
|
|
Packit |
0848f5 |
// is likely to fail to compile
|
|
Packit |
0848f5 |
using namespace std;
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
#else
|
|
Packit |
0848f5 |
#include <iostream.h>
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main( int argc, char *argv[] )
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int indegree, outdegree, sources[4], dests[4], sweights[4], dweights[4];
|
|
Packit |
0848f5 |
int wrank, wsize;
|
|
Packit |
0848f5 |
MPI::Distgraphcomm dcomm;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
// Create a graph where each process sends to rank+1, rank+3 and
|
|
Packit |
0848f5 |
// receives from rank - 2
|
|
Packit |
0848f5 |
wrank = MPI::COMM_WORLD.Get_rank();
|
|
Packit |
0848f5 |
wsize = MPI::COMM_WORLD.Get_size();
|
|
Packit |
0848f5 |
indegree = 0;
|
|
Packit |
0848f5 |
outdegree = 0;
|
|
Packit |
0848f5 |
if (wrank+1 < wsize) dests[outdegree++] = wrank+1;
|
|
Packit |
0848f5 |
if (wrank+3 < wsize) dests[outdegree++] = wrank+3;
|
|
Packit |
0848f5 |
if (wrank-2 >= 0) sources[indegree++] = wrank-2;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
// Create with no reordering to test final ranks
|
|
Packit |
0848f5 |
dcomm = MPI::COMM_WORLD.Dist_graph_create_adjacent( indegree, sources,
|
|
Packit |
0848f5 |
outdegree, dests, MPI::INFO_NULL, false );
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
// Check that the created communicator has the properties specified
|
|
Packit |
0848f5 |
if (dcomm.Get_topology() != MPI_DIST_GRAPH) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
cout << "Incorrect topology for dist_graph: " <<
|
|
Packit |
0848f5 |
dcomm.Get_topology() << "\n";
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
int myindegree, myoutdegree;
|
|
Packit |
0848f5 |
bool myweighted;
|
|
Packit |
0848f5 |
dcomm.Get_dist_neighbors_count( myindegree, myoutdegree, myweighted );
|
|
Packit |
0848f5 |
if (myindegree != indegree) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
cout << "Indegree is " << myindegree << " should be " << indegree
|
|
Packit |
0848f5 |
<< "\n";
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (myoutdegree != outdegree) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
cout << "Outdegree is " << myoutdegree << " should be " <<
|
|
Packit |
0848f5 |
outdegree << "\n";
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (myweighted) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
cout << "Weighted is true, should be false\n";
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (!errs) {
|
|
Packit |
0848f5 |
int mysources[4], mysweights[4], mydests[4], mydweights[4], i;
|
|
Packit |
0848f5 |
dcomm.Get_dist_neighbors( 4, mysources, mysweights,
|
|
Packit |
0848f5 |
4, mydests, mydweights );
|
|
Packit |
0848f5 |
// May need to sort mysources and mydests first
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
if (mysources[i] != sources[i]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
if (mydests[i] != dests[i]) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
dcomm.Free();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
// ToDo:
|
|
Packit |
0848f5 |
// Test dup and clone.
|
|
Packit |
0848f5 |
// Test with weights.
|
|
Packit |
0848f5 |
// Test with reorder.
|
|
Packit |
0848f5 |
// Test Dist_graph (not just adjacent) with awkward specification.
|
|
Packit |
0848f5 |
// Note that there is no dist_graph_map function in MPI (!)
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize( errs );
|
|
Packit |
0848f5 |
MPI::Finalize();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|