6 int main( int argc, char **argv )
12 MPI_Datatype type, newtype;
15 MPI_Init( &argc, &argv );
16 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
17 MPI_Comm_size( MPI_COMM_WORLD, &size );
20 table = (int *) calloc (size, sizeof(int));
21 table[rank] = rank + 1;
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 );
28 /* See if we have the correct answers */
29 for ( i=0; i<size; i++ )
30 if (table[i] != i+1) errors++;
32 MPI_Barrier ( MPI_COMM_WORLD );
34 /* Try the same thing, but with a derived datatype */
35 for ( i=0; i<size; i++ )
37 table[rank] = rank + 1;
38 for ( i=0; i<size; i++ ) {
39 //MPI_Address( &table[i], &address );
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 );
48 /* See if we have the correct answers */
49 for ( i=0; i<size; i++ )
50 if (table[i] != i+1) errors++;
52 MPI_Barrier ( MPI_COMM_WORLD );
57 printf( "[%d] done with ERRORS!\n", rank );