|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2006 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <stdlib.h>
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Test Ibsend and Request_free */
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
MPI_Comm comm = MPI_COMM_WORLD;
|
|
Packit |
0848f5 |
int dest = 1, src = 0, tag = 1;
|
|
Packit |
0848f5 |
int s1;
|
|
Packit |
0848f5 |
char *buf, *bbuf;
|
|
Packit |
0848f5 |
int smsg[5], rmsg[5];
|
|
Packit |
0848f5 |
int errs = 0, rank, size;
|
|
Packit |
0848f5 |
int bufsize, bsize;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit |
0848f5 |
if (src >= size || dest >= size) {
|
|
Packit |
0848f5 |
int r = src;
|
|
Packit |
0848f5 |
if (dest > r)
|
|
Packit |
0848f5 |
r = dest;
|
|
Packit |
0848f5 |
fprintf(stderr, "This program requires %d processes\n", r - 1);
|
|
Packit |
0848f5 |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (rank == src) {
|
|
Packit |
0848f5 |
MPI_Request r;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* According to the standard, we must use the PACK_SIZE length of each
|
|
Packit |
0848f5 |
* message in the computation of the message buffer size */
|
|
Packit |
0848f5 |
MPI_Pack_size(5, MPI_INT, comm, &s1;;
|
|
Packit |
0848f5 |
bufsize = MPI_BSEND_OVERHEAD + s1 + 2000;
|
|
Packit |
0848f5 |
buf = (char *) malloc(bufsize);
|
|
Packit |
0848f5 |
MPI_Buffer_attach(buf, bufsize);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "About create and free Isend request\n");
|
|
Packit |
0848f5 |
smsg[0] = 10;
|
|
Packit |
0848f5 |
MPI_Isend(&smsg[0], 1, MPI_INT, dest, tag, comm, &r);
|
|
Packit |
0848f5 |
MPI_Request_free(&r);
|
|
Packit |
0848f5 |
if (r != MPI_REQUEST_NULL) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Request not set to NULL after request free\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "About create and free Ibsend request\n");
|
|
Packit |
0848f5 |
smsg[1] = 11;
|
|
Packit |
0848f5 |
MPI_Ibsend(&smsg[1], 1, MPI_INT, dest, tag + 1, comm, &r);
|
|
Packit |
0848f5 |
MPI_Request_free(&r);
|
|
Packit |
0848f5 |
if (r != MPI_REQUEST_NULL) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Request not set to NULL after request free\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "About create and free Issend request\n");
|
|
Packit |
0848f5 |
smsg[2] = 12;
|
|
Packit |
0848f5 |
MPI_Issend(&smsg[2], 1, MPI_INT, dest, tag + 2, comm, &r);
|
|
Packit |
0848f5 |
MPI_Request_free(&r);
|
|
Packit |
0848f5 |
if (r != MPI_REQUEST_NULL) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Request not set to NULL after request free\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "About create and free Irsend request\n");
|
|
Packit |
0848f5 |
smsg[3] = 13;
|
|
Packit |
0848f5 |
MPI_Irsend(&smsg[3], 1, MPI_INT, dest, tag + 3, comm, &r);
|
|
Packit |
0848f5 |
MPI_Request_free(&r);
|
|
Packit |
0848f5 |
if (r != MPI_REQUEST_NULL) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Request not set to NULL after request free\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
smsg[4] = 14;
|
|
Packit |
0848f5 |
MPI_Isend(&smsg[4], 1, MPI_INT, dest, tag + 4, comm, &r);
|
|
Packit |
0848f5 |
MPI_Wait(&r, MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* We can't guarantee that messages arrive until the detach */
|
|
Packit |
0848f5 |
MPI_Buffer_detach(&bbuf, &bsize);
|
|
Packit |
0848f5 |
free(buf);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (rank == dest) {
|
|
Packit |
0848f5 |
MPI_Request r[5];
|
|
Packit |
0848f5 |
int i;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
for (i = 0; i < 5; i++) {
|
|
Packit |
0848f5 |
MPI_Irecv(&rmsg[i], 1, MPI_INT, src, tag + i, comm, &r[i]);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (rank != src) /* Just in case rank == src */
|
|
Packit |
0848f5 |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
for (i = 0; i < 4; i++) {
|
|
Packit |
0848f5 |
MPI_Wait(&r[i], MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
if (rmsg[i] != 10 + i) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "message %d (%d) should be %d\n", i, rmsg[i], 10 + i);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* The MPI standard says that there is no way to use MPI_Request_free
|
|
Packit |
0848f5 |
* safely with receive requests. A strict MPI implementation may
|
|
Packit |
0848f5 |
* choose to consider these erroreous (an IBM MPI implementation
|
|
Packit |
0848f5 |
* does so) */
|
|
Packit |
0848f5 |
#ifdef USE_STRICT_MPI
|
|
Packit |
0848f5 |
MPI_Wait(&r[4], MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
#else
|
|
Packit |
0848f5 |
MTestPrintfMsg(10, "About free Irecv request\n");
|
|
Packit |
0848f5 |
MPI_Request_free(&r[4]);
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (rank != dest && rank != src) {
|
|
Packit |
0848f5 |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|