Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initialize common variable.
[simgrid.git] / teshsuite / smpi / hvector_test.c
1 #include <stdio.h>
2 #include "mpi.h"
3 #define SIZE 4
4
5 int main(int argc, char **argv) {
6
7   int rank, i, j;
8   double a[SIZE][SIZE] = {{0}};
9
10   MPI_Datatype columntype;
11
12   MPI_Init(&argc,&argv);
13   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
14
15   MPI_Type_hvector(SIZE, 1, SIZE*sizeof(double), MPI_DOUBLE, &columntype);
16   MPI_Type_commit(&columntype);
17
18
19     if (rank == 0) {
20       for(i=0; i <SIZE;i++)
21         for(j=0; j <SIZE;j++)
22           a[i][j] = i*SIZE+j;
23     }
24
25     /* only one column is send
26      * this is an exemple for non-contignous data*/
27     MPI_Bcast(a, 1, columntype, 0, MPI_COMM_WORLD);
28
29     for(i=0; i<SIZE; i++){
30       for (j=0; j < SIZE; j++) {
31         printf("rank= %d, a[%d][%d]=%f\n",
32                rank, i, j, a[i][j]);
33       }
34       printf("\n");
35     }
36
37
38   MPI_Type_free(&columntype);
39   MPI_Finalize();
40   return 0;
41 }
42