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