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 / issendinit.c
1 /*
2  * Program to test that the "synchronous send" semantics
3  * of point to point communications in MPI is (probably) satisfied. 
4  * This is done by starting two synchronous sends and then testing that
5  * they do not complete until the matchine receives are issued.
6  */
7
8 #include <stdio.h>
9 #include "test.h"
10 #include "mpi.h"
11
12 #define SIZE 10000
13 /* Amount of time in seconds to wait for the receipt of the second Ssend
14    message */
15 #define MAX_TIME 20
16 static int src  = 1;
17 static int dest = 0;
18
19 /* Prototypes for picky compilers */
20 void Generate_Data ( int *, int );
21
22 void Generate_Data(buffer, buff_size)
23 int *buffer;
24 int buff_size;
25 {
26     int i;
27
28     for (i = 0; i < buff_size; i++)
29         buffer[i] = i+1;
30 }
31
32 int main( int argc, char **argv )
33 {
34     int rank; /* My Rank (0 or 1) */
35     int act_size = 1000;
36     int flag;
37     int buffer[SIZE];
38     double t0;
39     char *Current_Test = NULL;
40     MPI_Status status;
41     MPI_Request r[2];
42
43     MPI_Init(&argc, &argv);
44     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
45
46     if (rank == src) { 
47         Test_Init("issendinit", rank);
48         Generate_Data(buffer, SIZE);
49         Current_Test = (char*)"Ssend_init waits for recv";
50         MPI_Recv( buffer, 0, MPI_INT, dest, 0, MPI_COMM_WORLD, &status );
51         MPI_Send( buffer, 0, MPI_INT, dest, 0, MPI_COMM_WORLD );
52         MPI_Ssend_init( buffer, act_size, MPI_INT, dest, 1, MPI_COMM_WORLD, 
53                         &r[0] );
54         MPI_Ssend_init( buffer, act_size, MPI_INT, dest, 2, MPI_COMM_WORLD, 
55                         &r[1] );
56         MPI_Startall( 2, r );
57         t0 = MPI_Wtime();
58         flag = 0;
59         while (MPI_Wtime() - t0 < MAX_TIME) {
60             MPI_Test( &r[0], &flag, &status );
61             if (flag) {
62                 Test_Failed(Current_Test);
63                 break;
64                 }
65             }
66         if (!flag) 
67             Test_Passed(Current_Test);
68         MPI_Wait( &r[1], &status );
69         MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, dest, 13,
70                       MPI_BOTTOM, 0, MPI_INT, dest, 13,
71                       MPI_COMM_WORLD, &status );
72         MPI_Wait( &r[0], &status );
73         MPI_Request_free( &r[0] );
74         MPI_Request_free( &r[1] );
75         Test_Waitforall( );
76         {
77             int rval = Summarize_Test_Results(); /* Returns number of tests;
78                                                     that failed */
79             Test_Finalize();
80             MPI_Finalize();
81             return rval;
82         }
83
84     } else if (rank == dest) {
85         MPI_Send( buffer, 0, MPI_INT, src, 0, MPI_COMM_WORLD );
86         MPI_Recv( buffer, 0, MPI_INT, src, 0, MPI_COMM_WORLD, &status );
87         MPI_Recv( buffer, act_size, MPI_INT, src, 2, MPI_COMM_WORLD, &status );
88         MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, src, 13,
89                       MPI_BOTTOM, 0, MPI_INT, src, 13,
90                       MPI_COMM_WORLD, &status );
91         MPI_Recv( buffer, act_size, MPI_INT, src, 1, MPI_COMM_WORLD, &status );
92         /* Test 1 */
93         Test_Waitforall( );
94         MPI_Finalize();
95     } else {
96         fprintf(stderr, "*** This program uses exactly 2 processes! ***\n");
97         MPI_Abort( MPI_COMM_WORLD, 1 );
98     }
99
100     return 0;
101 }
102
103
104