forked from csc-training/summerschool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skeleton.c
65 lines (50 loc) · 1.24 KB
/
skeleton.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <mpi.h>
int main(int argc, char **argv)
{
int rank;
int sendarray[8][6];
int recvarray[8][6];
MPI_Datatype vector, vector2;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Initialize arrays
if (rank == 0) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 6; j++) {
sendarray[i][j] = (i + 1) * 10 + j + 1;
}
}
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 6; j++) {
recvarray[i][j] = 0;
}
}
if (rank == 0) {
printf("Data in rank 0\n");
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 6; j++) {
printf("%3d", sendarray[i][j]);
}
printf("\n");
}
}
// TODO create datatype
// Communicate with the datatype
if (rank == 0)
else if (rank == 1)
// free datatype
// TODO end
if (rank == 1) {
printf("Received data\n");
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 6; j++) {
printf("%3d", recvarray[i][j]);
}
printf("\n");
}
}
MPI_Finalize();
return 0;
}