/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/qcd/hmc/GenericHmcRunner.h Copyright (C) 2015 Author: paboyle Author: Guido Cossu 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 HMC_RESOURCE_MANAGER_H #define HMC_RESOURCE_MANAGER_H #include namespace Grid { namespace QCD { // HMC Resource manager class HMCResourceManager { // Storage for grid pairs (std + red-black) std::unordered_map Grids; RNGModule RNGs; bool have_RNG; public: HMCResourceManager():have_RNG(false){} void AddGrid(std::string s, GridModule& M){ // Check for name clashes auto search = Grids.find(s); if(search != Grids.end()) { std::cout << GridLogError << "Grid with name \"" << search->first << "\" already present. Terminating\n" ; exit(1); } Grids[s] = std::move(M); } // Add a named grid set void AddFourDimGrid(std::string s) { GridFourDimModule Mod; AddGrid(s,Mod); } GridCartesian* GetCartesian(std::string s="") { if (s.empty()) s = Grids.begin()->first; std::cout << GridLogDebug << "Getting cartesian grid from: "<< s << std::endl; return Grids[s].get_full(); } GridRedBlackCartesian* GetRBCartesian(std::string s="") { if (s.empty()) s = Grids.begin()->first; std::cout << GridLogDebug << "Getting rb-cartesian grid from: "<< s << std::endl; return Grids[s].get_rb(); } void AddRNGs(std::string s="") { // Couple the RNGs to the GridModule tagged by s // default is the first grid set assert(Grids.size()>0 && !have_RNG ); if (s.empty()) s = Grids.begin()->first; std::cout << GridLogDebug << "Adding RNG to grid: "<< s << std::endl; RNGs.set_pRNG(new GridParallelRNG(GetCartesian(s))); //pRNG.reset(new GridParallelRNG(GetCartesian(s))); have_RNG = true; } void AddRNGSeeds(const std::vector S, const std::vector P) { RNGs.set_RNGSeeds(S,P); //SerialSeed = S; //ParallelSeed = P; } GridSerialRNG& GetSerialRNG() {return RNGs.get_sRNG();} GridParallelRNG& GetParallelRNG() { assert(have_RNG); return RNGs.get_pRNG(); } void SeedFixedIntegers() { assert(have_RNG); RNGs.seed(); //sRNG.SeedFixedIntegers(SerialSeed); //pRNG->SeedFixedIntegers(ParallelSeed); } }; } } #endif // HMC_RESOURCE_MANAGER_H