|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <stdlib.h>
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* Test handling of truncated messages, including short and rendezvous
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
static int testShort = 1;
|
|
Packit |
0848f5 |
static int ShortLen = 2;
|
|
Packit |
0848f5 |
static int testMid = 1;
|
|
Packit |
0848f5 |
static int MidLen = 64;
|
|
Packit |
0848f5 |
static int testLong = 1;
|
|
Packit |
0848f5 |
static int LongLen = 100000;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int checkTruncError(int err, const char *msg);
|
|
Packit |
0848f5 |
int checkOk(int err, const char *msg);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
MPI_Status status;
|
|
Packit |
0848f5 |
int err, errs = 0, source, dest, rank, size;
|
|
Packit |
0848f5 |
int *buf = 0;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit |
0848f5 |
source = 0;
|
|
Packit |
0848f5 |
dest = size - 1;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
buf = (int *) malloc(LongLen * sizeof(int));
|
|
Packit |
0848f5 |
MTEST_VG_MEM_INIT(buf, LongLen * sizeof(int));
|
|
Packit |
0848f5 |
if (!buf) {
|
|
Packit |
0848f5 |
fprintf(stderr, "Unable to allocate communication buffer of size %d\n", LongLen);
|
|
Packit |
0848f5 |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (testShort) {
|
|
Packit |
0848f5 |
if (rank == source) {
|
|
Packit |
0848f5 |
err = MPI_Send(buf, ShortLen, MPI_INT, dest, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
errs += checkOk(err, "short");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (rank == dest) {
|
|
Packit |
0848f5 |
err = MPI_Recv(buf, ShortLen - 1, MPI_INT, source, 0, MPI_COMM_WORLD, &status);
|
|
Packit |
0848f5 |
errs += checkTruncError(err, "short");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* Try a message that is arrives after the receive is posted */
|
|
Packit |
0848f5 |
if (rank == source) {
|
|
Packit |
0848f5 |
MPI_Sendrecv(MPI_BOTTOM, 0, MPI_INT, dest, 1,
|
|
Packit |
0848f5 |
MPI_BOTTOM, 0, MPI_INT, dest, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
MPI_Send(buf, ShortLen, MPI_INT, dest, 2, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (rank == dest) {
|
|
Packit |
0848f5 |
MPI_Request req;
|
|
Packit |
0848f5 |
err = MPI_Irecv(buf, ShortLen - 1, MPI_INT, source, 2, MPI_COMM_WORLD, &req;;
|
|
Packit |
0848f5 |
errs += checkOk(err, "irecv-short");
|
|
Packit |
0848f5 |
MPI_Sendrecv(MPI_BOTTOM, 0, MPI_INT, source, 1,
|
|
Packit |
0848f5 |
MPI_BOTTOM, 0, MPI_INT, source, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
err = MPI_Wait(&req, &status);
|
|
Packit |
0848f5 |
errs += checkTruncError(err, "irecv-short");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (testMid) {
|
|
Packit |
0848f5 |
if (rank == source) {
|
|
Packit |
0848f5 |
err = MPI_Send(buf, MidLen, MPI_INT, dest, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
errs += checkOk(err, "medium");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (rank == dest) {
|
|
Packit |
0848f5 |
err = MPI_Recv(buf, MidLen - 1, MPI_INT, source, 0, MPI_COMM_WORLD, &status);
|
|
Packit |
0848f5 |
errs += checkTruncError(err, "medium");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (testLong) {
|
|
Packit |
0848f5 |
if (rank == source) {
|
|
Packit |
0848f5 |
err = MPI_Send(buf, LongLen, MPI_INT, dest, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
errs += checkOk(err, "long");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (rank == dest) {
|
|
Packit |
0848f5 |
err = MPI_Recv(buf, LongLen - 1, MPI_INT, source, 0, MPI_COMM_WORLD, &status);
|
|
Packit |
0848f5 |
errs += checkTruncError(err, "long");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
free(buf);
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int checkTruncError(int err, const char *msg)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
char errMsg[MPI_MAX_ERROR_STRING];
|
|
Packit |
0848f5 |
int errs = 0, msgLen, errclass;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (!err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "MPI_Recv (%s) returned MPI_SUCCESS instead of truncated message\n", msg);
|
|
Packit |
0848f5 |
fflush(stderr);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
MPI_Error_class(err, &errclass);
|
|
Packit |
0848f5 |
if (errclass != MPI_ERR_TRUNCATE) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MPI_Error_string(err, errMsg, &msgLen);
|
|
Packit |
0848f5 |
fprintf(stderr, "MPI_Recv (%s) returned unexpected error message: %s\n", msg, errMsg);
|
|
Packit |
0848f5 |
fflush(stderr);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
return errs;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int checkOk(int err, const char *msg)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
char errMsg[MPI_MAX_ERROR_STRING];
|
|
Packit |
0848f5 |
int errs = 0, msgLen;
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MPI_Error_string(err, errMsg, &msgLen);
|
|
Packit |
0848f5 |
fprintf(stderr, "MPI_Send(%s) failed with %s\n", msg, errMsg);
|
|
Packit |
0848f5 |
fflush(stderr);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return errs;
|
|
Packit |
0848f5 |
}
|