Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / irecvtest.c
1 /*
2  * Program to test that the "no overtaking messages" semantics
3  * of point to point communications in MPI is satisfied, 
4  * for a simple send/irecv operation.
5  *
6  * Derived from a program written by 
7  *                              Patrick Bridges
8  *                              bridges@mcs.anl.gov
9  *                              patrick@CS.MsState.Edu
10  */
11
12 #include <stdio.h>
13 #include "test.h"
14 #include "mpi.h"
15
16 #define SIZE 10000
17
18 static int src  = 0;
19 static int dest = 1;
20
21 /* Which tests to perform (not yet implemented) */
22 /* static int Do_Buffer = 1; */
23 /* static int Do_Standard = 1; */
24
25 /* Prototypes for picky compilers */
26 void Generate_Data ( double *, int );
27 void Normal_Test_Send ( double *, int );
28 void Async_Test_Recv ( double *, int );
29 int Check_Data ( double *, int );
30 void Clear_Buffer ( double *, int );
31
32 void Generate_Data(buffer, buff_size)
33 double *buffer;
34 int buff_size;
35 {
36     int i;
37
38     for (i = 0; i < buff_size; i++)
39         buffer[i] = (double)i+1;
40 }
41
42 #define NSHORT 10
43 void Normal_Test_Send(buffer, buff_size)
44 double *buffer;
45 int buff_size;
46 {
47     int i, j;
48
49     for (j = 0; j < 2; j++) {
50         /* send a long message */
51         MPI_Send(buffer, (buff_size/2 - NSHORT), MPI_DOUBLE, dest, 2000, 
52                  MPI_COMM_WORLD);
53         buffer += buff_size/2 - NSHORT;
54         /* Followed by NSHORT short ones */
55         for (i = 0; i < NSHORT; i++)
56             MPI_Send(buffer++, 1, MPI_DOUBLE, dest, 2000, MPI_COMM_WORLD);
57     }
58 }
59
60 void Async_Test_Recv(buffer, buff_size)
61 double *buffer;
62 int buff_size;
63 {
64     int i, j, req = 0;
65     MPI_Status Stat[22];
66     MPI_Request Hand[22];
67     
68     for (j = 0; j < 2; j++) {
69         /* Receive a long message */
70         MPI_Irecv(buffer, (buff_size/2 - NSHORT), MPI_DOUBLE, src, 
71                  2000, MPI_COMM_WORLD, &(Hand[req++]));
72         buffer += buff_size/2 - NSHORT;
73         /* Followed by NSHORT short ones */
74         for (i = 0; i < NSHORT; i++)
75             MPI_Irecv(buffer++, 1, MPI_DOUBLE, src, 2000, 
76                       MPI_COMM_WORLD, &(Hand[req++]));
77     }
78     MPI_Waitall(req, Hand, Stat);
79 }
80
81 int Check_Data(buffer, buff_size)
82 double *buffer;
83 int buff_size;
84 {
85     int i;
86     int err = 0;
87
88     for (i = 0; i < buff_size; i++)
89         if (buffer[i] != (i + 1)) {
90             err++;
91             fprintf( stderr, "Value at %d is %f, should be %f\n", i, 
92                     buffer[i], (double)(i+1) );
93             fflush( stderr );
94             if (err > 10) return 1;
95             }
96     return err;
97 }
98
99 void Clear_Buffer(buffer, buff_size)
100 double *buffer;
101 int buff_size;
102 {
103     int i;
104     for (i = 0; i < buff_size; i++)
105         buffer[i] = -1;
106 }
107
108
109 int main( int argc, char **argv)
110 {
111     int rank; /* My Rank (0 or 1) */
112     double buffer[SIZE];
113     char *Current_Test = NULL;
114
115     MPI_Init(&argc, &argv);
116     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
117
118     if (rank == src) { 
119         Generate_Data(buffer, SIZE);
120         Normal_Test_Send(buffer, SIZE);
121         Test_Waitforall( );
122         MPI_Finalize();
123
124     } else if (rank == dest) {
125         Test_Init("irecvtest", rank);
126         /* Test 2 */
127         Clear_Buffer(buffer, SIZE);
128         Current_Test = (char*)"Overtaking Test (Normal Send   ->  Async Receive)";
129         Async_Test_Recv(buffer, SIZE);
130         if (Check_Data(buffer, SIZE))
131             Test_Failed(Current_Test);
132         else
133             Test_Passed(Current_Test);
134         Test_Waitforall( );
135
136         MPI_Finalize();
137         {
138             int rval = Summarize_Test_Results(); /* Returns number of tests;
139                                                     that failed */
140             Test_Finalize();
141             return rval;
142         }
143     } else {
144         fprintf(stderr, "*** This program uses exactly 2 processes! ***\n");
145         MPI_Abort( MPI_COMM_WORLD, 1 );
146     }
147
148     return 0;
149 }
150
151
152