Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add/update copyright notices.
[simgrid.git] / teshsuite / smpi / hvector_test.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
13   int rank, i, j;
14   double a[SIZE][SIZE] = {{0}};
15
16   MPI_Datatype columntype;
17
18   MPI_Init(&argc,&argv);
19   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20
21   MPI_Type_hvector(SIZE, 1, SIZE*sizeof(double), MPI_DOUBLE, &columntype);
22   MPI_Type_commit(&columntype);
23
24
25     if (rank == 0) {
26       for(i=0; i <SIZE;i++)
27         for(j=0; j <SIZE;j++)
28           a[i][j] = i*SIZE+j;
29     }
30
31     /* only one column is send
32      * this is an exemple for non-contignous data*/
33     MPI_Bcast(a, 1, columntype, 0, MPI_COMM_WORLD);
34
35     for(i=0; i<SIZE; i++){
36       for (j=0; j < SIZE; j++) {
37         printf("rank= %d, a[%d][%d]=%f\n",
38                rank, i, j, a[i][j]);
39       }
40       printf("\n");
41     }
42
43
44   MPI_Type_free(&columntype);
45   MPI_Finalize();
46   return 0;
47 }
48