From 0a82fae45cd3c57db5e135fdff5b86d9d55d60db Mon Sep 17 00:00:00 2001 From: ferben Date: Tue, 22 Jan 2019 15:06:45 +0000 Subject: [PATCH] moved perambulator definition to shared header file --- Hadrons/DistilVectors.hpp | 124 ++++++++++++++++++++++ Hadrons/Modules/MDistil/DistilVectors.hpp | 84 +-------------- Hadrons/Modules/MDistil/PerambLight.hpp | 90 +++++++--------- 3 files changed, 161 insertions(+), 137 deletions(-) create mode 100644 Hadrons/DistilVectors.hpp diff --git a/Hadrons/DistilVectors.hpp b/Hadrons/DistilVectors.hpp new file mode 100644 index 00000000..54a45f04 --- /dev/null +++ b/Hadrons/DistilVectors.hpp @@ -0,0 +1,124 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/A2AVectors.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli +Author: fionnoh + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#ifndef Distil_Vectors_hpp_ +#define Distil_Vectors_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +template +class Perambulator : Serializable{ + // TODO: The next line makes friends across all combinations + // (not much of a problem given all public anyway ...) + // FYI, the bug here was that I forgot that the friend is templated + template friend std::ostream & operator<<(std::ostream &os, const Perambulator& p); +protected: +public: + GRID_SERIALIZABLE_CLASS_MEMBERS( Perambulator, + std::string, ID, // Allows owner to specialise + std::string, Provenance, // For info only + std::vector, dimensions, + std::vector, perambulator, + // Following items are redundant, but useful + int, nd, // Number of dimensions + size_t, NumElements); // Number of elements +protected: + // Constructor common code + inline void ConstructCommon(const int * Dimensions) { + assert(nd > 0); + dimensions.resize(nd); + NumElements = 1; + for(int i = 0 ; i < nd ; i++) { + assert(Dimensions[i] > 0); + NumElements *= (size_t) Dimensions[i]; + dimensions[i] = Dimensions[i]; + } + //const LatticeObj perambulatorDefault; + perambulator.resize(NumElements);//,perambulatorDefault); + } +public: + // Constructor with dimensions passed as std::vector + inline Perambulator(const std::vector & Dimensions) + : nd {(int) Dimensions.size()} { + ConstructCommon( &Dimensions[0] ); } + + // Constructor with dimensions passed as std::vector + inline Perambulator(const std::vector & Dimensions, const std::string sID) + : nd {(int) Dimensions.size()}, ID(sID) { + ConstructCommon( &Dimensions[0] ); } + + // Constructor with dimensions passed as std::vector + inline Perambulator(const std::vector & Dimensions, const std::string sID, const std::string sProvenance) + : nd {(int) Dimensions.size()}, ID(sID), Provenance(sProvenance) { + ConstructCommon( &Dimensions[0] ); } + + // Constructor with dimensions passed as individual parameters + // FYI: The caller is free to ignore the names and use the indices however they see fit + inline Perambulator(int NumNoise, int NumEvec=1, int NumTime=1, int NumSpin=1, int I_k=1, int I_t=1, int I_s=1) { + int Dimensions[]={NumNoise,NumEvec,NumTime,NumSpin,I_k,I_t,I_s}; + nd = sizeof(Dimensions)/sizeof(Dimensions[0]); + while( nd > 1 && Dimensions[nd-1] == 1 ) + nd--; + ConstructCommon( Dimensions ); + } + + inline LatticeObj & operator()(size_t count, const int * Coord) { + assert( count == nd ); + assert( Coord ); + size_t idx = 0; + // C memory order (???) + for( int d = 0 ; d < nd ; d++ ) { + assert( Coord[d] < dimensions[d] ); + idx *= (size_t) dimensions[d]; + idx += (size_t) Coord[d]; + } + return perambulator[idx]; + } + + inline LatticeObj & operator()(const std::vector Coord) { + return operator()(Coord.size(), &Coord[0]); + } + + inline LatticeObj & operator()(int idxNoise, int idxEvec=0, int idxTime=0, int idxSpin=0, int I_k=0, int I_t=0, int I_s=0) { + int MyIndex[]={idxNoise,idxEvec,idxTime,idxSpin,I_k,I_t,I_s}; + int i = sizeof(MyIndex)/sizeof(MyIndex[0]); + assert( i >= nd ); + while( i > nd ) + assert(MyIndex[--i] == 0); + return operator()(i, MyIndex); + } +}; + + +END_HADRONS_NAMESPACE + +#endif // Distil_Vectors_hpp_ diff --git a/Hadrons/Modules/MDistil/DistilVectors.hpp b/Hadrons/Modules/MDistil/DistilVectors.hpp index c5a387bf..49e6196e 100644 --- a/Hadrons/Modules/MDistil/DistilVectors.hpp +++ b/Hadrons/Modules/MDistil/DistilVectors.hpp @@ -8,92 +8,10 @@ #include #include #include +#include BEGIN_HADRONS_NAMESPACE -template -class Perambulator : Serializable{ - // TODO: The next line makes friends across all combinations - // (not much of a problem given all public anyway ...) - // FYI, the bug here was that I forgot that the friend is templated - template friend std::ostream & operator<<(std::ostream &os, const Perambulator& p); -protected: -public: - GRID_SERIALIZABLE_CLASS_MEMBERS( Perambulator, - std::string, ID, // Allows owner to specialise - std::string, Provenance, // For info only - std::vector, dimensions, - std::vector, perambulator, - // Following items are redundant, but useful - int, nd, // Number of dimensions - size_t, NumElements); // Number of elements -protected: - // Constructor common code - inline void ConstructCommon(const int * Dimensions) { - assert(nd > 0); - dimensions.resize(nd); - NumElements = 1; - for(int i = 0 ; i < nd ; i++) { - assert(Dimensions[i] > 0); - NumElements *= (size_t) Dimensions[i]; - dimensions[i] = Dimensions[i]; - } - //const LatticeObj perambulatorDefault; - perambulator.resize(NumElements);//,perambulatorDefault); - } -public: - // Constructor with dimensions passed as std::vector - inline Perambulator(const std::vector & Dimensions) - : nd {(int) Dimensions.size()} { - ConstructCommon( &Dimensions[0] ); } - - // Constructor with dimensions passed as std::vector - inline Perambulator(const std::vector & Dimensions, const std::string sID) - : nd {(int) Dimensions.size()}, ID(sID) { - ConstructCommon( &Dimensions[0] ); } - - // Constructor with dimensions passed as std::vector - inline Perambulator(const std::vector & Dimensions, const std::string sID, const std::string sProvenance) - : nd {(int) Dimensions.size()}, ID(sID), Provenance(sProvenance) { - ConstructCommon( &Dimensions[0] ); } - - // Constructor with dimensions passed as individual parameters - // FYI: The caller is free to ignore the names and use the indices however they see fit - inline Perambulator(int NumNoise, int NumEvec=1, int NumTime=1, int NumSpin=1, int I_k=1, int I_t=1, int I_s=1) { - int Dimensions[]={NumNoise,NumEvec,NumTime,NumSpin,I_k,I_t,I_s}; - nd = sizeof(Dimensions)/sizeof(Dimensions[0]); - while( nd > 1 && Dimensions[nd-1] == 1 ) - nd--; - ConstructCommon( Dimensions ); - } - - inline LatticeObj & operator()(size_t count, const int * Coord) { - assert( count == nd ); - assert( Coord ); - size_t idx = 0; - // C memory order (???) - for( int d = 0 ; d < nd ; d++ ) { - assert( Coord[d] < dimensions[d] ); - idx *= (size_t) dimensions[d]; - idx += (size_t) Coord[d]; - } - return perambulator[idx]; - } - - inline LatticeObj & operator()(const std::vector Coord) { - return operator()(Coord.size(), &Coord[0]); - } - - inline LatticeObj & operator()(int idxNoise, int idxEvec=0, int idxTime=0, int idxSpin=0, int I_k=0, int I_t=0, int I_s=0) { - int MyIndex[]={idxNoise,idxEvec,idxTime,idxSpin,I_k,I_t,I_s}; - int i = sizeof(MyIndex)/sizeof(MyIndex[0]); - assert( i >= nd ); - while( i > nd ) - assert(MyIndex[--i] == 0); - return operator()(i, MyIndex); - } -}; - /****************************************************************************** * DistilVectors * diff --git a/Hadrons/Modules/MDistil/PerambLight.hpp b/Hadrons/Modules/MDistil/PerambLight.hpp index 6fe5be72..51d565cb 100644 --- a/Hadrons/Modules/MDistil/PerambLight.hpp +++ b/Hadrons/Modules/MDistil/PerambLight.hpp @@ -1,32 +1,40 @@ -#ifndef Hadrons_MDistil_perambulator_l_hpp_ -#define Hadrons_MDistil_perambulator_l_hpp_ +#ifndef Hadrons_MDistil_PerambLight_hpp_ +#define Hadrons_MDistil_PerambLight_hpp_ #include #include #include +#include +#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE + /****************************************************************************** - * perambulator_l * + * PerambLight * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MDistil) -class perambulator_lPar: Serializable +class PerambLightPar: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(perambulator_lPar, - unsigned int, i); + GRID_SERIALIZABLE_CLASS_MEMBERS(PerambLightPar, + std::string, noise, + std::string, eigenPack, + bool, multiFile); }; template -class Tperambulator_l: public Module +class TPerambLight: public Module { public: // constructor - Tperambulator_l(const std::string name); + TPerambLight(const std::string name); // destructor - virtual ~Tperambulator_l(void) {}; + virtual ~TPerambLight(void) {}; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -36,81 +44,55 @@ public: virtual void execute(void); }; -MODULE_REGISTER_TMP(perambulator_l, Tperambulator_l, MDistil); +MODULE_REGISTER_TMP(PerambLight, TPerambLight, MDistil); /****************************************************************************** - * Tperambulator_l implementation * + * TPerambLight implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template -Tperambulator_l::Tperambulator_l(const std::string name) -: Module(name) +TPerambLight::TPerambLight(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// template -std::vector Tperambulator_l::getInput(void) +std::vector TPerambLight::getInput(void) { std::vector in; + + in.push_back(par().noise); + in.push_back(par().eigenPack); return in; } template -std::vector Tperambulator_l::getOutput(void) +std::vector TPerambLight::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {getName() + "_perambulator_light"}; return out; } // setup /////////////////////////////////////////////////////////////////////// template -void Tperambulator_l::setup(void) +void TPerambLight::setup(void) { -/* - std::cout << "Compute perambulator from timeslice " << tsrc << std::endl; - LatticeSpinColourVector dist_source(grid4d); - LatticeSpinColourVector tmp2(grid4d); - LatticeSpinColourVector tmp3d(grid3d); - LatticeColourVector tmp3d_nospin(grid3d); - LatticeColourVector evec3d(grid3d); - LatticeColourVector tmp_nospin(grid4d); + auto &noise = envGet(std::vector>>, par().noise); + + int nvec = 6; + int Nt=64; - LatticeColourVector result_tmp(grid3d); + envCreate(Perambulator, getName() + "_perambulator_light", 1, + noise.size() *nvec*Nt); - LatticeSpinVector peramb_tmp(grid4d); - LatticeFermion result(grid4d); result=zero; //Fermion = SpinColourVector!!! - LatticeFermion result_single_component(grid4d); result_single_component=zero; //Fermion = SpinColourVector!!! - LatticeColourVector result_nospin(grid4d); result_nospin=zero; //Fermion = SpinColourVector!!! - LatticeColourVector result_3d(grid3d); result_3d=zero; //Fermion = SpinColourVector!!! - LatticeFermion result_test(grid3d); result_test=zero; //Fermion = SpinColourVector!!! - - - Real mass=SPar.mass; // TODO Infile - Real M5 =SPar.M5; // TODO Infile - std::cout << "init RBG " << std::endl; - GridRedBlackCartesian RBGrid(grid4d); - std::cout << "init RBG done" << std::endl; - - GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(DPar.Ls,grid4d); - GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(DPar.Ls,grid4d); - - typedef DomainWallFermionR FermionAction; - - FermionAction Dop(Umu,*FGrid,*FrbGrid,*grid4d,RBGrid,mass,M5); - - MdagMLinearOperator HermOp(Dop); - ConjugateGradient CG(SPar.CGPrecision,SPar.MaxIterations); - SchurRedBlackDiagMooeeSolve SchurSolver(CG); -*/ - } // execution /////////////////////////////////////////////////////////////////// template -void Tperambulator_l::execute(void) +void TPerambLight::execute(void) { /* for (int inoise = 0; inoise < nnoise; inoise++) { @@ -180,4 +162,4 @@ END_MODULE_NAMESPACE END_HADRONS_NAMESPACE -#endif // Hadrons_MDistil_perambulator_l_hpp_ +#endif // Hadrons_MDistil_PerambLight_hpp_