Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / teshsuite / smpi / bug-17132 / bug-17132.c
1 /* Copyright (c) 2014-2020. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /* Bug report: https://gforge.inria.fr/tracker/index.php?func=detail&aid=17132&group_id=12&atid=165 */
8
9 #include <stdio.h>
10 #include <mpi.h>
11
12 int main(int argc, char ** argv)
13 {
14   size_t M = 8*1024;
15   size_t N = 32*1024;
16
17   MPI_Init(&argc, &argv);
18
19   int rank;
20   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
21
22   double *a = malloc(sizeof(double) * M);
23   double *b = malloc(sizeof(double) * N);
24
25   // A broadcast
26   size_t err = MPI_Bcast(a, M, MPI_DOUBLE, 0, MPI_COMM_WORLD);
27   if (err != MPI_SUCCESS) {
28     perror("Error Bcast A\n");
29     MPI_Finalize();
30     exit(-1);
31   }
32
33 //  Uncommenting this barrier fixes it!
34 //  MPI_Barrier(MPI_COMM_WORLD);
35
36   // Another broadcast
37   err = MPI_Bcast(b, N, MPI_DOUBLE, 0, MPI_COMM_WORLD );
38   if (err != MPI_SUCCESS) {
39     perror("Error Bcast B\n");
40     MPI_Finalize();
41     exit(-1);
42   }
43
44   // Commenting out this barrier fixes it!!
45   MPI_Barrier(MPI_COMM_WORLD);
46
47   if(rank==0) {
48     printf("Walltime = %g\n",MPI_Wtime());
49   }
50
51   MPI_Finalize();
52   free(a);
53   free(b);
54   return 0;
55 }