Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[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     {
29         if (strcmp(argv[1], "-novalidate") == 0 || strcmp(argv[1], "-noverify") == 0)
30             bVerify = 0;
31     }
32
33     buf = (int *) malloc(sizes[NUM_SIZES-1]*sizeof(int));
34     memset(buf, 0, sizes[NUM_SIZES-1]*sizeof(int));
35
36     for (n=0; n<NUM_SIZES; n++)
37     {
38 #ifdef DEBUG
39         if (rank == ROOT)
40         {
41             printf("bcasting %d MPI_INTs %d times\n", sizes[n], NUM_REPS);
42             fflush(stdout);
43         }
44 #endif
45         for (reps=0; reps < NUM_REPS; reps++)
46         {
47             if (bVerify)
48             {
49                 if (rank == ROOT)
50                 {
51                     for (i=0; i<sizes[n]; i++)
52                     {
53                         buf[i] = 1000000 * (n * NUM_REPS + reps) + i;
54                     }
55                 }
56                 else
57                 {
58                     for (i=0; i<sizes[n]; i++)
59                     {
60                         buf[i] = -1 - (n * NUM_REPS + reps);
61                     }
62                 }
63             }
64
65 #           ifdef DEBUG
66             {
67                 printf("rank=%d, n=%d, reps=%d\n", rank, n, reps);
68             }
69 #           endif
70             
71             MPI_Bcast(buf, sizes[n], MPI_INT, ROOT, MPI_COMM_WORLD);
72
73             if (bVerify)
74             {
75                 num_errors = 0;
76                 for (i=0; i<sizes[n]; i++)
77                 {
78                     if (buf[i] != 1000000 * (n * NUM_REPS + reps) + i)
79                     {
80                         num_errors++;
81                         if (num_errors < 10)
82                         {
83                             printf("Error: Rank=%d, n=%d, reps=%d, i=%d, buf[i]=%d expected=%d\n", rank, n, reps, i, buf[i],
84                                    1000000 * (n * NUM_REPS + reps) +i);
85                             fflush(stdout);
86                         }
87                     }
88                 }
89                 if (num_errors >= 10)
90                 {
91                     printf("Error: Rank=%d, num_errors = %d\n", rank, num_errors);
92                     fflush(stdout);
93                 }
94             }
95         }
96     }
97     
98     free(buf);
99
100     MTest_Finalize( num_errors );
101     MPI_Finalize();
102     return 0;
103 }