Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
handle nested datatypes in smpi (structs of vectors for example), which previously...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / self.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #if defined(NEEDS_STDLIB_PROTOTYPES)
6 #include "protofix.h"
7 #endif
8
9 /*
10  * This needs to test long messages as well as short ones.
11  * The most likely failure mode for this program is that it will
12  * hang.  Sorry about that....
13  *
14  */
15 int main( int argc, char **argv )
16 {
17 int           sendbuf[10];
18 int           sendcount = 10;
19 int           recvbuf[10];
20 int           recvcount = 10;
21 int           source = 0, recvtag = 2;
22 int           dest = 0, sendtag = 2;
23 int           i, *longsend, *longrecv;
24
25     int               mpi_errno = MPI_SUCCESS;
26     MPI_Status        status_array[2];
27     MPI_Request       req[2];
28
29     MPI_Init( &argc, &argv );
30     if ((mpi_errno = MPI_Irecv ( recvbuf, recvcount, MPI_INT,
31                             source, recvtag, MPI_COMM_WORLD, &req[1] ))) 
32         return mpi_errno;
33     if ((mpi_errno = MPI_Isend ( sendbuf, sendcount, MPI_INT, dest,   
34                             sendtag, MPI_COMM_WORLD, &req[0] ))) 
35         return mpi_errno;
36
37     fprintf( stdout, "[%d] Starting waitall\n", 0 );
38     mpi_errno = MPI_Waitall ( 2, req, status_array );
39     fprintf( stdout, "[%d] Ending waitall\n", 0 );
40
41     for (i=16; i<257000; i *= 2) {
42         longsend = (int *)malloc( i * sizeof(int) );
43         longrecv = (int *)malloc( i * sizeof(int) );
44         if (!longsend || !longrecv) {
45         }
46         if ((mpi_errno = MPI_Irecv ( longrecv, i, MPI_INT, source, recvtag, 
47                                      MPI_COMM_WORLD, &req[1] ))) 
48             return mpi_errno;
49         if ((mpi_errno = MPI_Isend ( longsend, i, MPI_INT, dest,  sendtag, 
50                                      MPI_COMM_WORLD, &req[0] ))) 
51         return mpi_errno;
52         
53         fprintf( stdout, "[%d] Starting waitall (%d)\n", 0, i );
54         mpi_errno = MPI_Waitall ( 2, req, status_array );
55         fprintf( stdout, "[%d] Ending waitall\n", 0 );
56
57         free( longsend );
58         free( longrecv );
59     }
60
61     MPI_Finalize();
62     return (mpi_errno);
63 }