Skip to content

Commit 68a5079

Browse files
committed
Merge branch 'develop' of https://github.com/paboyle/Grid into develop
2 parents 8634e19 + bfbf2f1 commit 68a5079

12 files changed

Lines changed: 193 additions & 11 deletions

benchmarks/Benchmark_comms.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ int main (int argc, char ** argv)
450450
}
451451

452452

453-
453+
#ifdef GRID_OMP
454454
std::cout<<GridLogMessage << "===================================================================================================="<<std::endl;
455455
std::cout<<GridLogMessage << "= Benchmarking threaded STENCIL halo exchange in "<<nmu<<" dimensions"<<std::endl;
456456
std::cout<<GridLogMessage << "===================================================================================================="<<std::endl;
@@ -537,7 +537,7 @@ int main (int argc, char ** argv)
537537

538538
}
539539
}
540-
540+
#endif
541541
std::cout<<GridLogMessage << "===================================================================================================="<<std::endl;
542542
std::cout<<GridLogMessage << "= All done; Bye Bye"<<std::endl;
543543
std::cout<<GridLogMessage << "===================================================================================================="<<std::endl;

lib/parallelIO/BinaryIO.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ PARALLEL_CRITICAL
263263
GridBase *grid,
264264
std::vector<fobj> &iodata,
265265
std::string file,
266-
uint64_t offset,
266+
uint64_t& offset,
267267
const std::string &format, int control,
268268
uint32_t &nersc_csum,
269269
uint32_t &scidac_csuma,
@@ -495,6 +495,7 @@ PARALLEL_CRITICAL
495495
exit(1);
496496
#endif
497497
}
498+
offset = fout.tellp();
498499
fout.close();
499500
}
500501
timer.Stop();
@@ -699,7 +700,6 @@ PARALLEL_CRITICAL
699700

700701
IOobject(w,grid,iodata,file,offset,format,BINARYIO_WRITE|BINARYIO_LEXICOGRAPHIC,
701702
nersc_csum,scidac_csuma,scidac_csumb);
702-
703703
iodata.resize(1);
704704
{
705705
std::vector<RngStateType> tmp(RngStateCount);

lib/qcd/hmc/HMCResourceManager.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4848
} \
4949
}
5050

