Newer
Older
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
*
* Created on: Sep 7, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include "BP3Deserializer.h"
#include "BP3Deserializer.tcc"
#include <future>
#include <vector>
#include "adios2/helper/adiosFunctions.h" //ReadValue<T>
namespace adios2
{
namespace format
{
std::mutex BP3Deserializer::m_Mutex;
BP3Deserializer::BP3Deserializer(MPI_Comm mpiComm, const bool debugMode)
: BP3Base(mpiComm, debugMode)
void BP3Deserializer::ParseMetadata(IO &io)
{
ParseMinifooter();
ParsePGIndex();
ParseVariablesIndex(io);
// ParseAttributesIndex(io);
}
void BP3Deserializer::ClipContiguousMemory(
const std::string &variableName, IO &io,
const std::vector<char> &contiguousMemory, const Box<Dims> &intersectionBox)
{
// get variable pointer and set data in it with local dimensions
const std::string type(io.InquireVariableType(variableName));
if (type == "compound")
{
}
#define declare_type(T) \
else if (type == GetType<T>()) \
{ \
Variable<T> *variable = io.InquireVariable<T>(variableName); \
if (variable != nullptr) \
{ \
ClipContiguousMemoryCommon(*variable, contiguousMemory, \
intersectionBox); \
} \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_type)
#undef declare_type
}
void BP3Deserializer::ParseMinifooter()
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
{
auto lf_GetEndianness = [](const uint8_t endianness, bool &isLittleEndian) {
switch (endianness)
{
case 0:
isLittleEndian = true;
break;
case 1:
isLittleEndian = false;
break;
}
};
const auto &buffer = m_Metadata.m_Buffer;
const size_t bufferSize = buffer.size();
size_t position = bufferSize - 4;
const uint8_t endianess = ReadValue<uint8_t>(buffer, position);
lf_GetEndianness(endianess, m_Minifooter.IsLittleEndian);
position += 1;
const uint8_t subFilesIndex = ReadValue<uint8_t>(buffer, position);
if (subFilesIndex > 0)
{
m_Minifooter.HasSubFiles = true;
}
m_Minifooter.Version = ReadValue<uint8_t>(buffer, position);
if (m_Minifooter.Version < 3)
{
throw std::runtime_error("ERROR: ADIOS2 only supports bp format "
"version 3 and above, found " +
std::to_string(m_Minifooter.Version) +
" version \n");
}
position = bufferSize - m_MetadataSet.MiniFooterSize;
m_Minifooter.PGIndexStart = ReadValue<uint64_t>(buffer, position);
m_Minifooter.VarsIndexStart = ReadValue<uint64_t>(buffer, position);
m_Minifooter.AttributesIndexStart = ReadValue<uint64_t>(buffer, position);
}
void BP3Deserializer::ParsePGIndex()
{
const auto &buffer = m_Metadata.m_Buffer;
auto &position = m_Metadata.m_Position;
position = m_Minifooter.PGIndexStart;
m_MetadataSet.DataPGCount = ReadValue<uint64_t>(buffer, position);
const uint64_t pgLength =
ReadValue<uint64_t>(buffer, position); // not required
}
void BP3Deserializer::ParseVariablesIndex(IO &io)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
{
auto lf_ReadElementIndex = [&](IO &io, const std::vector<char> &buffer,
size_t position) {
const ElementIndexHeader header =
ReadElementIndexHeader(buffer, position);
switch (header.DataType)
{
case (type_byte):
{
DefineVariableInIO<char>(header, io, buffer, position);
break;
}
case (type_short):
{
DefineVariableInIO<short>(header, io, buffer, position);
break;
}
case (type_integer):
{
DefineVariableInIO<int>(header, io, buffer, position);
break;
}
case (type_long):
{
DefineVariableInIO<long int>(header, io, buffer, position);
break;
}
case (type_unsigned_byte):
{
DefineVariableInIO<unsigned char>(header, io, buffer, position);
break;
}
case (type_unsigned_short):
{
DefineVariableInIO<unsigned short>(header, io, buffer, position);
break;
}
case (type_unsigned_integer):
{
DefineVariableInIO<unsigned int>(header, io, buffer, position);
break;
}
case (type_unsigned_long):
{
DefineVariableInIO<unsigned long int>(header, io, buffer, position);
break;
}
case (type_real):
{
DefineVariableInIO<float>(header, io, buffer, position);
break;
}
case (type_double):
{
DefineVariableInIO<double>(header, io, buffer, position);
break;
}
case (type_long_double):
{
DefineVariableInIO<long double>(header, io, buffer, position);
break;
}
case (type_complex):
{
DefineVariableInIO<std::complex<float>>(header, io, buffer,
position);
break;
}
case (type_double_complex):
{
DefineVariableInIO<std::complex<double>>(header, io, buffer,
position);
break;
}
case (type_long_double_complex):
{
DefineVariableInIO<std::complex<long double>>(header, io, buffer,
position);
break;
}
// TODO: string
} // end switch
};
const auto &buffer = m_Metadata.m_Buffer;
size_t position = m_Minifooter.VarsIndexStart;
const uint32_t count = ReadValue<uint32_t>(buffer, position);
const uint64_t length = ReadValue<uint64_t>(buffer, position);
const size_t startPosition = position;
size_t localPosition = 0;
// threads for reading Variables
std::vector<std::future<void>> asyncs(m_Threads);
std::vector<size_t> asyncPositions(m_Threads);
bool launched = false;
while (localPosition < length)
{
// extract async positions
for (unsigned int t = 0; t < m_Threads; ++t)
{
asyncPositions[t] = position;
const size_t elementIndexSize = static_cast<const size_t>(
ReadValue<uint32_t>(buffer, position));
position += elementIndexSize;
localPosition = position - startPosition;
if (launched)
{
asyncs[t].get();
}
if (localPosition <= length)
{
asyncs[t] = std::async(std::launch::async, lf_ReadElementIndex,
std::ref(io), std::ref(buffer),
asyncPositions[t]);
}
}
launched = true;
}
for (auto &async : asyncs)
{
if (async.valid())
{
async.wait();
}
}
}
void BP3Deserializer::ParseAttributesIndex(IO &io) {}
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
std::map<std::string, SubFileInfoMap>
BP3Deserializer::PerformGetsVariablesSubFileInfo(IO &io)
{
if (m_DeferredVariables.empty())
{
return m_DeferredVariables;
}
for (auto &subFileInfoPair : m_DeferredVariables)
{
const std::string variableName(subFileInfoPair.first);
const std::string type(io.InquireVariableType(variableName));
if (type == "compound")
{
}
#define declare_type(T) \
else if (type == GetType<T>()) \
{ \
subFileInfoPair.second = \
GetSubFileInfo(*io.InquireVariable<T>(variableName)); \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_type)
#undef declare_type
}
return m_DeferredVariables;
}
#define declare_template_instantiation(T) \
template std::map<std::string, SubFileInfoMap> \
BP3Deserializer::GetSyncVariableSubFileInfo(const Variable<T> &variable) \
const; \
\
template void BP3Deserializer::GetDeferredVariable(Variable<T> &variable, \
T *data);
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
} // end namespace format
} // end namespace adios2