Commit f8c432c5 authored by mark's avatar mark

ENH: provide singleton-like functions for mpi init/finialize

parent 7e07ce20
......@@ -24,13 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "adiosCore.H"
#include "adios.h"
#include "adios_types.h"
#include "fileNameList.H"
#include "IStringStream.H"
#include "token.H"
#include "OSspecific.H"
#include "scalar.H"
#include "OSspecific.H"
#include "Pstream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -65,6 +67,44 @@ Foam::adiosCore::foamAttribute = "/openfoam";
const Foam::string
Foam::adiosCore::timeAttribute = "/time";
int Foam::adiosCore::refCount_ = 0;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::adiosCore::global_init()
{
if (refCount_ == 0) // first one in
{
if (!Pstream::parRun())
{
// NULL args are OK for openmpi, mpich-2
MPI_Init(nullptr, nullptr);
}
// Runtime assertions (verify assumed sizes) - or emit a fatal error
adiosTraits<label>::ok();
adiosTraits<scalar>::ok();
}
++refCount_;
}
void Foam::adiosCore::global_finalize()
{
if (refCount_ == 1) // last one out
{
// Cleanup our own MPI_Init()
if (!Pstream::parRun())
{
MPI_Finalize();
}
}
--refCount_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -75,16 +115,16 @@ Foam::adiosCore::adiosCore
:
name_(name)
{
// verify assumed sizes now - or emit a fatal error
adiosTraits<label>::ok();
adiosTraits<scalar>::ok();
global_init();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::adiosCore::~adiosCore()
{}
{
global_finalize();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
......@@ -81,11 +81,29 @@ public:
private:
// Static data
//- Reference counting for handling mpi init/finalize in serial
static int refCount_;
// Private data
//- Group name within ADIOS files
word name_;
// Private Member Functions
//- Global initializations.
// Eg, Manual MPI_Init for serial runs (ADIOS always requires mpi).
static void global_init();
//- Cleanup global initializations.
// Eg, Manual MPI_Finalize for serial runs.
static void global_finalize();
protected:
// Protected data
......@@ -142,6 +160,7 @@ public:
const word& constantName = "constant"
);
//- Path name for a region
inline static const word& regionPath
(
......
......@@ -26,6 +26,7 @@ License
#include "adiosCoreWrite.H"
#include "adiosTime.H"
#include "foamVersion.H"
#include "endian.H"
#include "OSspecific.H"
// some internal pre-processor stringifications
......@@ -44,10 +45,8 @@ void Foam::adiosCoreWrite::read(const dictionary& dict)
writeMethod_ = "MPI";
writeParams_ = "";
dict.readIfPresent("readMethod", readMethod_);
dict.readIfPresent("adiosMethod", writeMethod_); // old name
dict.readIfPresent("writeMethod", writeMethod_);
dict.readIfPresent("methodparams", writeParams_); // old name
dict.readIfPresent("readMethod", readMethod_);
dict.readIfPresent("writeMethod", writeMethod_);
dict.readIfPresent("writeOptions", writeParams_);
Info<< " ADIOS writeMethod: " << writeMethod_ << nl
......@@ -72,12 +71,6 @@ Foam::adiosCoreWrite::adiosCoreWrite
comm_(MPI_COMM_NULL),
vars_()
{
if (!Pstream::parRun())
{
// serial - must do MPI_Init() ourselves
MPI_Init(NULL, NULL); // NULL args are OK for openmpi, mpich-2
}
MPI_Comm_dup(MPI_COMM_WORLD, &comm_);
// Initialize ADIOS
......@@ -108,12 +101,6 @@ Foam::adiosCoreWrite::~adiosCoreWrite()
adios_finalize(Pstream::myProcNo());
MPI_Comm_free(&comm_);
if (!Pstream::parRun())
{
// serial - must do MPI_Finalize() ourselves
MPI_Finalize();
}
}
......@@ -238,6 +225,18 @@ void Foam::adiosCoreWrite::defineBaseAttributes()
#endif
);
// Endian type (big|little)
defineAttribute
(
"endian",
adiosCore::foamAttribute,
#ifdef WM_BIG_ENDIAN
"big"
#else
"little"
#endif
);
// OpenFOAM label size (32|64)
defineIntAttribute
(
......@@ -255,7 +254,12 @@ void Foam::adiosCoreWrite::defineBaseAttributes()
);
// other general information
defineIntAttribute("nProcs", adiosCore::foamAttribute, Pstream::nProcs());
defineIntAttribute
(
"nProcs",
adiosCore::foamAttribute,
Pstream::nProcs()
);
}
......@@ -290,10 +294,22 @@ void Foam::adiosCoreWrite::defineTimeAttributes(const TimeState& t)
void Foam::adiosCoreWrite::defineTime()
{
defineIntVariable(adiosCore::timeAttribute/adiosTime::attr[adiosTime::INDEX]);
defineScalarVariable(adiosCore::timeAttribute/adiosTime::attr[adiosTime::VALUE]);
defineScalarVariable(adiosCore::timeAttribute/adiosTime::attr[adiosTime::DT]);
defineScalarVariable(adiosCore::timeAttribute/adiosTime::attr[adiosTime::DT0]);
defineIntVariable
(
adiosCore::timeAttribute/adiosTime::attr[adiosTime::INDEX]
);
defineScalarVariable
(
adiosCore::timeAttribute/adiosTime::attr[adiosTime::VALUE]
);
defineScalarVariable
(
adiosCore::timeAttribute/adiosTime::attr[adiosTime::DT]
);
defineScalarVariable
(
adiosCore::timeAttribute/adiosTime::attr[adiosTime::DT0]
);
}
......@@ -335,7 +351,7 @@ int64_t Foam::adiosCoreWrite::defineVariable
(
groupID_,
name.c_str(), // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
type, // data-type
local.c_str(), // local dimensions
global.c_str(), // global dimensions
......@@ -357,11 +373,11 @@ int64_t Foam::adiosCoreWrite::defineVariable
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
type, // data-type
Foam::name(count).c_str(), // local dimensions
NULL, // global dimensions
NULL // local offsets
nullptr, // global dimensions
nullptr // local offsets
);
vars_.insert(name, varid);
return varid;
......@@ -388,7 +404,7 @@ int64_t Foam::adiosCoreWrite::defineIntVariable
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
adios_integer, // data-type
"1", // local dimensions
Foam::name(Pstream::nProcs()).c_str(), // global 1D array of this info
......@@ -418,11 +434,11 @@ int64_t Foam::adiosCoreWrite::defineIntVariable
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
adiosTraits<label>::adiosType, // data-type
Foam::name(count).c_str(), // local dimensions
NULL, // global dimensions
NULL // local offsets
nullptr, // global dimensions
nullptr // local offsets
);
vars_.insert(name, varid);
return varid;
......@@ -448,7 +464,7 @@ int64_t Foam::adiosCoreWrite::defineScalarVariable
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
adiosTraits<scalar>::adiosType, // data-type
"1", // local dimensions
Foam::name(Pstream::nProcs()).c_str(), // global 1D array of this info
......@@ -478,11 +494,11 @@ int64_t Foam::adiosCoreWrite::defineScalarVariable
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
adiosTraits<scalar>::adiosType, // data-type
Foam::name(count).c_str(), // local dimensions
NULL, // global dimensions
NULL // local offsets
nullptr, // global dimensions
nullptr // local offsets
);
vars_.insert(name, varid);
return varid;
......@@ -505,18 +521,18 @@ int64_t Foam::adiosCoreWrite::defineStreamVariable
size_t count
)
{
// use unsigned byte:
// Use unsigned byte:
// keeps people from thinking that the min/max statistics have any meaning
int64_t varid = adios_define_var
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
adios_unsigned_byte, // data-type
Foam::name(count).c_str(), // local dimensions
NULL, // global dimensions
NULL // local offsets
nullptr, // global dimensions
nullptr // local offsets
);
vars_.insert(name, varid);
return varid;
......@@ -545,7 +561,7 @@ int64_t Foam::adiosCoreWrite::defineVectorVariable
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
adiosTraits<scalar>::adiosType, // data-type
"1,3", // local dimensions
global.c_str(), // global dimensions
......@@ -577,11 +593,11 @@ int64_t Foam::adiosCoreWrite::defineVectorVariable
(
groupID_,
name, // name
NULL, // path (deprecated)
nullptr, // path (deprecated)
adiosTraits<scalar>::adiosType, // data-type
local.c_str(), // local dimensions
NULL, // global dimensions
NULL // local offsets
nullptr, // global dimensions
nullptr // local offsets
);
vars_.insert(name, varid);
return varid;
......@@ -612,7 +628,7 @@ void Foam::adiosCoreWrite::defineAttribute
varName,
adios_string,
value.c_str(),
NULL
nullptr
);
}
......
......@@ -159,7 +159,7 @@ bool Foam::adiosReader::VarInfo::readInfo
nElem_ = 1; // scalar value
}
nBytes_ = nElem_ * adios_type_size(type_, NULL);
nBytes_ = nElem_ * adios_type_size(type_, nullptr);
if (verbose)
{
......
......@@ -90,7 +90,7 @@ bool Foam::adiosTraits<Foam::label>::ok()
if
(
sizeof(label) == adiosSize
&& adiosSize == adios_type_size(adiosType, NULL)
&& adiosSize == adios_type_size(adiosType, nullptr)
)
{
return true;
......@@ -111,7 +111,7 @@ bool Foam::adiosTraits<Foam::scalar>::ok()
if
(
sizeof(scalar) == adiosSize
&& adiosSize == adios_type_size(adiosType, NULL)
&& adiosSize == adios_type_size(adiosType, nullptr)
)
{
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment