Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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) || (status.MPI_ERROR != MPI_SUCCESS)) {
44         errs++;
45         fprintf(stderr, "non-empty MPI_Status returned for MPI_REQUEST_NULL\n");
46     }
47
48     /* also pass MPI_STATUS_IGNORE to make sure the implementation doesn't
49      * blow up when it is passed as the status argument */
50     MPI_Request_get_status(MPI_REQUEST_NULL, &flag, MPI_STATUS_IGNORE);
51     if (!flag) {
52         errs++;
53         fprintf(stderr, "flag not true for MPI_REQUEST_NULL with MPI_STATUS_IGNORE, flag=%d\n",
54                 flag);
55     }
56 #endif
57
58     if (rank == source) {
59         buf[0] = size;
60         buf[1] = 3;
61         MPI_Ssend(buf, 2, MPI_INT, dest, 10, comm);
62     }
63     if (rank == dest) {
64         MPI_Irecv(buf, 2, MPI_INT, source, 10, comm, &req);
65     }
66     MPI_Barrier(comm);
67     /* At this point, we know that the receive has at least started,
68      * because of the Ssend.  Check the status on the request */
69     if (rank == dest) {
70         status.MPI_SOURCE = -1;
71         status.MPI_TAG = -1;
72         MPI_Request_get_status(req, &flag, &status);
73         if (flag) {
74             if (status.MPI_TAG != 10) {
75                 errs++;
76                 fprintf(stderr, "Tag value %d should be 10\n", status.MPI_TAG);
77             }
78             if (status.MPI_SOURCE != source) {
79                 errs++;
80                 fprintf(stderr, "Source value %d should be %d\n", status.MPI_SOURCE, source);
81             }
82             MPI_Get_count(&status, MPI_INT, &count);
83             if (count != 2) {
84                 errs++;
85                 fprintf(stderr, "Count value %d should be 2\n", count);
86             }
87         }
88         else {
89             errs++;
90             fprintf(stderr, "Unexpected flag value from get_status\n");
91         }
92         /* Now, complete the request */
93         MPI_Wait(&req, &status2);
94         /* Check that the status is correct */
95         if (status2.MPI_TAG != 10) {
96             errs++;
97             fprintf(stderr, "(wait)Tag value %d should be 10\n", status2.MPI_TAG);
98         }
99         if (status2.MPI_SOURCE != source) {
100             errs++;
101             fprintf(stderr, "(wait)Source value %d should be %d\n", status2.MPI_SOURCE, source);
102         }
103         MPI_Get_count(&status2, MPI_INT, &count);
104         if (count != 2) {
105             errs++;
106             fprintf(stderr, "(wait)Count value %d should be 2\n", count);
107         }
108     }
109
110     MTest_Finalize(errs);
111     MPI_Finalize();
112     return 0;
113 }