-
Notifications
You must be signed in to change notification settings - Fork 12
/
buffered_test.cpp
167 lines (133 loc) · 3.26 KB
/
buffered_test.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <ctime>
#include <array>
#include <algorithm>
#include <limits>
#include <numeric>
#include "vlsv_writer.h"
#include "vlsv_amr.h"
using namespace vlsv;
// use the buffered API or not
#define BUFFERED
std::vector<int> sizes = {540,554,540,21,65,56,53,21,64,24};
std::vector<int> sizes2 = {1,2,10,100,1000,10000};
std::vector<int> parts = {1,3,2,1,1,1,10,1,1,1};
std::vector<int> parts2 = {1,2,5,10};
int *intData;
int myrank;
void writeNint(vlsv::Writer &vlsv, int N, int writeParts, int vectorSize)
{
std::cout << myrank << " added " << std::endl;
std::map<std::string, std::string> xmlAttributes;
xmlAttributes["Arr"] = "name";
vlsv.startMultiwrite(getStringDatatype<int>(),N*writeParts,vectorSize,sizeof(int));
for (size_t i = 0; i < writeParts; i++)
{
vlsv.addMultiwriteUnit((char*)intData,N);
}
vlsv.endMultiwrite("arrayName"+std::to_string(N),xmlAttributes);
}
void setBuffers(vlsv::Writer &vlsv, int bufferSize)
{
bool same = false;
#ifdef BUFFERED
if(!same)
{
if(myrank == 1)
vlsv.setBuffer(bufferSize);
else
vlsv.setBuffer(bufferSize/10);
}
else
vlsv.setBuffer(bufferSize);
#endif
}
int main(int argc,char* argv[]) {
bool success = true;
if (argc == 1)
{
std::cout << "usage : a.out buffer_size"
std::cout << "for MPI with up to 10 processes: mpiexec -n 10 a.out buffer_size"
}
// Init MPI:
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
int bufferSize = std::atoi(argv[1]);
int totSize = 10000;
intData = new int[totSize];
for (size_t i = 0; i < totSize; i++)
{
intData[i] = myrank;
}
{
// all writing the same size messages
vlsv::Writer vlsv;
setBuffers(vlsv, bufferSize);
if (vlsv.open("allTheSame.out"+std::to_string(bufferSize),MPI_COMM_WORLD,0) == false) {
success = false;
MPI_Finalize();
return 1;
}
for(auto size: sizes2)
for(auto part: parts)
writeNint(vlsv, size, part, 1);
if (vlsv.close() == false) {
success = false;
}
}
{
// all writing different size messages
vlsv::Writer vlsv;
setBuffers(vlsv, bufferSize);
if (vlsv.open("allDifferent.out"+std::to_string(bufferSize),MPI_COMM_WORLD,0) == false) {
success = false;
MPI_Finalize();
return 1;
}
writeNint(vlsv, sizes[myrank], parts[myrank], 1);
if (vlsv.close() == false) {
success = false;
}
}
{
// all but one writing
vlsv::Writer vlsv;
setBuffers(vlsv, bufferSize);
if (vlsv.open("allBut1.out"+std::to_string(bufferSize),MPI_COMM_WORLD,0) == false) {
success = false;
MPI_Finalize();
return 1;
}
if(myrank == 4)
writeNint(vlsv, 0, 1, 1);
else
writeNint(vlsv, sizes[myrank], parts[myrank], 1);
if (vlsv.close() == false) {
success = false;
}
}
{
// only one writing
vlsv::Writer vlsv;
setBuffers(vlsv, bufferSize);
if (vlsv.open("only1.out"+std::to_string(bufferSize),MPI_COMM_WORLD,0) == false) {
success = false;
MPI_Finalize();
return 1;
}
if(myrank == 5)
writeNint(vlsv, sizes[myrank], 1, 1);
else
writeNint(vlsv, 0, 0, 1);
if (vlsv.close() == false) {
success = false;
}
}
MPI_Finalize();
if (success == false) return 1;
return 0;
}