Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / coll / bcastvec.c
1 /*
2  * This program performs some simple tests of the MPI_Bcast broadcast
3  * functionality.
4  *
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.
8  */
9
10 #include "test.h"
11 #include "mpi.h"
12 #include <stdlib.h>
13
14 int main( int argc, char **argv )
15 {
16     int rank, size, ret, passed, i, *test_array;
17     int stride, count, root;
18     MPI_Datatype newtype;
19     MPI_Comm     comm = MPI_COMM_WORLD;
20
21     /* Set up MPI */
22     MPI_Init(&argc, &argv);
23     MPI_Comm_rank(comm, &rank);
24
25     /* Setup the tests */
26     Test_Init("bcastvec", rank);
27
28     /* Allow for additional communicators */
29     MPI_Comm_size(comm, &size);
30     /* MPI_Comm_rank(comm, &rank); */
31     stride = (rank + 1);
32     test_array = (int *)malloc(size*stride*sizeof(int));
33
34     /* Create the vector datatype EXCEPT for process 0 (vector of
35        stride 1 is contiguous) */
36     if (rank > 0) {
37         count = 1;
38         MPI_Type_vector( size, 1, stride, MPI_INT, &newtype);
39         MPI_Type_commit( &newtype );
40     }
41     else {
42         count = size;
43         newtype = MPI_INT;
44     }
45
46     /* Perform the test.  Each process in turn becomes the root.
47        After each operation, check that nothing has gone wrong */
48     passed = 1;
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;
52         if (rank == root) 
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) {
57                 passed = 0;
58             }
59         }
60     }
61     free(test_array);
62     if (rank != 0) MPI_Type_free( &newtype );
63
64     if (!passed)
65         Test_Failed("Simple Broadcast test with datatypes");
66     else {
67         if (rank == 0)
68             Test_Passed("Simple Broadcast test with datatypes");
69         }
70
71     /* Close down the tests */
72     if (rank == 0)
73         ret = Summarize_Test_Results();
74     else {
75         ret = 0;
76     }
77     Test_Finalize();
78
79     /* Close down MPI */
80     Test_Waitforall( );
81     MPI_Finalize();
82     return ret;
83 }