Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the compilation of MPICH3 tests with the absolute paranoid flags (enable_maintainer)
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / sendrecv1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Send-Recv";
13 */
14
15 int main(int argc, char *argv[])
16 {
17     int errs = 0, err;
18     int rank, size, source, dest;
19     int minsize = 2, count;
20     MPI_Comm comm;
21     MTestDatatype sendtype, recvtype;
22
23     MTest_Init(&argc, &argv);
24
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)
31             continue;
32
33         /* Determine the sender and receiver */
34         MPI_Comm_rank(comm, &rank);
35         MPI_Comm_size(comm, &size);
36         source = 0;
37         dest = size - 1;
38
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);
42
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);
47
48                 if (rank == source) {
49                     sendtype.InitBuf(&sendtype);
50
51                     err = MPI_Send(sendtype.buf, sendtype.count, sendtype.datatype, dest, 0, comm);
52                     if (err) {
53                         errs++;
54                         if (errs < 10) {
55                             MTestPrintError(err);
56                         }
57                     }
58                 }
59                 else if (rank == dest) {
60                     err = MPI_Recv(recvtype.buf, recvtype.count,
61                                    recvtype.datatype, source, 0, comm, MPI_STATUS_IGNORE);
62                     if (err) {
63                         errs++;
64                         if (errs < 10) {
65                             MTestPrintError(err);
66                         }
67                     }
68
69                     err = MTestCheckRecv(0, &recvtype);
70                     if (err) {
71                         if (errs < 10) {
72                             printf
73                                 ("Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n",
74                                  MTestGetDatatypeName(&recvtype), MTestGetDatatypeName(&sendtype),
75                                  count);
76                             recvtype.printErrors = 1;
77                             (void) MTestCheckRecv(0, &recvtype);
78                         }
79                         errs += err;
80                     }
81                 }
82                 MTestFreeDatatype(&sendtype);
83                 MTestFreeDatatype(&recvtype);
84             }
85         }
86         MTestFreeComm(&comm);
87     }
88
89     MTest_Finalize(errs);
90     MPI_Finalize();
91     return 0;
92 }