Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
102e9f8acd6ddc13d70229e4b64ffbb4dcde73c5
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / rqstatus.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[] = "Test Request_get_status";
13 */
14
15 int main( int argc, char *argv[] )
16 {
17     int errs = 0;
18     int rank, size, source, dest;
19     int buf[2], flag, count;
20     MPI_Comm      comm;
21     MPI_Status    status, status2;
22     MPI_Request   req;
23
24     MTest_Init( &argc, &argv );
25
26     comm = MPI_COMM_WORLD;
27     /* Determine the sender and receiver */
28     MPI_Comm_rank( comm, &rank );
29     MPI_Comm_size( comm, &size );
30     source = 0;
31     dest   = size - 1;
32
33
34     /* Handling MPI_REQUEST_NULL in MPI_Request_get_status was only required
35        starting with MPI-2.2. */
36 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
37     MPI_Request_get_status( MPI_REQUEST_NULL, &flag, &status );
38     if (!flag) {
39         errs++;
40         fprintf( stderr, "flag not true for MPI_REQUEST_NULL, flag=%d\n", flag );
41     }
42     if ((status.MPI_SOURCE != MPI_ANY_SOURCE) ||
43         (status.MPI_TAG != MPI_ANY_TAG) ||
44         (status.MPI_ERROR != MPI_SUCCESS))
45     {
46         errs++;
47         fprintf( stderr, "non-empty MPI_Status returned for MPI_REQUEST_NULL\n" );
48     }
49
50     /* also pass MPI_STATUS_IGNORE to make sure the implementation doesn't
51      * blow up when it is passed as the status argument */
52     MPI_Request_get_status( MPI_REQUEST_NULL, &flag, MPI_STATUS_IGNORE );
53     if (!flag) {
54         errs++;
55         fprintf( stderr, "flag not true for MPI_REQUEST_NULL with MPI_STATUS_IGNORE, flag=%d\n", flag );
56     }
57 #endif
58
59     if (rank == source) {
60         buf[0] = size;
61         buf[1] = 3;
62         MPI_Ssend( buf, 2, MPI_INT, dest, 10, comm );
63     }
64     if (rank == dest) {
65         MPI_Irecv( buf, 2, MPI_INT, source, 10, comm, &req );
66     }
67     MPI_Barrier( comm );
68     /* At this point, we know that the receive has at least started,
69        because of the Ssend.  Check the status on the request */
70     if (rank == dest) {
71         status.MPI_SOURCE = -1;
72         status.MPI_TAG    = -1;
73         MPI_Request_get_status( req, &flag, &status );
74         if (flag) {
75             if (status.MPI_TAG != 10) {
76                 errs++;
77                 fprintf( stderr, "Tag value %d should be 10\n", status.MPI_TAG );
78             }
79             if (status.MPI_SOURCE != source) {
80                 errs++;
81                 fprintf( stderr, "Source value %d should be %d\n", status.MPI_SOURCE, source );
82             }
83             MPI_Get_count( &status, MPI_INT, &count );
84             if (count != 2) {
85                 errs++;
86                 fprintf( stderr, "Count value %d should be 2\n", count );
87             }
88         }
89         else {
90             errs++;
91             fprintf( stderr, "Unexpected flag value from get_status\n" );
92         }
93         /* Now, complete the request */
94         MPI_Wait( &req, &status2 );
95         /* Check that the status is correct */
96         if (status2.MPI_TAG != 10) {
97             errs++;
98             fprintf( stderr, "(wait)Tag value %d should be 10\n", status2.MPI_TAG );
99         }
100         if (status2.MPI_SOURCE != source) {
101             errs++;
102             fprintf( stderr, "(wait)Source value %d should be %d\n", status2.MPI_SOURCE, source );
103         }
104         MPI_Get_count( &status2, MPI_INT, &count );
105         if (count != 2) {
106             errs++;
107             fprintf( stderr, "(wait)Count value %d should be 2\n", count );
108         }
109     }
110
111     MTest_Finalize( errs );
112     MPI_Finalize();
113     return 0;
114 }