Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / issendtest.c
1 /*
2  * Program to test that the "synchronous send" semantics
3  * of point to point communications in MPI is (probably) satisfied. 
4  * This uses tests on the completions of the SENDS (unlike the MPI_Ssend
5  * test) since the Issends return "immediately" but can not complete
6  * until the matching receive begins.
7  *
8  * This program has been patterned off of "overtake.c"
9  *
10  *                              William Gropp
11  *                              gropp@mcs.anl.gov
12  */
13
14 #include <stdio.h>
15 #include "test.h"
16 #include "mpi.h"
17
18 #define SIZE 10000
19 /* Amount of time in seconds to wait for the receipt of the second Ssend
20    message */
21 #define MAX_TIME 20
22 static int src  = 1;
23 static int dest = 0;
24
25 /* Prototypes for picky compilers */
26 void Generate_Data ( int *, int );
27
28 void Generate_Data( int *buffer, int buff_size)
29 {
30     int i;
31
32     for (i = 0; i < buff_size; i++)
33         buffer[i] = i+1;
34 }
35
36 int main( int argc, char **argv)
37 {
38     int rank; /* My Rank (0 or 1) */
39     int act_size = 1000;
40 /*    int flag;*/
41     int buffer[SIZE];
42     double t0;
43     char *Current_Test = NULL;
44     MPI_Status status;
45     MPI_Request r1, r2;
46
47     MPI_Init(&argc, &argv);
48     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
49
50     /* This test depends on a working wtime.  Make a simple check */
51     Current_Test = (char*)"Testing timer";
52     t0 = MPI_Wtime();
53     if (t0 == 0 && MPI_Wtime() == 0) {
54         int loopcount = 1000000;
55         /* This test is too severe (systems with fast 
56            processors and large MPI_Wtick values can 
57            fail.  Try harder to test MPI_Wtime */
58         while (loopcount-- && MPI_Wtime() == 0) ;
59         if (loopcount <= 0) {
60             fprintf( stderr, 
61                      "MPI_WTIME is returning 0; a working value is needed\n\
62 for this test.\n" );
63             Test_Failed(Current_Test);
64             MPI_Abort( MPI_COMM_WORLD, 1 );
65         }
66         t0 = MPI_Wtime();
67     }
68     /* Test that the timer increases */
69 /*    Current_Test = (char*)"Testing timer increases";*/
70 /*    for (flag=0; flag<1000000; flag++) {*/
71 /*      if (MPI_Wtime() > t0) break;*/
72 /*    }*/
73 /*    if (flag >= 1000000) {*/
74 /*      fprintf( stderr, "MPI_WTIME is not returning increasing values!\n" );*/
75 /*      Test_Failed(Current_Test);*/
76 /*      MPI_Abort( MPI_COMM_WORLD, 1 );*/
77 /*    }*/
78
79     Current_Test = (char*)"Issend waits for recv";
80     if (rank == src) { 
81         Test_Init("issendtest", rank);
82         Generate_Data(buffer, SIZE);
83         MPI_Recv( buffer, 0, MPI_INT, dest, 0, MPI_COMM_WORLD, &status );
84         MPI_Send( buffer, 0, MPI_INT, dest, 0, MPI_COMM_WORLD );
85         MPI_Issend( buffer, act_size, MPI_INT, dest, 1, MPI_COMM_WORLD, &r1 );
86         MPI_Issend( buffer, act_size, MPI_INT, dest, 2, MPI_COMM_WORLD, &r2 );
87         t0 = MPI_Wtime();
88 /*      flag = 0;*/
89 /*      while ( (MPI_Wtime() - t0) < MAX_TIME) {*/
90 /*          MPI_Test( &r1, &flag, &status );*/
91 /*          if (flag) {*/
92 /*              Test_Failed(Current_Test);*/
93 /*              break;*/
94 /*              }*/
95 /*          }*/
96 /*      if (!flag) */
97 /*          Test_Passed(Current_Test);*/
98         MPI_Wait( &r2, &status );
99         MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, dest, 13,
100                       MPI_BOTTOM, 0, MPI_INT, dest, 13,
101                       MPI_COMM_WORLD, &status );
102         MPI_Wait( &r1, &status );
103         Test_Waitforall( );
104         {
105             int rval = Summarize_Test_Results(); /* Returns number of tests;
106                                                     that failed */
107             Test_Finalize();
108             MPI_Finalize();
109             return rval;
110         }
111
112     } else if (rank == dest) {
113         /* Test 1 */
114         MPI_Send( buffer, 0, MPI_INT, src, 0, MPI_COMM_WORLD );
115         MPI_Recv( buffer, 0, MPI_INT, src, 0, MPI_COMM_WORLD, &status );
116         MPI_Recv( buffer, act_size, MPI_INT, src, 2, MPI_COMM_WORLD, &status );
117         MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, src, 13,
118                       MPI_BOTTOM, 0, MPI_INT, src, 13,
119                       MPI_COMM_WORLD, &status );
120         MPI_Recv( buffer, act_size, MPI_INT, src, 1, MPI_COMM_WORLD, &status );
121
122         Test_Waitforall( );
123         Test_Finalize();
124         MPI_Finalize();
125     } else {
126         fprintf(stderr, "*** This program uses exactly 2 processes! ***\n");
127         MPI_Abort( MPI_COMM_WORLD, 1 );
128     }
129
130     return 0;
131 }