|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2003 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int errs = 0, i, k;
|
|
Packit Service |
c5cf8c |
int dims[2], periods[2], wsize;
|
|
Packit Service |
c5cf8c |
int outdims[2], outperiods[2], outcoords[2];
|
|
Packit Service |
c5cf8c |
int topo_type;
|
|
Packit Service |
c5cf8c |
int *index, *edges, *outindex, *outedges;
|
|
Packit Service |
c5cf8c |
MPI_Comm comm1, comm2;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Create a cartesian topology, get its characteristics, then
|
|
Packit Service |
c5cf8c |
* dup it and check that the new communicator has the same properties */
|
|
Packit Service |
c5cf8c |
dims[0] = dims[1] = 0;
|
|
Packit Service |
c5cf8c |
MPI_Dims_create(wsize, 2, dims);
|
|
Packit Service |
c5cf8c |
periods[0] = periods[1] = 0;
|
|
Packit Service |
c5cf8c |
MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &comm1;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_dup(comm1, &comm2;;
|
|
Packit Service |
c5cf8c |
MPI_Topo_test(comm2, &topo_type);
|
|
Packit Service |
c5cf8c |
if (topo_type != MPI_CART) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("Topo type of duped cart was not cart\n");
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
MPI_Cart_get(comm2, 2, outdims, outperiods, outcoords);
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 2; i++) {
|
|
Packit Service |
c5cf8c |
if (outdims[i] != dims[i]) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("%d = outdims[%d] != dims[%d] = %d\n", outdims[i], i, i, dims[i]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (outperiods[i] != periods[i]) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("%d = outperiods[%d] != periods[%d] = %d\n",
|
|
Packit Service |
c5cf8c |
outperiods[i], i, i, periods[i]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&comm2;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&comm1;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Now do the same with a graph topology */
|
|
Packit Service |
c5cf8c |
if (wsize >= 3) {
|
|
Packit Service |
c5cf8c |
index = (int *) malloc(wsize * sizeof(int));
|
|
Packit Service |
c5cf8c |
edges = (int *) malloc(wsize * 2 * sizeof(int));
|
|
Packit Service |
c5cf8c |
if (!index || !edges) {
|
|
Packit Service |
c5cf8c |
printf("Unable to allocate %d words for index or edges\n", 3 * wsize);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
index[0] = 2;
|
|
Packit Service |
c5cf8c |
for (i = 1; i < wsize; i++) {
|
|
Packit Service |
c5cf8c |
index[i] = 2 + index[i - 1];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
k = 0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < wsize; i++) {
|
|
Packit Service |
c5cf8c |
edges[k++] = (i - 1 + wsize) % wsize;
|
|
Packit Service |
c5cf8c |
edges[k++] = (i + 1) % wsize;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Graph_create(MPI_COMM_WORLD, wsize, index, edges, 0, &comm1;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_dup(comm1, &comm2;;
|
|
Packit Service |
c5cf8c |
MPI_Topo_test(comm2, &topo_type);
|
|
Packit Service |
c5cf8c |
if (topo_type != MPI_GRAPH) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("Topo type of duped graph was not graph\n");
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
int nnodes, nedges;
|
|
Packit Service |
c5cf8c |
MPI_Graphdims_get(comm2, &nnodes, &nedges);
|
|
Packit Service |
c5cf8c |
if (nnodes != wsize) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("Nnodes = %d, should be %d\n", nnodes, wsize);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (nedges != 2 * wsize) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("Nedges = %d, should be %d\n", nedges, 2 * wsize);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
outindex = (int *) malloc(wsize * sizeof(int));
|
|
Packit Service |
c5cf8c |
outedges = (int *) malloc(wsize * 2 * sizeof(int));
|
|
Packit Service |
c5cf8c |
if (!outindex || !outedges) {
|
|
Packit Service |
c5cf8c |
printf("Unable to allocate %d words for outindex or outedges\n", 3 * wsize);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Graph_get(comm2, wsize, 2 * wsize, outindex, outedges);
|
|
Packit Service |
c5cf8c |
for (i = 0; i < wsize; i++) {
|
|
Packit Service |
c5cf8c |
if (index[i] != outindex[i]) {
|
|
Packit Service |
c5cf8c |
printf("%d = index[%d] != outindex[%d] = %d\n", index[i], i, i, outindex[i]);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 2 * wsize; i++) {
|
|
Packit Service |
c5cf8c |
if (edges[i] != outedges[i]) {
|
|
Packit Service |
c5cf8c |
printf("%d = edges[%d] != outedges[%d] = %d\n", edges[i], i, i, outedges[i]);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
free(outindex);
|
|
Packit Service |
c5cf8c |
free(outedges);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
free(index);
|
|
Packit Service |
c5cf8c |
free(edges);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&comm2;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&comm1;;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|