-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
41 lines (34 loc) · 1020 Bytes
/
main.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
37
38
39
40
41
#include <iostream>
#include "mpi.h"
using namespace std;
//Testing GitHUB
int main(int argc, char **argv)
{
int numtasks, rank, dest, source, rc, count, tag=1;
int version, subversion;
char inmsg, outmsg='x';
MPI::Status Stat;
MPI::Init(argc,argv);
numtasks = MPI::COMM_WORLD.Get_size();
rank = MPI::COMM_WORLD.Get_rank();
MPI::Get_version(version, subversion);
if(rank == 0)
cout << "MPI VERS: " << version << "." << subversion <<endl;
if (rank == 0) {
dest = 1;
source = 1;
MPI::COMM_WORLD.Send(&outmsg, 1, MPI_CHAR, dest, tag);
MPI::COMM_WORLD.Recv(&inmsg, 1, MPI_CHAR, source, tag, Stat);
}
else if (rank == 1) {
dest = 0;
source = 0;
MPI::COMM_WORLD.Recv(&inmsg, 1, MPI_CHAR, source, tag, Stat);
MPI::COMM_WORLD.Send(&outmsg, 1, MPI_CHAR, dest, tag);
}
count = Stat.Get_count(MPI_CHAR);
printf("Task %d: Received %d char(s) from task %d with tag %d \n",
rank, count, Stat.Get_source(), Stat.Get_tag());
MPI::Finalize();
return 0;
}