mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-15 14:27:06 +01:00
Adding reproducibility tests
This commit is contained in:
@ -33,17 +33,21 @@ directory
|
||||
|
||||
namespace Grid {
|
||||
|
||||
struct CG_state{
|
||||
struct CG_state {
|
||||
bool do_repro;
|
||||
std::vector<RealD> residuals;
|
||||
|
||||
CG_state(){
|
||||
CG_state() {
|
||||
do_repro = false;
|
||||
residuals.clear();}
|
||||
residuals.clear();
|
||||
}
|
||||
|
||||
void reset(){
|
||||
do_repro = false;
|
||||
residuals.clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Base classes for iterative processes based on operators
|
||||
// single input vec, single output vec.
|
||||
@ -57,7 +61,7 @@ class ConjugateGradient : public OperatorFunction<Field> {
|
||||
RealD Tolerance;
|
||||
Integer MaxIterations;
|
||||
bool ReproTest;
|
||||
CG_state CGState;
|
||||
CG_state CGState;//to check reproducibility by repeating the CG
|
||||
|
||||
ConjugateGradient(RealD tol, Integer maxit, bool err_on_no_conv = true,
|
||||
bool ReproducibilityTest = false)
|
||||
@ -199,8 +203,7 @@ class ConjugateGradient : public OperatorFunction<Field> {
|
||||
}
|
||||
|
||||
// Clear state
|
||||
CGState.residuals.clear();
|
||||
CGState.do_repro = false;
|
||||
CGState.reset();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,25 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
#define GRID_LATTICE_REDUCTION_H
|
||||
|
||||
namespace Grid {
|
||||
|
||||
template <class T>
|
||||
struct ReproducibilityState {
|
||||
int n_call;
|
||||
bool do_check;
|
||||
std::vector<std::vector<T, alignedAllocator<T> > > th_states;
|
||||
|
||||
void reset(){
|
||||
th_states.clear();
|
||||
do_check = false;
|
||||
n_call = 0;
|
||||
}
|
||||
|
||||
ReproducibilityState(){
|
||||
reset();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifdef GRID_WARN_SUBOPTIMAL
|
||||
#warning "Optimisation alert all these reduction loops are NOT threaded "
|
||||
#endif
|
||||
@ -43,6 +62,9 @@ namespace Grid {
|
||||
return std::real(nrm);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class vobj>
|
||||
inline ComplexD innerProduct(const Lattice<vobj> &left,const Lattice<vobj> &right)
|
||||
{
|
||||
@ -57,7 +79,9 @@ namespace Grid {
|
||||
sumarray[i]=zero;
|
||||
}
|
||||
|
||||
PARALLEL_FOR_LOOP
|
||||
// accumulation done in the same precision ad vobj...
|
||||
// may need to froce higher precision
|
||||
PARALLEL_FOR_LOOP
|
||||
for(int thr=0;thr<grid->SumArraySize();thr++){
|
||||
int nwork, mywork, myoff;
|
||||
GridThread::GetWork(left._grid->oSites(),thr,mywork,myoff);
|
||||
@ -69,6 +93,19 @@ PARALLEL_FOR_LOOP
|
||||
sumarray[thr]=TensorRemove(vnrm) ;
|
||||
}
|
||||
|
||||
/*
|
||||
if (repr.do_check){
|
||||
if (sumarray!=repr.th_states[n_call]){
|
||||
std::cout << GridLogMessage << "Reproducibility failure on node " << grid->ThisRank() << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
repr.th_states.push_back(sumarray);//save threads state
|
||||
repr.n_call +=1;
|
||||
}
|
||||
*/
|
||||
|
||||
vector_type vvnrm; vvnrm=zero; // sum across threads
|
||||
for(int i=0;i<grid->SumArraySize();i++){
|
||||
vvnrm = vvnrm+sumarray[i];
|
||||
@ -114,7 +151,7 @@ PARALLEL_FOR_LOOP
|
||||
sumarray[i]=zero;
|
||||
}
|
||||
|
||||
PARALLEL_FOR_LOOP
|
||||
PARALLEL_FOR_LOOP
|
||||
for(int thr=0;thr<grid->SumArraySize();thr++){
|
||||
int nwork, mywork, myoff;
|
||||
GridThread::GetWork(grid->oSites(),thr,mywork,myoff);
|
||||
@ -146,7 +183,7 @@ PARALLEL_FOR_LOOP
|
||||
|
||||
|
||||
template<class vobj> inline void sliceSum(const Lattice<vobj> &Data,std::vector<typename vobj::scalar_object> &result,int orthogdim)
|
||||
{
|
||||
{
|
||||
typedef typename vobj::scalar_object sobj;
|
||||
GridBase *grid = Data._grid;
|
||||
assert(grid!=NULL);
|
||||
|
Reference in New Issue
Block a user