Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Free memory.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / sendself.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2006 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Test of sending to self (with a preposted receive)";
13 */
14
15 int main(int argc, char *argv[])
16 {
17     int errs = 0, err;
18     int rank, size;
19     int count;
20     MPI_Comm comm;
21     MPI_Request req;
22     MTestDatatype sendtype, recvtype;
23
24     MTest_Init(&argc, &argv);
25
26     comm = MPI_COMM_WORLD;
27     MPI_Comm_rank(comm, &rank);
28     MPI_Comm_size(comm, &size);
29
30     /* To improve reporting of problems about operations, we
31      * change the error handler to errors return */
32     MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
33
34     MTEST_DATATYPE_FOR_EACH_COUNT(count) {
35         while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
36
37             sendtype.InitBuf(&sendtype);
38             recvtype.InitBuf(&recvtype);
39
40             err = MPI_Irecv(recvtype.buf, recvtype.count, recvtype.datatype, rank, 0, comm, &req);
41             if (err) {
42                 errs++;
43                 if (errs < 10) {
44                     MTestPrintError(err);
45                 }
46             }
47
48             err = MPI_Send(sendtype.buf, sendtype.count, sendtype.datatype, rank, 0, comm);
49             if (err) {
50                 errs++;
51                 if (errs < 10) {
52                     MTestPrintError(err);
53                 }
54             }
55             err = MPI_Wait(&req, MPI_STATUS_IGNORE);
56             err = MTestCheckRecv(0, &recvtype);
57             if (err) {
58                 if (errs < 10) {
59                     printf
60                         ("Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n",
61                          MTestGetDatatypeName(&recvtype), MTestGetDatatypeName(&sendtype), count);
62                     recvtype.printErrors = 1;
63                     (void) MTestCheckRecv(0, &recvtype);
64                 }
65                 errs += err;
66             }
67
68             err = MPI_Irecv(recvtype.buf, recvtype.count, recvtype.datatype, rank, 0, comm, &req);
69             if (err) {
70                 errs++;
71                 if (errs < 10) {
72                     MTestPrintError(err);
73                 }
74             }
75
76             err = MPI_Ssend(sendtype.buf, sendtype.count, sendtype.datatype, rank, 0, comm);
77             if (err) {
78                 errs++;
79                 if (errs < 10) {
80                     MTestPrintError(err);
81                 }
82             }
83             err = MPI_Wait(&req, MPI_STATUS_IGNORE);
84             err = MTestCheckRecv(0, &recvtype);
85             if (err) {
86                 if (errs < 10) {
87                     printf
88                         ("Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n",
89                          MTestGetDatatypeName(&recvtype), MTestGetDatatypeName(&sendtype), count);
90                     recvtype.printErrors = 1;
91                     (void) MTestCheckRecv(0, &recvtype);
92                 }
93                 errs += err;
94             }
95
96             err = MPI_Irecv(recvtype.buf, recvtype.count, recvtype.datatype, rank, 0, comm, &req);
97             if (err) {
98                 errs++;
99                 if (errs < 10) {
100                     MTestPrintError(err);
101                 }
102             }
103
104             err = MPI_Rsend(sendtype.buf, sendtype.count, sendtype.datatype, rank, 0, comm);
105             if (err) {
106                 errs++;
107                 if (errs < 10) {
108                     MTestPrintError(err);
109                 }
110             }
111             err = MPI_Wait(&req, MPI_STATUS_IGNORE);
112             err = MTestCheckRecv(0, &recvtype);
113             if (err) {
114                 if (errs < 10) {
115                     printf
116                         ("Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n",
117                          MTestGetDatatypeName(&recvtype), MTestGetDatatypeName(&sendtype), count);
118                     recvtype.printErrors = 1;
119                     (void) MTestCheckRecv(0, &recvtype);
120                 }
121                 errs += err;
122             }
123
124             MTestFreeDatatype(&sendtype);
125             MTestFreeDatatype(&recvtype);
126         }
127     }
128
129     MTest_Finalize(errs);
130     MPI_Finalize();
131     return 0;
132 }