-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_async_strategies.cpp
112 lines (83 loc) · 2.48 KB
/
test_async_strategies.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <vector>
#include "json.hpp"
#include "common.h"
#include <mpi.h>
using namespace std;
using json = nlohmann::json;
/*
* You must run these tests with exactly two MPI processes.
*/
void test_Isend(uint64_t compCount, uint64_t sendCount) {
int proc_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
VectorXd x(compCount);
VectorXd y(compCount);
VectorXd u(sendCount);
MPI_Status stat;
MPI_Request sendreq, recvreq;
if(proc_rank == 0) {
MPI_Isend(u.data(), sendCount, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD, &sendreq);
}
if(proc_rank == 1) {
MPI_Irecv(u.data(), sendCount, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &recvreq);
}
auto t = start_clock();
VectorXd z = x.array() * y.array();
double znorm = z.norm();
if(proc_rank == 0) {
cout << znorm << endl;
}
if(proc_rank == 0) {
cout << "Computation time: " << stop_clock_get_elapsed(t) << endl;
}
t = start_clock();
if(proc_rank == 0) {
MPI_Wait(&sendreq, &stat);
}
if(proc_rank == 1) {
MPI_Wait(&recvreq, &stat);
cout << "Additional time spent in communication: " << stop_clock_get_elapsed(t) << endl;
}
}
void test_RMA(int compCount, int sendCount) {
int proc_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
VectorXd x(compCount);
VectorXd y(compCount);
VectorXd u(sendCount);
MPI_Status stat;
MPI_Request req;
MPI_Info info;
MPI_Info_create(&info);
MPI_Win window;
double* ptr;
MPI_Win_allocate( sizeof(double) * sendCount, 8, info, MPI_COMM_WORLD, &ptr, &window );
MPI_Win_fence(0, window);
if(proc_rank == 1) {
MPI_Raccumulate(u.data(), sendCount, MPI_DOUBLE, 0, 0,
sendCount, MPI_DOUBLE, MPI_SUM, window, &req);
}
auto t = start_clock();
VectorXd z = x.array() * y.array();
double znorm = z.norm();
if(proc_rank == 0) {
cout << znorm << endl;
}
if(proc_rank == 1) {
cout << "Computation time: " << stop_clock_get_elapsed(t) << endl;
}
if(proc_rank == 1) {
t = start_clock();
MPI_Wait(&req, &stat);
cout << "Additional time spent in communication: " << stop_clock_get_elapsed(t) << endl;
}
MPI_Win_fence(0, window);
MPI_Win_free(&window);
}
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
test_Isend(500000000/*00000*/, 500000000);
//test_RMA(500000000/*00000*/, 50000000);
MPI_Finalize();
}