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 / bcast2.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) continue;
31
32         /* Determine the sender and receiver */
33         MPI_Comm_rank( comm, &rank );
34         MPI_Comm_size( comm, &size );
35         
36         /* To improve reporting of problems about operations, we
37            change the error handler to errors return */
38         MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
39
40         /* The max value of count must be very large to ensure that we 
41            reach the long message algorithms */
42         for (count = 1; count < 2800; count = count * 4) {
43             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
44                 for (root=0; root<size; root++) {
45                     if (rank == root) {
46                         sendtype.InitBuf( &sendtype );
47                         err = MPI_Bcast( sendtype.buf, sendtype.count,
48                                          sendtype.datatype, root, comm );
49                         if (err) {
50                             errs++;
51                             MTestPrintError( err );
52                         }
53                     }
54                     else {
55                         recvtype.InitBuf( &recvtype );
56                         err = MPI_Bcast( recvtype.buf, recvtype.count, 
57                                     recvtype.datatype, root, comm );
58                         if (err) {
59                             errs++;
60                             fprintf( stderr, "Error with communicator %s and datatype %s\n", 
61                                  MTestGetIntracommName(), 
62                                  MTestGetDatatypeName( &recvtype ) );
63                             MTestPrintError( err );
64                         }
65                         err = MTestCheckRecv( 0, &recvtype );
66                         if (err) {
67                             errs += errs;
68                         }
69                     }
70                 }
71                 MTestFreeDatatype( &recvtype );
72                 MTestFreeDatatype( &sendtype );
73             }
74         }
75         MTestFreeComm( &comm );
76     }
77
78     MTest_Finalize( errs );
79     MPI_Finalize();
80     return 0;
81 }