Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
30b6ea82ca4ffbc1e8f4d89b72829015908e053d
[simgrid.git] / teshsuite / smpi / type-hvector / type-hvector.c
1 /* Copyright (c) 2012-2019. 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;
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     if (rank == 0) {
24       for (int i = 0; i < SIZE; i++)
25         for (int j = 0; j < SIZE; j++)
26           a[i][j] = i * SIZE + j;
27     }
28
29     /* only one column is send this is an exemple for non-contignous data*/
30     MPI_Bcast(a, 1, columntype, 0, MPI_COMM_WORLD);
31
32     for (int i = 0; i < SIZE; i++) {
33       for (int j = 0; j < SIZE; j++) {
34         printf("rank= %d, a[%d][%d]=%f\n", rank, i, j, a[i][j]);
35       }
36       printf("\n");
37     }
38
39   MPI_Type_free(&columntype);
40   MPI_Finalize();
41   return 0;
42 }