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 / icgatherv.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 gatherv test";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0, err;
19     int *buf = 0;
20     int *recvcounts;
21     int *recvdispls;
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     while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
30         if (comm == MPI_COMM_NULL) continue;
31         MPI_Comm_rank( comm, &rank );
32         MPI_Comm_remote_size( comm, &rsize );
33         MPI_Comm_size( comm, &size );
34                 
35         /* To improve reporting of problems about operations, we
36            change the error handler to errors return */
37         MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
38
39         for (count = 1; count < 65000; count = 2 * count) {
40             /* Get an intercommunicator */
41             recvcounts = (int *)malloc( rsize * sizeof(int) );
42             recvdispls = (int *)malloc( rsize * sizeof(int) );
43             /* This simple test duplicates the Gather test, 
44                using the same lengths for all messages */
45             for (i=0; i<rsize; i++) {
46                 recvcounts[i] = count;
47                 recvdispls[i] = count * i;
48             }
49             if (leftGroup) {
50                 buf = (int *)malloc( count * rsize * sizeof(int) );
51                 for (i=0; i<count*rsize; i++) buf[i] = -1;
52
53                 err = MPI_Gatherv( NULL, 0, datatype,
54                                   buf, recvcounts, recvdispls, datatype, 
55                                  (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
56                                  comm );
57                 if (err) {
58                     errs++;
59                     MTestPrintError( err );
60                 }
61                 /* Test that no other process in this group received the 
62                    broadcast */
63                 if (rank != 0) {
64                     for (i=0; i<count; i++) {
65                         if (buf[i] != -1) {
66                             errs++;
67                         }
68                     }
69                 }
70                 else {
71                     /* Check for the correct data */
72                     for (i=0; i<count*rsize; i++) {
73                         if (buf[i] != i) {
74                             errs++;
75                         }
76                     }
77                 }
78             }
79             else {
80                 /* In the right group */
81                 buf = (int *)malloc( count * sizeof(int) );
82                 for (i=0; i<count; i++) buf[i] = rank * count + i;
83                 err = MPI_Gatherv( buf, count, datatype, 
84                                    NULL, 0, 0, datatype, 0, comm );
85                 if (err) {
86                     errs++;
87                     MTestPrintError( err );
88                 }
89             }
90             free( buf );
91             free( recvcounts );
92             free( recvdispls );
93         }
94         MTestFreeComm( &comm );
95     }
96
97     MTest_Finalize( errs );
98     MPI_Finalize();
99     return 0;
100 }