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 / allred5.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2003 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10 #include <assert.h>
11
12 /*
13 static char MTEST_Descrip[] = "Test MPI_Allreduce with count greater than the number of processes";
14 */
15
16 /* We make the error count global so that we can easily control the output
17    of error information (in particular, limiting it after the first 10 
18    errors */
19 int errs = 0;
20
21 int main( int argc, char *argv[] )
22 {
23     MPI_Comm comm;
24     MPI_Datatype dtype;
25     int count, *bufin, *bufout, size, i, minsize=1;
26
27     MTest_Init( &argc, &argv );
28     
29     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
30         if (comm == MPI_COMM_NULL) {
31             continue;
32         }
33         MPI_Comm_size( comm, &size );
34         count = size * 2;
35         bufin = (int *)malloc( count * sizeof(int) );
36         bufout = (int *)malloc( count * sizeof(int) );
37         if (!bufin || !bufout) {
38             fprintf( stderr, "Unable to allocated space for buffers (%d)\n",
39                      count );
40             MPI_Abort( MPI_COMM_WORLD, 1 );
41         }
42         for (i=0; i<count; i++) {
43             bufin[i] = i;
44             bufout[i] = -1;
45         }
46
47         dtype = MPI_INT;
48         MPI_Allreduce( bufin, bufout, count, dtype, MPI_SUM, comm );
49         /* Check output */
50         for (i=0; i<count; i++) {
51             if (bufout[i] != i * size) {
52                 fprintf( stderr, "Expected bufout[%d] = %d but found %d\n",
53                          i, i * size, bufout[i] );
54                 errs++;
55             }
56         }
57         free( bufin );
58         free( bufout );
59         MTestFreeComm( &comm );
60     }
61
62     MTest_Finalize( errs );
63     MPI_Finalize();
64     return 0;
65 }