Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finish pulling changes from mpich trunk testsuite
[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         exit(1);
39     }
40
41     for (testnum=0; msgsizes[testnum] > 0; testnum++) {
42         if (rank == source || rank == dest) {
43             int nmsg = nmsgs[testnum];
44             int msgSize = msgsizes[testnum];
45             MPI_Request r[MAX_NMSGS];
46             int *buf[MAX_NMSGS];
47
48             for (i=0; i<nmsg; i++) {
49                 buf[i] = (int *)malloc( msgSize * sizeof(int) );
50                 if (!buf[i]) {
51                     fprintf( stderr, "Unable to allocate %d bytes\n", 
52                              msgSize );
53                     MPI_Abort( MPI_COMM_WORLD, 1 );
54                     exit(1);
55                 }
56             }
57             partner = (rank + 1) % size;
58
59             MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 10, 
60                           MPI_BOTTOM, 0, MPI_INT, partner, 10, comm, 
61                           MPI_STATUS_IGNORE );
62             /* Try to fill up the outgoing message buffers */
63             for (i=0; i<nmsg; i++) {
64                 MPI_Isend( buf[i], msgSize, MPI_INT, partner, testnum, comm,
65                            &r[i] );
66             }
67             for (i=0; i<nmsg; i++) {
68                 MPI_Recv( buf[i], msgSize, MPI_INT, partner, testnum, comm,
69                           MPI_STATUS_IGNORE );
70             }
71             MPI_Waitall( nmsg, r, MPI_STATUSES_IGNORE );
72
73             /* Repeat the test, but make one of the processes sleep */
74             MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, partner, 10, 
75                           MPI_BOTTOM, 0, MPI_INT, partner, 10, comm, 
76                           MPI_STATUS_IGNORE );
77             if (rank == dest) MTestSleep( 1 );
78             /* Try to fill up the outgoing message buffers */
79             tsend = MPI_Wtime();
80             for (i=0; i<nmsg; i++) {
81                 MPI_Isend( buf[i], msgSize, MPI_INT, partner, testnum, comm,
82                            &r[i] );
83             }
84             tsend = MPI_Wtime() - tsend;
85             for (i=0; i<nmsg; i++) {
86                 MPI_Recv( buf[i], msgSize, MPI_INT, partner, testnum, comm,
87                           MPI_STATUS_IGNORE );
88             }
89             MPI_Waitall( nmsg, r, MPI_STATUSES_IGNORE );
90
91             if (tsend > 0.5) {
92                 printf( "Isends for %d messages of size %d took too long (%f seconds)\n", nmsg, msgSize, tsend );
93                 errs++;
94             }
95             MTestPrintfMsg( 1, "%d Isends for size = %d took %f seconds\n", 
96                             nmsg, msgSize, tsend );
97
98             for (i=0; i<nmsg; i++) {
99                 free( buf[i] );
100             }
101         }
102     }
103
104     MTest_Finalize( errs );
105     MPI_Finalize();
106     return 0;
107 }