forked from csc-training/mpi-introduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeleton.cpp
36 lines (29 loc) · 957 Bytes
/
skeleton.cpp
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
#include <cstdio>
#include <vector>
#include <mpi.h>
int main(int argc, char *argv[])
{
int myid, ntasks;
constexpr int arraysize = 100000;
constexpr int msgsize = 100;
std::vector<int> message(arraysize);
std::vector<int> receiveBuffer(arraysize);
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
// Initialize message
for (int i = 0; i < arraysize; i++) {
message[i] = myid;
}
// TODO: Implement sending and receiving as defined in the assignment
// Send msgsize elements from the array "message", and receive into
// "receiveBuffer"
if (myid == 0) {
printf("Rank %i received %i elements, first %i\n", myid, nrecv, receiveBuffer[0]);
} else if (myid == 1) {
printf("Rank %i received %i elements, first %i\n", myid, nrecv, receiveBuffer[0]);
}
MPI_Finalize();
return 0;
}