2 * This program performs some simple tests of the MPI_Bcast broadcast
5 * It checks the handling of different datatypes by different participants
6 * (with matching type signatures, of course), as well as different
7 * roots and communicators.
14 int main( int argc, char **argv )
16 int rank, size, ret, passed, i, *test_array;
17 int stride, count, root;
19 MPI_Comm comm = MPI_COMM_WORLD;
22 MPI_Init(&argc, &argv);
23 MPI_Comm_rank(comm, &rank);
26 Test_Init("bcastvec", rank);
28 /* Allow for additional communicators */
29 MPI_Comm_size(comm, &size);
30 /* MPI_Comm_rank(comm, &rank); */
32 test_array = (int *)malloc(size*stride*sizeof(int));
34 /* Create the vector datatype EXCEPT for process 0 (vector of
35 stride 1 is contiguous) */
38 MPI_Type_vector( size, 1, stride, MPI_INT, &newtype);
39 MPI_Type_commit( &newtype );
46 /* Perform the test. Each process in turn becomes the root.
47 After each operation, check that nothing has gone wrong */
49 for (root = 0; root < size; root++) {
50 /* Fill the array with -1 for unset, rank + i * size for set */
51 for (i=0; i<size*stride; i++) test_array[i] = -1;
53 for (i=0; i<size; i++) test_array[i*stride] = rank + i * size;
54 MPI_Bcast( test_array, count, newtype, root, comm );
55 for (i=0; i<size; i++) {
56 if (test_array[i*stride] != root + i * size) {
62 if (rank != 0) MPI_Type_free( &newtype );
65 Test_Failed("Simple Broadcast test with datatypes");
68 Test_Passed("Simple Broadcast test with datatypes");
71 /* Close down the tests */
73 ret = Summarize_Test_Results();