Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a15f6c2404b68d0623d91fc34508e0c1da905ae3
[simgrid.git] / teshsuite / smpi / mpich-test / coll / coll1.c
1 #include "mpi.h"
2 #include "test.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 int main( int argc, char **argv )
7 {
8     int              rank, size, i;
9     int             *table;
10     int              errors=0;
11     MPI_Aint         address;
12     MPI_Datatype     type, newtype;
13     int              lens;
14
15     MPI_Init( &argc, &argv );
16     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
17     MPI_Comm_size( MPI_COMM_WORLD, &size );
18
19     /* Make data table */
20     table = (int *) calloc (size, sizeof(int));
21     table[rank] = rank + 1;
22
23     MPI_Barrier ( MPI_COMM_WORLD );
24     /* Broadcast the data */
25     for ( i=0; i<size; i++ ) 
26       MPI_Bcast( &table[i], 1, MPI_INT, i, MPI_COMM_WORLD );
27
28     /* See if we have the correct answers */
29     for ( i=0; i<size; i++ )
30       if (table[i] != i+1) errors++;
31
32     MPI_Barrier ( MPI_COMM_WORLD );
33
34     /* Try the same thing, but with a derived datatype */
35     for ( i=0; i<size; i++ ) 
36         table[i] = 0;
37     table[rank] = rank + 1;
38     for ( i=0; i<size; i++ ) {
39         //MPI_Address( &table[i], &address );
40         address=0;
41   type = MPI_INT;
42         lens = 1;
43         MPI_Type_struct( 1, &lens, &address, &type, &newtype );
44         MPI_Type_commit( &newtype );
45         MPI_Bcast( &table[i], 1, newtype, i, MPI_COMM_WORLD );
46         MPI_Type_free( &newtype );
47         }
48     /* See if we have the correct answers */
49     for ( i=0; i<size; i++ )
50       if (table[i] != i+1) errors++;
51
52     MPI_Barrier ( MPI_COMM_WORLD );
53
54     Test_Waitforall( );
55     MPI_Finalize();
56     if (errors)
57       printf( "[%d] done with ERRORS!\n", rank );
58     return errors;
59 }
60
61