Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / gather_big.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2015 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 #include "mpi.h"
8 #include "mpitest.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #define ROOT 7
13 #if 0
14 /* Following should always work for -n 8  256, -N 32, using longs */
15 #define COUNT 1048576*32
16 #endif
17 #if 1
18 /* Following will fail for -n 8 unless gather path is 64 bit clean */
19 #define COUNT (1024*1024*128+1)
20 #endif
21 #define VERIFY_CONST 100000000L
22
23 int main(int argc, char *argv[])
24 {
25     int rank, size;
26     int i, j;
27     long *sendbuf = NULL;
28     long *recvbuf = NULL;
29
30     MPI_Init(&argc, &argv);
31     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32     MPI_Comm_size(MPI_COMM_WORLD, &size);
33
34     if (size < (ROOT+1)) {
35         fprintf(stderr, "At least %d processes required\n", ROOT+1);
36         MPI_Abort(MPI_COMM_WORLD, 1);
37     }
38
39     sendbuf = malloc(COUNT * sizeof(long));
40     if (sendbuf == NULL) {
41         fprintf(stderr, "PE %d:ERROR: malloc of sendbuf failed\n", rank);
42     }
43     for (i = 0; i < COUNT; i++) {
44         sendbuf[i] = (long) i + (long) rank *VERIFY_CONST;
45     }
46
47     if (rank == ROOT) {
48         recvbuf = malloc(COUNT * sizeof(long) * size);
49         if (recvbuf == NULL) {
50             fprintf(stderr, "PE %d:ERROR: malloc of recvbuf failed\n", rank);
51         }
52         for (i = 0; i < COUNT * size; i++) {
53             recvbuf[i] = -456789L;
54         }
55     }
56
57     MPI_Gather(sendbuf, COUNT, MPI_LONG, recvbuf, COUNT, MPI_LONG, ROOT, MPI_COMM_WORLD);
58
59     int lerr = 0;
60     if (rank == ROOT) {
61         for (i = 0; i < size; i++) {
62             for (j = 0; j < COUNT; j++) {
63                 if (recvbuf[i * COUNT + j] != i * VERIFY_CONST + j) {
64                     printf("PE 0: mismatch error");
65                     printf("  recbuf[%d * %d + %d] = ", i, COUNT, j);
66                     printf("  %ld,", recvbuf[i * COUNT + j]);
67                     printf("  should be %ld\n", i * VERIFY_CONST + j);
68                     lerr++;
69                     if (lerr > 10) {
70                         j = COUNT;
71                     }
72                 }
73             }
74         }
75         MTest_Finalize(lerr);
76         free(recvbuf);
77     }
78     else {
79         MTest_Finalize(lerr);
80     }
81
82     MPI_Barrier(MPI_COMM_WORLD);
83     MPI_Finalize();
84
85     free(sendbuf);
86     return 0;
87 }