From 34e9d3f0ca8afe88866f27ddc512991e2958f7d4 Mon Sep 17 00:00:00 2001 From: fionnoh Date: Sun, 22 Jul 2018 14:40:31 +0100 Subject: [PATCH] Moved the creation and resizing of the v and w high modes from the A2A class to the A2A module and made them an output of the module. This means that they have to be inputs of the contration modules and they will freed from memory if they are no longer needed. --- extras/Hadrons/AllToAllVectors.hpp | 24 ++++----------- .../Hadrons/Modules/MContraction/A2AMeson.hpp | 6 ++-- .../Modules/MContraction/MesonFieldGamma.hpp | 2 ++ extras/Hadrons/Modules/MSolver/A2AVectors.hpp | 29 +++++++++++++++---- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/extras/Hadrons/AllToAllVectors.hpp b/extras/Hadrons/AllToAllVectors.hpp index 7d9aa62e..df60b964 100644 --- a/extras/Hadrons/AllToAllVectors.hpp +++ b/extras/Hadrons/AllToAllVectors.hpp @@ -19,37 +19,25 @@ class A2AModesSchurDiagTwo const std::vector *eval; Matrix &action; Solver &solver; + std::vector w_high_5d, v_high_5d, w_high_4d, v_high_4d; const int Nl, Nh; const bool return_5d; - std::vector w_high_5d, v_high_5d, w_high_4d, v_high_4d; public: A2AModesSchurDiagTwo(const std::vector *_evec, const std::vector *_eval, Matrix &_action, Solver &_solver, + std::vector _w_high_5d, std::vector _v_high_5d, + std::vector _w_high_4d, std::vector _v_high_4d, const int _Nl, const int _Nh, const bool _return_5d) : evec(_evec), eval(_eval), action(_action), solver(_solver), + w_high_5d(_w_high_5d), v_high_5d(_v_high_5d), + w_high_4d(_w_high_4d), v_high_4d(_v_high_4d), Nl(_Nl), Nh(_Nh), - return_5d(_return_5d) - { - init_resize(1, Nh); - if (return_5d) init_resize(Nh, Nh); - }; - - void init_resize(const size_t size_5d, const size_t size_4d) - { - GridBase *grid_5d = action.Grid(); - GridBase *grid_4d = action.GaugeGrid(); - - w_high_5d.resize(size_5d, grid_5d); - v_high_5d.resize(size_5d, grid_5d); - - w_high_4d.resize(size_4d, grid_4d); - v_high_4d.resize(size_4d, grid_4d); - } + return_5d(_return_5d){}; void high_modes(Field &source_5d, Field &w_source_5d, Field &source_4d, int i) { diff --git a/extras/Hadrons/Modules/MContraction/A2AMeson.hpp b/extras/Hadrons/Modules/MContraction/A2AMeson.hpp index f8d7f74c..a13336ef 100644 --- a/extras/Hadrons/Modules/MContraction/A2AMeson.hpp +++ b/extras/Hadrons/Modules/MContraction/A2AMeson.hpp @@ -77,9 +77,9 @@ TA2AMeson::TA2AMeson(const std::string name) template std::vector TA2AMeson::getInput(void) { - std::vector in = {par().A2A1, par().A2A2}; - in.push_back(par().A2A1 + "_class"); - in.push_back(par().A2A2 + "_class"); + std::vector in = {par().A2A1 + "_class", par().A2A2 + "_class"}; + in.push_back(par().A2A1 + "_w_high_4d"); + in.push_back(par().A2A2 + "_v_high_4d"); return in; } diff --git a/extras/Hadrons/Modules/MContraction/MesonFieldGamma.hpp b/extras/Hadrons/Modules/MContraction/MesonFieldGamma.hpp index c7676904..6128534c 100644 --- a/extras/Hadrons/Modules/MContraction/MesonFieldGamma.hpp +++ b/extras/Hadrons/Modules/MContraction/MesonFieldGamma.hpp @@ -82,6 +82,8 @@ template std::vector TMesonFieldGamma::getInput(void) { std::vector in = {par().A2A1 + "_class", par().A2A2 + "_class"}; + in.push_back(par().A2A1 + "_w_high_4d"); + in.push_back(par().A2A2 + "_v_high_4d"); return in; } diff --git a/extras/Hadrons/Modules/MSolver/A2AVectors.hpp b/extras/Hadrons/Modules/MSolver/A2AVectors.hpp index 863ee04c..9481f268 100644 --- a/extras/Hadrons/Modules/MSolver/A2AVectors.hpp +++ b/extras/Hadrons/Modules/MSolver/A2AVectors.hpp @@ -107,7 +107,9 @@ std::vector TA2AVectors::getReference(void) template std::vector TA2AVectors::getOutput(void) { - std::vector out = {getName(), className_}; + std::vector out = {getName(), className_, + getName() + "_w_high_5d", getName() + "_v_high_5d", + getName() + "_w_high_4d", getName() + "_v_high_4d"}; return out; } @@ -120,17 +122,17 @@ void TA2AVectors::setup(void) int Nl = par().Nl; int Nh = N - Nl; bool return_5d = par().return_5d; - int Ls, Ls_; + int Ls; std::string sub_string = ""; if (Nl > 0) sub_string = "_subtract"; auto &solver = envGet(Solver, par().solver + sub_string); - Ls_ = env().getObjectLs(par().solver + sub_string); + Ls = env().getObjectLs(par().solver + sub_string); auto &action = envGet(FMat, par().action); - envTmpLat(FermionField, "ferm_src", Ls_); - envTmpLat(FermionField, "unphys_ferm", Ls_); + envTmpLat(FermionField, "ferm_src", Ls); + envTmpLat(FermionField, "unphys_ferm", Ls); envTmpLat(FermionField, "tmp"); envTmpLat(FermionField, "tmp2"); @@ -154,10 +156,25 @@ void TA2AVectors::setup(void) LOG(Message) << "Creating a2a vectors " << getName() << " using " << Nh << " high modes only." << std::endl; } - envCreate(A2ABase, className_, Ls_, + + int size_5d = 1; + if (return_5d) size_5d = Nh; + envCreate(std::vector, getName() + "_w_high_5d", Ls, size_5d, FermionField(env().getGrid(Ls))); + envCreate(std::vector, getName() + "_v_high_5d", Ls, size_5d, FermionField(env().getGrid(Ls))); + envCreate(std::vector, getName() + "_w_high_4d", 1, Nh, FermionField(env().getGrid(1))); + envCreate(std::vector, getName() + "_v_high_4d", 1, Nh, FermionField(env().getGrid(1))); + + auto &w_high_5d = envGet(std::vector, getName() + "_w_high_5d"); + auto &v_high_5d = envGet(std::vector, getName() + "_v_high_5d"); + auto &w_high_4d = envGet(std::vector, getName() + "_w_high_4d"); + auto &v_high_4d = envGet(std::vector, getName() + "_v_high_4d"); + + envCreate(A2ABase, className_, Ls, evec, eval, action, solver, + w_high_5d, v_high_5d, + w_high_4d, v_high_4d, Nl, Nh, return_5d); }