1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
12 static char MTEST_Descrip[] = "Send-Recv";
15 int main(int argc, char *argv[])
18 int rank, size, source, dest;
19 int minsize = 2, count;
21 MTestDatatype sendtype, recvtype;
23 MTest_Init(&argc, &argv);
25 /* The following illustrates the use of the routines to
26 * run through a selection of communicators and datatypes.
27 * Use subsets of these for tests that do not involve combinations
28 * of communicators, datatypes, and counts of datatypes */
29 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
30 if (comm == MPI_COMM_NULL)
33 /* Determine the sender and receiver */
34 MPI_Comm_rank(comm, &rank);
35 MPI_Comm_size(comm, &size);
39 /* To improve reporting of problems about operations, we
40 * change the error handler to errors return */
41 MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
43 MTEST_DATATYPE_FOR_EACH_COUNT(count) {
44 while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
45 /* Make sure that everyone has a recv buffer */
46 recvtype.InitBuf(&recvtype);
49 sendtype.InitBuf(&sendtype);
51 err = MPI_Send(sendtype.buf, sendtype.count, sendtype.datatype, dest, 0, comm);
59 else if (rank == dest) {
60 err = MPI_Recv(recvtype.buf, recvtype.count,
61 recvtype.datatype, source, 0, comm, MPI_STATUS_IGNORE);
69 err = MTestCheckRecv(0, &recvtype);
73 ("Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n",
74 MTestGetDatatypeName(&recvtype), MTestGetDatatypeName(&sendtype),
76 recvtype.printErrors = 1;
77 (void) MTestCheckRecv(0, &recvtype);
82 MTestFreeDatatype(&sendtype);
83 MTestFreeDatatype(&recvtype);