Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / inactivereq.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2005 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 /* This test program checks that the point-to-point completion routines
12    can be applied to an inactive persistent request, as required by the 
13    MPI-1 standard. See section 3.7.3, for example, 
14
15    One is allowed to call MPI TEST with a null or inactive request argument. 
16    In such a case the operation returns with flag = true and empty status.
17
18 */
19
20 int StatusEmpty( MPI_Status *s );
21 int StatusEmpty( MPI_Status *s )
22 {
23     int errs = 0;
24     int count = 10;
25
26     if (s->MPI_TAG != MPI_ANY_TAG) {
27         errs++;
28         printf( "MPI_TAG not MPI_ANY_TAG in status\n" );
29     }
30     if (s->MPI_SOURCE != MPI_ANY_SOURCE) {
31         errs++;
32         printf( "MPI_SOURCE not MPI_ANY_SOURCE in status\n" );
33     }
34     MPI_Get_count( s, MPI_INT, &count );
35     if (count != 0) {
36         errs++;
37         printf( "count in status is not 0\n" );
38     }
39     /* Return true only if status passed all tests */
40     return errs ? 0 : 1;
41 }
42
43 int main(int argc, char *argv[])
44 {
45     MPI_Request r;
46     MPI_Status  s;
47     int errs = 0;
48     int flag;
49     int buf[10];
50     int rbuf[10];
51     int tag = 27;
52     int dest = 0;
53     int rank, size;
54
55     MTest_Init( &argc, &argv );
56
57     MPI_Comm_size( MPI_COMM_WORLD, &size );
58     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
59
60     /* Create a persistent send request */
61     MPI_Send_init( buf, 10, MPI_INT, dest, tag, MPI_COMM_WORLD, &r );
62
63     flag = 0;
64     s.MPI_TAG = 10;
65     s.MPI_SOURCE = 10;
66     MPI_Test( &r, &flag, &s );
67     if (!flag) {
68         errs++;
69         printf( "Flag not true after MPI_Test (send)\n" );
70         printf( "Aborting further tests to avoid hanging in MPI_Wait\n" );
71         MTest_Finalize( errs );
72         MPI_Finalize();
73         return 0;
74     }
75     if (!StatusEmpty( &s )) {
76         errs++;
77         printf( "Status not empty after MPI_Test (send)\n" );
78     }
79
80     s.MPI_TAG = 10;
81     s.MPI_SOURCE = 10;
82     MPI_Wait( &r, &s );
83     if (!StatusEmpty( &s )) {
84         errs++;
85         printf( "Status not empty after MPI_Wait (send)\n" );
86     }
87
88     /* Now try to use that request, then check again */
89     if (rank == 0) {
90         int i;
91         MPI_Request *rr = (MPI_Request *)malloc(size * sizeof(MPI_Request));
92         for (i=0; i<size; i++) {
93             MPI_Irecv( rbuf, 10, MPI_INT, i, tag, MPI_COMM_WORLD, &rr[i] );
94         }
95         MPI_Start( &r );
96         MPI_Wait( &r, &s );
97         MPI_Waitall( size, rr, MPI_STATUSES_IGNORE );
98     }
99     else {
100         MPI_Start( &r );
101         MPI_Wait( &r, &s );
102     }
103
104     flag = 0;
105     s.MPI_TAG = 10;
106     s.MPI_SOURCE = 10;
107     MPI_Test( &r, &flag, &s );
108     if (!flag) {
109         errs++;
110         printf( "Flag not true after MPI_Test (send)\n" );
111         printf( "Aborting further tests to avoid hanging in MPI_Wait\n" );
112         MTest_Finalize( errs );
113         MPI_Finalize();
114         return 0;
115     }
116     if (!StatusEmpty( &s )) {
117         errs++;
118         printf( "Status not empty after MPI_Test (send)\n" );
119     }
120
121     s.MPI_TAG = 10;
122     s.MPI_SOURCE = 10;
123     MPI_Wait( &r, &s );
124     if (!StatusEmpty( &s )) {
125         errs++;
126         printf( "Status not empty after MPI_Wait (send)\n" );
127     }
128
129     
130
131     MPI_Request_free( &r );
132
133     /* Create a persistent receive request */
134     MPI_Recv_init( buf, 10, MPI_INT, dest, tag, MPI_COMM_WORLD, &r );
135
136     flag = 0;
137     s.MPI_TAG = 10;
138     s.MPI_SOURCE = 10;
139     MPI_Test( &r, &flag, &s );
140     if (!flag) {
141         errs++;
142         printf( "Flag not true after MPI_Test (recv)\n" );
143         printf( "Aborting further tests to avoid hanging in MPI_Wait\n" );
144         MTest_Finalize( errs );
145         MPI_Finalize();
146         return 0;
147     }
148     if (!StatusEmpty( &s )) {
149         errs++;
150         printf( "Status not empty after MPI_Test (recv)\n" );
151     }
152
153     s.MPI_TAG = 10;
154     s.MPI_SOURCE = 10;
155     MPI_Wait( &r, &s );
156     if (!StatusEmpty( &s )) {
157         errs++;
158         printf( "Status not empty after MPI_Wait (recv)\n" );
159     }
160
161     MPI_Request_free( &r );
162     
163     MTest_Finalize( errs );
164     MPI_Finalize();
165     return 0;
166 }