Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icscatter.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 scatter 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, size, rsize;
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_remote_size( comm, &rsize );
31         MPI_Comm_rank( comm, &rank );
32         MPI_Comm_size( comm, &size );
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 = 0;
40             if (leftGroup) {
41                 buf = (int *)malloc( count * rsize * sizeof(int) );
42                 if (rank == 0) {
43                     for (i=0; i<count*rsize; i++) buf[i] = i;
44                 }
45                 else {
46                     for (i=0; i<count*rsize; i++) buf[i] = -1;
47                 }
48                 err = MPI_Scatter( buf, count, datatype, 
49                                    NULL, 0, datatype,
50                                  (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
51                                  comm );
52                 if (err) {
53                     errs++;
54                     MTestPrintError( err );
55                 }
56                 /* Test that no other process in this group received the 
57                    scatter */
58                 if (rank != 0) {
59                     for (i=0; i<count*rsize; i++) {
60                         if (buf[i] != -1) {
61                             if (errs < 10) {
62                                 fprintf( stderr, "Received data on root group!\n" );
63                             }
64                             errs++;
65                         }
66                     }
67                 }
68             }
69             else {
70                 buf = (int *)malloc( count * sizeof(int) );
71                 /* In the right group */
72                 for (i=0; i<count; i++) buf[i] = -1;
73                 err = MPI_Scatter( NULL, 0, datatype, 
74                                    buf, count, datatype, 0, comm );
75                 if (err) {
76                     errs++;
77                     MTestPrintError( err );
78                 }
79                 /* Check that we have received the correct data */
80                 for (i=0; i<count; i++) {
81                     if (buf[i] != i + rank * count) {
82                         if (errs < 10) 
83                             fprintf( stderr, "buf[%d] = %d on %d\n", 
84                                      i, buf[i], rank );
85                         errs++;
86                     }
87                 }
88             }
89             free( buf );
90         }
91         MTestFreeComm( &comm );
92     }
93
94     MTest_Finalize( errs );
95     MPI_Finalize();
96     return 0;
97 }