Newer
Older
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
Podhorszki, Norbert
committed
* ADIOS1Reader.cpp
*
* Created on: Feb 27, 2017
* Author: wfg
*/
#include "ADIOS1Reader.h"
#include "adios2/core/Support.h"
#include "adios2/core/adiosFunctions.h" // CSVToVector
#include "adios2/transport/file/FStream.h" // uses C++ fstream
#include "adios2/transport/file/FileDescriptor.h" // uses POSIX
#include "adios2/transport/file/FilePointer.h" // uses C FILE*
ADIOS1Reader::ADIOS1Reader(ADIOS &adios, const std::string &name,
const std::string accessMode, MPI_Comm mpiComm,
const Method &method)
Podhorszki, Norbert
committed
: Engine(adios, "ADIOS1Reader", name, accessMode, mpiComm, method,
" ADIOS1Reader constructor (or call to ADIOS Open).\n")
Podhorszki, Norbert
committed
adios_read_init_method(m_ReadMethod, mpiComm, "");
Podhorszki, Norbert
committed
m_fh = adios_read_open(name.c_str(), m_ReadMethod, mpiComm,
ADIOS_LOCKMODE_CURRENT, 0.0);
Podhorszki, Norbert
committed
ADIOS1Reader::~ADIOS1Reader()
{
if (m_fh != nullptr)
adios_read_close(m_fh);
adios_read_finalize_method(m_ReadMethod);
}
Podhorszki, Norbert
committed
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariable(const std::string &variableName,
const bool readIn) // not yet implemented
{
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableChar(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<char>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableUChar(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<unsigned char>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableShort(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<short>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableUShort(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<unsigned short>(variableName, readIn);
Podhorszki, Norbert
committed
Variable<int> *ADIOS1Reader::InquireVariableInt(const std::string &variableName,
return InquireVariableCommon<int>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableUInt(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<unsigned int>(variableName, readIn);
Variable<long int> *
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableLInt(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<long int>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableULInt(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<unsigned long int>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableLLInt(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<long long int>(variableName, readIn);
}
Variable<unsigned long long int> *
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableULLInt(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<unsigned long long int>(variableName, readIn);
Variable<float> *
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableFloat(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<float>(variableName, readIn);
Variable<double> *
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableDouble(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<double>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableLDouble(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<long double>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableCFloat(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<std::complex<float>>(variableName, readIn);
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableCDouble(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<std::complex<double>>(variableName, readIn);
}
Variable<std::complex<long double>> *
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableCLDouble(const std::string &variableName,
const bool readIn)
return InquireVariableCommon<std::complex<long double>>(variableName,
readIn);
VariableCompound *
Podhorszki, Norbert
committed
ADIOS1Reader::InquireVariableCompound(const std::string &variableName,
const bool readIn)
Podhorszki, Norbert
committed
void ADIOS1Reader::ScheduleReadCommon(const std::string &name,
const Dims &ldims, const Dims &offs,
void *data)
{
uint64_t start[32], count[32];
for (int i = 0; i < ldims.size(); i++)
{
start[i] = (uint64_t)offs[i];
count[i] = (uint64_t)ldims[i];
}
ADIOS_SELECTION *sel =
adios_selection_boundingbox(ldims.size(), start, count);
adios_schedule_read(m_fh, sel, name.c_str(), 1, 0, data);
adios_selection_delete(sel);
}
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
void ADIOS1Reader::ScheduleRead(Variable<char> &variable, char *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<unsigned char> &variable,
unsigned char *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<short> &variable, short *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<unsigned short> &variable,
unsigned short *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<int> &variable, int *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<unsigned int> &variable,
unsigned int *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<long int> &variable, long int *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<unsigned long int> &variable,
unsigned long int *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<long long int> &variable,
long long int *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<unsigned long long int> &variable,
unsigned long long int *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<float> &variable, float *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
Podhorszki, Norbert
committed
void ADIOS1Reader::ScheduleRead(Variable<double> &variable, double *values)
{
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<long double> &variable,
long double *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<std::complex<float>> &variable,
std::complex<float> *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<std::complex<double>> &variable,
std::complex<double> *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
}
void ADIOS1Reader::ScheduleRead(Variable<std::complex<long double>> &variable,
std::complex<long double> *values)
{
ScheduleReadCommon(variable.m_Name, variable.m_Count, variable.m_Start,
(void *)values);
Podhorszki, Norbert
committed
}
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
void ADIOS1Reader::ScheduleRead(const std::string &variableName, char *values)
{
ScheduleRead(m_ADIOS.GetVariable<char>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
unsigned char *values)
{
ScheduleRead(m_ADIOS.GetVariable<unsigned char>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName, short *values)
{
ScheduleRead(m_ADIOS.GetVariable<short>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
unsigned short *values)
{
ScheduleRead(m_ADIOS.GetVariable<unsigned short>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName, int *values)
{
ScheduleRead(m_ADIOS.GetVariable<int>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
unsigned int *values)
{
ScheduleRead(m_ADIOS.GetVariable<unsigned int>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
long int *values)
{
ScheduleRead(m_ADIOS.GetVariable<long int>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
unsigned long int *values)
{
ScheduleRead(m_ADIOS.GetVariable<unsigned long int>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
long long int *values)
{
ScheduleRead(m_ADIOS.GetVariable<long long int>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
unsigned long long int *values)
{
ScheduleRead(m_ADIOS.GetVariable<unsigned long long int>(variableName),
values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName, float *values)
{
ScheduleRead(m_ADIOS.GetVariable<float>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName, double *values)
Podhorszki, Norbert
committed
{
ScheduleRead(m_ADIOS.GetVariable<double>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
long double *values)
{
ScheduleRead(m_ADIOS.GetVariable<long double>(variableName), values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
std::complex<float> *values)
{
ScheduleRead(m_ADIOS.GetVariable<std::complex<float>>(variableName),
values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
std::complex<double> *values)
{
ScheduleRead(m_ADIOS.GetVariable<std::complex<double>>(variableName),
values);
}
void ADIOS1Reader::ScheduleRead(const std::string &variableName,
std::complex<long double> *values)
{
ScheduleRead(m_ADIOS.GetVariable<std::complex<long double>>(variableName),
values);
}
Podhorszki, Norbert
committed
void ADIOS1Reader::PerformReads(PerformReadMode mode)
{
adios_perform_reads(m_fh, (int)mode);
}
void ADIOS1Reader::Close(const int transportIndex) { adios_read_close(m_fh); }
Podhorszki, Norbert
committed
void ADIOS1Reader::Init()
if (m_DebugMode == true)
{
if (m_AccessMode != "r" && m_AccessMode != "read")
throw std::invalid_argument(
Podhorszki, Norbert
committed
"ERROR: ADIOS1Reader doesn't support access mode " +
Podhorszki, Norbert
committed
", in call to ADIOS Open or ADIOS1Reader constructor\n");
Podhorszki, Norbert
committed
InitParameters();
Podhorszki, Norbert
committed
void ADIOS1Reader::InitParameters() {}
void ADIOS1Reader::InitTransports()
Podhorszki, Norbert
committed
if (TransportNamesUniqueness() == false)
{
throw std::invalid_argument(
"ERROR: two transports of the same kind (e.g file IO) "
"can't have the same name, modify with name= in Method "
"AddTransport\n");
}
for (const auto ¶meters : m_Method.m_TransportParameters)
auto itTransport = parameters.find("transport");
Podhorszki, Norbert
committed
if (itTransport->second == "file" || itTransport->second == "File" ||
itTransport->second == "bp" || itTransport->second == "BP")
Podhorszki, Norbert
committed
m_ReadMethod = ADIOS_READ_METHOD_BP;
}
else
{
if (m_DebugMode == true)
throw std::invalid_argument(
"ERROR: transport " + itTransport->second +
" (you mean File?) not supported, in " + m_Name +
m_EndMessage);
}
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
bool ADIOS1Reader::CheckADIOS1TypeCompatibility(std::string adios2Type,
enum ADIOS_DATATYPES adios1Type)
{
bool compatible = false;
switch (adios1Type)
{
case adios_unsigned_byte:
compatible = (adios2Type == "unsigned char");
break;
case adios_unsigned_short:
compatible = (adios2Type == "unsigned short");
break;
case adios_unsigned_integer:
compatible = (adios2Type == "unsigned int");
break;
case adios_unsigned_long:
compatible = (adios2Type == "unsigned long long int");
break;
case adios_byte:
compatible = (adios2Type == "char");
break;
case adios_short:
compatible = (adios2Type == "short");
break;
case adios_integer:
compatible = (adios2Type == "int");
break;
case adios_long:
compatible = (adios2Type == "long long int");
break;
case adios_real:
compatible = (adios2Type == "float");
break;
case adios_double:
compatible = (adios2Type == "double");
break;
case adios_long_double:
compatible = (adios2Type == "long double");
break;
case adios_string:
compatible = (adios2Type == "string");
break;
case adios_complex:
compatible = (adios2Type == "float complex");
break;
case adios_double_complex:
compatible = (adios2Type == "double complex");
break;
case adios_string_array:
compatible = false;
break;
default:
compatible = false;
}
if (!compatible)
{
std::string typeStr(adios_type_to_string(adios1Type));
throw std::invalid_argument("Type mismatch. The expected ADIOS2 type " +
adios2Type +
" is not compatible with ADIOS1 type " +
typeStr + " of the requested variable\n");
}
return true;
}