Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
528627207bd437807b6303d77ce1b7075dd94234
[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     for (count = 1; count < 65000; count = count * 2) {
35         while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
36             
37             sendtype.InitBuf( &sendtype );
38             recvtype.InitBuf( &recvtype );
39             
40             err = MPI_Irecv( recvtype.buf, recvtype.count, 
41                             recvtype.datatype, rank, 0, comm, &req );
42             if (err) {
43                 errs++;
44                 if (errs < 10) {
45                     MTestPrintError( err );
46                 }
47             }
48             
49             err = MPI_Send( sendtype.buf, sendtype.count, 
50                             sendtype.datatype, rank, 0, comm);
51             if (err) {
52                 errs++;
53                 if (errs < 10) {
54                     MTestPrintError( err );
55                 }
56             }
57             err = MPI_Wait( &req, MPI_STATUS_IGNORE );
58             err = MTestCheckRecv( 0, &recvtype );
59             if (err) {
60                 if (errs < 10) {
61                     printf( "Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n", 
62                             MTestGetDatatypeName( &recvtype ),
63                             MTestGetDatatypeName( &sendtype ),
64                             count );
65                     recvtype.printErrors = 1;
66                     (void)MTestCheckRecv( 0, &recvtype );
67                 }
68                 errs += err;
69             }
70
71             err = MPI_Irecv( recvtype.buf, recvtype.count, 
72                             recvtype.datatype, rank, 0, comm, &req );
73             if (err) {
74                 errs++;
75                 if (errs < 10) {
76                     MTestPrintError( err );
77                 }
78             }
79             
80             err = MPI_Ssend( sendtype.buf, sendtype.count, 
81                              sendtype.datatype, rank, 0, comm);
82             if (err) {
83                 errs++;
84                 if (errs < 10) {
85                     MTestPrintError( err );
86                 }
87             }
88             err = MPI_Wait( &req, MPI_STATUS_IGNORE );
89             err = MTestCheckRecv( 0, &recvtype );
90             if (err) {
91                 if (errs < 10) {
92                     printf( "Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n", 
93                             MTestGetDatatypeName( &recvtype ),
94                             MTestGetDatatypeName( &sendtype ),
95                             count );
96                     recvtype.printErrors = 1;
97                     (void)MTestCheckRecv( 0, &recvtype );
98                 }
99                 errs += err;
100             }
101
102             err = MPI_Irecv( recvtype.buf, recvtype.count, 
103                             recvtype.datatype, rank, 0, comm, &req );
104             if (err) {
105                 errs++;
106                 if (errs < 10) {
107                     MTestPrintError( err );
108                 }
109             }
110             
111             err = MPI_Rsend( sendtype.buf, sendtype.count, 
112                              sendtype.datatype, rank, 0, comm);
113             if (err) {
114                 errs++;
115                 if (errs < 10) {
116                     MTestPrintError( err );
117                 }
118             }
119             err = MPI_Wait( &req, MPI_STATUS_IGNORE );
120             err = MTestCheckRecv( 0, &recvtype );
121             if (err) {
122                 if (errs < 10) {
123                     printf( "Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d\n", 
124                             MTestGetDatatypeName( &recvtype ),
125                             MTestGetDatatypeName( &sendtype ),
126                             count );
127                     recvtype.printErrors = 1;
128                     (void)MTestCheckRecv( 0, &recvtype );
129                 }
130                 errs += err;
131             }
132
133             MTestFreeDatatype( &sendtype );
134             MTestFreeDatatype( &recvtype );
135         }
136     }
137
138     MTest_Finalize( errs );
139     MPI_Finalize();
140     return 0;
141 }