1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-16 23:07:05 +01:00

Adding reproducibility tests

This commit is contained in:
Guido Cossu
2016-11-21 09:52:07 +00:00
parent 036ec31c48
commit f1908c7bc9
2 changed files with 85 additions and 45 deletions

View File

@ -39,11 +39,15 @@ struct CG_state{
CG_state() { CG_state() {
do_repro = false; do_repro = false;
residuals.clear();} residuals.clear();
}
void reset(){
do_repro = false;
residuals.clear();
}
}; };
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Base classes for iterative processes based on operators // Base classes for iterative processes based on operators
// single input vec, single output vec. // single input vec, single output vec.
@ -57,7 +61,7 @@ class ConjugateGradient : public OperatorFunction<Field> {
RealD Tolerance; RealD Tolerance;
Integer MaxIterations; Integer MaxIterations;
bool ReproTest; 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, ConjugateGradient(RealD tol, Integer maxit, bool err_on_no_conv = true,
bool ReproducibilityTest = false) bool ReproducibilityTest = false)
@ -199,8 +203,7 @@ class ConjugateGradient : public OperatorFunction<Field> {
} }
// Clear state // Clear state
CGState.residuals.clear(); CGState.reset();
CGState.do_repro = false;
return; return;
} }
} }

View File

@ -31,6 +31,25 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
#define GRID_LATTICE_REDUCTION_H #define GRID_LATTICE_REDUCTION_H
namespace Grid { 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 #ifdef GRID_WARN_SUBOPTIMAL
#warning "Optimisation alert all these reduction loops are NOT threaded " #warning "Optimisation alert all these reduction loops are NOT threaded "
#endif #endif
@ -43,6 +62,9 @@ namespace Grid {
return std::real(nrm); return std::real(nrm);
} }
template<class vobj> template<class vobj>
inline ComplexD innerProduct(const Lattice<vobj> &left,const Lattice<vobj> &right) inline ComplexD innerProduct(const Lattice<vobj> &left,const Lattice<vobj> &right)
{ {
@ -57,6 +79,8 @@ namespace Grid {
sumarray[i]=zero; sumarray[i]=zero;
} }
// accumulation done in the same precision ad vobj...
// may need to froce higher precision
PARALLEL_FOR_LOOP PARALLEL_FOR_LOOP
for(int thr=0;thr<grid->SumArraySize();thr++){ for(int thr=0;thr<grid->SumArraySize();thr++){
int nwork, mywork, myoff; int nwork, mywork, myoff;
@ -69,6 +93,19 @@ PARALLEL_FOR_LOOP
sumarray[thr]=TensorRemove(vnrm) ; 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 vector_type vvnrm; vvnrm=zero; // sum across threads
for(int i=0;i<grid->SumArraySize();i++){ for(int i=0;i<grid->SumArraySize();i++){
vvnrm = vvnrm+sumarray[i]; vvnrm = vvnrm+sumarray[i];