Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'hypervisor' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid...
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / pingping.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 "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Send flood test";
13 */
14
15 #define MAX_MSG_SIZE 40000000
16 #define MAX_COUNT    4000
17 int main( int argc, char *argv[] )
18 {
19     int errs = 0, err;
20     int rank, size, source, dest;
21     int minsize = 2, count, nmsg, maxmsg; 
22     MPI_Comm      comm;
23     MTestDatatype sendtype, recvtype;
24
25     MTest_Init( &argc, &argv );
26
27     /* The following illustrates the use of the routines to 
28        run through a selection of communicators and datatypes.
29        Use subsets of these for tests that do not involve combinations 
30        of communicators, datatypes, and counts of datatypes */
31     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
32         if (comm == MPI_COMM_NULL) continue;
33         /* Determine the sender and receiver */
34         MPI_Comm_rank( comm, &rank );
35         MPI_Comm_size( comm, &size );
36         source = 0;
37         dest   = size - 1;
38         
39         /* To improve reporting of problems about operations, we
40            change the error handler to errors return */
41         MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
42
43         for (count = 1; count < MAX_COUNT; count = count * 2) {
44             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
45                 int nbytes;
46                 MPI_Type_size( sendtype.datatype, &nbytes );
47
48                 /* We may want to limit the total message size sent */
49                 if (nbytes > MAX_MSG_SIZE) {
50                     /* We do not need to free, as we haven't 
51                        initialized any of the buffers (?) */
52                     continue;
53                 }
54                 maxmsg = MAX_COUNT - count;
55                 MTestPrintfMsg( 1, "Sending count = %d of sendtype %s of total size %d bytes\n", 
56                                 count, MTestGetDatatypeName( &sendtype ), 
57                                 nbytes*count );
58                 /* Make sure that everyone has a recv buffer */
59                 recvtype.InitBuf( &recvtype );
60
61                 if (rank == source) {
62                     sendtype.InitBuf( &sendtype );
63                     
64                     for (nmsg=1; nmsg<maxmsg; nmsg++) {
65                         err = MPI_Send( sendtype.buf, sendtype.count, 
66                                         sendtype.datatype, dest, 0, comm);
67                         if (err) {
68                             errs++;
69                             if (errs < 10) {
70                                 MTestPrintError( err );
71                             }
72                         }
73                     }
74                 }
75                 else if (rank == dest) {
76                     for (nmsg=1; nmsg<maxmsg; nmsg++) {
77                         err = MPI_Recv( recvtype.buf, recvtype.count, 
78                                         recvtype.datatype, source, 0, 
79                                         comm, MPI_STATUS_IGNORE);
80                         if (err) {
81                             errs++;
82                             if (errs < 10) {
83                                 MTestPrintError( err );
84                             }
85                         }
86
87                         err = MTestCheckRecv( 0, &recvtype );
88                         if (err) {
89                             if (errs < 10) {
90                                 printf( "Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d, message iteration %d of %d\n", 
91                                         MTestGetDatatypeName( &recvtype ),
92                                         MTestGetDatatypeName( &sendtype ),
93                                         count, nmsg, maxmsg );
94                                 recvtype.printErrors = 1;
95                                 (void)MTestCheckRecv( 0, &recvtype );
96                             }
97                             errs += err;
98                         }
99                     }
100                 }
101                 MTestFreeDatatype( &recvtype );
102                 MTestFreeDatatype( &sendtype );
103             }
104         }
105         MTestFreeComm( &comm );
106     }
107
108     MTest_Finalize( errs );
109     MPI_Finalize();
110     return 0;
111 }