Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / bcasttest.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include "mpitest.h"
11
12 #define ROOT      0
13 #define NUM_REPS  5
14 #define NUM_SIZES 4
15
16 int main(int argc, char **argv)
17 {
18     int *buf;
19     int i, rank, reps, n;
20     int bVerify = 1;
21     int sizes[NUM_SIZES] = { 100, 64 * 1024, 128 * 1024, 1024 * 1024 };
22     int num_errors = 0;
23
24     MTest_Init(&argc, &argv);
25     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26
27     if (argc > 1) {
28         if (strcmp(argv[1], "-novalidate") == 0 || strcmp(argv[1], "-noverify") == 0)
29             bVerify = 0;
30     }
31
32     buf = (int *) malloc(sizes[NUM_SIZES - 1] * sizeof(int));
33     memset(buf, 0, sizes[NUM_SIZES - 1] * sizeof(int));
34
35     for (n = 0; n < NUM_SIZES; n++) {
36 #ifdef DEBUG
37         if (rank == ROOT) {
38             printf("bcasting %d MPI_INTs %d times\n", sizes[n], NUM_REPS);
39             fflush(stdout);
40         }
41 #endif
42         for (reps = 0; reps < NUM_REPS; reps++) {
43             if (bVerify) {
44                 if (rank == ROOT) {
45                     for (i = 0; i < sizes[n]; i++) {
46                         buf[i] = 1000000 * (n * NUM_REPS + reps) + i;
47                     }
48                 }
49                 else {
50                     for (i = 0; i < sizes[n]; i++) {
51                         buf[i] = -1 - (n * NUM_REPS + reps);
52                     }
53                 }
54             }
55
56 #           ifdef DEBUG
57             {
58                 printf("rank=%d, n=%d, reps=%d\n", rank, n, reps);
59             }
60 #           endif
61
62             MPI_Bcast(buf, sizes[n], MPI_INT, ROOT, MPI_COMM_WORLD);
63
64             if (bVerify) {
65                 num_errors = 0;
66                 for (i = 0; i < sizes[n]; i++) {
67                     if (buf[i] != 1000000 * (n * NUM_REPS + reps) + i) {
68                         num_errors++;
69                         if (num_errors < 10) {
70                             printf("Error: Rank=%d, n=%d, reps=%d, i=%d, buf[i]=%d expected=%d\n",
71                                    rank, n, reps, i, buf[i], 1000000 * (n * NUM_REPS + reps) + i);
72                             fflush(stdout);
73                         }
74                     }
75                 }
76                 if (num_errors >= 10) {
77                     printf("Error: Rank=%d, num_errors = %d\n", rank, num_errors);
78                     fflush(stdout);
79                 }
80             }
81         }
82     }
83
84     free(buf);
85
86     MTest_Finalize(num_errors);
87     MPI_Finalize();
88     return 0;
89 }