Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / bcast.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[] = "Test of broadcast with various roots and datatypes";
13 */
14
15 int main(int argc, char *argv[])
16 {
17     int errs = 0, err;
18     int rank, size, root;
19     int minsize = 2, count;
20     MPI_Comm comm;
21     MTestDatatype sendtype, recvtype;
22
23     MTest_Init(&argc, &argv);
24
25     /* The following illustrates the use of the routines to
26      * run through a selection of communicators and datatypes.
27      * Use subsets of these for tests that do not involve combinations
28      * of communicators, datatypes, and counts of datatypes */
29     while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
30         if (comm == MPI_COMM_NULL)
31             continue;
32
33 #if defined BCAST_COMM_WORLD_ONLY
34         if (comm != MPI_COMM_WORLD) {
35             MTestFreeComm(&comm);
36             continue;
37         }
38 #endif /* BCAST_COMM_WORLD_ONLY */
39
40         /* Determine the sender and receiver */
41         MPI_Comm_rank(comm, &rank);
42         MPI_Comm_size(comm, &size);
43
44         /* To improve reporting of problems about operations, we
45          * change the error handler to errors return */
46         MPI_Errhandler_set(comm, MPI_ERRORS_RETURN);
47
48         MTEST_DATATYPE_FOR_EACH_COUNT(count) {
49
50             /* To shorten test time, only run the default version of datatype tests
51              * for comm world and run the minimum version for other communicators. */
52 #if defined BCAST_MIN_DATATYPES_ONLY
53             MTestInitMinDatatypes();
54 #endif /* BCAST_MIN_DATATYPES_ONLY */
55
56             while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
57                 for (root = 0; root < size; root++) {
58                     if (rank == root) {
59                         sendtype.InitBuf(&sendtype);
60                         err = MPI_Bcast(sendtype.buf, sendtype.count,
61                                         sendtype.datatype, root, comm);
62                         if (err) {
63                             errs++;
64                             MTestPrintError(err);
65                         }
66                     }
67                     else {
68                         recvtype.InitBuf(&recvtype);
69                         err = MPI_Bcast(recvtype.buf, recvtype.count,
70                                         recvtype.datatype, root, comm);
71                         if (err) {
72                             errs++;
73                             fprintf(stderr, "Error with communicator %s and datatype %s\n",
74                                     MTestGetIntracommName(), MTestGetDatatypeName(&recvtype));
75                             MTestPrintError(err);
76                         }
77                         err = MTestCheckRecv(0, &recvtype);
78                         if (err) {
79                             errs += errs;
80                         }
81                     }
82                 }
83                 MTestFreeDatatype(&recvtype);
84                 MTestFreeDatatype(&sendtype);
85             }
86         }
87         MTestFreeComm(&comm);
88     }
89
90     MTest_Finalize(errs);
91     MPI_Finalize();
92     return 0;
93 }