Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge with jean noel's commit
[simgrid.git] / examples / smpi / vector_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, tag=1, i, j;
8   double a[SIZE][SIZE];
9
10   MPI_Status stat;
11   MPI_Datatype columntype;
12
13   MPI_Init(&argc,&argv);
14   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
15
16   MPI_Type_vector(SIZE, 1, SIZE, MPI_DOUBLE, &columntype);
17   MPI_Type_commit(&columntype);
18
19
20     if (rank == 0) {
21       for(i=0; i <SIZE;i++)
22         for(j=0; j <SIZE;j++)
23           a[i][j] = i*SIZE+j;
24     }
25
26     /* only one column is send
27      * this is an exemple for non-contignous data*/
28     MPI_Bcast(a, 1, columntype, 0, MPI_COMM_WORLD);
29
30     for(i=0; i<SIZE; i++){
31       for (j=0; j < SIZE; j++) {
32         printf("rank= %d, a[%d][%d]=%f\n",
33                rank, i, j, a[i][j]);
34       }
35       printf("\n");
36     }
37
38
39
40   MPI_Finalize();
41 }
42