Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Requests are deallocated inside the Waitall, do not deallocate them again after
[simgrid.git] / teshsuite / smpi / bcast_coll.c
1 /* Copyright (c) 2009. 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 #include <stdio.h>
8 #include <mpi.h>
9
10 int main(int argc, char **argv)
11 {
12   int i, size, rank;
13   int *values;
14   int status;
15
16   MPI_Init(&argc, &argv);
17   MPI_Comm_size(MPI_COMM_WORLD, &size);
18   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
19   
20   values = (int *) xbt_malloc(size * sizeof(int));  
21
22   for (i = 0; i < size; i++)
23     values[i] = (0 == rank) ? 17 : 3;
24
25   status = MPI_Bcast(values, size, MPI_INT, 0, MPI_COMM_WORLD);
26
27   printf("[%d] values=[", rank);
28   for (i = 0; i < size; i++)
29     printf("%d ", values[i]);
30   printf("]\n");
31
32   MPI_Barrier(MPI_COMM_WORLD);
33
34   if (rank == 0) {
35     if (status != MPI_SUCCESS) {
36       printf("bcast returned %d\n", status);
37       fflush(stdout);
38     }
39   }
40
41   MPI_Finalize();
42   return 0;
43 }