Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Free memory.
[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 40000
16 #define MAX_COUNT    5
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)
33             continue;
34         /* Determine the sender and receiver */
35         MPI_Comm_rank(comm, &rank);
36         MPI_Comm_size(comm, &size);
37         source = 0;
38         dest = size - 1;
39
40         /* To improve reporting of problems about operations, we
41          * change the error handler to errors return */
42         MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
43
44         for (count = 1; count < MAX_COUNT; count = count * 2) {
45
46             /* To shorten test time, only run the default version of datatype tests
47              * for comm world and run the minimum version for other communicators. */
48             if (comm != MPI_COMM_WORLD) {
49                 MTestInitMinDatatypes();
50             }
51
52             while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
53                 int nbytes;
54                 MPI_Type_size(sendtype.datatype, &nbytes);
55
56                 /* We may want to limit the total message size sent */
57                 if (nbytes > MAX_MSG_SIZE) {
58                     /* We do not need to free, as we haven't
59                      * initialized any of the buffers (?) */
60                     continue;
61                 }
62                 maxmsg = MAX_COUNT - count;
63                 MTestPrintfMsg(1, "Sending count = %d of sendtype %s of total size %d bytes\n",
64                                count, MTestGetDatatypeName(&sendtype), nbytes * count);
65                 /* Make sure that everyone has a recv buffer */
66                 recvtype.InitBuf(&recvtype);
67
68                 if (rank == source) {
69                     sendtype.InitBuf(&sendtype);
70
71                     for (nmsg = 1; nmsg < maxmsg; nmsg++) {
72                         err = MPI_Send(sendtype.buf, sendtype.count,
73                                        sendtype.datatype, dest, 0, comm);
74                         if (err) {
75                             errs++;
76                             if (errs < 10) {
77                                 MTestPrintError(err);
78                             }
79                         }
80                     }
81                 }
82                 else if (rank == dest) {
83                     for (nmsg = 1; nmsg < maxmsg; nmsg++) {
84                         err = MPI_Recv(recvtype.buf, recvtype.count,
85                                        recvtype.datatype, source, 0, comm, MPI_STATUS_IGNORE);
86                         if (err) {
87                             errs++;
88                             if (errs < 10) {
89                                 MTestPrintError(err);
90                             }
91                         }
92
93                         err = MTestCheckRecv(0, &recvtype);
94                         if (err) {
95                             if (errs < 10) {
96                                 printf
97                                     ("Data in target buffer did not match for destination datatype %s and source datatype %s, count = %d, message iteration %d of %d\n",
98                                      MTestGetDatatypeName(&recvtype),
99                                      MTestGetDatatypeName(&sendtype), count, nmsg, maxmsg);
100                                 recvtype.printErrors = 1;
101                                 (void) MTestCheckRecv(0, &recvtype);
102                             }
103                             errs += err;
104                         }
105                     }
106                 }
107                 MTestFreeDatatype(&recvtype);
108                 MTestFreeDatatype(&sendtype);
109             }
110         }
111         MTestFreeComm(&comm);
112     }
113
114     MTest_Finalize(errs);
115     MPI_Finalize();
116     return 0;
117 }