Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icscatterv.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 scatterv test";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0, err;
19     int *buf = 0;
20     int *sendcounts;
21     int *senddispls;
22     int leftGroup, i, count, rank, rsize, size;
23     MPI_Comm comm;
24     MPI_Datatype datatype;
25
26     MTest_Init( &argc, &argv );
27
28     datatype = MPI_INT;
29     /* Get an intercommunicator */
30     while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
31         if (comm == MPI_COMM_NULL) continue;
32         MPI_Comm_remote_size( comm, &rsize );
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_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
39
40         for (count = 1; count < 65000; count = 2 * count) {
41             buf = 0;
42             sendcounts = (int *)malloc( rsize * sizeof(int) );
43             senddispls = (int *)malloc( rsize * sizeof(int) );
44             for (i=0; i<rsize; i++) {
45                 sendcounts[i] = count;
46                 senddispls[i] = count * i;
47             }
48             if (leftGroup) {
49                 buf = (int *)malloc( count * rsize * sizeof(int) );
50                 if (rank == 0) {
51                     for (i=0; i<count*rsize; i++) buf[i] = i;
52                 }
53                 else {
54                     for (i=0; i<count*rsize; i++) buf[i] = -1;
55                 }
56                 err = MPI_Scatterv( buf, sendcounts, senddispls, datatype, 
57                                     NULL, 0, datatype,
58                                     (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
59                                     comm );
60                 if (err) {
61                     errs++;
62                     MTestPrintError( err );
63                 }
64                 /* Test that no other process in this group received the 
65                    scatter */
66                 if (rank != 0) {
67                     for (i=0; i<count*rsize; i++) {
68                         if (buf[i] != -1) {
69                             if (errs < 10) {
70                                 fprintf( stderr, "Received data on root group!\n" );
71                             }
72                             errs++;
73                         }
74                     }
75                 }
76             }
77             else {
78                 buf = (int *)malloc( count * sizeof(int) );
79                 /* In the right group */
80                 for (i=0; i<count; i++) buf[i] = -1;
81                 err = MPI_Scatterv( NULL, 0, 0, datatype, 
82                                     buf, count, datatype, 0, comm );
83                 if (err) {
84                     errs++;
85                     MTestPrintError( err );
86                 }
87                 /* Check that we have received the correct data */
88                 for (i=0; i<count; i++) {
89                     if (buf[i] != i + rank * count) {
90                         if (errs < 10) 
91                             fprintf( stderr, "buf[%d] = %d on %d\n", 
92                                      i, buf[i], rank );
93                         errs++;
94                     }
95                 }
96             }
97             free( sendcounts );
98             free( senddispls );
99             free( buf );
100         }
101         MTestFreeComm( &comm );
102     }
103
104     MTest_Finalize( errs );
105     MPI_Finalize();
106     return 0;
107 }