Logo AND Algorithmique Numérique Distribuée

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