51+
#define RegisterLoadCheckPointerMetadataFunction(NAME) \
52+
template < class Metadata > \
53+
void Load##NAME##Checkpointer(const CheckpointerParameters& Params_, const Metadata& M_) { \
54+
if (!have_CheckPointer) { \
55+
std::cout << GridLogDebug << "Loading Metadata Checkpointer " << #NAME \
56+
<< std::endl; \
57+
CP = std::unique_ptr<CheckpointerBaseModule>( \
58+
new NAME##CPModule<ImplementationPolicy, Metadata >(Params_, M_)); \
59+
have_CheckPointer = true; \
60+
} else { \
61+
std::cout << GridLogError << "Checkpointer already loaded " \
62+
<< std::endl; \
63+
exit(1); \
64+
} \
65+
}
66+
5167
namespace Grid {
5268
namespace QCD {
5369

@@ -77,7 +93,7 @@ class HMCResourceManager {
7793
bool have_CheckPointer;
7894

7995
// NOTE: operator << is not overloaded for std::vector<string>
80-
// so thsi function is necessary
96+
// so this function is necessary
8197
void output_vector_string(const std::vector<std::string> &vs){
8298
for (auto &i: vs)
8399
std::cout << i << " ";
@@ -254,6 +270,7 @@ class HMCResourceManager {
254270
RegisterLoadCheckPointerFunction(Nersc);
255271
#ifdef HAVE_LIME
256272
RegisterLoadCheckPointerFunction(ILDG);
273+
RegisterLoadCheckPointerMetadataFunction(Scidac);
257274
#endif
258275

259276
////////////////////////////////////////////////////////

lib/qcd/hmc/checkpointers/BaseCheckpointer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ class BaseHmcCheckpointer : public HmcObservable<typename Impl::Field> {
7676
}
7777
}
7878

79+
void check_filename(const std::string &filename){
80+
std::ifstream f(filename.c_str());
81+
if(!f.good()){
82+
std::cout << GridLogError << "Filename " << filename << " not found. Aborting. " << std::endl;
83+
abort();
84+
};
85+
}
86+
7987
virtual void initialize(const CheckpointerParameters &Params) = 0;
8088

8189
virtual void CheckpointRestore(int traj, typename Impl::Field &U,

lib/qcd/hmc/checkpointers/BinaryCheckpointer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class BinaryHmcCheckpointer : public BaseHmcCheckpointer<Impl> {
9393
void CheckpointRestore(int traj, Field &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG) {
9494
std::string config, rng;
9595
this->build_filenames(traj, Params, config, rng);
96+
this->check_filename(rng);
97+
this->check_filename(config);
98+
9699

97100
BinarySimpleMunger<sobj_double, sobj> munge;
98101

lib/qcd/hmc/checkpointers/CheckPointerModules.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ class ILDGCPModule: public CheckPointerModule< ImplementationPolicy> {
136136

137137
};
138138

139+
template<class ImplementationPolicy, class Metadata>
140+
class ScidacCPModule: public CheckPointerModule< ImplementationPolicy> {
141+
typedef CheckPointerModule< ImplementationPolicy> CPBase;
142+
Metadata M;
143+
144+
// acquire resource
145+
virtual void initialize(){
146+
this->CheckPointPtr.reset(new ScidacHmcCheckpointer<ImplementationPolicy, Metadata>(this->Par_, M));
147+
}
148+
public:
149+
ScidacCPModule(typename CPBase::APar Par, Metadata M_):M(M_), CPBase(Par) {}
150+
template <class ReaderClass>
151+
ScidacCPModule(Reader<ReaderClass>& Reader) : Parametrized<typename CPBase::APar>(Reader), M(Reader){};
152+
};
139153
#endif
140154

141155

lib/qcd/hmc/checkpointers/CheckPointers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ directory
3434
#include <Grid/qcd/hmc/checkpointers/NerscCheckpointer.h>
3535
#include <Grid/qcd/hmc/checkpointers/BinaryCheckpointer.h>
3636
#include <Grid/qcd/hmc/checkpointers/ILDGCheckpointer.h>
37+
#include <Grid/qcd/hmc/checkpointers/ScidacCheckpointer.h>
3738
//#include <Grid/qcd/hmc/checkpointers/CheckPointerModules.h>
3839

3940

lib/qcd/hmc/checkpointers/ILDGCheckpointer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class ILDGHmcCheckpointer : public BaseHmcCheckpointer<Implementation> {
9595
GridParallelRNG &pRNG) {
9696
std::string config, rng;
9797
this->build_filenames(traj, Params, config, rng);
98+
this->check_filename(rng);
99+
this->check_filename(config);
100+
101+
98102

99103
uint32_t nersc_csum,scidac_csuma,scidac_csumb;
100104
BinaryIO::readRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);

lib/qcd/hmc/checkpointers/NerscCheckpointer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class NerscHmcCheckpointer : public BaseHmcCheckpointer<Gimpl> {
6969
GridParallelRNG &pRNG) {
7070
std::string config, rng;
7171
this->build_filenames(traj, Params, config, rng);
72+
this->check_filename(rng);
73+
this->check_filename(config);
74+
7275

7376
FieldMetaData header;
7477
NerscIO::readRNGState(sRNG, pRNG, header, rng);
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*************************************************************************************
2+
3+
Grid physics library, www.github.com/paboyle/Grid
4+
5+
Source file: ./lib/qcd/hmc/ScidacCheckpointer.h
6+
7+
Copyright (C) 2018
8+
9+
Author: Guido Cossu <guido.cossu@ed.ac.uk>
10+
11+
This program is free software; you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation; either version 2 of the License, or
14+
(at your option) any later version.
15+
16+
This program is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
GNU General Public License for more details.
20+
21+
You should have received a copy of the GNU General Public License along
22+
with this program; if not, write to the Free Software Foundation, Inc.,
23+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24+
25+
See the full license in the file "LICENSE" in the top level distribution
26+
directory
27+
*************************************************************************************/
28+
/* END LEGAL */
29+
#ifndef SCIDAC_CHECKPOINTER
30+
#define SCIDAC_CHECKPOINTER
31+
32+
#ifdef HAVE_LIME
33+
34+
#include <iostream>
35+
#include <sstream>
36+
#include <string>
37+
38+
namespace Grid {
39+
namespace QCD {
40+
41+
// For generic fields
42+
template <class Implementation, class Metadata>
43+
class ScidacHmcCheckpointer : public BaseHmcCheckpointer<Implementation> {
44+
private:
45+
CheckpointerParameters Params;
46+
Metadata MData;
47+
48+
typedef typename Implementation::Field Field;
49+
50+
public:
51+
//INHERIT_GIMPL_TYPES(Implementation);
52+
53+
ScidacHmcCheckpointer(const CheckpointerParameters &Params_) { initialize(Params_); }
54+
ScidacHmcCheckpointer(const CheckpointerParameters &Params_, const Metadata& M_):MData(M_) { initialize(Params_); }
55+
56+
void initialize(const CheckpointerParameters &Params_) {
57+
Params = Params_;
58+
59+
// check here that the format is valid
60+
int ieee32big = (Params.format == std::string("IEEE32BIG"));
61+
int ieee32 = (Params.format == std::string("IEEE32"));
62+
int ieee64big = (Params.format == std::string("IEEE64BIG"));
63+
int ieee64 = (Params.format == std::string("IEEE64"));
64+
65+
if (!(ieee64big || ieee32 || ieee32big || ieee64)) {
66+
std::cout << GridLogError << "Unrecognized file format " << Params.format
67+
<< std::endl;
68+
std::cout << GridLogError
69+
<< "Allowed: IEEE32BIG | IEEE32 | IEEE64BIG | IEEE64"
70+
<< std::endl;
71+
72+
exit(1);
73+
}
74+
}
75+
76+
void TrajectoryComplete(int traj, Field &U, GridSerialRNG &sRNG,
77+
GridParallelRNG &pRNG) {
78+
if ((traj % Params.saveInterval) == 0) {
79+
std::string config, rng;
80+
this->build_filenames(traj, Params, config, rng);
81+
GridBase *grid = U._grid;
82+
uint32_t nersc_csum,scidac_csuma,scidac_csumb;
83+
BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
84+
ScidacWriter _ScidacWriter(grid->IsBoss());
85+
_ScidacWriter.open(config);
86+
_ScidacWriter.writeScidacFieldRecord(U, MData);
87+
_ScidacWriter.close();
88+
89+
std::cout << GridLogMessage << "Written Scidac Configuration on " << config
90+
<< " checksum " << std::hex << nersc_csum<<"/"
91+
<< scidac_csuma<<"/" << scidac_csumb
92+
<< std::dec << std::endl;
93+
}
94+
};
95+
96+
void CheckpointRestore(int traj, Field &U, GridSerialRNG &sRNG,
97+
GridParallelRNG &pRNG) {
98+
std::string config, rng;
99+
this->build_filenames(traj, Params, config, rng);
100+
this->check_filename(rng);
101+
this->check_filename(config);
102+
103+
104+
uint32_t nersc_csum,scidac_csuma,scidac_csumb;
105+
BinaryIO::readRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
106+
107+
Metadata md_content;
108+
ScidacReader _ScidacReader;
109+
_ScidacReader.open(config);
110+
_ScidacReader.readScidacFieldRecord(U,md_content); // format from the header
111+
_ScidacReader.close();
112+
113+
std::cout << GridLogMessage << "Read Scidac Configuration from " << config
114+
<< " checksum " << std::hex
115+
<< nersc_csum<<"/"
116+
<< scidac_csuma<<"/"
117+
<< scidac_csumb
118+
<< std::dec << std::endl;
119+
};
120+
};
121+
}
122+
}
123+
124+
#endif // HAVE_LIME
125+
#endif // ILDG_CHECKPOINTER

0 commit comments

Comments
 (0)