Commit b6c9c6a6 authored by kicici's avatar kicici

`Real` is now a template parameter

User app must specify `Block::Real` and `ElementType::Real`.
parent 4bbe1a66
......@@ -55,6 +55,7 @@ public:
// For CUBISM internals.
typedef T ElementType;
typedef T element_type; // For GridMPI.
typedef typename T::Real Real;
// Data structure to store grid point for this block.
ElementType data[sizeZ][sizeY][sizeX];
......
......@@ -26,12 +26,6 @@
CUBISM_NAMESPACE_BEGIN
#ifdef _FLOAT_PRECISION_
typedef float Real;
#else
typedef double Real;
#endif
/**
* Working copy of Block + Ghosts.
* Data of original block is copied (!) here. So when changing something in
......@@ -49,6 +43,7 @@ class BlockLab
public:
typedef ElementTypeT ElementType;
typedef typename ElementTypeT::Real Real; // Element type MUST provide `Real` type.
protected:
typedef TBlock BlockType;
......
......@@ -15,8 +15,13 @@ CUBISM_NAMESPACE_BEGIN
template<typename MyBlockLab>
class BlockLabMPI : public MyBlockLab
{
const SynchronizerMPI * refSynchronizerMPI;
public:
typedef typename MyBlockLab::Real Real;
private:
typedef typename MyBlockLab::BlockType BlockType;
typedef SynchronizerMPI<Real> SynchronizerMPIType;
const SynchronizerMPIType * refSynchronizerMPI;
protected:
int mypeindex[3], pesize[3], mybpd[3];
......@@ -24,9 +29,9 @@ protected:
public:
template< typename TGrid >
void prepare(GridMPI<TGrid>& grid, const SynchronizerMPI& SynchronizerMPI)
void prepare(GridMPI<TGrid>& grid, const SynchronizerMPIType& synchronizer)
{
refSynchronizerMPI = &SynchronizerMPI;
refSynchronizerMPI = &synchronizer;
refSynchronizerMPI->getpedata(mypeindex, pesize, mybpd);
StencilInfo stencil = refSynchronizerMPI->getstencil();
assert(stencil.isvalid());
......
......@@ -83,6 +83,7 @@ public:
template <typename Grid, typename Lab, typename ProcessingMT, int nSlots>
class BlockProcessingMT_TBB
{
typedef typename Lab::Real Real;
ProcessingMT& processing;
const BlockInfo * ptrInfos;
......
......@@ -23,6 +23,7 @@ class BlockProcessingMPI
struct TBBWorker
{
typedef typename TGrid::BlockType BlockType;
typedef typename TGrid::Real Real;
const std::vector<BlockInfo>& myInfo;
Operator myrhs;
TGrid* grid;
......
......@@ -92,8 +92,8 @@ protected:
}
public:
typedef Block BlockType;
typedef typename Block::Real Real; // Block MUST provide `Real` type.
Grid(const unsigned int _NX, const unsigned int _NY = 1, const unsigned int _NZ = 1, const double _maxextent = 1) :
m_blocks(NULL), maxextent(_maxextent), N(_NX*_NY*_NZ), NX(_NX), NY(_NY), NZ(_NZ),
......
......@@ -21,11 +21,14 @@ CUBISM_NAMESPACE_BEGIN
template < typename TGrid >
class GridMPI : public TGrid
{
public:
typedef typename TGrid::Real Real;
private:
size_t timestamp;
protected:
friend class SynchronizerMPI;
typedef SynchronizerMPI<Real> SynchronizerMPIType;
friend class SynchronizerMPI<Real>;
int myrank, mypeindex[3], pesize[3];
int periodic[3];
......@@ -33,7 +36,7 @@ protected:
std::vector<BlockInfo> cached_blockinfo;
std::map<StencilInfo, SynchronizerMPI *> SynchronizerMPIs;
std::map<StencilInfo, SynchronizerMPIType *> SynchronizerMPIs;
MPI_Comm worldcomm;
MPI_Comm cartcomm;
......@@ -213,7 +216,7 @@ public:
~GridMPI()
{
for( std::map<StencilInfo, SynchronizerMPI*>::const_iterator it = SynchronizerMPIs.begin(); it != SynchronizerMPIs.end(); ++it)
for (auto it = SynchronizerMPIs.begin(); it != SynchronizerMPIs.end(); ++it)
delete it->second;
SynchronizerMPIs.clear();
......@@ -286,18 +289,18 @@ public:
}
template<typename Processing>
SynchronizerMPI& sync(Processing& p)
SynchronizerMPIType& sync(Processing& p)
{
const StencilInfo stencil = p.stencil;
assert(stencil.isvalid());
SynchronizerMPI * queryresult = NULL;
SynchronizerMPIType * queryresult = NULL;
typename std::map<StencilInfo, SynchronizerMPI*>::iterator itSynchronizerMPI = SynchronizerMPIs.find(stencil);
typename std::map<StencilInfo, SynchronizerMPIType*>::iterator itSynchronizerMPI = SynchronizerMPIs.find(stencil);
if (itSynchronizerMPI == SynchronizerMPIs.end())
{
queryresult = new SynchronizerMPI(stencil, getBlocksInfo(), cartcomm, mybpd, blocksize);
queryresult = new SynchronizerMPIType(stencil, getBlocksInfo(), cartcomm, mybpd, blocksize);
SynchronizerMPIs[stencil] = queryresult;
}
......@@ -311,7 +314,7 @@ public:
}
template<typename Processing>
const SynchronizerMPI& get_SynchronizerMPI(Processing& p) const
const SynchronizerMPIType& get_SynchronizerMPI(Processing& p) const
{
assert((SynchronizerMPIs.find(p.stencil) != SynchronizerMPIs.end()));
......
......@@ -35,7 +35,12 @@ CUBISM_NAMESPACE_BEGIN
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TGrid>
void DumpHDF5(const TGrid &grid, const int iCounter, const Real absTime, const std::string fname, const std::string dpath=".", const bool bXMF=true)
void DumpHDF5(const TGrid &grid,
const int iCounter,
const typename TGrid::Real absTime,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true)
{
#ifdef _USE_HDF_
typedef typename TGrid::BlockType B;
......
......@@ -39,7 +39,12 @@ CUBISM_NAMESPACE_BEGIN
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TGrid>
void DumpHDF5_MPI(const TGrid &grid, const int iCounter, const Real absTime, const std::string fname, const std::string dpath=".", const bool bXMF=true)
void DumpHDF5_MPI(const TGrid &grid,
const int iCounter,
const typename TGrid::Real absTime,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true)
{
#ifdef _USE_HDF_
typedef typename TGrid::BlockType B;
......
......@@ -310,7 +310,12 @@ namespace SliceTypes
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSlice>
void DumpSliceHDF5(const TSlice& slice, const int stepID, const Real t, const std::string fname, const std::string dpath=".", const bool bXMF=true)
void DumpSliceHDF5(const TSlice& slice,
const int stepID,
const typename TSlice::GridType::Real t,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true)
{
#ifdef _USE_HDF_
typedef typename TSlice::GridType::BlockType B;
......
......@@ -98,7 +98,12 @@ namespace SliceTypesMPI
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSlice>
void DumpSliceHDF5MPI(const TSlice& slice, const int stepID, const Real t, const std::string fname, const std::string dpath=".", const bool bXMF=true)
void DumpSliceHDF5MPI(const TSlice& slice,
const int stepID,
const typename TSlice::GridType::Real t,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true)
{
#ifdef _USE_HDF_
typedef typename TSlice::GridType::BlockType B;
......
......@@ -309,7 +309,12 @@ namespace SubdomainTypes
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSubdomain>
void DumpSubdomainHDF5(const TSubdomain& subdomain, const int stepID, const Real t, const std::string fname, const std::string dpath=".", const bool bXMF=true)
void DumpSubdomainHDF5(const TSubdomain& subdomain,
const int stepID,
const typename TSubdomain::GridType::Real t,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true)
{
#ifdef _USE_HDF_
typedef typename TSubdomain::GridType::BlockType B;
......
......@@ -153,7 +153,12 @@ namespace SubdomainTypesMPI
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSubdomain>
void DumpSubdomainHDF5MPI(const TSubdomain& subdomain, const int stepID, const Real t, const std::string fname, const std::string dpath=".", const bool bXMF=true)
void DumpSubdomainHDF5MPI(const TSubdomain& subdomain,
const int stepID,
const typename TSubdomain::GridType::Real t,
const std::string &fname,
const std::string &dpath = ".",
const bool bXMF = true)
{
#ifdef _USE_HDF_
typedef typename TSubdomain::GridType::BlockType B;
......
......@@ -25,6 +25,7 @@ inline size_t ZZcompress(unsigned char *buf, unsigned len, int layout[4], unsign
inline size_t ZZdecompress(unsigned char * inputbuf, size_t ninputbytes, int layout[4], unsigned char * outputbuf, const size_t maxsize);
template <typename Real>
inline size_t ZZdecompress(unsigned char * inputbuf, size_t ninputbytes, int layout[4], unsigned char * outputbuf, const size_t maxsize)
{
int decompressedbytes = 0;
......@@ -43,6 +44,7 @@ inline size_t ZZdecompress(unsigned char * inputbuf, size_t ninputbytes, int lay
return decompressedbytes;
}
template <typename Real>
inline size_t ZZcompress(unsigned char *buf, unsigned len, int layout[4], unsigned *max)
{
#if 1
......
......@@ -14,6 +14,7 @@
CUBISM_NAMESPACE_BEGIN
template <typename Real>
inline void pack(const Real * const srcbase, Real * const dst,
const unsigned int gptfloats,
int * selected_components, const int ncomponents,
......@@ -32,6 +33,7 @@ inline void pack(const Real * const srcbase, Real * const dst,
}
}
template <typename Real>
inline void pack_stripes1(const Real * const srcbase, Real * const dst,
const unsigned int gptfloats,
const int selstart, const int selend,
......@@ -49,6 +51,7 @@ inline void pack_stripes1(const Real * const srcbase, Real * const dst,
}
}
template <typename Real>
inline void pack_stripes_(const Real * const srcbase, Real * const dst,
const unsigned int gptfloats,
const int selstart, const int selend,
......@@ -72,6 +75,7 @@ inline void pack_stripes_(const Real * const srcbase, Real * const dst,
}
}
template <typename Real>
inline void pack_stripes_x(const Real * const srcbase, Real * const dst,
const unsigned int gptfloats,
const int selstart, const int selend,
......@@ -106,6 +110,7 @@ inline void pack_stripes_x(const Real * const srcbase, Real * const dst,
#define memcpy2(a,b,c) memcpy((a),(b),(c))
#endif
template <typename Real>
inline void pack_stripes_unroll0(const Real * const srcbase, Real * const dst,
const unsigned int gptfloats,
const int selstart, const int selend,
......@@ -174,6 +179,7 @@ inline void pack_stripes_unroll0(const Real * const srcbase, Real * const dst,
}
}
template <typename Real>
inline void pack_stripesxx(const Real * const srcbase, Real * const dst,
const unsigned int gptfloats,
const int selstart, const int selend,
......@@ -241,6 +247,7 @@ inline void pack_stripesxx(const Real * const srcbase, Real * const dst,
}
}
template <typename Real>
inline void pack_stripes(const Real * const srcbase, Real * const dst,
const unsigned int gptfloats,
const int selstart, const int selend,
......@@ -295,6 +302,7 @@ inline void pack_stripes(const Real * const srcbase, Real * const dst,
}
}
template <typename Real>
inline void unpack(const Real * const pack, Real * const dstbase,
const unsigned int gptfloats,
const int * const selected_components, const int ncomponents,
......@@ -313,6 +321,7 @@ inline void unpack(const Real * const pack, Real * const dstbase,
}
}
template <typename Real>
inline void unpack1(const Real * const pack, Real * const dstbase,
const unsigned int gptfloats,
const int * const selected_components, const int ncomponents,
......@@ -335,6 +344,7 @@ inline void unpack1(const Real * const pack, Real * const dstbase,
}
template <typename Real>
inline void unpack2(const Real * const pack, Real * const dstbase,
const unsigned int gptfloats,
const int * const selected_components, const int ncomponents,
......@@ -379,6 +389,7 @@ inline void unpack2(const Real * const pack, Real * const dstbase,
}
template <typename Real>
inline void unpack_subregion(const Real * const pack, Real * const dstbase,
const unsigned int gptfloats,
const int * const selected_components, const int ncomponents,
......
......@@ -25,6 +25,7 @@ class SerializerIO_ImageVTK
typedef typename TBlock::ElementType TElement;
public:
typedef typename GridType::Real Real;
void Write(GridType & inputGrid, std::string fileName)
{
......
......@@ -18,12 +18,6 @@
CUBISM_NAMESPACE_BEGIN
#ifdef _FLOAT_PRECISION_
typedef float Real;
#else
typedef double Real;
#endif
struct StencilInfo
{
int sx, sy, sz, ex, ey, ez;
......
......@@ -23,6 +23,7 @@
CUBISM_NAMESPACE_BEGIN
template <typename Real>
class SynchronizerMPI
{
struct I3
......@@ -704,8 +705,8 @@ public:
std::vector<PackInfo> packinfos;
recv_subpackinfos = _setup<true>(recv, recv_thickness, blockstart, blockend, origin, packinfos);
for(std::vector<PackInfo>::const_iterator it = packinfos.begin(); it<packinfos.end(); ++it)
recv_packinfos[it->block].push_back(*it);
for (const PackInfo &pi : packinfos)
recv_packinfos[pi.block].push_back(pi);
}
assert(recv.pending.size() == 0);
......@@ -1431,7 +1432,7 @@ class MyRange
//packs
{
std::map<Real *, std::vector<PackInfo> >::const_iterator it = recv_packinfos.find(const_cast<Real *>(ptrBlock));
auto it = recv_packinfos.find(const_cast<Real *>(ptrBlock));
if( it!=recv_packinfos.end() )
{
......@@ -1440,7 +1441,7 @@ class MyRange
//assert(!stencil.tensorial || packs.size() <= 7 || mybpd[0]*mybpd[1]*mybpd[2] == 1);
//assert(stencil.tensorial || packs.size()<=3 || mybpd[0]*mybpd[1]*mybpd[2] == 1);
for(std::vector<PackInfo>::const_iterator itpack=packs.begin(); itpack!=packs.end(); ++itpack)
for (auto itpack=packs.cbegin(); itpack != packs.cend(); ++itpack)
{
MyRange packrange(itpack->sx, itpack->ex, itpack->sy, itpack->ey, itpack->sz, itpack->ez);
......@@ -1459,7 +1460,7 @@ class MyRange
//subregions inside packs
if (stencil.tensorial)
{
std::map<Real *, std::vector<SubpackInfo> >::const_iterator it = recv_subpackinfos.find(const_cast<Real *>(ptrBlock));
auto it = recv_subpackinfos.find(const_cast<Real *>(ptrBlock));
assert(stencil.tensorial || it==recv_subpackinfos.end());
......@@ -1469,7 +1470,7 @@ class MyRange
// assert(subpacks.size()<=12+8);
for(std::vector<SubpackInfo>::const_iterator itsubpack=subpacks.begin(); itsubpack!=subpacks.end(); ++itsubpack)
for (auto itsubpack = subpacks.cbegin(); itsubpack != subpacks.cend(); ++itsubpack)
{
MyRange packrange(itsubpack->sx, itsubpack->ex, itsubpack->sy, itsubpack->ey, itsubpack->sz, itsubpack->ez);
......
......@@ -19,12 +19,6 @@
CUBISM_NAMESPACE_BEGIN
#ifdef _FLOAT_PRECISION_
typedef float Real;
#else
typedef double Real;
#endif
typedef struct _header_serial
{
long size[8];
......@@ -39,8 +33,13 @@ inline size_t ZZdecompress(unsigned char * inputbuf, size_t ninputbytes, int lay
// TStreamer::NCHANNELS : Number of data elements (1=Scalar, 3=Vector, 9=Tensor)
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TGrid>
void DumpZBin(const TGrid &grid, const int iCounter, const Real t, const std::string f_name, const std::string dump_path=".", const bool bDummy=false)
template <typename TStreamer, typename TGrid>
void DumpZBin(const TGrid &grid,
const int iCounter,
const typename TGrid::Real t,
const std::string &f_name,
const std::string &dump_path = ".",
const bool bDummy = false)
{
typedef typename TGrid::BlockType B;
......@@ -132,10 +131,11 @@ void DumpZBin(const TGrid &grid, const int iCounter, const Real t, const std::st
}
template<typename TStreamer, typename TGrid>
template <typename TStreamer, typename TGrid>
void ReadZBin(TGrid &grid, const std::string f_name, const std::string read_path=".")
{
typedef typename TGrid::BlockType B;
typedef typename TGrid::Real Real;
// f_name is the base filename without file type extension
std::ostringstream filename;
......
......@@ -29,13 +29,6 @@ typedef struct _header
long size[8];
} header;
#ifdef _FLOAT_PRECISION_
typedef float Real;
#else
typedef double Real;
#endif
/*
inline size_t ZZcompress(unsigned char *buf, unsigned len, int layout[4], unsigned *max)
inline size_t ZZdecompress(unsigned char * inputbuf, size_t ninputbytes, int layout[4], unsigned char * outputbuf, const size_t maxsize);
......@@ -46,7 +39,13 @@ inline size_t ZZdecompress(unsigned char * inputbuf, size_t ninputbytes, int lay
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TGrid>
void DumpZBin_MPI(const TGrid &grid, const int iCounter, const Real t, const std::string f_name, const std::string dump_path=".", const bool bDummy=false)
void DumpZBin_MPI(
const TGrid &grid,
const int iCounter,
const TGrid::Real t,
const std::string &f_name,
const std::string &dump_path = ".",
const bool bDummy = false)
{
typedef typename TGrid::BlockType B;
......
......@@ -10,7 +10,6 @@
using MyReal = double;
#else
using MyReal = float;
#define _FLOAT_PRECISION_
#endif /* _DOUBLE_ */
#define _BLOCKSIZE_ 16
......@@ -34,6 +33,7 @@ struct Block
{
typedef TReal ElementType;
typedef TReal element_type;
typedef TReal Real;
static const size_t sizeX = _BLOCKSIZE_;
static const size_t sizeY = _BLOCKSIZE_;
static const size_t sizeZ = _BLOCKSIZE_;
......
......@@ -19,7 +19,9 @@ CFLAGS+= -Wpedantic -Wno-unused-parameter # does not make much sense with functi
LIBS =
# LIBS += -L${HDF5_ROOT}/lib
ifneq (${HDF5_ROOT},)
LIBS += -L${HDF5_ROOT}/lib
endif
.PHONY: all clean
......
......@@ -219,7 +219,7 @@ int main(int argc, char* argv[])
fname << "mpi_plain_bin_" << prec_string;
BlockInfo info_front = grid->getBlocksInfo().front();
Real* const src = (Real*)info_front.ptrBlock;
MyReal* const src = (MyReal*)info_front.ptrBlock;
const int NX = grid->getResidentBlocksPerDimension(0);
const int NY = grid->getResidentBlocksPerDimension(1);
......
......@@ -30,7 +30,7 @@ template<typename TKernel, typename TGrid>
static void process(TKernel& kernel, TGrid& grid, Profiler& prof, const int rank)
{
static size_t pass = 0;
SynchronizerMPI& Synch = grid.sync(kernel);
SynchronizerMPI<MyReal> & Synch = grid.sync(kernel);
prof.push_start("Inner");
const vector<BlockInfo> avail0 = Synch.avail_inner();
......
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