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 / icgather.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 gather 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, rsize, size;
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) continue;
30         MPI_Comm_rank( comm, &rank );
31         MPI_Comm_remote_size( comm, &rsize );
32         MPI_Comm_size( comm, &size );
33         /* To improve reporting of problems about operations, we
34            change the error handler to errors return */
35         MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
36         for (count = 1; count < 65000; count = 2 * count) {
37             if (leftGroup) {
38                 buf = (int *)malloc( count * rsize * sizeof(int) );
39                 for (i=0; i<count*rsize; i++) buf[i] = -1;
40
41                 err = MPI_Gather( NULL, 0, datatype,
42                                   buf, count, datatype, 
43                                  (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
44                                  comm );
45                 if (err) {
46                     errs++;
47                     MTestPrintError( err );
48                 }
49                 /* Test that no other process in this group received the 
50                    broadcast */
51                 if (rank != 0) {
52                     for (i=0; i<count; i++) {
53                         if (buf[i] != -1) {
54                             errs++;
55                         }
56                     }
57                 }
58                 else {
59                     /* Check for the correct data */
60                     for (i=0; i<count*rsize; i++) {
61                         if (buf[i] != i) {
62                             errs++;
63                         }
64                     }
65                 }
66             }
67             else {
68                 /* In the right group */
69                 buf = (int *)malloc( count * sizeof(int) );
70                 for (i=0; i<count; i++) buf[i] = rank * count + i;
71                 err = MPI_Gather( buf, count, datatype, 
72                                   NULL, 0, datatype, 0, comm );
73                 if (err) {
74                     errs++;
75                     MTestPrintError( err );
76                 }
77             }
78         free( buf );
79         }
80         MTestFreeComm( &comm );
81     }
82
83     MTest_Finalize( errs );
84     MPI_Finalize();
85     return 0;
86 }