Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix errors in make distcheck.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / sendrecv3.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Head to head send-recv to test backoff in device when large messages are being transferred";
14 */
15
16 #define  MAX_NMSGS 100
17 int main( int argc, char *argv[] )
18 {
19     int errs = 0;
20     int rank, size, source, dest, partner;
21     int i, testnum; 
22     double tsend;
23     static int msgsizes[] = { 100, 1000, 10000, 100000, -1 };
24     static int nmsgs[]    = { 100, 10,   10,    4 };
25     MPI_Comm      comm;
26
27     MTest_Init( &argc, &argv );
28
29     comm = MPI_COMM_WORLD;
30
31     MPI_Comm_rank( comm, &rank );
32     MPI_Comm_size( comm, &size );
33     source = 0;
34     dest   = 1;
35     if (size < 2) {
36         printf( "This test requires at least 2 processes\n" );
37         MPI_Abort( MPI_COMM_WORLD, 1 );
38     }
39
40     for (testnum=0; msgsizes[testnum] > 0; testnum++) {
41         if (rank == source || rank == dest) {
42             int nmsg = nmsgs[testnum];
43             int msgSize = msgsizes[testnum];
44             MPI_Request r[MAX_NMSGS];
45             int *buf[MAX_NMSGS];
46
47             for (i=0; i<nmsg; i++) {
48                 buf[i] = (int *)malloc( msgSize );
49                 if (!buf[i]) {
50                     fprintf( stderr, "Unable to allocate %d bytes\n", 
51                              msgSize );
52                     MPI_Abort( MPI_COMM_WORLD, 1 );
53                 }
54             }
55             partner = (rank + 1) % size;
56
57             MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 10, 
58                           MPI_BOTTOM, 0, MPI_INT, partner, 10, comm, 
59                           MPI_STATUS_IGNORE );
60             /* Try to fill up the outgoing message buffers */
61             for (i=0; i<nmsg; i++) {
62                 MPI_Isend( buf[i], msgSize, MPI_CHAR, partner, testnum, comm,
63                            &r[i] );
64             }
65             for (i=0; i<nmsg; i++) {
66                 MPI_Recv( buf[i], msgSize, MPI_CHAR, partner, testnum, comm,
67                           MPI_STATUS_IGNORE );
68             }
69             MPI_Waitall( nmsg, r, MPI_STATUSES_IGNORE );
70
71             /* Repeat the test, but make one of the processes sleep */
72             MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 10, 
73                           MPI_BOTTOM, 0, MPI_INT, partner, 10, comm, 
74                           MPI_STATUS_IGNORE );
75             if (rank == dest) MTestSleep( 1 );
76             /* Try to fill up the outgoing message buffers */
77             tsend = MPI_Wtime();
78             for (i=0; i<nmsg; i++) {
79                 MPI_Isend( buf[i], msgSize, MPI_CHAR, partner, testnum, comm,
80                            &r[i] );
81             }
82             tsend = MPI_Wtime() - tsend;
83             for (i=0; i<nmsg; i++) {
84                 MPI_Recv( buf[i], msgSize, MPI_CHAR, partner, testnum, comm,
85                           MPI_STATUS_IGNORE );
86             }
87             MPI_Waitall( nmsg, r, MPI_STATUSES_IGNORE );
88
89             if (tsend > 0.5) {
90                 printf( "Isends for %d messages of size %d took too long (%f seconds)\n", nmsg, msgSize, tsend );
91                 errs++;
92             }
93             MTestPrintfMsg( 1, "%d Isends for size = %d took %f seconds\n", 
94                             nmsg, msgSize, tsend );
95
96             for (i=0; i<nmsg; i++) {
97                 free( buf[i] );
98             }
99         }
100     }
101
102     MTest_Finalize( errs );
103     MPI_Finalize();
104     return 0;
105 }