-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtimed_test.cpp
223 lines (183 loc) · 6.49 KB
/
timed_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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <ctime>
#include <array>
#include <algorithm>
#include <limits>
#include <numeric>
#include <random>
#include "vlsv_writer.h"
#include "vlsv_reader_parallel.h"
#include "vlsv_amr.h"
using namespace vlsv;
std::vector<int> chunkSizes;
std::vector<int> chunkCounts;
std::vector<int> intData;
int myRank, nRanks;
void writeNint(vlsv::Writer &vlsv, int chunkSize, int chunkCount)
{
std::map<std::string, std::string> xmlAttributes;
xmlAttributes["Arr"] = "name";
vlsv.startMultiwrite(getStringDatatype<int>(),chunkSize*chunkCount,1 /*vectorSize */,sizeof(int));
for (int i = 0; i < chunkCount; i++)
{
vlsv.addMultiwriteUnit(intData.data(),chunkSize);
}
vlsv.endMultiwrite("arrayName"+std::to_string(chunkSize),xmlAttributes);
}
void readNint(vlsv::ParallelReader &vlsv, int chunkSize, int chunkCount, uint64_t fileOffset)
{
std::list<std::pair<std::string,std::string> > xmlAttributes;
xmlAttributes.push_back({"Arr", "name"});
vlsv.startMultiread("Arr", xmlAttributes);
for (int i = 0; i < chunkCount; i++)
{
vlsv.addMultireadUnit((char*)intData.data() + chunkSize*i*sizeof(int), chunkSize);
}
vlsv.endMultiread(fileOffset);
}
int main(int argc,char* argv[]) {
bool success = true;
if (argc < 6)
{
std::cout << "usage : srun timed_test buffer_size min_rank_chunk_size max_rank_chunk_size min_rank_chunk_count max_rank_chunk_count [WR mpiio_hint mpiio_value] [RD mpiio_hint mpiio_value]" << std::endl;
}
// Init MPI:
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
MPI_Comm_size(MPI_COMM_WORLD, &nRanks);
const double GiB = 1024*1024*1024;
int bufferSize = std::atoi(argv[1]);
int minChunkSize = std::atoi(argv[2]);
int maxChunkSize = std::atoi(argv[3]);
int minChunkCount = std::atoi(argv[4]);
int maxChunkCount = std::atoi(argv[5]);
MPI_Info MPIinfo_wr, MPIinfo_rd;
if (argc == 6) {
MPIinfo_wr = MPIinfo_rd = MPI_INFO_NULL;
} else {
int i=6, wr_count=0, rd_count=0;
MPI_Info_create(&MPIinfo_wr);
MPI_Info_create(&MPIinfo_rd);
MPI_Info * MPIinfo_ptr;
while(true) {
if(i >= argc) {
break;
}
if(argv[i] == std::string("WR")) {
MPIinfo_ptr = &MPIinfo_wr;
i++;
wr_count++;
}
if(argv[i] == std::string("RD")) {
MPIinfo_ptr = &MPIinfo_rd;
i++;
rd_count++;
}
MPI_Info_set(*MPIinfo_ptr, argv[i], argv[i+1]);
i += 2;
}
if(wr_count == 0) {
MPIinfo_wr = MPI_INFO_NULL;
}
if(rd_count == 0) {
MPIinfo_rd = MPI_INFO_NULL;
}
}
if(myRank == 0) {
std::cout << "INFO: This will write int data, int has size " << sizeof(int) << std::endl;
std::cout << "INFO: This will write between " << minChunkCount << " and " << maxChunkCount << " chunks of between " << minChunkSize*sizeof(int) / GiB << " and " << maxChunkSize*sizeof(int) / GiB << " GiB on each of the " << nRanks << " tasks." << std::endl;
}
std::default_random_engine generatorChunkSizes(42), generatorChunkCounts(43);
std::uniform_int_distribution<int> randomChunkSizes(minChunkSize, maxChunkSize), randomChunkCounts(minChunkCount, maxChunkCount);
for (int i=0; i<nRanks; i++) {
chunkSizes.push_back(randomChunkSizes(generatorChunkSizes));
chunkCounts.push_back(randomChunkCounts(generatorChunkCounts));
}
if(myRank == 0) {
std::stringstream stream;
stream << "# RD/WR \t Rank \t chunks \t size (GiB) \t total (GiB) \t time (s) \t speed (GiB/s)" << std::endl;
std::cerr << stream.str();
}
// WRITE
// For writing, we need only one chunk that'll be written a number of times
intData.assign(chunkSizes[myRank], myRank);
vlsv::Writer vlsvWriter;
vlsvWriter.setBuffer(bufferSize);
if (vlsvWriter.open("file.out",MPI_COMM_WORLD,0, MPIinfo_wr) == false) {
success = false;
MPI_Finalize();
return 1;
}
const double chunkSize = chunkSizes[myRank]*sizeof(int) / GiB;
MPI_Barrier(MPI_COMM_WORLD);
double tStart = MPI_Wtime();
writeNint(vlsvWriter, chunkSizes[myRank], chunkCounts[myRank]);
double tTime = MPI_Wtime() - tStart;
std::stringstream stream;
stream << "WR\t" << myRank << "\t" << chunkCounts[myRank] << "\t" << chunkSize << "\t" << chunkCounts[myRank]*chunkSize << "\t" << tTime << "\t" << chunkCounts[myRank]*chunkSize / tTime << std::endl;
std::cerr << stream.str();
if (vlsvWriter.close() == false) {
success = false;
}
// Do this here as the close call does the actual writing when buffering
MPI_Barrier(MPI_COMM_WORLD);
uint64_t totalChunkCount = 0;
double totalSize = 0;
if(myRank == 0) {
const double totalTime = MPI_Wtime() - tStart;
for (int i=0; i<nRanks; i++) {
totalChunkCount += chunkCounts[i];
totalSize += chunkCounts[i]*chunkSizes[i];
}
totalSize *= sizeof(int) / GiB;
std::stringstream stream;
stream << "WR\t" << nRanks << "\t" << totalChunkCount << "\t" << totalSize / totalChunkCount << "\t" << totalSize << "\t" << totalTime << "\t" << totalSize / totalTime << std::endl;
std::cerr << stream.str();
}
// READ
// For reading we want the buffer to have the full size
intData.resize(chunkSizes[myRank]*chunkCounts[myRank]);
vlsv::ParallelReader vlsvReader;
if (vlsvReader.open("file.out",MPI_COMM_WORLD,0, MPIinfo_rd) == false) {
success = false;
MPI_Finalize();
return 1;
}
uint64_t myFileOffset = 0;
for(int t=0; t<myRank; t++) {
myFileOffset += chunkSizes[t]*chunkCounts[t]*sizeof(int);
}
MPI_Barrier(MPI_COMM_WORLD);
tStart = MPI_Wtime();
readNint(vlsvReader, chunkSizes[myRank], chunkCounts[myRank], myFileOffset);
tTime = MPI_Wtime() - tStart;
stream.clear();
stream.str(std::string());
stream << "RD\t" << myRank << "\t" << chunkCounts[myRank] << "\t" << chunkSize << "\t" << chunkCounts[myRank]*chunkSize << "\t" << tTime << "\t" << chunkCounts[myRank]*chunkSize / tTime << std::endl;
std::cerr << stream.str();
if (vlsvReader.close() == false) {
success = false;
}
stream.clear();
stream.str(std::string());
for (auto i : intData) {
stream << myRank << " " << intData.size() << " " << intData[i] << std::endl;
std::cerr << stream.str();
stream.clear();
stream.str(std::string());
}
MPI_Barrier(MPI_COMM_WORLD);
if(myRank == 0) {
const double totalTime = MPI_Wtime() - tStart;
std::stringstream stream;
stream << "RD\t" << nRanks << "\t" << totalChunkCount << "\t" << totalSize / totalChunkCount << "\t" << totalSize << "\t" << totalTime << "\t" << totalSize / totalTime << std::endl;
std::cerr << stream.str();
}
MPI_Finalize();
if (success == false) return 1;
return 0;
}