|
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 "mpitest.h"
|
|
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 rank, size, wrank, wsize, dest, a, b;
|
|
Packit Service |
c5cf8c |
MPI_Comm newcomm;
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Can we run comm dup at all? */
|
|
Packit Service |
c5cf8c |
MPI_Comm_dup(MPI_COMM_WORLD, &newcomm);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Check basic properties */
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(newcomm, &size);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(newcomm, &rank;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (size != wsize || rank != wrank) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Size (%d) or rank (%d) wrong\n", size, rank);
|
|
Packit Service |
c5cf8c |
fflush(stderr);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Can we communicate with this new communicator? */
|
|
Packit Service |
c5cf8c |
dest = MPI_PROC_NULL;
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
dest = size - 1;
|
|
Packit Service |
c5cf8c |
a = rank;
|
|
Packit Service |
c5cf8c |
b = -1;
|
|
Packit Service |
c5cf8c |
MPI_Sendrecv(&a, 1, MPI_INT, dest, 0, &b, 1, MPI_INT, dest, 0, newcomm, &status);
|
|
Packit Service |
c5cf8c |
if (b != dest) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Received %d expected %d on %d\n", b, dest, rank);
|
|
Packit Service |
c5cf8c |
fflush(stderr);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (status.MPI_SOURCE != dest) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Source not set correctly in status on %d\n", rank);
|
|
Packit Service |
c5cf8c |
fflush(stderr);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else if (rank == size - 1) {
|
|
Packit Service |
c5cf8c |
dest = 0;
|
|
Packit Service |
c5cf8c |
a = rank;
|
|
Packit Service |
c5cf8c |
b = -1;
|
|
Packit Service |
c5cf8c |
MPI_Sendrecv(&a, 1, MPI_INT, dest, 0, &b, 1, MPI_INT, dest, 0, newcomm, &status);
|
|
Packit Service |
c5cf8c |
if (b != dest) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Received %d expected %d on %d\n", b, dest, rank);
|
|
Packit Service |
c5cf8c |
fflush(stderr);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (status.MPI_SOURCE != dest) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Source not set correctly in status on %d\n", rank);
|
|
Packit Service |
c5cf8c |
fflush(stderr);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&newcomm);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|