Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f8c983a5acdb8a0b84853f9e1a85f976cb3d1b7e
[simgrid.git] / teshsuite / smpi / mpich-test / coll / bcast.c
1 /*
2  * This program performs some simple tests of the MPI_Bcast broadcast
3  * functionality.
4  */
5
6 #include "test.h"
7 #include "mpi.h"
8 #include <stdlib.h>
9
10 int
11 main( int argc, char **argv)
12 {
13     int rank, size, ret, passed, i, *test_array;
14
15     /* Set up MPI */
16     MPI_Init(&argc, &argv);
17     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
18     MPI_Comm_size(MPI_COMM_WORLD, &size);
19
20     /* Setup the tests */
21     Test_Init("bcast", rank);
22     test_array = (int *)malloc(size*sizeof(int));
23
24     /* Perform the test - this operation should really be done
25        with an allgather, but it makes a good test... */
26     passed = 1;
27     for (i=0; i < size; i++) {
28         if (i == rank)
29             test_array[i] = i;
30         MPI_Bcast(test_array, size, MPI_INT, i, MPI_COMM_WORLD);
31         if (test_array[i] != i)
32             passed = 0;
33     }
34     if (!passed)
35         Test_Failed("Simple Broadcast test");
36     else {
37         if (rank == 0)
38             Test_Passed("Simple Broadcast test");
39         }
40
41     /* Close down the tests */
42     free(test_array);
43     if (rank == 0)
44         ret = Summarize_Test_Results();
45     else
46         ret = 0;
47     Test_Finalize();
48
49     /* Close down MPI */
50     Test_Waitforall( );
51     MPI_Finalize();
52     return ret;
53 }