Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icbcast.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 #include "mpicolltest.h"
12
13 /*
14 static char MTEST_Descrip[] = "Simple intercomm broadcast test";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0, err;
20     int *buf = 0;
21     int leftGroup, i, count, rank;
22     MPI_Comm comm;
23     MPI_Datatype datatype;
24
25     MTest_Init(&argc, &argv);
26
27     datatype = MPI_INT;
28     /* Get an intercommunicator */
29     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
30         if (comm == MPI_COMM_NULL)
31             continue;
32
33         MPI_Comm_rank(comm, &rank);
34
35         /* To improve reporting of problems about operations, we
36          * change the error handler to errors return */
37         MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);
38
39         for (count = 1; count < 65000; count = 2 * count) {
40             buf = (int *) malloc(count * sizeof(int));
41             if (leftGroup) {
42                 if (rank == 0) {
43                     for (i = 0; i < count; i++)
44                         buf[i] = i;
45                 }
46                 else {
47                     for (i = 0; i < count; i++)
48                         buf[i] = -1;
49                 }
50                 err = MTest_Bcast(buf, count, datatype,
51                                   (rank == 0) ? MPI_ROOT : MPI_PROC_NULL, comm);
52                 if (err) {
53                     errs++;
54                     MTestPrintError(err);
55                 }
56                 /* Test that no other process in this group received the
57                  * broadcast */
58                 if (rank != 0) {
59                     for (i = 0; i < count; i++) {
60                         if (buf[i] != -1) {
61                             errs++;
62                         }
63                     }
64                 }
65             }
66             else {
67                 /* In the right group */
68                 for (i = 0; i < count; i++)
69                     buf[i] = -1;
70                 err = MTest_Bcast(buf, count, datatype, 0, comm);
71                 if (err) {
72                     errs++;
73                     MTestPrintError(err);
74                 }
75                 /* Check that we have received the correct data */
76                 for (i = 0; i < count; i++) {
77                     if (buf[i] != i) {
78                         errs++;
79                     }
80                 }
81             }
82             free(buf);
83         }
84         MTestFreeComm(&comm);
85     }
86
87     MTest_Finalize(errs);
88     MPI_Finalize();
89     return 0;
90 }