update and improve ADIOS support

- modernize code
- remove dead code and unused definitions, enums, and includes
- create default adios2_config.xml file if it doesn't exist
- enable and apply clang-format
- update documentation
This commit is contained in:
Axel Kohlmeyer
2022-03-29 00:31:12 -04:00
parent 333e3b0491
commit b211f97efa
6 changed files with 787 additions and 924 deletions

View File

@ -35,13 +35,21 @@ Examples
Description
"""""""""""
Dump a snapshot of atom coordinates every N timesteps in the
`ADIOS <adios_>`_ based "BP" file format, or using different I/O solutions in ADIOS,
to a stream that can be read on-line by another program.
Dump a snapshot of atom coordinates every N timesteps in the `ADIOS
<adios_>`_ based "BP" file format, or using different I/O solutions in
ADIOS, to a stream that can be read on-line by another program.
ADIOS-BP files are binary, portable and self-describing.
.. _adios: https://github.com/ornladios/ADIOS2
.. note::
To be able to use ADIOS, a file ``adios2_config.xml`` with specific
configuration settings is expected in the current working directory.
If the file is not present, LAMMPS will try to create a minimal
default file. Please refer to the ADIOS documentation for details on
how to adjust this file for optimal performance and desired features.
**Use from write_dump:**
It is possible to use these dump styles with the

39
src/ADIOS/adios_common.h Normal file
View File

@ -0,0 +1,39 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
Contributed by Norbert Podhorszki (Oak Ridge National Laboratory)
------------------------------------------------------------------------- */
#ifndef LMP_ADIOS_COMMON_H
#define LMP_ADIOS_COMMON_H
// common definitions for all ADIOS package classes
static const char default_config[] = "<?xml version=\"1.0\"?>\n"
"<adios-config>\n"
" <io name=\"atom\">\n"
" <engine type=\"BP4\">\n"
" <parameter key=\"substreams\" value=\"1\"/>\n"
" </engine>\n"
" </io>\n"
" <io name=\"custom\">\n"
" <engine type=\"BP4\">\n"
" <parameter key=\"substreams\" value=\"1\"/>\n"
" </engine>\n"
" </io>\n"
" <io name=\"read_dump\">\n"
" <engine type=\"BP4\">\n"
" </engine>\n"
" </io>\n"
"</adios-config>\n";
#endif

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -24,20 +23,16 @@
#include "memory.h"
#include "universe.h"
#include "update.h"
#include <cstring>
#include "adios2.h"
#include "adios_common.h"
using namespace LAMMPS_NS;
#define MAX_TEXT_HEADER_SIZE 4096
#define DUMP_BUF_CHUNK_SIZE 16384
#define DUMP_BUF_INCREMENT_SIZE 4096
namespace LAMMPS_NS
{
class DumpAtomADIOSInternal
{
namespace LAMMPS_NS {
class DumpAtomADIOSInternal {
public:
DumpAtomADIOSInternal(){};
@ -55,18 +50,21 @@ public:
/* ---------------------------------------------------------------------- */
DumpAtomADIOS::DumpAtomADIOS(LAMMPS *lmp, int narg, char **arg)
: DumpAtom(lmp, narg, arg)
DumpAtomADIOS::DumpAtomADIOS(LAMMPS *lmp, int narg, char **arg) : DumpAtom(lmp, narg, arg)
{
// create a default adios2_config.xml if it doesn't exist yet.
FILE *cfgfp = fopen("adios2_config.xml", "r");
if (!cfgfp) {
cfgfp = fopen("adios2_config.xml", "w");
if (cfgfp) fputs(default_config, cfgfp);
}
if (cfgfp) fclose(cfgfp);
internal = new DumpAtomADIOSInternal();
try {
internal->ad =
new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON);
internal->ad = new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON);
} catch (std::ios_base::failure &e) {
char str[256];
snprintf(str, sizeof(str), "ADIOS initialization failed with error: %s",
e.what());
error->one(FLERR, str);
error->all(FLERR, "ADIOS initialization failed with error: {}", e.what());
}
}
@ -74,9 +72,7 @@ DumpAtomADIOS::DumpAtomADIOS(LAMMPS *lmp, int narg, char **arg)
DumpAtomADIOS::~DumpAtomADIOS()
{
if (internal->fh) {
internal->fh.Close();
}
if (internal->fh) internal->fh.Close();
delete internal->ad;
delete internal;
}
@ -192,8 +188,7 @@ void DumpAtomADIOS::write()
pack(ids);
else
pack(nullptr);
if (sort_flag)
sort();
if (sort_flag) sort();
openfile();
internal->fh.BeginStep();
@ -225,9 +220,7 @@ void DumpAtomADIOS::write()
internal->fh.Put<double>(internal->varAtoms, buf);
internal->fh.EndStep(); // I/O will happen now...
if (multifile) {
internal->fh.Close();
}
if (multifile) internal->fh.Close();
}
/* ---------------------------------------------------------------------- */
@ -244,14 +237,13 @@ void DumpAtomADIOS::init_style()
domain->boundary_string(boundstr);
// remove % from filename since ADIOS always writes a global file with
// data/metadata
int len = strlen(filename);
// data/metadata.
char *ptr = strchr(filename, '%');
if (ptr) {
*ptr = '\0';
char *s = new char[len - 1];
snprintf(s, sizeof(s), "%s%s", filename, ptr + 1);
strncpy(filename, s, len);
while (*ptr) {
ptr[0] = ptr[1];
++ptr;
}
}
// setup column string
@ -295,16 +287,12 @@ void DumpAtomADIOS::init_style()
// BPFile is the default writer
internal->io.SetEngine("BPFile");
int num_aggregators = multiproc;
if (num_aggregators == 0)
num_aggregators = 1;
char nstreams[128];
snprintf(nstreams, sizeof(nstreams), "%d", num_aggregators);
if (num_aggregators == 0) num_aggregators = 1;
auto nstreams = std::to_string(num_aggregators);
internal->io.SetParameters({{"substreams", nstreams}});
if (me == 0 && screen)
fprintf(
screen,
"ADIOS method for %s is n-to-m (aggregation with %s writers)\n",
filename, nstreams);
if (me == 0)
utils::logmesg(lmp, "ADIOS method for {} is n-to-m (aggregation with {} writers)\n", filename,
nstreams);
}
internal->io.DefineVariable<uint64_t>("ntimestep");
@ -332,25 +320,20 @@ void DumpAtomADIOS::init_style()
internal->io.DefineAttribute<int>("boundary", boundaryptr, 6);
size_t nColumns = static_cast<size_t>(size_one);
internal->io.DefineAttribute<std::string>("columns", columnNames.data(),
nColumns);
internal->io.DefineAttribute<std::string>("columns", columnNames.data(), nColumns);
internal->io.DefineAttribute<std::string>("columnstr", columns);
internal->io.DefineAttribute<std::string>("boundarystr", boundstr);
internal->io.DefineAttribute<std::string>("LAMMPS/dump_style", "atom");
internal->io.DefineAttribute<std::string>("LAMMPS/version",
lmp->version);
internal->io.DefineAttribute<std::string>("LAMMPS/num_ver",
std::to_string(lmp->num_ver));
internal->io.DefineAttribute<std::string>("LAMMPS/version", lmp->version);
internal->io.DefineAttribute<std::string>("LAMMPS/num_ver", std::to_string(lmp->num_ver));
internal->io.DefineVariable<uint64_t>(
"nme", {adios2::LocalValueDim}); // local dimension variable
internal->io.DefineVariable<uint64_t>(
"offset", {adios2::LocalValueDim}); // local dimension variable
// local dimension variables
internal->io.DefineVariable<uint64_t>("nme", {adios2::LocalValueDim});
internal->io.DefineVariable<uint64_t>("offset", {adios2::LocalValueDim});
// atom table size is not known at the moment
// it will be correctly defined at the moment of write
size_t UnknownSizeYet = 1;
internal->varAtoms = internal->io.DefineVariable<double>(
"atoms", {UnknownSizeYet, nColumns}, {UnknownSizeYet, 0},
{UnknownSizeYet, nColumns});
"atoms", {UnknownSizeYet, nColumns}, {UnknownSizeYet, 0}, {UnknownSizeYet, nColumns});
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -17,98 +16,28 @@
------------------------------------------------------------------------- */
#include "dump_custom_adios.h"
#include "atom.h"
#include "compute.h"
#include "domain.h"
#include "error.h"
#include "fix.h"
#include "force.h"
#include "group.h"
#include "input.h"
#include "memory.h"
#include "modify.h"
#include "region.h"
#include "universe.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
#include "adios2.h"
#include "adios_common.h"
using namespace LAMMPS_NS;
#define MAX_TEXT_HEADER_SIZE 4096
#define DUMP_BUF_CHUNK_SIZE 16384
#define DUMP_BUF_INCREMENT_SIZE 4096
enum {
ID,
MOL,
TYPE,
ELEMENT,
MASS,
X,
Y,
Z,
XS,
YS,
ZS,
XSTRI,
YSTRI,
ZSTRI,
XU,
YU,
ZU,
XUTRI,
YUTRI,
ZUTRI,
XSU,
YSU,
ZSU,
XSUTRI,
YSUTRI,
ZSUTRI,
IX,
IY,
IZ,
VX,
VY,
VZ,
FX,
FY,
FZ,
Q,
MUX,
MUY,
MUZ,
MU,
RADIUS,
DIAMETER,
OMEGAX,
OMEGAY,
OMEGAZ,
ANGMOMX,
ANGMOMY,
ANGMOMZ,
TQX,
TQY,
TQZ,
SPIN,
ERADIUS,
ERVEL,
ERFORCE,
COMPUTE,
FIX,
VARIABLE
};
enum { LT, LE, GT, GE, EQ, NEQ };
enum { INT, DOUBLE, STRING, BIGINT }; // same as in DumpCustom
namespace LAMMPS_NS
{
class DumpCustomADIOSInternal
{
namespace LAMMPS_NS {
class DumpCustomADIOSInternal {
public:
DumpCustomADIOSInternal(){};
@ -129,28 +58,25 @@ public:
/* ---------------------------------------------------------------------- */
DumpCustomADIOS::DumpCustomADIOS(LAMMPS *lmp, int narg, char **arg)
: DumpCustom(lmp, narg, arg)
DumpCustomADIOS::DumpCustomADIOS(LAMMPS *lmp, int narg, char **arg) : DumpCustom(lmp, narg, arg)
{
// create a default adios2_config.xml if it doesn't exist yet.
FILE *cfgfp = fopen("adios2_config.xml", "r");
if (!cfgfp) {
cfgfp = fopen("adios2_config.xml", "w");
if (cfgfp) fputs(default_config, cfgfp);
}
if (cfgfp) fclose(cfgfp);
internal = new DumpCustomADIOSInternal();
try {
internal->ad =
new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON);
internal->ad = new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON);
} catch (std::ios_base::failure &e) {
char str[256];
snprintf(str, sizeof(str), "ADIOS initialization failed with error: %s",
e.what());
error->one(FLERR, str);
error->all(FLERR, "ADIOS initialization failed with error: {}", e.what());
}
// if (screen) fprintf(screen, "DumpCustomADIOS constructor: nvariable=%d
// id_variable=%p, variables=%p, nfield=%d, earg=%p\n", nvariable,
// id_variable, variable, nfield, earg);
internal->columnNames.reserve(nfield);
for (int i = 0; i < nfield; ++i) {
internal->columnNames.push_back(earg[i]);
// if (screen) fprintf(screen, "earg[%d] = '%s'\n", i, earg[i]);
}
for (int i = 0; i < nfield; ++i) { internal->columnNames.push_back(earg[i]); }
}
/* ---------------------------------------------------------------------- */
@ -158,9 +84,7 @@ DumpCustomADIOS::DumpCustomADIOS(LAMMPS *lmp, int narg, char **arg)
DumpCustomADIOS::~DumpCustomADIOS()
{
internal->columnNames.clear();
if (internal->fh) {
internal->fh.Close();
}
if (internal->fh) { internal->fh.Close(); }
delete internal->ad;
delete internal;
}
@ -260,8 +184,7 @@ void DumpCustomADIOS::write()
// sort buf as needed
if (nme > maxbuf) {
if ((bigint)nme * size_one > MAXSMALLINT)
error->all(FLERR, "Too much per-proc info for dump");
if ((bigint) nme * size_one > MAXSMALLINT) error->all(FLERR, "Too much per-proc info for dump");
maxbuf = nme;
memory->destroy(buf);
memory->create(buf, (maxbuf * size_one), "dump:buf");
@ -276,8 +199,7 @@ void DumpCustomADIOS::write()
pack(ids);
else
pack(nullptr);
if (sort_flag)
sort();
if (sort_flag) sort();
openfile();
internal->fh.BeginStep();
@ -309,29 +231,25 @@ void DumpCustomADIOS::write()
internal->fh.Put<double>("atoms", buf);
internal->fh.EndStep(); // I/O will happen now...
if (multifile) {
internal->fh.Close();
}
if (multifile) { internal->fh.Close(); }
}
/* ---------------------------------------------------------------------- */
void DumpCustomADIOS::init_style()
{
// setup boundary string
domain->boundary_string(boundstr);
// remove % from filename since ADIOS always writes a global file with
// data/metadata
int len = strlen(filename);
char *ptr = strchr(filename, '%');
if (ptr) {
*ptr = '\0';
char *s = new char[len - 1];
sprintf(s, "%s%s", filename, ptr + 1);
strncpy(filename, s, len);
while (*ptr) {
ptr[0] = ptr[1];
++ptr;
}
}
/* The next four loops are copied from dump_custom_mpiio, but nothing is
@ -345,35 +263,30 @@ void DumpCustomADIOS::init_style()
int icompute;
for (int i = 0; i < ncompute; i++) {
icompute = modify->find_compute(id_compute[i]);
if (icompute < 0)
error->all(FLERR, "Could not find dump custom compute ID");
if (icompute < 0) error->all(FLERR, "Could not find dump custom compute ID");
compute[i] = modify->compute[icompute];
}
int ifix;
for (int i = 0; i < nfix; i++) {
ifix = modify->find_fix(id_fix[i]);
if (ifix < 0)
error->all(FLERR, "Could not find dump custom fix ID");
if (ifix < 0) error->all(FLERR, "Could not find dump custom fix ID");
fix[i] = modify->fix[ifix];
if (nevery % modify->fix[ifix]->peratom_freq)
error->all(FLERR,
"Dump custom and fix not computed at compatible times");
error->all(FLERR, "Dump custom and fix not computed at compatible times");
}
int ivariable;
for (int i = 0; i < nvariable; i++) {
ivariable = input->variable->find(id_variable[i]);
if (ivariable < 0)
error->all(FLERR, "Could not find dump custom variable name");
if (ivariable < 0) error->all(FLERR, "Could not find dump custom variable name");
variable[i] = ivariable;
}
// set index and check validity of region
if (iregion >= 0) {
iregion = domain->find_region(idregion);
if (iregion == -1)
error->all(FLERR, "Region ID for dump custom does not exist");
if (iregion == -1) error->all(FLERR, "Region ID for dump custom does not exist");
}
/* Define the group of variables for the atom style here since it's a fixed
@ -384,16 +297,12 @@ void DumpCustomADIOS::init_style()
// BPFile is the default writer
internal->io.SetEngine("BPFile");
int num_aggregators = multiproc;
if (num_aggregators == 0)
num_aggregators = 1;
char nstreams[128];
sprintf(nstreams, "%d", num_aggregators);
if (num_aggregators == 0) num_aggregators = 1;
auto nstreams = std::to_string(num_aggregators);
internal->io.SetParameters({{"substreams", nstreams}});
if (me == 0 && screen)
fprintf(
screen,
"ADIOS method for %s is n-to-m (aggregation with %s writers)\n",
filename, nstreams);
if (me == 0)
utils::logmesg(lmp, "ADIOS method for {} is n-to-m (aggregation with {} writers)\n", filename,
nstreams);
}
internal->io.DefineVariable<uint64_t>("ntimestep");
@ -419,25 +328,21 @@ void DumpCustomADIOS::init_style()
internal->io.DefineAttribute<int>("boundary", boundaryptr, 6);
size_t nColumns = static_cast<size_t>(size_one);
internal->io.DefineAttribute<std::string>(
"columns", internal->columnNames.data(), nColumns);
internal->io.DefineAttribute<std::string>("columns", internal->columnNames.data(), nColumns);
internal->io.DefineAttribute<std::string>("columnstr", columns);
internal->io.DefineAttribute<std::string>("boundarystr", boundstr);
internal->io.DefineAttribute<std::string>("LAMMPS/dump_style", "custom");
internal->io.DefineAttribute<std::string>("LAMMPS/version",
lmp->version);
internal->io.DefineAttribute<std::string>("LAMMPS/num_ver",
std::to_string(lmp->num_ver));
internal->io.DefineAttribute<std::string>("LAMMPS/version", lmp->version);
internal->io.DefineAttribute<std::string>("LAMMPS/num_ver", std::to_string(lmp->num_ver));
internal->io.DefineVariable<uint64_t>(
"nme", {adios2::LocalValueDim}); // local dimension variable
internal->io.DefineVariable<uint64_t>(
"offset", {adios2::LocalValueDim}); // local dimension variable
internal->io.DefineVariable<uint64_t>("nme",
{adios2::LocalValueDim}); // local dimension variable
internal->io.DefineVariable<uint64_t>("offset",
{adios2::LocalValueDim}); // local dimension variable
// atom table size is not known at the moment
// it will be correctly defined at the moment of write
size_t UnknownSizeYet = 1;
internal->varAtoms = internal->io.DefineVariable<double>(
"atoms", {UnknownSizeYet, nColumns}, {UnknownSizeYet, 0},
{UnknownSizeYet, nColumns});
"atoms", {UnknownSizeYet, nColumns}, {UnknownSizeYet, 0}, {UnknownSizeYet, nColumns});
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -17,20 +16,20 @@
------------------------------------------------------------------------- */
#include "reader_adios.h"
#include "comm.h"
#include "error.h"
#include "memory.h"
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "adios2.h"
#include "math_const.h"
#include "adios_common.h"
using namespace LAMMPS_NS;
using namespace MathConst;
// also in read_dump.cpp
enum { ID, TYPE, X, Y, Z, VX, VY, VZ, Q, IX, IY, IZ, FX, FY, FZ };
@ -38,17 +37,8 @@ enum { UNSET, NOSCALE_NOWRAP, NOSCALE_WRAP, SCALE_NOWRAP, SCALE_WRAP };
#define SMALL 1.0e-6
// true if the difference between two floats is "small".
// cannot use fabsf() since it is not fully portable.
static bool is_smalldiff(const float &val1, const float &val2)
{
return (fabs(static_cast<double>(val1 - val2)) < SMALL);
}
namespace LAMMPS_NS
{
class ReadADIOSInternal
{
namespace LAMMPS_NS {
class ReadADIOSInternal {
public:
ReadADIOSInternal(){};
@ -82,15 +72,19 @@ ReaderADIOS::ReaderADIOS(LAMMPS *lmp) : Reader(lmp)
nid = 0;
me = comm->me;
// create a default adios2_config.xml if it doesn't exist yet.
FILE *cfgfp = fopen("adios2_config.xml", "r");
if (!cfgfp) {
cfgfp = fopen("adios2_config.xml", "w");
if (cfgfp) fputs(default_config, cfgfp);
}
if (cfgfp) fclose(cfgfp);
internal = new ReadADIOSInternal();
try {
internal->ad =
new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON);
internal->ad = new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON);
} catch (std::ios_base::failure &e) {
char str[256];
snprintf(str, sizeof(str), "ADIOS initialization failed with error: %s",
e.what());
error->one(FLERR, str);
error->one(FLERR, "ADIOS initialization failed with error: {}", e.what());
}
/* Define the group holding all variables and attributes */
@ -101,13 +95,9 @@ ReaderADIOS::ReaderADIOS(LAMMPS *lmp) : Reader(lmp)
ReaderADIOS::~ReaderADIOS()
{
if (me == 0) {
memory->destroy(fieldindex);
}
if (me == 0) memory->destroy(fieldindex);
internal->columnNames.clear();
if (internal->fh) {
internal->fh.Close();
}
if (internal->fh) internal->fh.Close();
delete internal->ad;
delete internal;
}
@ -126,11 +116,7 @@ void ReaderADIOS::settings(int narg, char **arg)
internal->io.SetParameter("OpenTimeoutSecs", arg[idx + 1]);
++idx;
} else {
char str[128];
snprintf(str, sizeof(str),
"Missing value for 'timeout' option for ADIOS "
"read_dump command");
error->one(FLERR, str);
error->one(FLERR, "Missing value for 'timeout' option for ADIOS read_dump command");
}
}
++idx;
@ -142,26 +128,17 @@ void ReaderADIOS::settings(int narg, char **arg)
Every process must call this Collective operation
------------------------------------------------------------------------- */
void ReaderADIOS::open_file(const char *file)
void ReaderADIOS::open_file(const std::string &file)
{
int rv;
char str[1024];
// close open file, if needed.
if (internal->fh)
internal->fh.Close();
if (internal->fh) internal->fh.Close();
try {
internal->fh = internal->io.Open(file, adios2::Mode::Read, world);
} catch (std::ios_base::failure &e) {
char str[256];
snprintf(str, sizeof(str), "%s", e.what());
error->one(FLERR, str);
}
if (!internal->fh) {
snprintf(str, sizeof(str), "Cannot open file %s using ADIOS", file);
error->one(FLERR, str);
error->one(FLERR, "Error opening file {}: {}", file, e.what());
}
if (!internal->fh) error->one(FLERR, "Cannot open file {} using ADIOS", file);
}
/* ----------------------------------------------------------------------
@ -172,9 +149,7 @@ void ReaderADIOS::open_file(const char *file)
void ReaderADIOS::close_file()
{
// close open file, if needed.
if (internal->fh) {
internal->fh.Close();
}
if (internal->fh) { internal->fh.Close(); }
}
/* ----------------------------------------------------------------------
@ -185,10 +160,7 @@ void ReaderADIOS::close_file()
int ReaderADIOS::read_time(bigint &ntimestep)
{
char str[1024];
adios2::StepStatus status =
internal->fh.BeginStep(adios2::StepMode::Read, internal->timeout);
adios2::StepStatus status = internal->fh.BeginStep(adios2::StepMode::Read, internal->timeout);
switch (status) {
case adios2::StepStatus::EndOfStream:
@ -199,19 +171,12 @@ int ReaderADIOS::read_time(bigint &ntimestep)
break;
}
internal->varNtimestep =
internal->io.InquireVariable<uint64_t>("ntimestep");
internal->varNtimestep = internal->io.InquireVariable<uint64_t>("ntimestep");
if (!internal->varNtimestep) {
snprintf(str, sizeof(str),
"Did not find 'ntimestep' variable in ADIOS file %s",
internal->fh.Name().c_str());
error->one(FLERR, str);
}
if (!internal->varNtimestep)
error->one(FLERR, "Did not find 'ntimestep' variable in ADIOS file {}", internal->fh.Name());
ntimestep = static_cast<bigint>(internal->varNtimestep.Max());
// std::cerr << " **** ReaderADIOS::read_time found step " << ntimestep
// << " **** " << std::endl;
return 0;
}
@ -220,7 +185,10 @@ int ReaderADIOS::read_time(bigint &ntimestep)
Called by all processors.
------------------------------------------------------------------------- */
void ReaderADIOS::skip() { internal->fh.EndStep(); }
void ReaderADIOS::skip()
{
internal->fh.EndStep();
}
/* ----------------------------------------------------------------------
read remaining header info:
@ -236,31 +204,24 @@ void ReaderADIOS::skip() { internal->fh.EndStep(); }
only called by proc 0
------------------------------------------------------------------------- */
bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
int fieldinfo, int nfield, int *fieldtype,
char **fieldlabel, int scaleflag, int wrapflag,
int &fieldflag, int &xflag, int &yflag,
int &zflag)
bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic, int fieldinfo,
int nfield, int *fieldtype, char **fieldlabel, int scaleflag,
int wrapflag, int &fieldflag, int &xflag, int &yflag, int &zflag)
{
char str[1024];
nid = 0;
// signal that we have no box info at all so far.
internal->varNatoms = internal->io.InquireVariable<uint64_t>("natoms");
if (!internal->varNatoms) {
snprintf(str, sizeof(str),
"Did not find 'natoms' variable in ADIOS file %s",
internal->fh.Name().c_str());
error->one(FLERR, str);
}
if (!internal->varNatoms)
error->one(FLERR, "Did not find 'natoms' variable in ADIOS file {}", internal->fh.Name());
/* nAtoms */
nAtomsTotal = internal->varNatoms.Max();
uint64_t rem = nAtomsTotal % comm->nprocs;
nAtoms = nAtomsTotal / comm->nprocs;
atomOffset = comm->me * nAtoms;
if (comm->me < rem) {
if (comm->me < (int)rem) {
++nAtoms;
atomOffset += comm->me;
} else {
@ -268,30 +229,19 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
}
/* triclinic */
adios2::Attribute<int32_t> attTriclinic =
internal->io.InquireAttribute<int32_t>("triclinic");
if (!attTriclinic) {
snprintf(str, sizeof(str),
"Did not find 'triclinic' attribute in ADIOS file %s",
internal->fh.Name().c_str());
error->one(FLERR, str);
}
adios2::Attribute<int32_t> attTriclinic = internal->io.InquireAttribute<int32_t>("triclinic");
if (!attTriclinic)
error->one(FLERR, "Did not find 'triclinic' attribute in ADIOS file {}", internal->fh.Name());
triclinic = attTriclinic.Data()[0];
/* read Box */
adios2::Variable<double> varBoxxlo =
internal->io.InquireVariable<double>("boxxlo");
adios2::Variable<double> varBoxxhi =
internal->io.InquireVariable<double>("boxxhi");
adios2::Variable<double> varBoxylo =
internal->io.InquireVariable<double>("boxylo");
adios2::Variable<double> varBoxyhi =
internal->io.InquireVariable<double>("boxyhi");
adios2::Variable<double> varBoxzlo =
internal->io.InquireVariable<double>("boxzlo");
adios2::Variable<double> varBoxzhi =
internal->io.InquireVariable<double>("boxzhi");
adios2::Variable<double> varBoxxlo = internal->io.InquireVariable<double>("boxxlo");
adios2::Variable<double> varBoxxhi = internal->io.InquireVariable<double>("boxxhi");
adios2::Variable<double> varBoxylo = internal->io.InquireVariable<double>("boxylo");
adios2::Variable<double> varBoxyhi = internal->io.InquireVariable<double>("boxyhi");
adios2::Variable<double> varBoxzlo = internal->io.InquireVariable<double>("boxzlo");
adios2::Variable<double> varBoxzhi = internal->io.InquireVariable<double>("boxzhi");
box[0][0] = varBoxxlo.Max();
box[0][1] = varBoxxhi.Max();
@ -304,12 +254,9 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
box[2][2] = 0.0;
if (triclinic) {
adios2::Variable<double> varBoxxy =
internal->io.InquireVariable<double>("boxxy");
adios2::Variable<double> varBoxxz =
internal->io.InquireVariable<double>("boxxz");
adios2::Variable<double> varBoxyz =
internal->io.InquireVariable<double>("boxyz");
adios2::Variable<double> varBoxxy = internal->io.InquireVariable<double>("boxxy");
adios2::Variable<double> varBoxxz = internal->io.InquireVariable<double>("boxxz");
adios2::Variable<double> varBoxyz = internal->io.InquireVariable<double>("boxyz");
box[0][2] = varBoxxy.Max();
box[1][2] = varBoxxz.Max();
@ -320,21 +267,17 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
// if no field info requested, just return
if (!fieldinfo)
return nAtoms;
if (!fieldinfo) return nAtoms;
memory->create(fieldindex, nfield, "read_dump:fieldindex");
/* Columns */
adios2::Attribute<std::string> attColumns =
internal->io.InquireAttribute<std::string>("columns");
adios2::Attribute<std::string> attColumns = internal->io.InquireAttribute<std::string>("columns");
std::vector<std::string> labelVector = attColumns.Data();
int nwords = labelVector.size();
std::map<std::string, int> labels;
for (int i = 0; i < nwords; ++i) {
labels.emplace(labelVector[i], i);
}
for (int i = 0; i < nwords; ++i) { labels.emplace(labelVector[i], i); }
int s_index, u_index, su_index;
xflag = UNSET;
@ -380,8 +323,7 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
xflag = SCALE_NOWRAP;
}
}
if (fieldindex[i] == nwords)
fieldindex[i] = -1;
if (fieldindex[i] == nwords) fieldindex[i] = -1;
} else if (fieldtype[i] == Y) {
fieldindex[i] = find_label("y", labels);
@ -404,8 +346,7 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
yflag = SCALE_NOWRAP;
}
}
if (fieldindex[i] == nwords)
fieldindex[i] = -1;
if (fieldindex[i] == nwords) fieldindex[i] = -1;
} else if (fieldtype[i] == Z) {
fieldindex[i] = find_label("z", labels);
@ -428,8 +369,7 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
zflag = SCALE_NOWRAP;
}
}
if (fieldindex[i] == nwords)
fieldindex[i] = -1;
if (fieldindex[i] == nwords) fieldindex[i] = -1;
} else if (fieldtype[i] == VX)
fieldindex[i] = find_label("vx", labels);
@ -460,8 +400,7 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
fieldflag = 0;
for (int i = 0; i < nfield; i++)
if (fieldindex[i] < 0)
fieldflag = -1;
if (fieldindex[i] < 0) fieldflag = -1;
return nAtoms;
}
@ -475,24 +414,18 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic,
void ReaderADIOS::read_atoms(int n, int nfield, double **fields)
{
char str[1024];
/* Read Atoms */
/* This is the firsts (and last) read of array data, so we
* call EndStep() here instead of PerformGets()
*/
adios2::Variable<double> varAtoms =
internal->io.InquireVariable<double>("atoms");
adios2::Variable<double> varAtoms = internal->io.InquireVariable<double>("atoms");
if (n != nAtoms) {
snprintf(
str, sizeof(str),
"ReaderADIOS::read_atoms() expects 'n=%d' equal to the number of "
"atoms (=%" PRIu64 ") for process %d in ADIOS file %s.",
n, nAtoms, comm->me, internal->fh.Name().c_str());
error->one(FLERR, str);
}
if ((uint64_t)n != nAtoms)
error->one(FLERR,
"ReaderADIOS::read_atoms() expects 'n={}' equal to the number of "
"atoms (={}) for process {} in ADIOS file {}.",
n, nAtoms, comm->me, internal->fh.Name());
size_t ncols = varAtoms.Count()[1];
varAtoms.SetSelection({{atomOffset, 0}, {nAtoms, ncols}});
@ -504,11 +437,9 @@ void ReaderADIOS::read_atoms(int n, int nfield, double **fields)
internal->fh.EndStep();
size_t idx;
for (int i = 0; i < nAtoms; i++) {
for (uint64_t i = 0; i < nAtoms; i++) {
idx = i * ncols;
for (int m = 0; m < nfield; m++) {
fields[i][m] = table[idx + fieldindex[m]];
}
for (int m = 0; m < nfield; m++) { fields[i][m] = table[idx + fieldindex[m]]; }
}
}
@ -517,12 +448,9 @@ void ReaderADIOS::read_atoms(int n, int nfield, double **fields)
return index of match or -1 if no match
------------------------------------------------------------------------- */
int ReaderADIOS::find_label(const std::string &label,
const std::map<std::string, int> &labels)
int ReaderADIOS::find_label(const std::string &label, const std::map<std::string, int> &labels)
{
std::map<std::string, int>::const_iterator it = labels.find(label);
if (it != labels.end()) {
return it->second;
}
if (it != labels.end()) { return it->second; }
return -1;
}

View File

@ -44,7 +44,7 @@ class ReaderADIOS : public Reader {
int &, int &, int &) override;
void read_atoms(int, int, double **) override;
void open_file(const char *) override;
void open_file(const std::string &) override;
void close_file() override;
private: