Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
activate a bunch of tests using mpi_ssend, and change back those where they had been...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / ssendtest.c
1 /*
2  * Program to test that the "synchronous send" semantics
3  * of point to point communications in MPI is (probably) satisfied. 
4  * Two messages are send in one order; the destination uses MPI_Iprobe
5  * to look for the SECOND message before doing a receive on the first.
6  * To give a finite-termination, a fixed amount of time is used for
7  * the Iprobe test.
8  *
9  * This program has been patterned off of "overtake.c"
10  *
11  *                              William Gropp
12  *                              gropp@mcs.anl.gov
13  */
14
15 #include <stdio.h>
16 #include "test.h"
17 #include "mpi.h"
18
19 #define SIZE 10000
20 /* Amount of time in seconds to wait for the receipt of the second Ssend
21    message */
22 #define MAX_TIME 10
23 static int src  = 0;
24 static int dest = 1;
25
26 /* Prototypes for picky compilers */
27 void Generate_Data ( int *, int );
28
29 void Generate_Data( int *buffer, int buff_size)
30 {
31     int i;
32
33     for (i = 0; i < buff_size; i++)
34         buffer[i] = i+1;
35 }
36
37 int main( int argc, char **argv)
38 {
39     int rank; /* My Rank (0 or 1) */
40     int act_size = 0;
41     int flag, np, rval, i;
42     int buffer[SIZE];
43     double t0;
44     char *Current_Test = NULL;
45     MPI_Status status, status1, status2;
46     int count1, count2;
47     int sizes[4];
48
49     MPI_Init(&argc, &argv);
50     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
51     MPI_Comm_size( MPI_COMM_WORLD, &np );
52     if (np != 2) {
53         fprintf(stderr, "*** This program uses exactly 2 processes! ***\n");
54         MPI_Abort( MPI_COMM_WORLD, 1 );
55         }
56
57     sizes[0] = 0;
58     sizes[1] = 1;
59     sizes[2] = 1000;
60     sizes[3] = SIZE;
61 /*    for (i = 0; i < 4; i++ ) { */
62     for (i = 1; i < 2; i++ ) {
63         act_size = sizes[i];
64         if (rank == src) { 
65             Generate_Data(buffer, SIZE);
66             MPI_Recv( buffer, 0, MPI_INT, dest, 0, MPI_COMM_WORLD, &status );
67             MPI_Send( buffer, 0, MPI_INT, dest, 0, MPI_COMM_WORLD );
68             MPI_Ssend( buffer, act_size, MPI_INT, dest, 1, MPI_COMM_WORLD );
69             MPI_Ssend( buffer, act_size, MPI_INT, dest, 2, MPI_COMM_WORLD );
70             
71         } else if (rank == dest) {
72             Test_Init("ssendtest", rank);
73             /* Test 1 */
74             Current_Test = (char*)"Ssend Test (Synchronous Send -> Normal Recieve)";
75             MPI_Send( buffer, 0, MPI_INT, src, 0, MPI_COMM_WORLD );
76             MPI_Recv( buffer, 0, MPI_INT, src, 0, MPI_COMM_WORLD, &status );
77             t0 = MPI_Wtime();
78             flag = 0;
79             /* This test depends on a working wtime.  Make a simple check */
80             if (t0 == 0 && MPI_Wtime() == 0) {
81                 int loopcount = 1000000;
82                 /* This test is too severe (systems with fast 
83                    processors and large MPI_Wtick values can 
84                    fail.  Try harder to test MPI_Wtime */
85                 while (loopcount-- && MPI_Wtime() == 0) ;
86                 if (loopcount <= 0) {
87                     fprintf( stderr, 
88                              "MPI_WTIME is returning 0; a working value is needed\n\
89 for this test.\n" );
90                     Test_Failed(Current_Test);
91                     MPI_Abort( MPI_COMM_WORLD, 1 );
92                 }
93                 t0 = MPI_Wtime();
94             }
95             /*while (MPI_Wtime() - t0 < MAX_TIME) {
96                 MPI_Iprobe( src, 2, MPI_COMM_WORLD, &flag, &status );
97                 if (flag) {
98                     Test_Failed(Current_Test);
99                     break;
100                     }
101                 }*/
102             if (!flag) 
103                 Test_Passed(Current_Test);
104             MPI_Recv( buffer, act_size, MPI_INT, src, 1, MPI_COMM_WORLD, 
105                      &status1 );
106             MPI_Recv( buffer, act_size, MPI_INT, src, 2, MPI_COMM_WORLD, 
107                      &status2 );
108             
109             MPI_Get_count( &status1, MPI_INT, &count1 );
110             MPI_Get_count( &status2, MPI_INT, &count2 );
111             if (count1 != act_size) {
112                 fprintf( stdout, 
113                         "(1) Wrong count from recv of ssend: got %d (%d)\n", 
114                         count1, act_size );
115                 }
116             if (status1.MPI_TAG != 1) {
117                 fprintf( stdout, "(1) Wrong tag from recv of ssend: got %d\n", 
118                         status1.MPI_TAG );
119                 }
120             if (count2 != act_size) {
121                 fprintf( stdout, 
122                         "(2) Wrong count from recv of ssend: got %d (%d)\n", 
123                         count1, act_size );
124                 }
125             if (status2.MPI_TAG != 2) {
126                 fprintf( stdout, "(2) Wrong tag from recv of ssend: got %d\n", 
127                         status2.MPI_TAG );
128                 }
129
130             }
131         }
132
133     Test_Waitforall( );
134     rval = 0;
135     if (rank == dest) {
136             rval = Summarize_Test_Results(); /* Returns number of tests;
137                                                     that failed */
138             Test_Finalize();
139             }
140     MPI_Finalize();
141     return rval;
142 }
143
144
145