|
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 |
/*
|
|
Packit Service |
c5cf8c |
static char MTEST_Descrip[] = "Test that communicators have reference count semantics";
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define NELM 128
|
|
Packit Service |
c5cf8c |
#define NCOMM 1020
|
|
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, source, dest, i;
|
|
Packit Service |
c5cf8c |
MPI_Comm comm;
|
|
Packit Service |
c5cf8c |
MPI_Comm tmpComm[NCOMM];
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
MPI_Request req;
|
|
Packit Service |
c5cf8c |
int *buf = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_dup(MPI_COMM_WORLD, &comm);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* This is similar to the datatype test, except that we post
|
|
Packit Service |
c5cf8c |
* an irecv on a simple data buffer but use a rank-reordered communicator.
|
|
Packit Service |
c5cf8c |
* In this case, an error in handling the reference count will most
|
|
Packit Service |
c5cf8c |
* likely cause the program to hang, so this should be run only
|
|
Packit Service |
c5cf8c |
* if (a) you are confident that the code is correct or (b)
|
|
Packit Service |
c5cf8c |
* a timeout is set for mpiexec
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(comm, &rank;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(comm, &size);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (size < 2) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "This test requires at least two processes.");
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
source = 0;
|
|
Packit Service |
c5cf8c |
dest = size - 1;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (rank == dest) {
|
|
Packit Service |
c5cf8c |
buf = (int *) malloc(NELM * sizeof(int));
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NELM; i++)
|
|
Packit Service |
c5cf8c |
buf[i] = -i;
|
|
Packit Service |
c5cf8c |
MPI_Irecv(buf, NELM, MPI_INT, source, 0, comm, &req;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&comm);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (comm != MPI_COMM_NULL) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("Freed comm was not set to COMM_NULL\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NCOMM; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_split(MPI_COMM_WORLD, 0, size - rank, &tmpComm[i]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Sendrecv(NULL, 0, MPI_INT, source, 1,
|
|
Packit Service |
c5cf8c |
NULL, 0, MPI_INT, source, 1, MPI_COMM_WORLD, &status);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Wait(&req, &status);
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NELM; i++) {
|
|
Packit Service |
c5cf8c |
if (buf[i] != i) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
if (errs < 10) {
|
|
Packit Service |
c5cf8c |
printf("buf[%d] = %d, expected %d\n", i, buf[i], i);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NCOMM; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&tmpComm[i]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
free(buf);
|
|
Packit Service |
c5cf8c |
} else if (rank == source) {
|
|
Packit Service |
c5cf8c |
buf = (int *) malloc(NELM * sizeof(int));
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NELM; i++)
|
|
Packit Service |
c5cf8c |
buf[i] = i;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NCOMM; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_split(MPI_COMM_WORLD, 0, size - rank, &tmpComm[i]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* Synchronize with the receiver */
|
|
Packit Service |
c5cf8c |
MPI_Sendrecv(NULL, 0, MPI_INT, dest, 1, NULL, 0, MPI_INT, dest, 1, MPI_COMM_WORLD, &status);
|
|
Packit Service |
c5cf8c |
MPI_Send(buf, NELM, MPI_INT, dest, 0, comm);
|
|
Packit Service |
c5cf8c |
free(buf);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NCOMM; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_split(MPI_COMM_WORLD, 0, size - rank, &tmpComm[i]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (rank != dest) {
|
|
Packit Service |
c5cf8c |
/* Clean up the communicators */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NCOMM; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&tmpComm[i]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (comm != MPI_COMM_NULL) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&comm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|