Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Give a LD_LIBRARY_PATH to java tests
[simgrid.git] / teshsuite / smpi / coll-bcast / coll-bcast.c
1 /* Copyright (c) 2009, 2013-2014. 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 count = 2048;
14
15   MPI_Init(&argc, &argv);
16   MPI_Comm_size(MPI_COMM_WORLD, &size);
17   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
18
19   int *values = (int *) xbt_malloc(count * sizeof(int));
20
21   for (i = 0; i < count; i++)
22     values[i] = (0 == rank) ? 17 : 3;
23
24   MPI_Bcast(values, count, MPI_INT, 0, MPI_COMM_WORLD);
25
26   int good = 0;
27   for (i = 0; i < count; i++)
28     if (values[i]==17) good++;
29   printf("[%d] number of values equals to 17: %d\n", rank, good);
30
31   MPI_Barrier(MPI_COMM_WORLD);
32   xbt_free(values);
33
34   count = 4096;
35   values = (int *) xbt_malloc(count * sizeof(int));  
36
37   for (i = 0; i < count; i++)
38     values[i] = (size -1 == rank) ? 17 : 3;
39
40   int status = MPI_Bcast(values, count, MPI_INT, size-1, MPI_COMM_WORLD);
41
42   good = 0;
43   for (i = 0; i < count; i++)
44     if (values[i]==17) good++;
45   printf("[%d] number of values equals to 17: %d\n", rank, good);
46
47   if (rank == 0) {
48     if (status != MPI_SUCCESS) {
49       printf("bcast returned %d\n", status);
50       fflush(stdout);
51     }
52   }
53   xbt_free(values);
54   MPI_Finalize();
55   return 0;
56 }