Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / type-hvector / type-hvector.c
1 /* Copyright (c) 2012-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include "mpi.h"
9 #define SIZE 4
10
11 int main(int argc, char **argv) {
12   int rank, i, j;
13   double a[SIZE][SIZE] = {{0}};
14
15   MPI_Datatype columntype;
16
17   MPI_Init(&argc,&argv);
18   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
19
20   MPI_Type_hvector(SIZE, 1, SIZE*sizeof(double), MPI_DOUBLE, &columntype);
21   MPI_Type_commit(&columntype);
22
23
24     if (rank == 0) {
25       for(i=0; i <SIZE;i++)
26         for(j=0; j <SIZE;j++)
27           a[i][j] = i*SIZE+j;
28     }
29
30     /* only one column is send this is an exemple for non-contignous data*/
31     MPI_Bcast(a, 1, columntype, 0, MPI_COMM_WORLD);
32
33     for(i=0; i<SIZE; i++){
34       for (j=0; j < SIZE; j++) {
35         printf("rank= %d, a[%d][%d]=%f\n", rank, i, j, a[i][j]);
36       }
37       printf("\n");
38     }
39
40   MPI_Type_free(&columntype);
41   MPI_Finalize();
42   return 0;
43 }
44