Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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", count);
39             MPI_Abort(MPI_COMM_WORLD, 1);
40         }
41         for (i = 0; i < count; i++) {
42             bufin[i] = i;
43             bufout[i] = -1;
44         }
45
46         dtype = MPI_INT;
47         MPI_Allreduce(bufin, bufout, count, dtype, MPI_SUM, comm);
48         /* Check output */
49         for (i = 0; i < count; i++) {
50             if (bufout[i] != i * size) {
51                 fprintf(stderr, "Expected bufout[%d] = %d but found %d\n", i, i * size, bufout[i]);
52                 errs++;
53             }
54         }
55         free(bufin);
56         free(bufout);
57         MTestFreeComm(&comm);
58     }
59
60     MTest_Finalize(errs);
61     MPI_Finalize();
62     return 0;
63 }