From 538b16610b773613a5b0689b55ff976310264dc8 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 27 Oct 2015 17:33:18 +0000 Subject: [PATCH 001/106] First commit for measurement software 'Hadrons' --- Makefile.am | 2 +- configure | 6 ++++ configure.ac | 2 ++ programs/Hadrons/Application.cc | 58 ++++++++++++++++++++++++++++++++ programs/Hadrons/Application.hpp | 47 ++++++++++++++++++++++++++ programs/Hadrons/Global.cc | 31 +++++++++++++++++ programs/Hadrons/Global.hpp | 47 ++++++++++++++++++++++++++ programs/Hadrons/Hadrons.cc | 32 ++++++++++++++++++ programs/Hadrons/Makefile.am | 13 +++++++ programs/Makefile.am | 1 + 10 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 programs/Hadrons/Application.cc create mode 100644 programs/Hadrons/Application.hpp create mode 100644 programs/Hadrons/Global.cc create mode 100644 programs/Hadrons/Global.hpp create mode 100644 programs/Hadrons/Hadrons.cc create mode 100644 programs/Hadrons/Makefile.am create mode 100644 programs/Makefile.am diff --git a/Makefile.am b/Makefile.am index 3b1d5690..1b3db103 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # additional include paths necessary to compile the C++ library AM_CXXFLAGS = -I$(top_srcdir)/ -SUBDIRS = lib tests benchmarks +SUBDIRS = lib tests benchmarks programs filelist: $(SUBDIRS) \ No newline at end of file diff --git a/configure b/configure index dbc34570..b3b95c09 100755 --- a/configure +++ b/configure @@ -6536,6 +6536,10 @@ ac_config_files="$ac_config_files tests/Makefile" ac_config_files="$ac_config_files benchmarks/Makefile" +ac_config_files="$ac_config_files programs/Makefile" + +ac_config_files="$ac_config_files programs/Hadrons/Makefile" + cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure @@ -7279,6 +7283,8 @@ do "lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;; "tests/Makefile") CONFIG_FILES="$CONFIG_FILES tests/Makefile" ;; "benchmarks/Makefile") CONFIG_FILES="$CONFIG_FILES benchmarks/Makefile" ;; + "programs/Makefile") CONFIG_FILES="$CONFIG_FILES programs/Makefile" ;; + "programs/Hadrons/Makefile") CONFIG_FILES="$CONFIG_FILES programs/Hadrons/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac diff --git a/configure.ac b/configure.ac index e81abd0f..8e61e750 100644 --- a/configure.ac +++ b/configure.ac @@ -175,6 +175,8 @@ AC_CONFIG_FILES(Makefile) AC_CONFIG_FILES(lib/Makefile) AC_CONFIG_FILES(tests/Makefile) AC_CONFIG_FILES(benchmarks/Makefile) +AC_CONFIG_FILES(programs/Makefile) +AC_CONFIG_FILES(programs/Hadrons/Makefile) AC_OUTPUT diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc new file mode 100644 index 00000000..6fea55d5 --- /dev/null +++ b/programs/Hadrons/Application.cc @@ -0,0 +1,58 @@ +/* + * Application.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#include + +using namespace std; +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** + * Application implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +Application::Application(int argc, char *argv[]) +{ + if (argc < 2) + { + cerr << "usage: " << argv[0] << " [Grid options]"; + cerr << endl; + exit(EXIT_FAILURE); + } + parameterFileName_ = argv[1]; + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << endl; +} + +// destructor ////////////////////////////////////////////////////////////////// +Application::~Application(void) +{ + LOG(Message) << "Grid is finalizing now" << endl; + Grid_finalize(); +} + +// execute ///////////////////////////////////////////////////////////////////// +void Application::run(void) +{ + +} diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp new file mode 100644 index 00000000..4246c071 --- /dev/null +++ b/programs/Hadrons/Application.hpp @@ -0,0 +1,47 @@ +/* + * Application.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#ifndef Hadrons_Application_hpp_ +#define Hadrons_Application_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Main program manager * + ******************************************************************************/ +class Application +{ +public: + // constructor + Application(int argc, char *argv[]); + // destructor + virtual ~Application(void); + // execute + void run(void); +private: + void parseParameters(void); +private: + std::string parameterFileName_; +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Application_hpp_ diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc new file mode 100644 index 00000000..aea2f7c1 --- /dev/null +++ b/programs/Hadrons/Global.cc @@ -0,0 +1,31 @@ +/* + * Application.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#include + +using namespace std; +using namespace Grid; +using namespace Hadrons; + +HadronsLogger Hadrons::HadronsLogError(1,"Error"); +HadronsLogger Hadrons::HadronsLogWarning(1,"Warning"); +HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); +HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); + + diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp new file mode 100644 index 00000000..12e8158f --- /dev/null +++ b/programs/Hadrons/Global.hpp @@ -0,0 +1,47 @@ +/* + * Globals.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * LatCore 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 3 of the License, or + * (at your option) any later version. + * + * LatCore 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 LatCore. If not, see . + */ + +#ifndef Hadrons_Global_hpp_ +#define Hadrons_Global_hpp_ + +#include + +#define BEGIN_HADRONS_NAMESPACE \ +namespace Hadrons {\ +using namespace Grid; +#define END_HADRONS_NAMESPACE } + +BEGIN_HADRONS_NAMESPACE + +class HadronsLogger: public Logger +{ +public: + HadronsLogger(int on, std::string nm): Logger("Hadrons", on, nm){}; +}; + +#define LOG(channel) std::cout << HadronsLog##channel + +extern HadronsLogger HadronsLogError; +extern HadronsLogger HadronsLogWarning; +extern HadronsLogger HadronsLogMessage; +extern HadronsLogger HadronsLogDebug; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Global_hpp_ diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc new file mode 100644 index 00000000..6788c237 --- /dev/null +++ b/programs/Hadrons/Hadrons.cc @@ -0,0 +1,32 @@ +/* + * Hadrons.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * LatCore 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 3 of the License, or + * (at your option) any later version. + * + * LatCore 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 LatCore. If not, see . + */ + +#include + +using namespace std; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + Application application(argc, argv); + + application.run(); + + return EXIT_SUCCESS; +} diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am new file mode 100644 index 00000000..870b0747 --- /dev/null +++ b/programs/Hadrons/Makefile.am @@ -0,0 +1,13 @@ +AM_CXXFLAGS = -I$(top_srcdir)/programs -I$(top_srcdir)/lib +AM_LDFLAGS = -L$(top_builddir)/lib + +bin_PROGRAMS = Hadrons + +Hadrons_SOURCES = \ + Application.cc \ + Application.hpp \ + Global.hpp \ + Global.cc \ + Hadrons.cc + +Hadrons_LDADD = -lGrid diff --git a/programs/Makefile.am b/programs/Makefile.am new file mode 100644 index 00000000..d8c2b675 --- /dev/null +++ b/programs/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = Hadrons \ No newline at end of file From c4e22025503a22261e92c3a3193eac3b85075cb0 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 5 Nov 2015 14:28:14 +0000 Subject: [PATCH 002/106] First graph class implementation and test --- programs/Hadrons/Application.cc | 31 ++++ programs/Hadrons/Application.hpp | 3 +- programs/Hadrons/Environment.cc | 31 ++++ programs/Hadrons/Environment.hpp | 43 +++++ programs/Hadrons/Global.hpp | 6 + programs/Hadrons/Graph.hpp | 299 +++++++++++++++++++++++++++++++ programs/Hadrons/Make.inc | 4 + 7 files changed, 416 insertions(+), 1 deletion(-) create mode 100644 programs/Hadrons/Environment.cc create mode 100644 programs/Hadrons/Environment.hpp create mode 100644 programs/Hadrons/Graph.hpp create mode 100644 programs/Hadrons/Make.inc diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 6fea55d5..5cbd1baa 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -18,6 +18,7 @@ */ #include +#include using namespace std; using namespace Grid; @@ -53,6 +54,36 @@ Application::~Application(void) // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) +{ + Graph g; + + cout << g << endl; + g.addEdge("A", "B"); + g.addEdge("B", "D"); + g.addEdge("D", "E"); + g.addEdge("E", "C"); + g.addEdge("C", "A"); + g.addEdge("Z", "Y"); + g.addEdge("Z", "W"); + g.addEdge("Z", "R"); + g.addEdge("W", "R"); + auto v = g.getAdjacentVertices("B"); + for (auto &s: v) + { + cout << s << " "; + } + cout << endl; + cout << g << endl; + g.depthFirstSearch(); + g.removedMarked(); + cout << g << endl; + g.depthFirstSearch(); + g.removedMarked(); + cout << g << endl; +} + +// parse parameter file //////////////////////////////////////////////////////// +void Application::parseParameterFile(void) { } diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 4246c071..deb1160f 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -37,7 +37,8 @@ public: // execute void run(void); private: - void parseParameters(void); + // parse parameter file + void parseParameterFile(void); private: std::string parameterFileName_; }; diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc new file mode 100644 index 00000000..bf95b175 --- /dev/null +++ b/programs/Hadrons/Environment.cc @@ -0,0 +1,31 @@ +/* + * Environment.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#include + +using namespace std; +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** + * Environment implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +Environment::Environment(void) +{} diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp new file mode 100644 index 00000000..205f0aa0 --- /dev/null +++ b/programs/Hadrons/Environment.hpp @@ -0,0 +1,43 @@ +/* + * Environment.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#ifndef Hadrons_Environment_hpp_ +#define Hadrons_Environment_hpp_ + +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Global environment * + ******************************************************************************/ +// TODO: make it a singleton +class Environment +{ +public: + // constructor + Environment(void); + // destructor + virtual ~Environment(void) = default; +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Environment_hpp_ diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 12e8158f..44c395db 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -21,6 +21,7 @@ #define Hadrons_Global_hpp_ #include +#include #define BEGIN_HADRONS_NAMESPACE \ namespace Hadrons {\ @@ -36,6 +37,11 @@ public: }; #define LOG(channel) std::cout << HadronsLog##channel +#define HADRON_ERROR(msg)\ +LOG(Error) << msg << std::endl;\ +abort(); + +#define DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl; extern HadronsLogger HadronsLogError; extern HadronsLogger HadronsLogWarning; diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp new file mode 100644 index 00000000..802812c7 --- /dev/null +++ b/programs/Hadrons/Graph.hpp @@ -0,0 +1,299 @@ +/* + * Graph.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#ifndef Hadrons_Graph_hpp_ +#define Hadrons_Graph_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Oriented graph class * + ******************************************************************************/ +// I/O for edges +template +std::ostream & operator<<(std::ostream &out, const std::pair &e) +{ + out << "\"" << e.first << "\" -> \"" << e.second << "\""; + + return out; +} + +// main class +template +class Graph +{ +public: + typedef std::pair Edge; +public: + // constructor + Graph(void) = default; + // destructor + virtual ~Graph(void) = default; + // access + void addVertex(const T &value); + void addEdge(const Edge &e); + void addEdge(const T &start, const T &end); + void removeVertex(const T &value); + void removeEdge(const Edge &e); + void removeEdge(const T &start, const T &end); + // tests + bool gotValue(const T &value) const; + // graph topological manipulations + std::vector getAdjacentVertices(const T &value) const; + std::vector> getConnectedComponents(void) const; + // I/O + friend std::ostream & operator<<(std::ostream &out, const Graph &g) + { + out << "{"; + for (auto &e: g.edgeSet_) + { + out << e << ", "; + } + if (g.edgeSet_.size() != 0) + { + out << "\b\b"; + } + out << "}"; + + return out; + } +public: + // vertex marking + void mark(const T &value, const bool doMark = true); + void unmark(const T &value); + bool isMarked(const T &value) const; + // prune marked/unmarked vertices + void removedMarked(const bool isMarked = true); + void removedUnmarked(void); + // depth-first search marking + void depthFirstSearch(void); + void depthFirstSearch(const T &root); +private: + std::map isMarked_; + std::set edgeSet_; +}; + +/****************************************************************************** + * template implementation * + ******************************************************************************/ +// access ////////////////////////////////////////////////////////////////////// +template +void Graph::addVertex(const T &value) +{ + isMarked_[value] = false; +} + +template +void Graph::addEdge(const Edge &e) +{ + addVertex(e.first); + addVertex(e.second); + edgeSet_.insert(e); +} + +template +void Graph::addEdge(const T &start, const T &end) +{ + addEdge(Edge(start, end)); +} + +template +void Graph::removeVertex(const T &value) +{ + // remove vertex from the mark table + auto vIt = isMarked_.find(value); + + if (vIt != isMarked_.end()) + { + isMarked_.erase(vIt); + } + else + { + HADRON_ERROR("vertex " << value << " does not exists"); + } + + // remove all edges containing the vertex + auto pred = [&value](const Edge &e) + { + return ((e.first == value) or (e.second == value)); + }; + auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + + while (eIt != edgeSet_.end()) + { + edgeSet_.erase(eIt); + eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + } +} + +template +void Graph::removeEdge(const Edge &e) +{ + auto eIt = edgeSet_.find(e); + + if (eIt != edgeSet_.end()) + { + edgeSet_.erase(eIt); + } + else + { + HADRON_ERROR("edge " << e << " does not exists"); + } +} + +template +void Graph::removeEdge(const T &start, const T &end) +{ + removeEdge(Edge(start, end)); +} + +// tests /////////////////////////////////////////////////////////////////////// +template +bool Graph::gotValue(const T &value) const +{ + try + { + isMarked_.at(value); + } + catch (std::out_of_range &) + { + return false; + } + + return true; +} + +// vertex marking ////////////////////////////////////////////////////////////// +template +void Graph::mark(const T &value, const bool doMark) +{ + try + { + isMarked_.at(value) = doMark; + } + catch (std::out_of_range &) + { + HADRON_ERROR("vertex " << value << " does not exists"); + } +} + +template +void Graph::unmark(const T &value) +{ + mark(value, false); +} + +template +bool Graph::isMarked(const T &value) const +{ + try + { + return isMarked_.at(value); + } + catch (std::out_of_range &) + { + HADRON_ERROR("vertex " << value << " does not exists"); + + return false; + } +} + +// prune marked/unmarked vertices ////////////////////////////////////////////// +template +void Graph::removedMarked(const bool isMarked) +{ + auto isMarkedCopy = isMarked_; + + for (auto &v: isMarkedCopy) + { + if (v.second == isMarked) + { + removeVertex(v.first); + } + } +} + +template +void Graph::removedUnmarked(void) +{ + removedMarked(false); +} + +// depth-first search marking ////////////////////////////////////////////////// +template +void Graph::depthFirstSearch(void) +{ + depthFirstSearch(isMarked_.begin()->first); +} + +template +void Graph::depthFirstSearch(const T &root) +{ + std::vector adjacentVertex; + + mark(root); + adjacentVertex = getAdjacentVertices(root); + for (auto &v: adjacentVertex) + { + if (!isMarked(v)) + { + depthFirstSearch(v); + } + } +} + +// graph topological manipulations ///////////////////////////////////////////// +template +std::vector Graph::getAdjacentVertices(const T &value) const +{ + std::vector adjacentVertex; + + auto pred = [&value](const Edge &e) + { + return ((e.first == value) or (e.second == value)); + }; + auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + + while (eIt != edgeSet_.end()) + { + if (eIt->first == value) + { + adjacentVertex.push_back((*eIt).second); + } + else if (eIt->second == value) + { + adjacentVertex.push_back((*eIt).first); + } + eIt = find_if(++eIt, edgeSet_.end(), pred); + } + + return adjacentVertex; +} + +template +std::vector> Graph::getConnectedComponents(void) const +{ + +} + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Graph_hpp_ diff --git a/programs/Hadrons/Make.inc b/programs/Hadrons/Make.inc new file mode 100644 index 00000000..13c13c4e --- /dev/null +++ b/programs/Hadrons/Make.inc @@ -0,0 +1,4 @@ +bin_PROGRAMS = Hadrons + +Hadrons_SOURCES = Hadrons.cc +Hadrons_LDADD = -lGrid From 6f090e22c0da75e7447edafc82adaec5d123e263 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 2 Dec 2015 19:33:34 +0000 Subject: [PATCH 003/106] Hadrons: graph topological sort --- programs/Hadrons/Application.cc | 29 +++-- programs/Hadrons/Global.hpp | 1 + programs/Hadrons/Graph.hpp | 203 +++++++++++++++++++++++++++++--- 3 files changed, 205 insertions(+), 28 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 5cbd1baa..923bd0eb 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -57,29 +57,32 @@ void Application::run(void) { Graph g; - cout << g << endl; g.addEdge("A", "B"); g.addEdge("B", "D"); g.addEdge("D", "E"); g.addEdge("E", "C"); - g.addEdge("C", "A"); g.addEdge("Z", "Y"); g.addEdge("Z", "W"); g.addEdge("Z", "R"); g.addEdge("W", "R"); - auto v = g.getAdjacentVertices("B"); - for (auto &s: v) + g.addEdge("U", "I"); + + cout << g << endl; + auto vec = g.getConnectedComponents(); + for (auto &h: vec) { - cout << s << " "; + cout << h << endl; + } + for (auto &h: vec) + { + auto top = h.topoSort(); + while (!top.empty()) + { + cout << top.top() << " "; + top.pop(); + } + cout << endl; } - cout << endl; - cout << g << endl; - g.depthFirstSearch(); - g.removedMarked(); - cout << g << endl; - g.depthFirstSearch(); - g.removedMarked(); - cout << g << endl; } // parse parameter file //////////////////////////////////////////////////////// diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 44c395db..3b90b7ed 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -22,6 +22,7 @@ #include #include +#include #define BEGIN_HADRONS_NAMESPACE \ namespace Hadrons {\ diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 802812c7..e96c22b9 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -48,17 +48,22 @@ public: // destructor virtual ~Graph(void) = default; // access - void addVertex(const T &value); - void addEdge(const Edge &e); - void addEdge(const T &start, const T &end); - void removeVertex(const T &value); - void removeEdge(const Edge &e); - void removeEdge(const T &start, const T &end); + void addVertex(const T &value); + void addEdge(const Edge &e); + void addEdge(const T &start, const T &end); + void removeVertex(const T &value); + void removeEdge(const Edge &e); + void removeEdge(const T &start, const T &end); + unsigned int size(void) const; // tests bool gotValue(const T &value) const; // graph topological manipulations std::vector getAdjacentVertices(const T &value) const; + std::vector getChildren(const T &value) const; + std::vector getParents(const T &value) const; + std::vector getRoots(void) const; std::vector> getConnectedComponents(void) const; + std::stack topoSort(void); // I/O friend std::ostream & operator<<(std::ostream &out, const Graph &g) { @@ -75,14 +80,18 @@ public: return out; } -public: +private: // vertex marking - void mark(const T &value, const bool doMark = true); - void unmark(const T &value); - bool isMarked(const T &value) const; + void mark(const T &value, const bool doMark = true); + void markAll(const bool doMark = true); + void unmark(const T &value); + void unmarkAll(void); + bool isMarked(const T &value) const; + const T * getFirstMarked(const bool isMarked = true) const; + const T * getFirstUnmarked(void) const; // prune marked/unmarked vertices - void removedMarked(const bool isMarked = true); - void removedUnmarked(void); + void removeMarked(const bool isMarked = true); + void removeUnmarked(void); // depth-first search marking void depthFirstSearch(void); void depthFirstSearch(const T &root); @@ -165,6 +174,12 @@ void Graph::removeEdge(const T &start, const T &end) removeEdge(Edge(start, end)); } +template +unsigned int Graph::size(void) const +{ + return isMarked_.size(); +} + // tests /////////////////////////////////////////////////////////////////////// template bool Graph::gotValue(const T &value) const @@ -195,12 +210,27 @@ void Graph::mark(const T &value, const bool doMark) } } +template +void Graph::markAll(const bool doMark) +{ + for (auto &v: isMarked_) + { + mark(v.first, doMark); + } +} + template void Graph::unmark(const T &value) { mark(value, false); } +template +void Graph::unmarkAll(void) +{ + markAll(false); +} + template bool Graph::isMarked(const T &value) const { @@ -216,9 +246,34 @@ bool Graph::isMarked(const T &value) const } } +template +const T * Graph::getFirstMarked(const bool isMarked) const +{ + auto pred = [&isMarked](const std::pair &v) + { + return (v.second == isMarked); + }; + auto vIt = std::find_if(isMarked_.begin(), isMarked_.end(), pred); + + if (vIt != isMarked_.end()) + { + return &(vIt->first); + } + else + { + return nullptr; + } +} + +template +const T * Graph::getFirstUnmarked(void) const +{ + return getFirstMarked(false); +} + // prune marked/unmarked vertices ////////////////////////////////////////////// template -void Graph::removedMarked(const bool isMarked) +void Graph::removeMarked(const bool isMarked) { auto isMarkedCopy = isMarked_; @@ -232,9 +287,9 @@ void Graph::removedMarked(const bool isMarked) } template -void Graph::removedUnmarked(void) +void Graph::removeUnmarked(void) { - removedMarked(false); + removeMarked(false); } // depth-first search marking ////////////////////////////////////////////////// @@ -288,10 +343,128 @@ std::vector Graph::getAdjacentVertices(const T &value) const return adjacentVertex; } +template +std::vector Graph::getChildren(const T &value) const +{ + std::vector child; + + auto pred = [&value](const Edge &e) + { + return (e.first == value); + }; + auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + + while (eIt != edgeSet_.end()) + { + child.push_back((*eIt).second); + eIt = find_if(++eIt, edgeSet_.end(), pred); + } + + return child; +} + +template +std::vector Graph::getParents(const T &value) const +{ + std::vector parent; + + auto pred = [&value](const Edge &e) + { + return (e.second == value); + }; + auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + + while (eIt != edgeSet_.end()) + { + parent.push_back((*eIt).first); + eIt = find_if(++eIt, edgeSet_.end(), pred); + } + + return parent; +} + +template +std::vector Graph::getRoots(void) const +{ + std::vector root; + + for (auto &v: isMarked_) + { + auto parent = getParents(v.first); + + if (parent.size() == 0) + { + root.push_back(v.first); + } + } + + return root; +} + template std::vector> Graph::getConnectedComponents(void) const { + std::vector> res; + Graph copy(*this); + while (copy.size() > 0) + { + copy.depthFirstSearch(); + res.push_back(copy); + res.back().removeUnmarked(); + res.back().unmarkAll(); + copy.removeMarked(); + copy.unmarkAll(); + } + + return res; +} + +// topological sort using Kahn's algorithm +template +std::stack Graph::topoSort(void) +{ + std::stack res; + const T *vPt; + std::map tmpMarked(isMarked_); + + // visit function + std::function visit = [&](const T &v) + { + if (tmpMarked.at(v)) + { + HADRON_ERROR("cannot topologically sort a cyclic graph"); + } + if (!this->isMarked(v)) + { + std::vector child = this->getChildren(v); + + tmpMarked[v] = true; + for (auto &c: child) + { + visit(c); + } + this->mark(v); + tmpMarked[v] = false; + res.push(v); + } + }; + + // reset temporary marks + for (auto &v: tmpMarked) + { + tmpMarked.at(v.first) = false; + } + // loop on unmarked vertices + vPt = getFirstUnmarked(); + while (vPt) + { + visit(*vPt); + vPt = getFirstUnmarked(); + } + unmarkAll(); + + return res; } END_HADRONS_NAMESPACE From bb195607ab067a8ad26e3138282111d737050205 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 2 Dec 2015 19:40:11 +0000 Subject: [PATCH 004/106] Hadrons: fix in topological sort algorithm name --- programs/Hadrons/Graph.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index e96c22b9..15eba21a 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -420,7 +420,7 @@ std::vector> Graph::getConnectedComponents(void) const return res; } -// topological sort using Kahn's algorithm +// topological sort using Tarjan's algorithm template std::stack Graph::topoSort(void) { From 20ce7e0270d982fd6d11171f21a72a916795546c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 7 Dec 2015 15:46:36 +0000 Subject: [PATCH 005/106] Hadrons: algorithm to determine all possible topological ordering --- programs/Hadrons/Application.cc | 15 +++-- programs/Hadrons/Graph.hpp | 113 ++++++++++++++++++++++++++++---- 2 files changed, 111 insertions(+), 17 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 923bd0eb..8f132056 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -59,6 +59,8 @@ void Application::run(void) g.addEdge("A", "B"); g.addEdge("B", "D"); + g.addEdge("B", "X1"); + g.addEdge("X1", "X2"); g.addEdge("D", "E"); g.addEdge("E", "C"); g.addEdge("Z", "Y"); @@ -75,13 +77,16 @@ void Application::run(void) } for (auto &h: vec) { - auto top = h.topoSort(); - while (!top.empty()) + auto top = h.allTopoSort(); + for (auto &s: top) { - cout << top.top() << " "; - top.pop(); + for (auto &v: s) + { + cout << v << " "; + } + cout << endl; } - cout << endl; + cout << "--------" << endl; } } diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 15eba21a..14077ed0 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -58,12 +58,13 @@ public: // tests bool gotValue(const T &value) const; // graph topological manipulations - std::vector getAdjacentVertices(const T &value) const; - std::vector getChildren(const T &value) const; - std::vector getParents(const T &value) const; - std::vector getRoots(void) const; - std::vector> getConnectedComponents(void) const; - std::stack topoSort(void); + std::vector getAdjacentVertices(const T &value) const; + std::vector getChildren(const T &value) const; + std::vector getParents(const T &value) const; + std::vector getRoots(void) const; + std::vector> getConnectedComponents(void) const; + std::vector topoSort(void); + std::vector> allTopoSort(void); // I/O friend std::ostream & operator<<(std::ostream &out, const Graph &g) { @@ -96,8 +97,8 @@ private: void depthFirstSearch(void); void depthFirstSearch(const T &root); private: - std::map isMarked_; - std::set edgeSet_; + std::map isMarked_; + std::set edgeSet_; }; /****************************************************************************** @@ -422,12 +423,13 @@ std::vector> Graph::getConnectedComponents(void) const // topological sort using Tarjan's algorithm template -std::stack Graph::topoSort(void) +std::vector Graph::topoSort(void) { - std::stack res; + std::stack buf; + std::vector res; const T *vPt; std::map tmpMarked(isMarked_); - + // visit function std::function visit = [&](const T &v) { @@ -446,7 +448,7 @@ std::stack Graph::topoSort(void) } this->mark(v); tmpMarked[v] = false; - res.push(v); + buf.push(v); } }; @@ -455,6 +457,7 @@ std::stack Graph::topoSort(void) { tmpMarked.at(v.first) = false; } + // loop on unmarked vertices vPt = getFirstUnmarked(); while (vPt) @@ -464,6 +467,92 @@ std::stack Graph::topoSort(void) } unmarkAll(); + // create result vector + while (!buf.empty()) + { + res.push_back(buf.top()); + buf.pop(); + } + + return res; +} + +// generate all possible topological sorts +// Y. L. Varol & D. Rotem, Comput. J. 24(1), pp. 83–84, 1981 +// http://comjnl.oupjournals.org/cgi/doi/10.1093/comjnl/24.1.83 +template +std::vector> Graph::allTopoSort(void) +{ + std::vector> res; + std::map> iMat; + + // create incidence matrix + for (auto &v1: isMarked_) + for (auto &v2: isMarked_) + { + iMat[v1.first][v2.first] = false; + } + for (auto &v: isMarked_) + { + auto cVec = getChildren(v.first); + + for (auto &c: cVec) + { + iMat[v.first][c] = true; + } + } + + // generate initial topological sort + res.push_back(topoSort()); + + // generate all other topological sorts by permutation + std::vector p = res[0]; + const unsigned int n = size(); + std::vector loc(n); + unsigned int i, k, k1; + T obj_k, obj_k1; + bool isFinal; + + for (unsigned int j = 0; j < n; ++j) + { + loc[j] = j; + } + i = 0; + while (i < n-1) + { + k = loc[i]; + k1 = k + 1; + obj_k = p[k]; + if (k1 >= n) + { + isFinal = true; + obj_k1 = obj_k; + } + else + { + isFinal = false; + obj_k1 = p[k1]; + } + if (iMat[res[0][i]][obj_k1] or isFinal) + { + for (unsigned int l = k; l >= i + 1; --l) + { + p[l] = p[l-1]; + } + p[i] = obj_k; + loc[i] = i; + i++; + } + else + { + p[k] = obj_k1; + p[k1] = obj_k; + loc[i] = k1; + i = 0; + res.push_back(p); + } + } + return res; } From d4db009a5804a28a1ec9dac15f888d131cc8c34d Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 7 Dec 2015 18:26:38 +0000 Subject: [PATCH 006/106] Hadrons: starting scheduler implementation --- programs/Hadrons/Application.cc | 79 ++++++++++++++++++------------- programs/Hadrons/Application.hpp | 4 ++ programs/Hadrons/Graph.hpp | 32 +++++++++++++ programs/Hadrons/InputObjects.hpp | 60 +++++++++++++++++++++++ 4 files changed, 142 insertions(+), 33 deletions(-) create mode 100644 programs/Hadrons/InputObjects.hpp diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 8f132056..f0e6f6a4 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -55,43 +55,56 @@ Application::~Application(void) // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { - Graph g; - - g.addEdge("A", "B"); - g.addEdge("B", "D"); - g.addEdge("B", "X1"); - g.addEdge("X1", "X2"); - g.addEdge("D", "E"); - g.addEdge("E", "C"); - g.addEdge("Z", "Y"); - g.addEdge("Z", "W"); - g.addEdge("Z", "R"); - g.addEdge("W", "R"); - g.addEdge("U", "I"); - - cout << g << endl; - auto vec = g.getConnectedComponents(); - for (auto &h: vec) - { - cout << h << endl; - } - for (auto &h: vec) - { - auto top = h.allTopoSort(); - for (auto &s: top) - { - for (auto &v: s) - { - cout << v << " "; - } - cout << endl; - } - cout << "--------" << endl; - } + parseParameterFile(); + schedule(); } // parse parameter file //////////////////////////////////////////////////////// void Application::parseParameterFile(void) { + XmlReader reader(parameterFileName_); + LOG(Message) << "Reading '" << parameterFileName_ << "'..." << endl; + read(reader, "parameters", parameters_); +} + +// schedule computation //////////////////////////////////////////////////////// +void Application::schedule(void) +{ + Graph moduleGraph; + + LOG(Message) << "Scheduling computation..." << endl; + for (auto &m: parameters_.modules) + { + for (auto &p: m.in) + { + moduleGraph.addEdge(p, m.name); + } + } + + vector> con = moduleGraph.getConnectedComponents(); + + LOG(Message) << "Program:" << endl; + LOG(Message) << " #segments: " << con.size() << endl; + for (unsigned int i = 0; i < con.size(); ++i) + { + vector> t = con[i].allTopoSort(); + auto m = makeDependencyMatrix(t); + + for (auto &v: t[0]) + { + cout << v << " "; + } + cout << endl; + for (auto &v1: t[0]) + { + for (auto &v2: t[0]) + { + cout << m[v1][v2] << " "; + } + cout << endl; + } + + LOG(Message) << " segment " << i << ":" << endl; + } } diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index deb1160f..670c644e 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -21,6 +21,7 @@ #define Hadrons_Application_hpp_ #include +#include BEGIN_HADRONS_NAMESPACE @@ -39,8 +40,11 @@ public: private: // parse parameter file void parseParameterFile(void); + // schedule computation + void schedule(void); private: std::string parameterFileName_; + Parameters parameters_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 14077ed0..a2747c1a 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -101,6 +101,11 @@ private: std::set edgeSet_; }; +// build depedency matrix from topological sorts +template +std::map> +makeDependencyMatrix(const std::vector> &topSort); + /****************************************************************************** * template implementation * ******************************************************************************/ @@ -556,6 +561,33 @@ std::vector> Graph::allTopoSort(void) return res; } +// build depedency matrix from topological sorts /////////////////////////////// +template +std::map> +makeDependencyMatrix(const std::vector> &topSort) +{ + std::map> m; + const std::vector &vList = topSort[0]; + + for (auto &v1: vList) + for (auto &v2: vList) + { + bool dep = true; + + for (auto &t: topSort) + { + auto i1 = std::find(t.begin(), t.end(), v1); + auto i2 = std::find(t.begin(), t.end(), v2); + + dep = dep and (i1 - i2 > 0); + if (!dep) break; + } + m[v1][v2] = dep; + } + + return m; +} + END_HADRONS_NAMESPACE #endif // Hadrons_Graph_hpp_ diff --git a/programs/Hadrons/InputObjects.hpp b/programs/Hadrons/InputObjects.hpp new file mode 100644 index 00000000..d18615fa --- /dev/null +++ b/programs/Hadrons/InputObjects.hpp @@ -0,0 +1,60 @@ +/* + * InputObjects.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#ifndef Hadrons_InputObjects_hpp_ +#define Hadrons_InputObjects_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Serializable input classes * + ******************************************************************************/ +class Module: Serializable +{ +public: + // constructor + Module(void) = default; + // destructor + virtual ~Module(void) = default; + // serializable members + GRID_DECL_CLASS_MEMBERS(Module, + std::string , name, + std::vector, in + ); +}; + +class Parameters: Serializable +{ +public: + // constructor + Parameters(void) = default; + // destructor + virtual ~Parameters(void) = default; + // serializable members + GRID_DECL_CLASS_MEMBERS(Parameters, + std::vector, latticeSize, + std::vector , modules + ); +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_InputObjects_hpp_ From 76c78f04e232b9daba647cd30fc8781413cc5178 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 23 Dec 2015 14:21:35 +0000 Subject: [PATCH 007/106] Hadrons: first complete prototype for run loop --- programs/Hadrons/Application.cc | 101 ++++++++++++++---- programs/Hadrons/Application.hpp | 46 +++++++- programs/Hadrons/CMeson.cc | 65 +++++++++++ programs/Hadrons/CMeson.hpp | 65 +++++++++++ programs/Hadrons/Environment.cc | 1 + programs/Hadrons/Environment.hpp | 8 +- programs/Hadrons/Global.hpp | 13 +++ programs/Hadrons/MQuark.cc | 63 +++++++++++ .../Hadrons/{InputObjects.hpp => MQuark.hpp} | 54 +++++----- programs/Hadrons/Makefile.am | 13 ++- programs/Hadrons/Module.cc | 38 +++++++ programs/Hadrons/Module.hpp | 72 +++++++++++++ programs/Hadrons/ModuleFactory.cc | 70 ++++++++++++ programs/Hadrons/ModuleFactory.hpp | 51 +++++++++ 14 files changed, 600 insertions(+), 60 deletions(-) create mode 100644 programs/Hadrons/CMeson.cc create mode 100644 programs/Hadrons/CMeson.hpp create mode 100644 programs/Hadrons/MQuark.cc rename programs/Hadrons/{InputObjects.hpp => MQuark.hpp} (52%) create mode 100644 programs/Hadrons/Module.cc create mode 100644 programs/Hadrons/Module.hpp create mode 100644 programs/Hadrons/ModuleFactory.cc create mode 100644 programs/Hadrons/ModuleFactory.hpp diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index f0e6f6a4..c21dba5d 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -29,6 +29,8 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// Application::Application(int argc, char *argv[]) +: env_(Environment::getInstance()) +, modFactory_(ModuleFactory::getInstance()) { if (argc < 2) { @@ -43,6 +45,12 @@ Application::Application(int argc, char *argv[]) HadronsLogMessage.Active(GridLogMessage.isActive()); HadronsLogDebug.Active(GridLogDebug.isActive()); LOG(Message) << "Grid initialized" << endl; + LOG(Message) << "Modules available:" << endl; + auto list = modFactory_.getModuleList(); + for (auto &m: list) + { + LOG(Message) << " " << m << endl; + } } // destructor ////////////////////////////////////////////////////////////////// @@ -57,15 +65,40 @@ void Application::run(void) { parseParameterFile(); schedule(); + configLoop(); } // parse parameter file //////////////////////////////////////////////////////// +class ModuleId: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(ModuleId, + std::string, name, + std::string, type); +}; + void Application::parseParameterFile(void) { XmlReader reader(parameterFileName_); + ModuleId id; LOG(Message) << "Reading '" << parameterFileName_ << "'..." << endl; - read(reader, "parameters", parameters_); + read(reader, "parameters", par_); + push(reader, "modules"); + push(reader, "module"); + do + { + read(reader, "id", id); + module_[id.name] = modFactory_.create(id.type, id.name); + module_[id.name]->parseParameters(reader, "options"); + vector output = module_[id.name]->getOutput(); + for (auto &n: output) + { + associatedModule_[n] = id.name; + } + } while (reader.nextElement("module")); + pop(reader); + pop(reader); } // schedule computation //////////////////////////////////////////////////////// @@ -74,37 +107,63 @@ void Application::schedule(void) Graph moduleGraph; LOG(Message) << "Scheduling computation..." << endl; - for (auto &m: parameters_.modules) + + // create dependency graph + for (auto &m: module_) { - for (auto &p: m.in) + vector input = m.second->getInput(); + for (auto &n: input) { - moduleGraph.addEdge(p, m.name); + try + { + moduleGraph.addEdge(associatedModule_.at(n), m.first); + } + catch (out_of_range &) + { + HADRON_ERROR("unknown object '" + n + "'"); + } } } - vector> con = moduleGraph.getConnectedComponents(); + // topological sort + map> m; + unsigned int k = 0; + vector> con = moduleGraph.getConnectedComponents(); LOG(Message) << "Program:" << endl; - LOG(Message) << " #segments: " << con.size() << endl; for (unsigned int i = 0; i < con.size(); ++i) { vector> t = con[i].allTopoSort(); - auto m = makeDependencyMatrix(t); - - for (auto &v: t[0]) + + m = makeDependencyMatrix(t); + for (unsigned int j = 0; j < t[0].size(); ++j) { - cout << v << " "; + program_.push_back(t[0][j]); + LOG(Message) << setw(4) << right << k << ": " + << program_[k] << endl; + k++; } - cout << endl; - for (auto &v1: t[0]) - { - for (auto &v2: t[0]) - { - cout << m[v1][v2] << " "; - } - cout << endl; - } - - LOG(Message) << " segment " << i << ":" << endl; + } +} + +// program execution /////////////////////////////////////////////////////////// +void Application::configLoop(void) +{ + auto range = par_.configs.range; + + for (unsigned int t = range.start; t < range.end; t += range.step) + { + LOG(Message) << "Starting measurement for trajectory " << t << endl; + execute(); + } +} + +void Application::execute(void) +{ + for (unsigned int i = 0; i < program_.size(); ++i) + { + LOG(Message) << "Measurement step (" << i+1 << "/" << program_.size() + << ")" << endl; + (*module_[program_[i]])(env_); } } diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 670c644e..71cc0a80 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -21,15 +21,47 @@ #define Hadrons_Application_hpp_ #include -#include +#include +#include + +namespace Grid { + GRID_SERIALIZABLE_ENUM(ConfigType, undef, load, 1, unit, 2, gen, 3); +} BEGIN_HADRONS_NAMESPACE +class TrajRange: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange, + unsigned int, start, + unsigned int, end, + unsigned int, step); +}; + +class ConfigPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(ConfigPar, + std::string, ioStem, + TrajRange, range); +}; + +class GlobalPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, + std::vector, latticeSize, + ConfigPar, configs); +}; + /****************************************************************************** * Main program manager * ******************************************************************************/ class Application { +public: + public: // constructor Application(int argc, char *argv[]); @@ -42,9 +74,17 @@ private: void parseParameterFile(void); // schedule computation void schedule(void); + // program execution + void configLoop(void); + void execute(void); private: - std::string parameterFileName_; - Parameters parameters_; + std::string parameterFileName_; + GlobalPar par_; + Environment &env_; + ModuleFactory &modFactory_; + std::map> module_; + std::map associatedModule_; + std::vector program_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc new file mode 100644 index 00000000..d9fe3547 --- /dev/null +++ b/programs/Hadrons/CMeson.cc @@ -0,0 +1,65 @@ +/* + * CMeson.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#include + +using namespace std; +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** + * CMeson implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +CMeson::CMeson(const string &name) +: Module(name) +{} + +// parse parameters //////////////////////////////////////////////////////////// +void CMeson::parseParameters(XmlReader &reader, const std::string &name) +{ + read(reader, name, par_); +} + +// dependency relation ///////////////////////////////////////////////////////// +vector CMeson::getInput(void) +{ + vector input = {par_.q1, par_.q2}; + + return input; +} + +vector CMeson::getOutput(void) +{ + vector output = {getName()}; + + return output; +} + +// memory footprint //////////////////////////////////////////////////////////// +double CMeson::nCreatedProp(void) +{ + return 0.; +} + +// execution /////////////////////////////////////////////////////////////////// +void CMeson::operator()(Environment &env) +{ + LOG(Message) << "computing meson contraction '" << getName() << "'" << endl; +} diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp new file mode 100644 index 00000000..7f13ce9a --- /dev/null +++ b/programs/Hadrons/CMeson.hpp @@ -0,0 +1,65 @@ +/* + * CMeson.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#ifndef Hadrons_CMeson_hpp_ +#define Hadrons_CMeson_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * CMeson * + ******************************************************************************/ +class CMeson: public Module +{ +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, + std::string, q1, + std::string, q2, + std::string, output); + }; +public: + // constructor + CMeson(const std::string &name); + // destructor + virtual ~CMeson(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string &name); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // memory footprint + virtual double nCreatedProp(void); + // execution + virtual void operator()(Environment &env); +private: + Par par_; +}; + +MODULE_REGISTER(CMeson); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_CMeson_hpp_ diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index bf95b175..66dd540e 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -29,3 +29,4 @@ using namespace Hadrons; // constructor ///////////////////////////////////////////////////////////////// Environment::Environment(void) {} + diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 205f0aa0..62da9839 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -21,21 +21,15 @@ #define Hadrons_Environment_hpp_ #include -#include BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Global environment * ******************************************************************************/ -// TODO: make it a singleton class Environment { -public: - // constructor - Environment(void); - // destructor - virtual ~Environment(void) = default; + SINGLETON(Environment); }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 3b90b7ed..2294adef 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -49,6 +49,19 @@ extern HadronsLogger HadronsLogWarning; extern HadronsLogger HadronsLogMessage; extern HadronsLogger HadronsLogDebug; +// singleton pattern +#define SINGLETON(name)\ +public:\ + name(const name &e) = delete;\ + void operator=(const name &e) = delete;\ + static name & getInstance(void)\ + {\ + static name e;\ + return e;\ + }\ +private:\ + name(void); + END_HADRONS_NAMESPACE #endif // Hadrons_Global_hpp_ diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc new file mode 100644 index 00000000..82c46c52 --- /dev/null +++ b/programs/Hadrons/MQuark.cc @@ -0,0 +1,63 @@ +/* + * MQuark.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#include + +using namespace std; +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** + * MQuark implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +MQuark::MQuark(const std::string &name) +: Module(name) +{} + +// parse parameters +void MQuark::parseParameters(XmlReader &reader, const std::string &name) +{ + read(reader, name, par_); +} + +// dependency relation +vector MQuark::getInput(void) +{ + return vector(); +} + +vector MQuark::getOutput(void) +{ + vector out = {getName(), getName() + "_5d"}; + + return out; +} + +// memory footprint +double MQuark::nCreatedProp(void) +{ + return static_cast((par_.Ls > 1) ? par_.Ls + 1 : 1); +} + +// execution +void MQuark::operator()(Environment &env) +{ + LOG(Message) << "computing quark propagator '" << getName() << "'" << endl; +} diff --git a/programs/Hadrons/InputObjects.hpp b/programs/Hadrons/MQuark.hpp similarity index 52% rename from programs/Hadrons/InputObjects.hpp rename to programs/Hadrons/MQuark.hpp index d18615fa..ae1efa12 100644 --- a/programs/Hadrons/InputObjects.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -1,5 +1,5 @@ /* - * InputObjects.hpp, part of Grid + * MQuark.hpp, part of Grid * * Copyright (C) 2015 Antonin Portelli * @@ -17,44 +17,46 @@ * along with Grid. If not, see . */ -#ifndef Hadrons_InputObjects_hpp_ -#define Hadrons_InputObjects_hpp_ +#ifndef Hadrons_MQuark_hpp_ +#define Hadrons_MQuark_hpp_ #include +#include +#include BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * Serializable input classes * + * MQuark * ******************************************************************************/ -class Module: Serializable +class MQuark: public Module { +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, Ls); + }; public: // constructor - Module(void) = default; + MQuark(const std::string &name); // destructor - virtual ~Module(void) = default; - // serializable members - GRID_DECL_CLASS_MEMBERS(Module, - std::string , name, - std::vector, in - ); + virtual ~MQuark(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string &name); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // memory footprint + virtual double nCreatedProp(void); + // execution + virtual void operator()(Environment &env); +private: + Par par_; }; -class Parameters: Serializable -{ -public: - // constructor - Parameters(void) = default; - // destructor - virtual ~Parameters(void) = default; - // serializable members - GRID_DECL_CLASS_MEMBERS(Parameters, - std::vector, latticeSize, - std::vector , modules - ); -}; +MODULE_REGISTER(MQuark); END_HADRONS_NAMESPACE -#endif // Hadrons_InputObjects_hpp_ +#endif // Hadrons_MQuark_hpp_ diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 870b0747..b907f8c8 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -5,9 +5,16 @@ bin_PROGRAMS = Hadrons Hadrons_SOURCES = \ Application.cc \ - Application.hpp \ - Global.hpp \ + Environment.cc \ Global.cc \ - Hadrons.cc + Hadrons.cc \ + Module.cc \ + ModuleFactory.cc + +Hadrons_SOURCES += \ + MQuark.cc + +Hadrons_SOURCES += \ + CMeson.cc Hadrons_LDADD = -lGrid diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc new file mode 100644 index 00000000..be689867 --- /dev/null +++ b/programs/Hadrons/Module.cc @@ -0,0 +1,38 @@ +/* + * Module.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#include + +using namespace std; +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** + * Module implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +Module::Module(const string &name) +: name_(name) +{} + +// access ////////////////////////////////////////////////////////////////////// +string Module::getName(void) const +{ + return name_; +} diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp new file mode 100644 index 00000000..bf82a9e7 --- /dev/null +++ b/programs/Hadrons/Module.hpp @@ -0,0 +1,72 @@ +/* + * Module.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#ifndef Hadrons_Module_hpp_ +#define Hadrons_Module_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +// module registration macro +#define MODULE_REGISTER(mod)\ +class mod##Registrar\ +{\ +public:\ + mod##Registrar(void)\ + {\ + ModuleFactory &modFac = ModuleFactory::getInstance();\ + modFac.registerModule(#mod, [&](const std::string &name)\ + {\ + return std::unique_ptr(new mod(name));\ + });\ + }\ +};\ +static mod##Registrar mod##RegistrarInstance; + +/****************************************************************************** + * Module * + ******************************************************************************/ +class Environment; + +class Module +{ +public: + // constructor + Module(const std::string &name); + // destructor + virtual ~Module(void) = default; + // access + std::string getName(void) const; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string &name) = 0; + // dependency relation + virtual std::vector getInput(void) = 0; + virtual std::vector getOutput(void) = 0; + // memory footprint + virtual double nCreatedProp(void) = 0; + // execution + virtual void operator()(Environment &env) = 0; +private: + std::string name_; +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Module_hpp_ diff --git a/programs/Hadrons/ModuleFactory.cc b/programs/Hadrons/ModuleFactory.cc new file mode 100644 index 00000000..2a87da3a --- /dev/null +++ b/programs/Hadrons/ModuleFactory.cc @@ -0,0 +1,70 @@ +/* + * ModuleFactory.cc, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#include + +using namespace std; +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** + * ModuleFactory implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +ModuleFactory::ModuleFactory(void) +{ +} + +// registration //////////////////////////////////////////////////////////////// +void ModuleFactory::registerModule(const std::string &type, + const FactoryFunc &f) +{ + factory_[type] = f; +} + +// get module list ///////////////////////////////////////////////////////////// +std::vector ModuleFactory::getModuleList(void) const +{ + std::vector list; + + for (auto &f: factory_) + { + list.push_back(f.first); + } + + return list; +} + +// factory ///////////////////////////////////////////////////////////////////// +unique_ptr ModuleFactory::create(const string &type, + const string &name) const +{ + FactoryFunc func; + + try + { + func = factory_.at(type); + } + catch (out_of_range) + { + HADRON_ERROR("module type '" + type + "' unknown"); + } + + return func(name); +} diff --git a/programs/Hadrons/ModuleFactory.hpp b/programs/Hadrons/ModuleFactory.hpp new file mode 100644 index 00000000..822dc8e7 --- /dev/null +++ b/programs/Hadrons/ModuleFactory.hpp @@ -0,0 +1,51 @@ +/* + * ModuleFactory.hpp, part of Grid + * + * Copyright (C) 2015 Antonin Portelli + * + * Grid 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 3 of the License, or + * (at your option) any later version. + * + * Grid 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 Grid. If not, see . + */ + +#ifndef Hadrons_ModuleFactory_hpp_ +#define Hadrons_ModuleFactory_hpp_ + +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * ModuleFactory * + ******************************************************************************/ +class ModuleFactory +{ + SINGLETON(ModuleFactory) +public: + typedef std::function(const std::string &)> + FactoryFunc; +public: + // registration + void registerModule(const std::string &type, const FactoryFunc &f); + // get module list + std::vector getModuleList(void) const; + // factory + std::unique_ptr create(const std::string &type, + const std::string &name) const; +private: + std::map factory_; +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_ModuleFactory_hpp_ From 54eacec2614d0059d50072e21df8978ed37cc6d6 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 23 Dec 2015 14:30:33 +0000 Subject: [PATCH 008/106] Hadrons: namespace std not used anymore in compiled sources --- programs/Hadrons/Application.cc | 46 +++++++++++++++---------------- programs/Hadrons/CMeson.cc | 14 +++++----- programs/Hadrons/Environment.cc | 1 - programs/Hadrons/Global.cc | 1 - programs/Hadrons/Hadrons.cc | 1 - programs/Hadrons/MQuark.cc | 12 ++++---- programs/Hadrons/Module.cc | 5 ++-- programs/Hadrons/ModuleFactory.cc | 7 ++--- 8 files changed, 41 insertions(+), 46 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index c21dba5d..21184667 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -20,7 +20,6 @@ #include #include -using namespace std; using namespace Grid; using namespace Hadrons; @@ -34,9 +33,9 @@ Application::Application(int argc, char *argv[]) { if (argc < 2) { - cerr << "usage: " << argv[0] << " [Grid options]"; - cerr << endl; - exit(EXIT_FAILURE); + std::cerr << "usage: " << argv[0] << " [Grid options]"; + std::cerr << std::endl; + std::exit(EXIT_FAILURE); } parameterFileName_ = argv[1]; Grid_init(&argc, &argv); @@ -44,19 +43,19 @@ Application::Application(int argc, char *argv[]) HadronsLogWarning.Active(GridLogWarning.isActive()); HadronsLogMessage.Active(GridLogMessage.isActive()); HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << endl; - LOG(Message) << "Modules available:" << endl; + LOG(Message) << "Grid initialized" << std::endl; + LOG(Message) << "Modules available:" << std::endl; auto list = modFactory_.getModuleList(); for (auto &m: list) { - LOG(Message) << " " << m << endl; + LOG(Message) << " " << m << std::endl; } } // destructor ////////////////////////////////////////////////////////////////// Application::~Application(void) { - LOG(Message) << "Grid is finalizing now" << endl; + LOG(Message) << "Grid is finalizing now" << std::endl; Grid_finalize(); } @@ -82,7 +81,7 @@ void Application::parseParameterFile(void) XmlReader reader(parameterFileName_); ModuleId id; - LOG(Message) << "Reading '" << parameterFileName_ << "'..." << endl; + LOG(Message) << "Reading '" << parameterFileName_ << "'..." << std::endl; read(reader, "parameters", par_); push(reader, "modules"); push(reader, "module"); @@ -91,7 +90,7 @@ void Application::parseParameterFile(void) read(reader, "id", id); module_[id.name] = modFactory_.create(id.type, id.name); module_[id.name]->parseParameters(reader, "options"); - vector output = module_[id.name]->getOutput(); + std::vector output = module_[id.name]->getOutput(); for (auto &n: output) { associatedModule_[n] = id.name; @@ -104,21 +103,21 @@ void Application::parseParameterFile(void) // schedule computation //////////////////////////////////////////////////////// void Application::schedule(void) { - Graph moduleGraph; + Graph moduleGraph; - LOG(Message) << "Scheduling computation..." << endl; + LOG(Message) << "Scheduling computation..." << std::endl; // create dependency graph for (auto &m: module_) { - vector input = m.second->getInput(); + std::vector input = m.second->getInput(); for (auto &n: input) { try { moduleGraph.addEdge(associatedModule_.at(n), m.first); } - catch (out_of_range &) + catch (std::out_of_range &) { HADRON_ERROR("unknown object '" + n + "'"); } @@ -126,21 +125,21 @@ void Application::schedule(void) } // topological sort - map> m; - unsigned int k = 0; + std::map> m; + unsigned int k = 0; - vector> con = moduleGraph.getConnectedComponents(); - LOG(Message) << "Program:" << endl; + std::vector> con = moduleGraph.getConnectedComponents(); + LOG(Message) << "Program:" << std::endl; for (unsigned int i = 0; i < con.size(); ++i) { - vector> t = con[i].allTopoSort(); + std::vector> t = con[i].allTopoSort(); m = makeDependencyMatrix(t); for (unsigned int j = 0; j < t[0].size(); ++j) { program_.push_back(t[0][j]); - LOG(Message) << setw(4) << right << k << ": " - << program_[k] << endl; + LOG(Message) << std::setw(4) << std::right << k << ": " + << program_[k] << std::endl; k++; } } @@ -153,7 +152,8 @@ void Application::configLoop(void) for (unsigned int t = range.start; t < range.end; t += range.step) { - LOG(Message) << "Starting measurement for trajectory " << t << endl; + LOG(Message) << "Starting measurement for trajectory " << t + << std::endl; execute(); } } @@ -163,7 +163,7 @@ void Application::execute(void) for (unsigned int i = 0; i < program_.size(); ++i) { LOG(Message) << "Measurement step (" << i+1 << "/" << program_.size() - << ")" << endl; + << ")" << std::endl; (*module_[program_[i]])(env_); } } diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index d9fe3547..32febc13 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -19,7 +19,6 @@ #include -using namespace std; using namespace Grid; using namespace Hadrons; @@ -27,7 +26,7 @@ using namespace Hadrons; * CMeson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -CMeson::CMeson(const string &name) +CMeson::CMeson(const std::string &name) : Module(name) {} @@ -38,16 +37,16 @@ void CMeson::parseParameters(XmlReader &reader, const std::string &name) } // dependency relation ///////////////////////////////////////////////////////// -vector CMeson::getInput(void) +std::vector CMeson::getInput(void) { - vector input = {par_.q1, par_.q2}; + std::vector input = {par_.q1, par_.q2}; return input; } -vector CMeson::getOutput(void) +std::vector CMeson::getOutput(void) { - vector output = {getName()}; + std::vector output = {getName()}; return output; } @@ -61,5 +60,6 @@ double CMeson::nCreatedProp(void) // execution /////////////////////////////////////////////////////////////////// void CMeson::operator()(Environment &env) { - LOG(Message) << "computing meson contraction '" << getName() << "'" << endl; + LOG(Message) << "computing meson contraction '" << getName() << "'" + << std::endl; } diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 66dd540e..391f0c04 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -19,7 +19,6 @@ #include -using namespace std; using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc index aea2f7c1..a560d71f 100644 --- a/programs/Hadrons/Global.cc +++ b/programs/Hadrons/Global.cc @@ -19,7 +19,6 @@ #include -using namespace std; using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc index 6788c237..00da4a76 100644 --- a/programs/Hadrons/Hadrons.cc +++ b/programs/Hadrons/Hadrons.cc @@ -19,7 +19,6 @@ #include -using namespace std; using namespace Hadrons; int main(int argc, char *argv[]) diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index 82c46c52..2cc27311 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -19,7 +19,6 @@ #include -using namespace std; using namespace Grid; using namespace Hadrons; @@ -38,14 +37,14 @@ void MQuark::parseParameters(XmlReader &reader, const std::string &name) } // dependency relation -vector MQuark::getInput(void) +std::vector MQuark::getInput(void) { - return vector(); + return std::vector(); } -vector MQuark::getOutput(void) +std::vector MQuark::getOutput(void) { - vector out = {getName(), getName() + "_5d"}; + std::vector out = {getName(), getName() + "_5d"}; return out; } @@ -59,5 +58,6 @@ double MQuark::nCreatedProp(void) // execution void MQuark::operator()(Environment &env) { - LOG(Message) << "computing quark propagator '" << getName() << "'" << endl; + LOG(Message) << "computing quark propagator '" << getName() << "'" + << std::endl; } diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index be689867..5267449c 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -19,7 +19,6 @@ #include -using namespace std; using namespace Grid; using namespace Hadrons; @@ -27,12 +26,12 @@ using namespace Hadrons; * Module implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -Module::Module(const string &name) +Module::Module(const std::string &name) : name_(name) {} // access ////////////////////////////////////////////////////////////////////// -string Module::getName(void) const +std::string Module::getName(void) const { return name_; } diff --git a/programs/Hadrons/ModuleFactory.cc b/programs/Hadrons/ModuleFactory.cc index 2a87da3a..084d272d 100644 --- a/programs/Hadrons/ModuleFactory.cc +++ b/programs/Hadrons/ModuleFactory.cc @@ -19,7 +19,6 @@ #include -using namespace std; using namespace Grid; using namespace Hadrons; @@ -52,8 +51,8 @@ std::vector ModuleFactory::getModuleList(void) const } // factory ///////////////////////////////////////////////////////////////////// -unique_ptr ModuleFactory::create(const string &type, - const string &name) const +std::unique_ptr ModuleFactory::create(const std::string &type, + const std::string &name) const { FactoryFunc func; @@ -61,7 +60,7 @@ unique_ptr ModuleFactory::create(const string &type, { func = factory_.at(type); } - catch (out_of_range) + catch (std::out_of_range) { HADRON_ERROR("module type '" + type + "' unknown"); } From 30146e977c31327a328e328f59f78b888c0da55f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 13 Jan 2016 20:20:43 -0800 Subject: [PATCH 009/106] gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d40d0a86..ce2bf144 100644 --- a/.gitignore +++ b/.gitignore @@ -95,6 +95,7 @@ Thumbs.db # build directory # ################### build/* +build_debug/* # IDE related files # ##################### From 17c43f49acecb40da3b137fb4800f4a0912b3f52 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 13 Jan 2016 20:22:37 -0800 Subject: [PATCH 010/106] Hadrons: application class now take parameter file name as argument --- programs/Hadrons/Application.cc | 18 +++--------------- programs/Hadrons/Application.hpp | 2 +- programs/Hadrons/Hadrons.cc | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 21184667..0fad9c1e 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -27,23 +27,11 @@ using namespace Hadrons; * Application implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -Application::Application(int argc, char *argv[]) -: env_(Environment::getInstance()) +Application::Application(const std::string parameterFileName) +: parameterFileName_(parameterFileName) +, env_(Environment::getInstance()) , modFactory_(ModuleFactory::getInstance()) { - if (argc < 2) - { - std::cerr << "usage: " << argv[0] << " [Grid options]"; - std::cerr << std::endl; - std::exit(EXIT_FAILURE); - } - parameterFileName_ = argv[1]; - Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; LOG(Message) << "Modules available:" << std::endl; auto list = modFactory_.getModuleList(); for (auto &m: list) diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 71cc0a80..7b53af98 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -64,7 +64,7 @@ public: public: // constructor - Application(int argc, char *argv[]); + Application(const std::string parameterFileName); // destructor virtual ~Application(void); // execute diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc index 00da4a76..853de83c 100644 --- a/programs/Hadrons/Hadrons.cc +++ b/programs/Hadrons/Hadrons.cc @@ -23,7 +23,25 @@ using namespace Hadrons; int main(int argc, char *argv[]) { - Application application(argc, argv); + // parse command line + std::string parameterFileName; + + if (argc < 2) + { + std::cerr << "usage: " << argv[0] << " [Grid options]"; + std::cerr << std::endl; + std::exit(EXIT_FAILURE); + } + parameterFileName = argv[1]; + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + + // execution + Application application(parameterFileName); application.run(); From ae682674e0dc1bae84c3a0e9c5225062e031267b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 13 Jan 2016 20:23:51 -0800 Subject: [PATCH 011/106] Hadrons: first full implementation of the scheduler --- programs/Hadrons/Application.cc | 63 ++++++++++++--- programs/Hadrons/Application.hpp | 22 +++--- programs/Hadrons/CMeson.cc | 8 +- programs/Hadrons/CMeson.hpp | 6 +- programs/Hadrons/Environment.cc | 130 ++++++++++++++++++++++++++++++- programs/Hadrons/Environment.hpp | 23 ++++++ programs/Hadrons/Global.hpp | 3 +- programs/Hadrons/Graph.hpp | 24 +++--- programs/Hadrons/MQuark.cc | 14 +++- programs/Hadrons/MQuark.hpp | 7 +- programs/Hadrons/Module.cc | 9 +++ programs/Hadrons/Module.hpp | 10 +-- 12 files changed, 264 insertions(+), 55 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 0fad9c1e..c8c44adc 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -83,6 +83,7 @@ void Application::parseParameterFile(void) { associatedModule_[n] = id.name; } + input_[id.name] = module_[id.name]->getInput(); } while (reader.nextElement("module")); pop(reader); pop(reader); @@ -113,19 +114,35 @@ void Application::schedule(void) } // topological sort - std::map> m; - unsigned int k = 0; + unsigned int k = 0; std::vector> con = moduleGraph.getConnectedComponents(); LOG(Message) << "Program:" << std::endl; for (unsigned int i = 0; i < con.size(); ++i) { std::vector> t = con[i].allTopoSort(); + int memPeak, minMemPeak = -1; + unsigned int bestInd; + bool msg; - m = makeDependencyMatrix(t); - for (unsigned int j = 0; j < t[0].size(); ++j) + env_.dryRun(true); + for (unsigned int p = 0; p < t.size(); ++p) { - program_.push_back(t[0][j]); + msg = HadronsLogMessage.isActive(); + HadronsLogMessage.Active(false); + memPeak = execute(t[p]); + if ((memPeak < minMemPeak) or (minMemPeak < 0)) + { + minMemPeak = memPeak; + bestInd = p; + } + HadronsLogMessage.Active(msg); + env_.freeAll(); + } + env_.dryRun(false); + for (unsigned int j = 0; j < t[bestInd].size(); ++j) + { + program_.push_back(t[bestInd][j]); LOG(Message) << std::setw(4) << std::right << k << ": " << program_[k] << std::endl; k++; @@ -142,16 +159,42 @@ void Application::configLoop(void) { LOG(Message) << "Starting measurement for trajectory " << t << std::endl; - execute(); + execute(program_); + env_.freeAll(); } } -void Application::execute(void) +unsigned int Application::execute(const std::vector &program) { - for (unsigned int i = 0; i < program_.size(); ++i) + unsigned int memPeak = 0; + + for (unsigned int i = 0; i < program.size(); ++i) { - LOG(Message) << "Measurement step (" << i+1 << "/" << program_.size() + LOG(Message) << "Measurement step (" << i+1 << "/" << program.size() << ")" << std::endl; - (*module_[program_[i]])(env_); + (*module_[program[i]])(env_); + LOG(Message) << "allocated propagators: " << env_.nProp() << std::endl; + if (env_.nProp() > memPeak) + { + memPeak = env_.nProp(); + } + for (auto &n: associatedModule_) + { + bool canFree = true; + + for (unsigned int j = i + 1; j < program.size(); ++j) + { + auto &in = input_[program[j]]; + auto it = std::find(in.begin(), in.end(), n.first); + canFree = canFree and (it == in.end()); + } + if (canFree and env_.propExists(n.first)) + { + LOG(Message) << "freeing '" << n.first << "'" << std::endl; + env_.free(n.first); + } + } } + + return memPeak; } diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 7b53af98..fd583fce 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -51,8 +51,7 @@ class GlobalPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, - std::vector, latticeSize, - ConfigPar, configs); + ConfigPar, configs); }; /****************************************************************************** @@ -75,16 +74,17 @@ private: // schedule computation void schedule(void); // program execution - void configLoop(void); - void execute(void); + void configLoop(void); + unsigned int execute(const std::vector &program); private: - std::string parameterFileName_; - GlobalPar par_; - Environment &env_; - ModuleFactory &modFactory_; - std::map> module_; - std::map associatedModule_; - std::vector program_; + std::string parameterFileName_; + GlobalPar par_; + Environment &env_; + ModuleFactory &modFactory_; + std::map> module_; + std::map associatedModule_; + std::map> input_; + std::vector program_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index 32febc13..e93cb18c 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -52,13 +52,11 @@ std::vector CMeson::getOutput(void) } // memory footprint //////////////////////////////////////////////////////////// -double CMeson::nCreatedProp(void) -{ - return 0.; -} +void CMeson::allocate(Environment &env) +{} // execution /////////////////////////////////////////////////////////////////// -void CMeson::operator()(Environment &env) +void CMeson::execute(Environment &env) { LOG(Message) << "computing meson contraction '" << getName() << "'" << std::endl; diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp index 7f13ce9a..843ae00b 100644 --- a/programs/Hadrons/CMeson.hpp +++ b/programs/Hadrons/CMeson.hpp @@ -50,10 +50,10 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); - // memory footprint - virtual double nCreatedProp(void); + // allocation + virtual void allocate(Environment &env); // execution - virtual void operator()(Environment &env); + virtual void execute(Environment &env); private: Par par_; }; diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 391f0c04..fb9052f0 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -20,6 +20,7 @@ #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** @@ -27,5 +28,132 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// Environment::Environment(void) -{} +{ + grid4d_.reset(SpaceTimeGrid::makeFourDimGrid( + GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), + GridDefaultMpi())); +} +// dry run ///////////////////////////////////////////////////////////////////// +void Environment::dryRun(const bool isDry) +{ + dryRun_ = isDry; +} + +bool Environment::isDryRun(void) +{ + return dryRun_; +} + +// quark propagators /////////////////////////////////////////////////////////// +void Environment::addProp(const std::string name, const unsigned int Ls) +{ + if (propExists(name)) + { + HADRON_ERROR("propagator '" + name + "' already exists"); + } + if (Ls > 1) + { + GridCartesian *pt; + + try + { + pt = grid5d_.at(Ls).get(); + } + catch(std::out_of_range &) + { + grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, + grid4d_.get())); + pt = grid5d_[Ls].get(); + } + if (!isDryRun()) + { + prop_[name].reset(new LatticePropagator(pt)); + } + else + { + prop_[name].reset(nullptr); + } + propSize_[name] = Ls; + } + else + { + if (!isDryRun()) + { + prop_[name].reset(new LatticePropagator(grid4d_.get())); + } + else + { + prop_[name].reset(nullptr); + } + propSize_[name] = 1; + } +} + +void Environment::freeProp(const std::string name) +{ + if (propExists(name)) + { + prop_.erase(name); + propSize_.erase(name); + } + else + { + HADRON_ERROR("trying to free unknown propagator '" + name + "'"); + } +} + +LatticePropagator * Environment::getProp(const std::string name) +{ + if (propExists(name)) + { + return prop_[name].get(); + } + else + { + HADRON_ERROR("propagator '" + name + "' unknown"); + + return nullptr; + } +} + +bool Environment::propExists(const std::string name) +{ + auto it = prop_.find(name); + + if (it == prop_.end()) + { + return false; + } + else + { + return true; + } +} + +unsigned int Environment::nProp(void) +{ + unsigned int size = 0; + + for (auto &s: propSize_) + { + size += s.second; + } + + return size; +} + +// general free //////////////////////////////////////////////////////////////// +void Environment::free(const std::string name) +{ + if (propExists(name)) + { + freeProp(name); + } +} + +void Environment::freeAll(void) +{ + prop_.clear(); + propSize_.clear(); +} diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 62da9839..66576658 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -30,6 +30,29 @@ BEGIN_HADRONS_NAMESPACE class Environment { SINGLETON(Environment); +public: + typedef std::unique_ptr GridPt; + typedef std::unique_ptr PropPt; +public: + // dry run + void dryRun(const bool isDry); + bool isDryRun(void); + // quark propagators + void addProp(const std::string name, + const unsigned int Ls = 1); + void freeProp(const std::string name); + LatticePropagator * getProp(const std::string name); + bool propExists(const std::string name); + unsigned int nProp(void); + // general free + void free(const std::string name); + void freeAll(void); +private: + bool dryRun_{false}; + GridPt grid4d_; + std::map grid5d_; + std::map prop_; + std::map propSize_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 2294adef..693a9829 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -26,7 +26,8 @@ #define BEGIN_HADRONS_NAMESPACE \ namespace Hadrons {\ -using namespace Grid; +using namespace Grid;\ +using namespace QCD; #define END_HADRONS_NAMESPACE } BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index a2747c1a..7440975b 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -190,27 +190,27 @@ unsigned int Graph::size(void) const template bool Graph::gotValue(const T &value) const { - try - { - isMarked_.at(value); - } - catch (std::out_of_range &) + auto it = isMarked_.find(value); + + if (it == isMarked_.end()) { return false; } - - return true; + else + { + return true; + } } // vertex marking ////////////////////////////////////////////////////////////// template void Graph::mark(const T &value, const bool doMark) { - try + if (gotValue(value)) { - isMarked_.at(value) = doMark; + isMarked_[value] = doMark; } - catch (std::out_of_range &) + else { HADRON_ERROR("vertex " << value << " does not exists"); } @@ -240,11 +240,11 @@ void Graph::unmarkAll(void) template bool Graph::isMarked(const T &value) const { - try + if (gotValue(value)) { return isMarked_.at(value); } - catch (std::out_of_range &) + else { HADRON_ERROR("vertex " << value << " does not exists"); diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index 2cc27311..f2ae3ee9 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -49,14 +49,20 @@ std::vector MQuark::getOutput(void) return out; } -// memory footprint -double MQuark::nCreatedProp(void) +// allocation ////////////////////////////////////////////////////////////////// +void MQuark::allocate(Environment &env) { - return static_cast((par_.Ls > 1) ? par_.Ls + 1 : 1); + env.addProp(getName()); + quark_ = env.getProp(getName()); + if (par_.Ls > 1) + { + env.addProp(getName() + "_5d", par_.Ls); + quark5d_ = env.getProp(getName() + "_5d"); + } } // execution -void MQuark::operator()(Environment &env) +void MQuark::execute(Environment &env) { LOG(Message) << "computing quark propagator '" << getName() << "'" << std::endl; diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/MQuark.hpp index ae1efa12..f5ab94fb 100644 --- a/programs/Hadrons/MQuark.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -47,12 +47,13 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); - // memory footprint - virtual double nCreatedProp(void); + // allocation + virtual void allocate(Environment &env); // execution - virtual void operator()(Environment &env); + virtual void execute(Environment &env); private: Par par_; + LatticePropagator *quark_{nullptr}, *quark5d_{nullptr}; }; MODULE_REGISTER(MQuark); diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index 5267449c..a5809155 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -35,3 +35,12 @@ std::string Module::getName(void) const { return name_; } + +void Module::operator()(Environment &env) +{ + allocate(env); + if (!env.isDryRun()) + { + execute(env); + } +} diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index bf82a9e7..a8d3b40e 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -21,6 +21,7 @@ #define Hadrons_Module_hpp_ #include +#include BEGIN_HADRONS_NAMESPACE @@ -43,8 +44,6 @@ static mod##Registrar mod##RegistrarInstance; /****************************************************************************** * Module * ******************************************************************************/ -class Environment; - class Module { public: @@ -59,10 +58,11 @@ public: // dependency relation virtual std::vector getInput(void) = 0; virtual std::vector getOutput(void) = 0; - // memory footprint - virtual double nCreatedProp(void) = 0; + // allocation + virtual void allocate(Environment &env) = 0; // execution - virtual void operator()(Environment &env) = 0; + void operator()(Environment &env); + virtual void execute(Environment &env) = 0; private: std::string name_; }; From 1e10b4571de52c404a578f61c663dd4104f10e27 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 23 Feb 2016 16:21:45 +0000 Subject: [PATCH 012/106] fix after Grid update --- programs/Hadrons/Global.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 693a9829..e99b491a 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -35,7 +35,8 @@ BEGIN_HADRONS_NAMESPACE class HadronsLogger: public Logger { public: - HadronsLogger(int on, std::string nm): Logger("Hadrons", on, nm){}; + HadronsLogger(int on, std::string nm): Logger("Hadrons", on, nm, + Logger::BLACK){}; }; #define LOG(channel) std::cout << HadronsLog##channel From a0d8eb2c245aa1245f61ac2c2dce7bde26a82479 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 23 Feb 2016 16:33:00 +0000 Subject: [PATCH 013/106] minor code cleaning --- programs/Hadrons/Application.cc | 5 +---- programs/Hadrons/Global.cc | 2 -- programs/Hadrons/Hadrons.cc | 6 ++++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index c8c44adc..5eb43363 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -42,10 +42,7 @@ Application::Application(const std::string parameterFileName) // destructor ////////////////////////////////////////////////////////////////// Application::~Application(void) -{ - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); -} +{} // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc index a560d71f..a8d8f22b 100644 --- a/programs/Hadrons/Global.cc +++ b/programs/Hadrons/Global.cc @@ -26,5 +26,3 @@ HadronsLogger Hadrons::HadronsLogError(1,"Error"); HadronsLogger Hadrons::HadronsLogWarning(1,"Warning"); HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); - - diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc index 853de83c..d53ca497 100644 --- a/programs/Hadrons/Hadrons.cc +++ b/programs/Hadrons/Hadrons.cc @@ -33,6 +33,8 @@ int main(int argc, char *argv[]) std::exit(EXIT_FAILURE); } parameterFileName = argv[1]; + + // initialization Grid_init(&argc, &argv); HadronsLogError.Active(GridLogError.isActive()); HadronsLogWarning.Active(GridLogWarning.isActive()); @@ -45,5 +47,9 @@ int main(int argc, char *argv[]) application.run(); + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + return EXIT_SUCCESS; } From 5980fa86407b5bcd538db2cb17b537324d266256 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 25 Feb 2016 11:56:16 +0000 Subject: [PATCH 014/106] test implementation of DWF inverter --- programs/Hadrons/Application.cc | 1 + programs/Hadrons/Environment.cc | 73 +++++++++++++++++++++++++++++--- programs/Hadrons/Environment.hpp | 41 ++++++++++++------ programs/Hadrons/MQuark.cc | 16 +++++++ 4 files changed, 112 insertions(+), 19 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 5eb43363..00ca8f61 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -156,6 +156,7 @@ void Application::configLoop(void) { LOG(Message) << "Starting measurement for trajectory " << t << std::endl; + env_.loadUnitGauge(); execute(program_); env_.freeAll(); } diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index fb9052f0..ac7c81fa 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -29,9 +29,15 @@ using namespace Hadrons; // constructor ///////////////////////////////////////////////////////////////// Environment::Environment(void) { + std::vector seed4d({1,2,3,4}); + grid4d_.reset(SpaceTimeGrid::makeFourDimGrid( GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), GridDefaultMpi())); + gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get())); + rng4d_.reset(new GridParallelRNG(grid4d_.get())); + rng4d_->SeedFixedIntegers(seed4d); + gauge_.reset(new LatticeGaugeField(grid4d_.get())); } // dry run ///////////////////////////////////////////////////////////////////// @@ -45,30 +51,67 @@ bool Environment::isDryRun(void) return dryRun_; } +// grids /////////////////////////////////////////////////////////////////////// +GridCartesian * Environment::get4dGrid(void) +{ + return grid4d_.get(); +} + +GridRedBlackCartesian * Environment::getRb4dGrid(void) +{ + return gridRb4d_.get(); +} + +GridCartesian * Environment::get5dGrid(const unsigned int Ls) +{ + try + { + return grid5d_.at(Ls).get(); + } + catch(std::out_of_range &) + { + HADRON_ERROR("no 5D grid with Ls= " << Ls); + } +} + +GridRedBlackCartesian * Environment::getRb5dGrid(const unsigned int Ls) +{ + try + { + return gridRb5d_.at(Ls).get(); + } + catch(std::out_of_range &) + { + HADRON_ERROR("no red-black 5D grid with Ls= " << Ls); + } +} + // quark propagators /////////////////////////////////////////////////////////// void Environment::addProp(const std::string name, const unsigned int Ls) { + GridCartesian *p4 = grid4d_.get(); + if (propExists(name)) { HADRON_ERROR("propagator '" + name + "' already exists"); } if (Ls > 1) { - GridCartesian *pt; + GridCartesian *p; try { - pt = grid5d_.at(Ls).get(); + p = grid5d_.at(Ls).get(); } catch(std::out_of_range &) { - grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, - grid4d_.get())); - pt = grid5d_[Ls].get(); + grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, p4)); + gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, p4)); + p = grid5d_[Ls].get(); } if (!isDryRun()) { - prop_[name].reset(new LatticePropagator(pt)); + prop_[name].reset(new LatticePropagator(p)); } else { @@ -80,7 +123,7 @@ void Environment::addProp(const std::string name, const unsigned int Ls) { if (!isDryRun()) { - prop_[name].reset(new LatticePropagator(grid4d_.get())); + prop_[name].reset(new LatticePropagator(p4)); } else { @@ -143,6 +186,22 @@ unsigned int Environment::nProp(void) return size; } +// gauge configuration ///////////////////////////////////////////////////////// +LatticeGaugeField * Environment::getGauge(void) +{ + return gauge_.get(); +} + +void Environment::loadUnitGauge(void) +{ + SU3::ColdConfiguration(*rng4d_, *gauge_); +} + +void Environment::loadRandomGauge(void) +{ + SU3::HotConfiguration(*rng4d_, *gauge_); +} + // general free //////////////////////////////////////////////////////////////// void Environment::free(const std::string name) { diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 66576658..17ca462d 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -31,28 +31,45 @@ class Environment { SINGLETON(Environment); public: - typedef std::unique_ptr GridPt; - typedef std::unique_ptr PropPt; + typedef std::unique_ptr GridPt; + typedef std::unique_ptr GridRbPt; + typedef std::unique_ptr RngPt; + typedef std::unique_ptr PropPt; + typedef std::unique_ptr GaugePt; public: // dry run - void dryRun(const bool isDry); - bool isDryRun(void); + void dryRun(const bool isDry); + bool isDryRun(void); + // grids + GridCartesian * get4dGrid(void); + GridRedBlackCartesian * getRb4dGrid(void); + GridCartesian * get5dGrid(const unsigned int Ls); + GridRedBlackCartesian * getRb5dGrid(const unsigned int Ls); // quark propagators - void addProp(const std::string name, - const unsigned int Ls = 1); - void freeProp(const std::string name); - LatticePropagator * getProp(const std::string name); - bool propExists(const std::string name); - unsigned int nProp(void); + void addProp(const std::string name, + const unsigned int Ls = 1); + void freeProp(const std::string name); + LatticePropagator * getProp(const std::string name); + bool propExists(const std::string name); + unsigned int nProp(void); + // gauge configuration + LatticeGaugeField * getGauge(void); + void loadUnitGauge(void); + void loadRandomGauge(void); // general free - void free(const std::string name); - void freeAll(void); + void free(const std::string name); + void freeAll(void); private: bool dryRun_{false}; GridPt grid4d_; std::map grid5d_; + GridRbPt gridRb4d_; + std::map gridRb5d_; + RngPt rng4d_; std::map prop_; std::map propSize_; + GaugePt gauge_; + }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index f2ae3ee9..c328e3a8 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -66,4 +66,20 @@ void MQuark::execute(Environment &env) { LOG(Message) << "computing quark propagator '" << getName() << "'" << std::endl; + + GridCartesian *g4d = env.get4dGrid(), + *g5d = env.get5dGrid(par_.Ls); + GridRedBlackCartesian *gRb4d = env.getRb4dGrid(), + *gRb5d = env.getRb5dGrid(par_.Ls); + LatticeGaugeField &Umu = *env.getGauge(); + LatticeFermion src(g5d); src=zero; + LatticeFermion result(g5d); result=zero; + + RealD mass=0.1; + RealD M5=1.8; + DomainWallFermionR Ddwf(Umu, *g5d, *gRb5d, *g4d, *gRb4d, mass, M5); + + ConjugateGradient CG(1.0e-8,10000); + SchurRedBlackDiagMooeeSolve SchurSolver(CG); + SchurSolver(Ddwf,src,result); } From 92f666905fa08a6ca92840e252e32e3f33d09b04 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 25 Feb 2016 12:06:24 +0000 Subject: [PATCH 015/106] copyright script update to 80 column text --- scripts/copyright | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/copyright b/scripts/copyright index 76ed6603..b4783b74 100755 --- a/scripts/copyright +++ b/scripts/copyright @@ -5,13 +5,12 @@ while (( "$#" )); do echo $1 cat > message <> message cat >> message < tmp.fil From fdd084859304d69cc456c142a7c6840cbe18694d Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 25 Feb 2016 12:07:21 +0000 Subject: [PATCH 016/106] Hadrons: license text update --- programs/Hadrons/Application.cc | 44 ++++++++++++++++++------------ programs/Hadrons/Application.hpp | 44 ++++++++++++++++++------------ programs/Hadrons/CMeson.cc | 44 ++++++++++++++++++------------ programs/Hadrons/CMeson.hpp | 44 ++++++++++++++++++------------ programs/Hadrons/Environment.cc | 44 ++++++++++++++++++------------ programs/Hadrons/Environment.hpp | 44 ++++++++++++++++++------------ programs/Hadrons/Global.cc | 44 ++++++++++++++++++------------ programs/Hadrons/Global.hpp | 44 ++++++++++++++++++------------ programs/Hadrons/Graph.hpp | 44 ++++++++++++++++++------------ programs/Hadrons/Hadrons.cc | 44 ++++++++++++++++++------------ programs/Hadrons/MQuark.cc | 44 ++++++++++++++++++------------ programs/Hadrons/MQuark.hpp | 44 ++++++++++++++++++------------ programs/Hadrons/Module.cc | 44 ++++++++++++++++++------------ programs/Hadrons/Module.hpp | 44 ++++++++++++++++++------------ programs/Hadrons/ModuleFactory.cc | 44 ++++++++++++++++++------------ programs/Hadrons/ModuleFactory.hpp | 44 ++++++++++++++++++------------ 16 files changed, 416 insertions(+), 288 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 00ca8f61..fe33953f 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -1,21 +1,29 @@ -/* - * Application.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Application.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include #include diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index fd583fce..b02382e4 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -1,21 +1,29 @@ -/* - * Application.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Application.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_Application_hpp_ #define Hadrons_Application_hpp_ diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index e93cb18c..e9748f83 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -1,21 +1,29 @@ -/* - * CMeson.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/CMeson.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp index 843ae00b..f9916131 100644 --- a/programs/Hadrons/CMeson.hpp +++ b/programs/Hadrons/CMeson.hpp @@ -1,21 +1,29 @@ -/* - * CMeson.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/CMeson.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_CMeson_hpp_ #define Hadrons_CMeson_hpp_ diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index ac7c81fa..c78dec9a 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -1,21 +1,29 @@ -/* - * Environment.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Environment.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 17ca462d..12138d88 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -1,21 +1,29 @@ -/* - * Environment.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Environment.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_Environment_hpp_ #define Hadrons_Environment_hpp_ diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc index a8d8f22b..18c3028e 100644 --- a/programs/Hadrons/Global.cc +++ b/programs/Hadrons/Global.cc @@ -1,21 +1,29 @@ -/* - * Application.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Global.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index e99b491a..f364452e 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -1,21 +1,29 @@ -/* - * Globals.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * LatCore 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 3 of the License, or - * (at your option) any later version. - * - * LatCore 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 LatCore. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Global.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_Global_hpp_ #define Hadrons_Global_hpp_ diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 7440975b..8b8afcc6 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -1,21 +1,29 @@ -/* - * Graph.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Graph.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_Graph_hpp_ #define Hadrons_Graph_hpp_ diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc index d53ca497..73ac03f9 100644 --- a/programs/Hadrons/Hadrons.cc +++ b/programs/Hadrons/Hadrons.cc @@ -1,21 +1,29 @@ -/* - * Hadrons.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * LatCore 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 3 of the License, or - * (at your option) any later version. - * - * LatCore 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 LatCore. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Hadrons.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index c328e3a8..92311a37 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -1,21 +1,29 @@ -/* - * MQuark.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/MQuark.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/MQuark.hpp index f5ab94fb..c11cc8c1 100644 --- a/programs/Hadrons/MQuark.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -1,21 +1,29 @@ -/* - * MQuark.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/MQuark.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_MQuark_hpp_ #define Hadrons_MQuark_hpp_ diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index a5809155..62f7fc68 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -1,21 +1,29 @@ -/* - * Module.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Module.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index a8d3b40e..d929afec 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -1,21 +1,29 @@ -/* - * Module.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Module.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_Module_hpp_ #define Hadrons_Module_hpp_ diff --git a/programs/Hadrons/ModuleFactory.cc b/programs/Hadrons/ModuleFactory.cc index 084d272d..bb8cefad 100644 --- a/programs/Hadrons/ModuleFactory.cc +++ b/programs/Hadrons/ModuleFactory.cc @@ -1,21 +1,29 @@ -/* - * ModuleFactory.cc, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/ModuleFactory.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #include diff --git a/programs/Hadrons/ModuleFactory.hpp b/programs/Hadrons/ModuleFactory.hpp index 822dc8e7..f2db8d6a 100644 --- a/programs/Hadrons/ModuleFactory.hpp +++ b/programs/Hadrons/ModuleFactory.hpp @@ -1,21 +1,29 @@ -/* - * ModuleFactory.hpp, part of Grid - * - * Copyright (C) 2015 Antonin Portelli - * - * Grid 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 3 of the License, or - * (at your option) any later version. - * - * Grid 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 Grid. If not, see . - */ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/ModuleFactory.hpp + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ #ifndef Hadrons_ModuleFactory_hpp_ #define Hadrons_ModuleFactory_hpp_ From feae35d92ce603a10981bf290c9d67300528b2c9 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 16 Apr 2016 08:41:12 +0100 Subject: [PATCH 017/106] Hadrons: pass strings by value --- programs/Hadrons/CMeson.cc | 4 ++-- programs/Hadrons/CMeson.hpp | 4 ++-- programs/Hadrons/MQuark.cc | 4 ++-- programs/Hadrons/MQuark.hpp | 4 ++-- programs/Hadrons/MSource.cc | 9 +++++++++ programs/Hadrons/MSource.hpp | 14 ++++++++++++++ programs/Hadrons/Module.cc | 2 +- programs/Hadrons/Module.hpp | 6 +++--- programs/Hadrons/ModuleFactory.cc | 6 +++--- programs/Hadrons/ModuleFactory.hpp | 8 ++++---- 10 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 programs/Hadrons/MSource.cc create mode 100644 programs/Hadrons/MSource.hpp diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index e9748f83..8283cb9d 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -34,12 +34,12 @@ using namespace Hadrons; * CMeson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -CMeson::CMeson(const std::string &name) +CMeson::CMeson(const std::string name) : Module(name) {} // parse parameters //////////////////////////////////////////////////////////// -void CMeson::parseParameters(XmlReader &reader, const std::string &name) +void CMeson::parseParameters(XmlReader &reader, const std::string name) { read(reader, name, par_); } diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp index f9916131..c834f1e0 100644 --- a/programs/Hadrons/CMeson.hpp +++ b/programs/Hadrons/CMeson.hpp @@ -50,11 +50,11 @@ public: }; public: // constructor - CMeson(const std::string &name); + CMeson(const std::string name); // destructor virtual ~CMeson(void) = default; // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string &name); + virtual void parseParameters(XmlReader &reader, const std::string name); // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index 92311a37..a39fa927 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -34,12 +34,12 @@ using namespace Hadrons; * MQuark implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -MQuark::MQuark(const std::string &name) +MQuark::MQuark(const std::string name) : Module(name) {} // parse parameters -void MQuark::parseParameters(XmlReader &reader, const std::string &name) +void MQuark::parseParameters(XmlReader &reader, const std::string name) { read(reader, name, par_); } diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/MQuark.hpp index c11cc8c1..da0933e4 100644 --- a/programs/Hadrons/MQuark.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -47,11 +47,11 @@ public: }; public: // constructor - MQuark(const std::string &name); + MQuark(const std::string name); // destructor virtual ~MQuark(void) = default; // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string &name); + virtual void parseParameters(XmlReader &reader, const std::string name); // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); diff --git a/programs/Hadrons/MSource.cc b/programs/Hadrons/MSource.cc new file mode 100644 index 00000000..f9b7f9d1 --- /dev/null +++ b/programs/Hadrons/MSource.cc @@ -0,0 +1,9 @@ +// +// MSource.cpp +// Grid +// +// Created by Antonin Portelli on 16/04/2016. +// +// + +#include "MSource.hpp" diff --git a/programs/Hadrons/MSource.hpp b/programs/Hadrons/MSource.hpp new file mode 100644 index 00000000..1ba667e8 --- /dev/null +++ b/programs/Hadrons/MSource.hpp @@ -0,0 +1,14 @@ +// +// MSource.hpp +// Grid +// +// Created by Antonin Portelli on 16/04/2016. +// +// + +#ifndef MSource_hpp +#define MSource_hpp + +#include + +#endif /* MSource_hpp */ diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index 62f7fc68..a588ce97 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -34,7 +34,7 @@ using namespace Hadrons; * Module implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -Module::Module(const std::string &name) +Module::Module(const std::string name) : name_(name) {} diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index d929afec..67a201bc 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -41,7 +41,7 @@ public:\ mod##Registrar(void)\ {\ ModuleFactory &modFac = ModuleFactory::getInstance();\ - modFac.registerModule(#mod, [&](const std::string &name)\ + modFac.registerModule(#mod, [&](const std::string name)\ {\ return std::unique_ptr(new mod(name));\ });\ @@ -56,13 +56,13 @@ class Module { public: // constructor - Module(const std::string &name); + Module(const std::string name); // destructor virtual ~Module(void) = default; // access std::string getName(void) const; // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string &name) = 0; + virtual void parseParameters(XmlReader &reader, const std::string name) = 0; // dependency relation virtual std::vector getInput(void) = 0; virtual std::vector getOutput(void) = 0; diff --git a/programs/Hadrons/ModuleFactory.cc b/programs/Hadrons/ModuleFactory.cc index bb8cefad..6e59aa57 100644 --- a/programs/Hadrons/ModuleFactory.cc +++ b/programs/Hadrons/ModuleFactory.cc @@ -39,7 +39,7 @@ ModuleFactory::ModuleFactory(void) } // registration //////////////////////////////////////////////////////////////// -void ModuleFactory::registerModule(const std::string &type, +void ModuleFactory::registerModule(const std::string type, const FactoryFunc &f) { factory_[type] = f; @@ -59,8 +59,8 @@ std::vector ModuleFactory::getModuleList(void) const } // factory ///////////////////////////////////////////////////////////////////// -std::unique_ptr ModuleFactory::create(const std::string &type, - const std::string &name) const +std::unique_ptr ModuleFactory::create(const std::string type, + const std::string name) const { FactoryFunc func; diff --git a/programs/Hadrons/ModuleFactory.hpp b/programs/Hadrons/ModuleFactory.hpp index f2db8d6a..a959847f 100644 --- a/programs/Hadrons/ModuleFactory.hpp +++ b/programs/Hadrons/ModuleFactory.hpp @@ -40,16 +40,16 @@ class ModuleFactory { SINGLETON(ModuleFactory) public: - typedef std::function(const std::string &)> + typedef std::function(const std::string )> FactoryFunc; public: // registration - void registerModule(const std::string &type, const FactoryFunc &f); + void registerModule(const std::string type, const FactoryFunc &f); // get module list std::vector getModuleList(void) const; // factory - std::unique_ptr create(const std::string &type, - const std::string &name) const; + std::unique_ptr create(const std::string type, + const std::string name) const; private: std::map factory_; }; From 9ee54e0db76e11d6945f184d042a06b573a0daa3 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 16 Apr 2016 08:41:28 +0100 Subject: [PATCH 018/106] debug output removed --- lib/communicator/Communicator_mpi.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/communicator/Communicator_mpi.cc b/lib/communicator/Communicator_mpi.cc index f804e8fe..dff9811a 100644 --- a/lib/communicator/Communicator_mpi.cc +++ b/lib/communicator/Communicator_mpi.cc @@ -53,7 +53,6 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) _Nprocessors=1; _processors = processors; _processor_coor.resize(_ndimension); - std::cout << processors << std::endl; MPI_Cart_create(MPI_COMM_WORLD, _ndimension,&_processors[0],&periodic[0],1,&communicator); MPI_Comm_rank(communicator,&_processor); From e33b0f6ff73e0160c2efe7d9351eb7f6bbb0450c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 16 Apr 2016 08:41:53 +0100 Subject: [PATCH 019/106] cleaner output --- lib/Log.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Log.h b/lib/Log.h index e55c2e52..05676775 100644 --- a/lib/Log.h +++ b/lib/Log.h @@ -69,8 +69,8 @@ public: StopWatch.Stop(); GridTime now = StopWatch.Elapsed(); StopWatch.Start(); - stream << BLACK<< log.topName << BLACK<< " : "; - stream << log.COLOUR < Date: Sat, 30 Apr 2016 00:17:04 -0700 Subject: [PATCH 020/106] Hadrons: first prototype with working inversions --- programs/Hadrons/AWilson.cc | 56 +++++++ programs/Hadrons/AWilson.hpp | 65 ++++++++ programs/Hadrons/Application.cc | 118 +++++++++----- programs/Hadrons/Application.hpp | 6 +- programs/Hadrons/CMeson.cc | 4 - programs/Hadrons/CMeson.hpp | 2 - programs/Hadrons/Environment.cc | 152 ++++++++++++++---- programs/Hadrons/Environment.hpp | 47 ++++-- programs/Hadrons/Factory.hpp | 104 ++++++++++++ .../{ModuleFactory.cc => FermionAction.cc} | 51 ++---- programs/Hadrons/FermionAction.hpp | 83 ++++++++++ programs/Hadrons/FermionActionFactory.hpp | 47 ++++++ programs/Hadrons/Global.hpp | 15 +- programs/Hadrons/MQuark.cc | 75 ++++++--- programs/Hadrons/MQuark.hpp | 11 +- programs/Hadrons/MSource.cc | 148 ++++++++++++++++- programs/Hadrons/MSource.hpp | 111 +++++++++++-- programs/Hadrons/Makefile.am | 20 ++- programs/Hadrons/Module.cc | 1 + programs/Hadrons/Module.hpp | 12 +- programs/Hadrons/ModuleFactory.hpp | 18 +-- programs/Hadrons/SRBPrecCG.cc | 74 +++++++++ programs/Hadrons/SRBPrecCG.hpp | 69 ++++++++ 23 files changed, 1092 insertions(+), 197 deletions(-) create mode 100644 programs/Hadrons/AWilson.cc create mode 100644 programs/Hadrons/AWilson.hpp create mode 100644 programs/Hadrons/Factory.hpp rename programs/Hadrons/{ModuleFactory.cc => FermionAction.cc} (55%) create mode 100644 programs/Hadrons/FermionAction.hpp create mode 100644 programs/Hadrons/FermionActionFactory.hpp create mode 100644 programs/Hadrons/SRBPrecCG.cc create mode 100644 programs/Hadrons/SRBPrecCG.hpp diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc new file mode 100644 index 00000000..2f8483f3 --- /dev/null +++ b/programs/Hadrons/AWilson.cc @@ -0,0 +1,56 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/AWilson.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* AWilson implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +AWilson::AWilson(const std::string name) +: FermionAction(name) +{} + +// parse parameters //////////////////////////////////////////////////////////// +void AWilson::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_); +} + +// create operator ///////////////////////////////////////////////////////////// +void AWilson::create(Environment &env) +{ + auto &U = *env.getGauge(); + auto &grid = *env.getGrid(); + auto &gridRb = *env.getRbGrid(); + + setFMat(new WilsonFermionR(U, grid, gridRb, par_.mass)); +} diff --git a/programs/Hadrons/AWilson.hpp b/programs/Hadrons/AWilson.hpp new file mode 100644 index 00000000..aa40b99d --- /dev/null +++ b/programs/Hadrons/AWilson.hpp @@ -0,0 +1,65 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/AWilson.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_AWilson_hpp_ +#define Hadrons_AWilson_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Wilson fermions * + ******************************************************************************/ +class AWilson: public FermionAction +{ +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, double, mass); + }; +public: + // constructor + AWilson(const std::string name); + // destructor + virtual ~AWilson(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name); + // create operator + virtual void create(Environment &env); +private: + Par par_; +}; + +ACTION_REGISTER(AWilson); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_AWilson_hpp_ diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index fe33953f..af12d227 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -38,10 +38,17 @@ using namespace Hadrons; Application::Application(const std::string parameterFileName) : parameterFileName_(parameterFileName) , env_(Environment::getInstance()) +, actionFactory_(FermionActionFactory::getInstance()) , modFactory_(ModuleFactory::getInstance()) { + LOG(Message) << "Fermion actions available:" << std::endl; + auto list = actionFactory_.getBuilderList(); + for (auto &m: list) + { + LOG(Message) << " " << m << std::endl; + } LOG(Message) << "Modules available:" << std::endl; - auto list = modFactory_.getModuleList(); + list = modFactory_.getBuilderList(); for (auto &m: list) { LOG(Message) << " " << m << std::endl; @@ -61,10 +68,10 @@ void Application::run(void) } // parse parameter file //////////////////////////////////////////////////////// -class ModuleId: Serializable +class ObjectId: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(ModuleId, + GRID_SERIALIZABLE_CLASS_MEMBERS(ObjectId, std::string, name, std::string, type); }; @@ -72,10 +79,22 @@ public: void Application::parseParameterFile(void) { XmlReader reader(parameterFileName_); - ModuleId id; + ObjectId id; LOG(Message) << "Reading '" << parameterFileName_ << "'..." << std::endl; read(reader, "parameters", par_); + push(reader, "actions"); + push(reader, "action"); + do + { + read(reader, "id", id); + env_.addFermionAction(actionFactory_.create(id.type, id.name)); + auto &action = *env_.getFermionAction(id.name); + action.parseParameters(reader, "options"); + action.create(env_); + } while (reader.nextElement("action")); + pop(reader); + pop(reader); push(reader, "modules"); push(reader, "module"); do @@ -92,6 +111,7 @@ void Application::parseParameterFile(void) } while (reader.nextElement("module")); pop(reader); pop(reader); + env_.setSeed(strToVec(par_.seed)); } // schedule computation //////////////////////////////////////////////////////// @@ -122,33 +142,38 @@ void Application::schedule(void) unsigned int k = 0; std::vector> con = moduleGraph.getConnectedComponents(); - LOG(Message) << "Program:" << std::endl; + for (unsigned int i = 0; i < con.size(); ++i) { - std::vector> t = con[i].allTopoSort(); - int memPeak, minMemPeak = -1; - unsigned int bestInd; - bool msg; - - env_.dryRun(true); - for (unsigned int p = 0; p < t.size(); ++p) +// std::vector> t = con[i].allTopoSort(); +// int memPeak, minMemPeak = -1; +// unsigned int bestInd; +// bool msg; +// +// LOG(Message) << "analyzing " << t.size() << " possible programs..." +// << std::endl; +// env_.dryRun(true); +// for (unsigned int p = 0; p < t.size(); ++p) +// { +// msg = HadronsLogMessage.isActive(); +// HadronsLogMessage.Active(false); +// +// memPeak = execute(t[p]); +// if ((memPeak < minMemPeak) or (minMemPeak < 0)) +// { +// minMemPeak = memPeak; +// bestInd = p; +// } +// HadronsLogMessage.Active(msg); +// env_.freeAll(); +// } +// env_.dryRun(false); + std::vector t = con[i].topoSort(); + LOG(Message) << "Program " << i + 1 << ":" << std::endl; + for (unsigned int j = 0; j < t.size(); ++j) { - msg = HadronsLogMessage.isActive(); - HadronsLogMessage.Active(false); - memPeak = execute(t[p]); - if ((memPeak < minMemPeak) or (minMemPeak < 0)) - { - minMemPeak = memPeak; - bestInd = p; - } - HadronsLogMessage.Active(msg); - env_.freeAll(); - } - env_.dryRun(false); - for (unsigned int j = 0; j < t[bestInd].size(); ++j) - { - program_.push_back(t[bestInd][j]); - LOG(Message) << std::setw(4) << std::right << k << ": " + program_.push_back(t[j]); + LOG(Message) << std::setw(4) << std::right << k + 1 << ": " << program_[k] << std::endl; k++; } @@ -164,7 +189,7 @@ void Application::configLoop(void) { LOG(Message) << "Starting measurement for trajectory " << t << std::endl; - env_.loadUnitGauge(); + env_.loadRandomGauge(); execute(program_); env_.freeAll(); } @@ -172,8 +197,25 @@ void Application::configLoop(void) unsigned int Application::execute(const std::vector &program) { - unsigned int memPeak = 0; + unsigned int memPeak = 0; + std::vector> freeProg; + freeProg.resize(program.size()); + for (auto &n: associatedModule_) + { + auto pred = [&n, this](const std::string &s) + { + auto &in = input_[s]; + auto it = std::find(in.begin(), in.end(), n.first); + + return (it != in.end()) or (s == n.second); + }; + auto it = std::find_if(program.rbegin(), program.rend(), pred); + if (it != program.rend()) + { + freeProg[program.rend() - it - 1].push_back(n.first); + } + } for (unsigned int i = 0; i < program.size(); ++i) { LOG(Message) << "Measurement step (" << i+1 << "/" << program.size() @@ -184,21 +226,9 @@ unsigned int Application::execute(const std::vector &program) { memPeak = env_.nProp(); } - for (auto &n: associatedModule_) + for (auto &n: freeProg[i]) { - bool canFree = true; - - for (unsigned int j = i + 1; j < program.size(); ++j) - { - auto &in = input_[program[j]]; - auto it = std::find(in.begin(), in.end(), n.first); - canFree = canFree and (it == in.end()); - } - if (canFree and env_.propExists(n.first)) - { - LOG(Message) << "freeing '" << n.first << "'" << std::endl; - env_.free(n.first); - } + env_.free(n); } } diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index b02382e4..a5e0e3c4 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -29,6 +29,7 @@ directory. #define Hadrons_Application_hpp_ #include +#include #include #include @@ -59,7 +60,8 @@ class GlobalPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, - ConfigPar, configs); + ConfigPar, configs, + std::string, seed); }; /****************************************************************************** @@ -88,11 +90,13 @@ private: std::string parameterFileName_; GlobalPar par_; Environment &env_; + FermionActionFactory &actionFactory_; ModuleFactory &modFactory_; std::map> module_; std::map associatedModule_; std::map> input_; std::vector program_; + std::vector> freeProg_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index 8283cb9d..537f157f 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -59,10 +59,6 @@ std::vector CMeson::getOutput(void) return output; } -// memory footprint //////////////////////////////////////////////////////////// -void CMeson::allocate(Environment &env) -{} - // execution /////////////////////////////////////////////////////////////////// void CMeson::execute(Environment &env) { diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp index c834f1e0..8725d938 100644 --- a/programs/Hadrons/CMeson.hpp +++ b/programs/Hadrons/CMeson.hpp @@ -58,8 +58,6 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); - // allocation - virtual void allocate(Environment &env); // execution virtual void execute(Environment &env); private: diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index c78dec9a..ebd8d010 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -37,15 +37,13 @@ using namespace Hadrons; // constructor ///////////////////////////////////////////////////////////////// Environment::Environment(void) { - std::vector seed4d({1,2,3,4}); - grid4d_.reset(SpaceTimeGrid::makeFourDimGrid( GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), GridDefaultMpi())); gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get())); rng4d_.reset(new GridParallelRNG(grid4d_.get())); - rng4d_->SeedFixedIntegers(seed4d); gauge_.reset(new LatticeGaugeField(grid4d_.get())); + loadUnitGauge(); } // dry run ///////////////////////////////////////////////////////////////////// @@ -54,27 +52,24 @@ void Environment::dryRun(const bool isDry) dryRun_ = isDry; } -bool Environment::isDryRun(void) +bool Environment::isDryRun(void) const { return dryRun_; } // grids /////////////////////////////////////////////////////////////////////// -GridCartesian * Environment::get4dGrid(void) -{ - return grid4d_.get(); -} - -GridRedBlackCartesian * Environment::getRb4dGrid(void) -{ - return gridRb4d_.get(); -} - -GridCartesian * Environment::get5dGrid(const unsigned int Ls) +GridCartesian * Environment::getGrid(const unsigned int Ls) const { try { - return grid5d_.at(Ls).get(); + if (Ls == 1) + { + return grid4d_.get(); + } + else + { + return grid5d_.at(Ls).get(); + } } catch(std::out_of_range &) { @@ -82,11 +77,18 @@ GridCartesian * Environment::get5dGrid(const unsigned int Ls) } } -GridRedBlackCartesian * Environment::getRb5dGrid(const unsigned int Ls) +GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const { try { - return gridRb5d_.at(Ls).get(); + if (Ls == 1) + { + return gridRb4d_.get(); + } + else + { + return gridRb5d_.at(Ls).get(); + } } catch(std::out_of_range &) { @@ -94,6 +96,52 @@ GridRedBlackCartesian * Environment::getRb5dGrid(const unsigned int Ls) } } +// fermion actions ///////////////////////////////////////////////////////////// +void Environment::addFermionAction(FActionPt action) +{ + fAction_[action->getName()] = std::move(action); +} + +FermionAction * Environment::getFermionAction(const std::string name) const +{ + try + { + return fAction_.at(name).get(); + } + catch(std::out_of_range &) + { + try + { + return fAction_.at(solverAction_.at(name)).get(); + } + catch (std::out_of_range &) + { + HADRON_ERROR("no action with name '" << name << "'"); + } + } +} + +// solvers ///////////////////////////////////////////////////////////////////// +void Environment::addSolver(const std::string name, Solver s, + const std::string actionName) +{ + solver_[name] = s; + solverAction_[name] = actionName; +} + +void Environment::callSolver(const std::string name, LatticeFermion &sol, + const LatticeFermion &source) const +{ + try + { + solver_.at(name)(sol, source); + } + catch(std::out_of_range &) + { + HADRON_ERROR("no solver with name '" << name << "'"); + } +} + // quark propagators /////////////////////////////////////////////////////////// void Environment::addProp(const std::string name, const unsigned int Ls) { @@ -154,11 +202,46 @@ void Environment::freeProp(const std::string name) } } -LatticePropagator * Environment::getProp(const std::string name) +bool Environment::isProp5d(const std::string name) const { if (propExists(name)) { - return prop_[name].get(); + return (getProp(name)->_grid->GlobalDimensions().size() == Nd + 1); + } + else + { + HADRON_ERROR("propagator '" + name + "' unknown"); + + return false; + } +} + +unsigned int Environment::getPropLs(const std::string name) const +{ + if (propExists(name)) + { + if (isProp5d(name)) + { + return getProp(name)->_grid->GlobalDimensions()[0]; + } + else + { + return 1; + } + } + else + { + HADRON_ERROR("propagator '" + name + "' unknown"); + + return 0; + } +} + +LatticePropagator * Environment::getProp(const std::string name) const +{ + if (propExists(name)) + { + return prop_.at(name).get(); } else { @@ -168,21 +251,12 @@ LatticePropagator * Environment::getProp(const std::string name) } } -bool Environment::propExists(const std::string name) +bool Environment::propExists(const std::string name) const { - auto it = prop_.find(name); - - if (it == prop_.end()) - { - return false; - } - else - { - return true; - } + return (prop_.find(name) != prop_.end()); } -unsigned int Environment::nProp(void) +unsigned int Environment::nProp(void) const { unsigned int size = 0; @@ -195,7 +269,7 @@ unsigned int Environment::nProp(void) } // gauge configuration ///////////////////////////////////////////////////////// -LatticeGaugeField * Environment::getGauge(void) +LatticeGaugeField * Environment::getGauge(void) const { return gauge_.get(); } @@ -210,11 +284,23 @@ void Environment::loadRandomGauge(void) SU3::HotConfiguration(*rng4d_, *gauge_); } +// random number generator ///////////////////////////////////////////////////// +void Environment::setSeed(const std::vector &seed) +{ + rng4d_->SeedFixedIntegers(seed); +} + +GridParallelRNG * Environment::get4dRng(void) const +{ + return rng4d_.get(); +} + // general free //////////////////////////////////////////////////////////////// void Environment::free(const std::string name) { if (propExists(name)) { + LOG(Message) << "freeing '" << name << "'" << std::endl; freeProp(name); } } diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 12138d88..906c5aa1 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -29,6 +29,7 @@ directory. #define Hadrons_Environment_hpp_ #include +#include BEGIN_HADRONS_NAMESPACE @@ -39,31 +40,46 @@ class Environment { SINGLETON(Environment); public: - typedef std::unique_ptr GridPt; - typedef std::unique_ptr GridRbPt; - typedef std::unique_ptr RngPt; - typedef std::unique_ptr PropPt; - typedef std::unique_ptr GaugePt; + typedef std::function Solver; + typedef std::unique_ptr GridPt; + typedef std::unique_ptr GridRbPt; + typedef std::unique_ptr RngPt; + typedef std::unique_ptr FActionPt; + typedef std::unique_ptr PropPt; + typedef std::unique_ptr GaugePt; public: // dry run void dryRun(const bool isDry); - bool isDryRun(void); + bool isDryRun(void) const; // grids - GridCartesian * get4dGrid(void); - GridRedBlackCartesian * getRb4dGrid(void); - GridCartesian * get5dGrid(const unsigned int Ls); - GridRedBlackCartesian * getRb5dGrid(const unsigned int Ls); + GridCartesian * getGrid(const unsigned int Ls = 1) const; + GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; + // fermion actions + void addFermionAction(FActionPt action); + FermionAction * getFermionAction(const std::string name) const; + // solvers + void addSolver(const std::string name, Solver s, + const std::string actionName); + void callSolver(const std::string name, + LatticeFermion &sol, + const LatticeFermion &src) const; // quark propagators void addProp(const std::string name, const unsigned int Ls = 1); void freeProp(const std::string name); - LatticePropagator * getProp(const std::string name); - bool propExists(const std::string name); - unsigned int nProp(void); + bool isProp5d(const std::string name) const; + unsigned int getPropLs(const std::string name) const; + LatticePropagator * getProp(const std::string name) const; + bool propExists(const std::string name) const; + unsigned int nProp(void) const; // gauge configuration - LatticeGaugeField * getGauge(void); + LatticeGaugeField * getGauge(void) const; void loadUnitGauge(void); void loadRandomGauge(void); + // random number generator + void setSeed(const std::vector &seed); + GridParallelRNG * get4dRng(void) const; // general free void free(const std::string name); void freeAll(void); @@ -74,6 +90,9 @@ private: GridRbPt gridRb4d_; std::map gridRb5d_; RngPt rng4d_; + std::map fAction_; + std::map solver_; + std::map solverAction_; std::map prop_; std::map propSize_; GaugePt gauge_; diff --git a/programs/Hadrons/Factory.hpp b/programs/Hadrons/Factory.hpp new file mode 100644 index 00000000..2b219dcc --- /dev/null +++ b/programs/Hadrons/Factory.hpp @@ -0,0 +1,104 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Factory.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_Factory_hpp_ +#define Hadrons_Factory_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * abstract factory class * + ******************************************************************************/ +template +class Factory +{ +public: + typedef std::function(const std::string)> Func; +public: + // constructor + Factory(void) = default; + // destructor + virtual ~Factory(void) = default; + // registration + void registerBuilder(const std::string type, const Func &f); + // get module list + std::vector getBuilderList(void) const; + // factory + std::unique_ptr create(const std::string type, + const std::string name) const; +private: + std::map builder_; +}; + +/****************************************************************************** + * template implementation * + ******************************************************************************/ +// registration //////////////////////////////////////////////////////////////// +template +void Factory::registerBuilder(const std::string type, const Func &f) +{ + builder_[type] = f; +} + +// get module list ///////////////////////////////////////////////////////////// +template +std::vector Factory::getBuilderList(void) const +{ + std::vector list; + + for (auto &b: builder_) + { + list.push_back(b.first); + } + + return list; +} + +// factory ///////////////////////////////////////////////////////////////////// +template +std::unique_ptr Factory::create(const std::string type, + const std::string name) const +{ + Func func; + + try + { + func = builder_.at(type); + } + catch (std::out_of_range) + { + HADRON_ERROR("object of type '" + type + "' unknown"); + } + + return func(name); +} + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Factory_hpp_ diff --git a/programs/Hadrons/ModuleFactory.cc b/programs/Hadrons/FermionAction.cc similarity index 55% rename from programs/Hadrons/ModuleFactory.cc rename to programs/Hadrons/FermionAction.cc index 6e59aa57..0857008b 100644 --- a/programs/Hadrons/ModuleFactory.cc +++ b/programs/Hadrons/FermionAction.cc @@ -1,9 +1,9 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/ModuleFactory.cc +Source file: programs/Hadrons/FermionAction.cc -Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -25,53 +25,36 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; /****************************************************************************** - * ModuleFactory implementation * + * FermionAction implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -ModuleFactory::ModuleFactory(void) +FermionAction::FermionAction(const std::string name) +: name_(name) +{} + +// access ////////////////////////////////////////////////////////////////////// +std::string FermionAction::getName(void) const { + return name_; } -// registration //////////////////////////////////////////////////////////////// -void ModuleFactory::registerModule(const std::string type, - const FactoryFunc &f) +unsigned int FermionAction::getLs(void) const { - factory_[type] = f; + return 1; } -// get module list ///////////////////////////////////////////////////////////// -std::vector ModuleFactory::getModuleList(void) const +void FermionAction::setFMat(FMat *fMat) { - std::vector list; - - for (auto &f: factory_) - { - list.push_back(f.first); - } - - return list; + fMat_.reset(fMat); } -// factory ///////////////////////////////////////////////////////////////////// -std::unique_ptr ModuleFactory::create(const std::string type, - const std::string name) const +FermionAction::FMat * FermionAction::getFMat(void) { - FactoryFunc func; - - try - { - func = factory_.at(type); - } - catch (std::out_of_range) - { - HADRON_ERROR("module type '" + type + "' unknown"); - } - - return func(name); + return fMat_.get(); } diff --git a/programs/Hadrons/FermionAction.hpp b/programs/Hadrons/FermionAction.hpp new file mode 100644 index 00000000..f3cd1cf7 --- /dev/null +++ b/programs/Hadrons/FermionAction.hpp @@ -0,0 +1,83 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/FermionAction.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_FermionAction_hpp_ +#define Hadrons_FermionAction_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +// action registration macro +#define ACTION_REGISTER(action)\ +class action##ActionRegistrar\ +{\ +public:\ + action##ActionRegistrar(void)\ + {\ + FermionActionFactory &actionFac = FermionActionFactory::getInstance();\ + actionFac.registerBuilder(#action, [&](const std::string name)\ + {\ + return std::unique_ptr(\ + new action(name));\ + });\ + }\ +};\ +static action##ActionRegistrar action##ActionRegistrarInstance; + +/****************************************************************************** + * FermionAction * + ******************************************************************************/ +class Environment; + +class FermionAction +{ +public: + typedef FermionOperator FMat; + typedef std::unique_ptr FMatPt; +public: + // constructor + FermionAction(const std::string name); + // destructor + virtual ~FermionAction(void) = default; + // access + std::string getName(void) const; + virtual unsigned int getLs(void) const; + void setFMat(FMat *fMat); + FMat * getFMat(void); + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name) = 0; + // create operator + virtual void create(Environment &env) = 0; +private: + std::string name_; + FMatPt fMat_; +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_FermionAction_hpp_ diff --git a/programs/Hadrons/FermionActionFactory.hpp b/programs/Hadrons/FermionActionFactory.hpp new file mode 100644 index 00000000..d9522c31 --- /dev/null +++ b/programs/Hadrons/FermionActionFactory.hpp @@ -0,0 +1,47 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/FermionActionFactory.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_FermionActionFactory_hpp_ +#define Hadrons_FermionActionFactory_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * FermionActionFactory * + ******************************************************************************/ +class FermionActionFactory: public Factory +{ + SINGLETON_DEFCTOR(FermionActionFactory) +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_FermionActionFactory_hpp_ diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index f364452e..39758b7e 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -49,7 +49,8 @@ public: #define LOG(channel) std::cout << HadronsLog##channel #define HADRON_ERROR(msg)\ -LOG(Error) << msg << std::endl;\ +LOG(Error) << msg << " (" << __FUNCTION__ << " at " << __FILE__ << ":"\ + << __LINE__ << ")" << std::endl;\ abort(); #define DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl; @@ -72,6 +73,18 @@ public:\ private:\ name(void); +#define SINGLETON_DEFCTOR(name)\ +public:\ + name(const name &e) = delete;\ + void operator=(const name &e) = delete;\ + static name & getInstance(void)\ + {\ + static name e;\ + return e;\ + }\ +private:\ + name(void) = default; + END_HADRONS_NAMESPACE #endif // Hadrons_Global_hpp_ diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index a39fa927..575914e4 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -47,7 +47,9 @@ void MQuark::parseParameters(XmlReader &reader, const std::string name) // dependency relation std::vector MQuark::getInput(void) { - return std::vector(); + std::vector in = {par_.source, par_.solver}; + + return in; } std::vector MQuark::getOutput(void) @@ -57,14 +59,20 @@ std::vector MQuark::getOutput(void) return out; } +// setup /////////////////////////////////////////////////////////////////////// +void MQuark::setup(Environment &env) +{ + Ls_ = env.getFermionAction(par_.solver)->getLs(); +} + // allocation ////////////////////////////////////////////////////////////////// void MQuark::allocate(Environment &env) { env.addProp(getName()); quark_ = env.getProp(getName()); - if (par_.Ls > 1) + if (Ls_ > 1) { - env.addProp(getName() + "_5d", par_.Ls); + env.addProp(getName() + "_5d", Ls_); quark5d_ = env.getProp(getName() + "_5d"); } } @@ -72,22 +80,53 @@ void MQuark::allocate(Environment &env) // execution void MQuark::execute(Environment &env) { + LatticePropagator *fullSource; + LatticeFermion source(env.getGrid(Ls_)), sol(env.getGrid(Ls_)); + LOG(Message) << "computing quark propagator '" << getName() << "'" << std::endl; + if (!env.isProp5d(par_.source)) + { + if (Ls_ == 1) + { + fullSource = env.getProp(par_.source); + } + else + { + HADRON_ERROR("MQuark not implemented with 5D actions"); + } + } + else + { + if (Ls_ == 1) + { + HADRON_ERROR("MQuark not implemented with 5D actions"); + } + else if (Ls_ != env.getPropLs(par_.source)) + { + HADRON_ERROR("MQuark not implemented with 5D actions"); + } + else + { + fullSource = env.getProp(par_.source); + } + } - GridCartesian *g4d = env.get4dGrid(), - *g5d = env.get5dGrid(par_.Ls); - GridRedBlackCartesian *gRb4d = env.getRb4dGrid(), - *gRb5d = env.getRb5dGrid(par_.Ls); - LatticeGaugeField &Umu = *env.getGauge(); - LatticeFermion src(g5d); src=zero; - LatticeFermion result(g5d); result=zero; - - RealD mass=0.1; - RealD M5=1.8; - DomainWallFermionR Ddwf(Umu, *g5d, *gRb5d, *g4d, *gRb4d, mass, M5); - - ConjugateGradient CG(1.0e-8,10000); - SchurRedBlackDiagMooeeSolve SchurSolver(CG); - SchurSolver(Ddwf,src,result); + LOG(Message) << "inverting using solver '" << par_.solver + << "' on source '" << par_.source << "'" << std::endl; + for (unsigned int s = 0; s < Ns; ++s) + for (unsigned int c = 0; c < Nc; ++c) + { + PropToFerm(source, *fullSource, s, c); + sol = zero; + env.callSolver(par_.solver, sol, source); + if (Ls_ == 1) + { + FermToProp(*quark_, sol, s, c); + } + else + { + HADRON_ERROR("MQuark not implemented with 5D actions"); + } + } } diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/MQuark.hpp index da0933e4..90e5f0e4 100644 --- a/programs/Hadrons/MQuark.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -43,7 +43,8 @@ public: class Par: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, Ls); + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string , source, + std::string , solver); }; public: // constructor @@ -55,13 +56,17 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); + // setup + virtual void setup(Environment &env); // allocation virtual void allocate(Environment &env); // execution virtual void execute(Environment &env); private: - Par par_; - LatticePropagator *quark_{nullptr}, *quark5d_{nullptr}; + Par par_; + unsigned int Ls_; + LatticePropagator *source_{nullptr}, *quark_{nullptr}, *quark5d_{nullptr}; + Environment::Solver *solver_{nullptr}; }; MODULE_REGISTER(MQuark); diff --git a/programs/Hadrons/MSource.cc b/programs/Hadrons/MSource.cc index f9b7f9d1..79cc899f 100644 --- a/programs/Hadrons/MSource.cc +++ b/programs/Hadrons/MSource.cc @@ -1,9 +1,141 @@ -// -// MSource.cpp -// Grid -// -// Created by Antonin Portelli on 16/04/2016. -// -// +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid -#include "MSource.hpp" +Source file: programs/Hadrons/MSource.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +#define ERROR_SUF " (source '" << getName() << "')" +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* MSource implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +MSource::MSource(const std::string name) +: Module(name) +{} + +// parse parameters +void MSource::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_); +} + +// dependency relation +std::vector MSource::getInput(void) +{ + return std::vector(); +} + +std::vector MSource::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// allocation ////////////////////////////////////////////////////////////////// +void MSource::allocate(Environment &env) +{ + switch (par_.sourceType) + { + // 4D sources + case Grid::SourceType::point: + case Grid::SourceType::z2Band: + env.addProp(getName()); + src_ = env.getProp(getName()); + break; + // error + default: + HADRON_ERROR("no allocation implemented for source type '" + << par_.sourceType << "'" << ERROR_SUF); + break; + } +} + +// execution +#define ARG_CHECK(n)\ +if (par_.arguments.size() != (n))\ +{\ + HADRON_ERROR("source type '" << par_.sourceType << "' expect "\ + << (n) << " arguments (got "\ + << par_.arguments.size() << ")" << ERROR_SUF);\ +} + +void MSource::execute(Environment &env) +{ + LOG(Message) << "generating source '" << getName() << "' of type '" + << par_.sourceType << "'" << std::endl; + switch (par_.sourceType) + { + // point source + case Grid::SourceType::point: + { + ARG_CHECK(1); + + std::vector origin = strToVec(par_.arguments[0]); + SpinColourMatrix id(1.); + + if (origin.size() != Nd) + { + HADRON_ERROR("point source origin dimension different from " + << Nd << ERROR_SUF); + } + *src_ = zero; + pokeSite(id, *src_, origin); + + break; + } + // z2Band source + case Grid::SourceType::z2Band: + { + ARG_CHECK(2); + + int ta = std::stoi(par_.arguments[0]); + int tb = std::stoi(par_.arguments[1]); + Lattice> t(env.getGrid()); + LatticeComplex eta(env.getGrid()); + LatticeFermion phi(env.getGrid()); + ComplexD shift(1., 1.); + + LatticeCoordinate(t, Tp); + bernoulli(*env.get4dRng(), eta); + eta = (2.*eta - shift)*(1./::sqrt(2.)); + *src_ = 1.; + *src_ = where((t >= ta) and (t <= tb), (*src_)*eta, (*src_)*0.); + + break; + } + // error + default: + { + HADRON_ERROR("no definition implemented for source type '" + << par_.sourceType << "'" << ERROR_SUF); + break; + } + } +} diff --git a/programs/Hadrons/MSource.hpp b/programs/Hadrons/MSource.hpp index 1ba667e8..3bc901ad 100644 --- a/programs/Hadrons/MSource.hpp +++ b/programs/Hadrons/MSource.hpp @@ -1,14 +1,103 @@ -// -// MSource.hpp -// Grid -// -// Created by Antonin Portelli on 16/04/2016. -// -// +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid -#ifndef MSource_hpp -#define MSource_hpp +Source file: programs/Hadrons/MSource.hpp -#include +Copyright (C) 2016 -#endif /* MSource_hpp */ +Author: Antonin Portelli + +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. +*******************************************************************************/ + +/************ + * Sources * + ************ + + Description of all source types. + Convention: the discrete Heavyside function verifies theta(0) = 1. + + point: Point source + ------------------- + * src(x) = delta_x,o + + * arguments: o + - o: origin, space-separated integer sequence (e.g. "0 1 1 0") + + z2Band: Z_2 stochastic source + ----------------------------- + * src(x) = eta_x * theta(x_0 - ta) * theta(tb - x_0) + + * arguments: ta tb + - ta: begin timeslice (integer) + - tb: end timesilce (integer) + + */ + + +#ifndef Hadrons_MSource_hpp_ +#define Hadrons_MSource_hpp_ + +#include +#include +#include + +namespace Grid{ + GRID_SERIALIZABLE_ENUM(SourceType, undef, + point, 1, + z2Band, 2); +} + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Source module * + ******************************************************************************/ +class MSource: public Module +{ +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, SourceType, sourceType, + std::vector, arguments); + }; +public: + // constructor + MSource(const std::string name); + // destructor + virtual ~MSource(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // allocation + virtual void allocate(Environment &env); + // execution + virtual void execute(Environment &env); +private: + Par par_; + LatticePropagator *src_{nullptr}; +}; + +MODULE_REGISTER(MSource); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MSource_hpp_ diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index b907f8c8..41da337e 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -1,19 +1,31 @@ AM_CXXFLAGS = -I$(top_srcdir)/programs -I$(top_srcdir)/lib -AM_LDFLAGS = -L$(top_builddir)/lib +AM_LDFLAGS = -L$(top_builddir)/lib bin_PROGRAMS = Hadrons +## general sources Hadrons_SOURCES = \ Application.cc \ Environment.cc \ + FermionAction.cc\ Global.cc \ Hadrons.cc \ - Module.cc \ - ModuleFactory.cc + Module.cc +## fermion actions Hadrons_SOURCES += \ - MQuark.cc + AWilson.cc +## general modules +Hadrons_SOURCES += \ + MQuark.cc \ + MSource.cc + +## solver modules +Hadrons_SOURCES += \ + SRBPrecCG.cc + +## contraction modules Hadrons_SOURCES += \ CMeson.cc diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index a588ce97..1437046e 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -46,6 +46,7 @@ std::string Module::getName(void) const void Module::operator()(Environment &env) { + setup(env); allocate(env); if (!env.isDryRun()) { diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 67a201bc..4153e77b 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -35,19 +35,19 @@ BEGIN_HADRONS_NAMESPACE // module registration macro #define MODULE_REGISTER(mod)\ -class mod##Registrar\ +class mod##ModuleRegistrar\ {\ public:\ - mod##Registrar(void)\ + mod##ModuleRegistrar(void)\ {\ ModuleFactory &modFac = ModuleFactory::getInstance();\ - modFac.registerModule(#mod, [&](const std::string name)\ + modFac.registerBuilder(#mod, [&](const std::string name)\ {\ return std::unique_ptr(new mod(name));\ });\ }\ };\ -static mod##Registrar mod##RegistrarInstance; +static mod##ModuleRegistrar mod##ModuleRegistrarInstance; /****************************************************************************** * Module * @@ -66,8 +66,10 @@ public: // dependency relation virtual std::vector getInput(void) = 0; virtual std::vector getOutput(void) = 0; + // setup + virtual void setup(Environment &env) {}; // allocation - virtual void allocate(Environment &env) = 0; + virtual void allocate(Environment &env) {}; // execution void operator()(Environment &env); virtual void execute(Environment &env) = 0; diff --git a/programs/Hadrons/ModuleFactory.hpp b/programs/Hadrons/ModuleFactory.hpp index a959847f..263a0828 100644 --- a/programs/Hadrons/ModuleFactory.hpp +++ b/programs/Hadrons/ModuleFactory.hpp @@ -29,6 +29,7 @@ directory. #define Hadrons_ModuleFactory_hpp_ #include +#include #include BEGIN_HADRONS_NAMESPACE @@ -36,22 +37,9 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * ModuleFactory * ******************************************************************************/ -class ModuleFactory +class ModuleFactory: public Factory { - SINGLETON(ModuleFactory) -public: - typedef std::function(const std::string )> - FactoryFunc; -public: - // registration - void registerModule(const std::string type, const FactoryFunc &f); - // get module list - std::vector getModuleList(void) const; - // factory - std::unique_ptr create(const std::string type, - const std::string name) const; -private: - std::map factory_; + SINGLETON_DEFCTOR(ModuleFactory) }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/SRBPrecCG.cc b/programs/Hadrons/SRBPrecCG.cc new file mode 100644 index 00000000..22206ed3 --- /dev/null +++ b/programs/Hadrons/SRBPrecCG.cc @@ -0,0 +1,74 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/SRBPrecCG.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* SRBPrecCG implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +SRBPrecCG::SRBPrecCG(const std::string name) +: Module(name) +{} + +// parse parameters +void SRBPrecCG::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_); +} + +// dependency relation +std::vector SRBPrecCG::getInput(void) +{ + return std::vector(); +} + +std::vector SRBPrecCG::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// execution /////////////////////////////////////////////////////////////////// +void SRBPrecCG::execute(Environment &env) +{ + auto &mat = *(env.getFermionAction(par_.action)->getFMat()); + auto solver = [&mat, this](LatticeFermion &sol, + const LatticeFermion &source) + { + ConjugateGradient cg(par_.residual, 10000); + SchurRedBlackDiagMooeeSolve schurSolver(cg); + + schurSolver(mat, source, sol); + }; + + env.addSolver(getName(), solver, par_.action); +} diff --git a/programs/Hadrons/SRBPrecCG.hpp b/programs/Hadrons/SRBPrecCG.hpp new file mode 100644 index 00000000..1b072c37 --- /dev/null +++ b/programs/Hadrons/SRBPrecCG.hpp @@ -0,0 +1,69 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/SRBPrecCG.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_SRBPrecCG_hpp_ +#define Hadrons_SRBPrecCG_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * SRBPrecCG * + ******************************************************************************/ +class SRBPrecCG: public Module +{ +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, action, + double , residual); + }; +public: + // constructor + SRBPrecCG(const std::string name); + // destructor + virtual ~SRBPrecCG(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // execution + virtual void execute(Environment &env); +private: + Par par_; +}; + +MODULE_REGISTER(SRBPrecCG); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_SRBPrecCG_hpp_ From 5e4b58ac40aca56e52d81b9ef0d1d57fd07d56f7 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 1 May 2016 12:49:26 -0700 Subject: [PATCH 021/106] Hadrons: Z2 source expression fix --- programs/Hadrons/MSource.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/programs/Hadrons/MSource.cc b/programs/Hadrons/MSource.cc index 79cc899f..87e93b2d 100644 --- a/programs/Hadrons/MSource.cc +++ b/programs/Hadrons/MSource.cc @@ -119,14 +119,17 @@ void MSource::execute(Environment &env) int tb = std::stoi(par_.arguments[1]); Lattice> t(env.getGrid()); LatticeComplex eta(env.getGrid()); + LatticeComplex z(env.getGrid()), shift(env.getGrid()); LatticeFermion phi(env.getGrid()); - ComplexD shift(1., 1.); LatticeCoordinate(t, Tp); bernoulli(*env.get4dRng(), eta); - eta = (2.*eta - shift)*(1./::sqrt(2.)); - *src_ = 1.; - *src_ = where((t >= ta) and (t <= tb), (*src_)*eta, (*src_)*0.); + shift = ComplexD(1., 1.); + z = zero; + eta = (2.*eta - shift)*(1./::sqrt(2.)); + eta = where((t >= ta) and (t <= tb), eta, z); + *src_ = 1.; + *src_ *= eta; break; } From 7905c5b8e59a1ab92e086a5f1e6e0bde5cea8b61 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 1 May 2016 14:49:45 -0700 Subject: [PATCH 022/106] Hadrons: Z2 source code fix --- programs/Hadrons/MSource.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/programs/Hadrons/MSource.cc b/programs/Hadrons/MSource.cc index 87e93b2d..f09c0b1d 100644 --- a/programs/Hadrons/MSource.cc +++ b/programs/Hadrons/MSource.cc @@ -119,17 +119,15 @@ void MSource::execute(Environment &env) int tb = std::stoi(par_.arguments[1]); Lattice> t(env.getGrid()); LatticeComplex eta(env.getGrid()); - LatticeComplex z(env.getGrid()), shift(env.getGrid()); LatticeFermion phi(env.getGrid()); + Complex shift(1., 1.); LatticeCoordinate(t, Tp); bernoulli(*env.get4dRng(), eta); - shift = ComplexD(1., 1.); - z = zero; - eta = (2.*eta - shift)*(1./::sqrt(2.)); - eta = where((t >= ta) and (t <= tb), eta, z); - *src_ = 1.; - *src_ *= eta; + eta = (2.*eta - shift)*(1./::sqrt(2.)); + eta = where((t >= ta) and (t <= tb), eta, 0.*eta); + *src_ = 1.; + *src_ = (*src_)*eta; break; } From 63b730de80b5e099211ab7964918f3e707ef64a4 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 1 May 2016 14:50:57 -0700 Subject: [PATCH 023/106] Hadrons: for the moment, test with unit gauge --- programs/Hadrons/Application.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index af12d227..5cdb6ed2 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -189,7 +189,7 @@ void Application::configLoop(void) { LOG(Message) << "Starting measurement for trajectory " << t << std::endl; - env_.loadRandomGauge(); + env_.loadUnitGauge(); execute(program_); env_.freeAll(); } From 48fcc34d724386134b38cf57d280722fd348bd9f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 1 May 2016 18:31:40 -0700 Subject: [PATCH 024/106] CMeson: first implementation, still need proper output --- programs/Hadrons/CMeson.cc | 31 +++++++++++++++++++++++++++++++ programs/Hadrons/CMeson.hpp | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index 537f157f..c171fb95 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -64,4 +64,35 @@ void CMeson::execute(Environment &env) { LOG(Message) << "computing meson contraction '" << getName() << "'" << std::endl; + + XmlWriter writer(par_.output); + LatticePropagator &q1 = *env.getProp(par_.q1); + LatticePropagator &q2 = *env.getProp(par_.q2); + LatticeComplex c(env.getGrid()); + SpinMatrix g[Ns*Ns], g5; + std::vector buf; + Result result; + unsigned int nt = env.getGrid()->GlobalDimensions()[Tp]; + + g5 = makeGammaProd(Ns*Ns - 1); + result.corr.resize(Ns*Ns); + for (unsigned int i = 0; i < Ns*Ns; ++i) + { + g[i] = makeGammaProd(i); + } + for (unsigned int iSink = 0; iSink < Ns*Ns; ++iSink) + { + result.corr[iSink].resize(Ns*Ns); + for (unsigned int iSrc = 0; iSrc < Ns*Ns; ++iSrc) + { + c = trace(g[iSink]*q1*g[iSrc]*g5*adj(q2)*g5); + sliceSum(c, buf, Tp); + result.corr[iSink][iSrc].resize(buf.size()); + for (unsigned int t = 0; t < buf.size(); ++t) + { + result.corr[iSink][iSrc][t] = TensorRemove(buf[t]); + } + } + } + write(writer, "meson", result); } diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp index 8725d938..5e18cfbf 100644 --- a/programs/Hadrons/CMeson.hpp +++ b/programs/Hadrons/CMeson.hpp @@ -48,6 +48,12 @@ public: std::string, q2, std::string, output); }; + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::vector>>, corr); + }; public: // constructor CMeson(const std::string name); From 6e83b6a20382cf07d7e87761b05d2b75aadb6e91 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 2 May 2016 19:31:21 -0700 Subject: [PATCH 025/106] Hadrons: namespace reorganisation, now everything is in Grid::Hadrons, the 'using Grid::operator<<' statement is used to prevent a very nasty compilation error with GCC. --- programs/Hadrons/AWilson.cc | 1 + programs/Hadrons/Application.cc | 1 + programs/Hadrons/CMeson.cc | 3 ++- programs/Hadrons/Factory.hpp | 4 ++-- programs/Hadrons/FermionAction.cc | 1 + programs/Hadrons/Global.cc | 1 + programs/Hadrons/Global.hpp | 13 +++++++++---- programs/Hadrons/Graph.hpp | 4 ++-- programs/Hadrons/Hadrons.cc | 2 ++ programs/Hadrons/MQuark.cc | 1 + programs/Hadrons/MSource.cc | 2 ++ programs/Hadrons/Module.cc | 1 + programs/Hadrons/SRBPrecCG.cc | 1 + 13 files changed, 26 insertions(+), 9 deletions(-) diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc index 2f8483f3..f9de0926 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/AWilson.cc @@ -29,6 +29,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 5cdb6ed2..1a24f8b6 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -29,6 +29,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index c171fb95..a6e958f9 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -28,6 +28,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** @@ -85,7 +86,7 @@ void CMeson::execute(Environment &env) result.corr[iSink].resize(Ns*Ns); for (unsigned int iSrc = 0; iSrc < Ns*Ns; ++iSrc) { - c = trace(g[iSink]*q1*g[iSrc]*g5*adj(q2)*g5); + c = trace(g[iSink]*q1*g[iSrc]*g5*adj(q2)*g5); sliceSum(c, buf, Tp); result.corr[iSink][iSrc].resize(buf.size()); for (unsigned int t = 0; t < buf.size(); ++t) diff --git a/programs/Hadrons/Factory.hpp b/programs/Hadrons/Factory.hpp index 2b219dcc..e609949a 100644 --- a/programs/Hadrons/Factory.hpp +++ b/programs/Hadrons/Factory.hpp @@ -47,7 +47,7 @@ public: virtual ~Factory(void) = default; // registration void registerBuilder(const std::string type, const Func &f); - // get module list + // get builder list std::vector getBuilderList(void) const; // factory std::unique_ptr create(const std::string type, @@ -91,7 +91,7 @@ std::unique_ptr Factory::create(const std::string type, { func = builder_.at(type); } - catch (std::out_of_range) + catch (std::out_of_range &) { HADRON_ERROR("object of type '" + type + "' unknown"); } diff --git a/programs/Hadrons/FermionAction.cc b/programs/Hadrons/FermionAction.cc index 0857008b..fdd9530c 100644 --- a/programs/Hadrons/FermionAction.cc +++ b/programs/Hadrons/FermionAction.cc @@ -28,6 +28,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc index 18c3028e..6b855cda 100644 --- a/programs/Hadrons/Global.cc +++ b/programs/Hadrons/Global.cc @@ -28,6 +28,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; HadronsLogger Hadrons::HadronsLogError(1,"Error"); diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 39758b7e..f5a5c144 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -28,15 +28,20 @@ directory. #ifndef Hadrons_Global_hpp_ #define Hadrons_Global_hpp_ -#include #include #include +#include #define BEGIN_HADRONS_NAMESPACE \ +namespace Grid {\ +using namespace QCD;\ namespace Hadrons {\ -using namespace Grid;\ -using namespace QCD; -#define END_HADRONS_NAMESPACE } +using Grid::operator<<; +#define END_HADRONS_NAMESPACE }} + +/* the 'using Grid::operator<<;' statement prevents a very nasty compilation + * error with GCC (clang compiles fine without it). + */ BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 8b8afcc6..c7591350 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -105,8 +105,8 @@ private: void depthFirstSearch(void); void depthFirstSearch(const T &root); private: - std::map isMarked_; - std::set edgeSet_; + std::map isMarked_; + std::set edgeSet_; }; // build depedency matrix from topological sorts diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc index 73ac03f9..da5e02b1 100644 --- a/programs/Hadrons/Hadrons.cc +++ b/programs/Hadrons/Hadrons.cc @@ -27,6 +27,8 @@ directory. #include +using namespace Grid; +using namespace QCD; using namespace Hadrons; int main(int argc, char *argv[]) diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index 575914e4..04f9042d 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -28,6 +28,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** diff --git a/programs/Hadrons/MSource.cc b/programs/Hadrons/MSource.cc index f09c0b1d..3897db7c 100644 --- a/programs/Hadrons/MSource.cc +++ b/programs/Hadrons/MSource.cc @@ -28,7 +28,9 @@ directory. #include #define ERROR_SUF " (source '" << getName() << "')" + using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index 1437046e..a590b81a 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -28,6 +28,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** diff --git a/programs/Hadrons/SRBPrecCG.cc b/programs/Hadrons/SRBPrecCG.cc index 22206ed3..ff4a50d5 100644 --- a/programs/Hadrons/SRBPrecCG.cc +++ b/programs/Hadrons/SRBPrecCG.cc @@ -28,6 +28,7 @@ directory. #include using namespace Grid; +using namespace QCD; using namespace Hadrons; /****************************************************************************** From 02ec23cdad924f77622080f6b8eaa8d5c7a8ad97 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 May 2016 16:30:29 -0700 Subject: [PATCH 026/106] Hadrons: Fermion actions and gauge fields are modules now --- programs/Hadrons/AWilson.cc | 30 +++++-- programs/Hadrons/AWilson.hpp | 20 +++-- programs/Hadrons/Application.cc | 26 +----- programs/Hadrons/Application.hpp | 2 - programs/Hadrons/CMeson.cc | 2 +- programs/Hadrons/CMeson.hpp | 2 +- programs/Hadrons/Environment.cc | 75 ++++++++++++----- programs/Hadrons/Environment.hpp | 26 +++--- programs/Hadrons/FermionAction.hpp | 83 ------------------- .../Hadrons/{FermionAction.cc => GUnit.cc} | 36 ++++---- .../{FermionActionFactory.hpp => GUnit.hpp} | 33 ++++++-- programs/Hadrons/MQuark.cc | 21 +++-- programs/Hadrons/MQuark.hpp | 2 +- programs/Hadrons/MSource.cc | 6 +- programs/Hadrons/MSource.hpp | 2 +- programs/Hadrons/Makefile.am | 23 ++--- programs/Hadrons/Module.hpp | 4 +- programs/Hadrons/SRBPrecCG.cc | 10 ++- programs/Hadrons/SRBPrecCG.hpp | 4 +- 19 files changed, 191 insertions(+), 216 deletions(-) delete mode 100644 programs/Hadrons/FermionAction.hpp rename programs/Hadrons/{FermionAction.cc => GUnit.cc} (59%) rename programs/Hadrons/{FermionActionFactory.hpp => GUnit.hpp} (64%) diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc index f9de0926..ad5cae2a 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/AWilson.cc @@ -26,18 +26,16 @@ directory. *******************************************************************************/ #include -#include using namespace Grid; -using namespace QCD; using namespace Hadrons; /****************************************************************************** -* AWilson implementation * +* AWilson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// AWilson::AWilson(const std::string name) -: FermionAction(name) +: Module(name) {} // parse parameters //////////////////////////////////////////////////////////// @@ -46,12 +44,28 @@ void AWilson::parseParameters(XmlReader &reader, const std::string name) read(reader, name, par_); } -// create operator ///////////////////////////////////////////////////////////// -void AWilson::create(Environment &env) +// dependencies/products /////////////////////////////////////////////////////// +std::vector AWilson::getInput(void) { - auto &U = *env.getGauge(); + std::vector in = {par_.gauge}; + + return in; +} + +std::vector AWilson::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// execution /////////////////////////////////////////////////////////////////// +void AWilson::execute(Environment &env) +{ + auto &U = *env.getGauge(par_.gauge); auto &grid = *env.getGrid(); auto &gridRb = *env.getRbGrid(); - setFMat(new WilsonFermionR(U, grid, gridRb, par_.mass)); + env.addFermionMatrix(getName(), + new WilsonFermionR(U, grid, gridRb, par_.mass)); } diff --git a/programs/Hadrons/AWilson.hpp b/programs/Hadrons/AWilson.hpp index aa40b99d..cf21eff3 100644 --- a/programs/Hadrons/AWilson.hpp +++ b/programs/Hadrons/AWilson.hpp @@ -29,21 +29,22 @@ directory. #define Hadrons_AWilson_hpp_ #include -#include -#include +#include +#include BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * Wilson fermions * + * Wilson quark action * ******************************************************************************/ -class AWilson: public FermionAction +class AWilson: public Module { public: class Par: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, double, mass); + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, gauge, + double , mass); }; public: // constructor @@ -52,13 +53,16 @@ public: virtual ~AWilson(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); - // create operator - virtual void create(Environment &env); + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // execution + virtual void execute(Environment &env); private: Par par_; }; -ACTION_REGISTER(AWilson); +MODULE_REGISTER(AWilson); END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 1a24f8b6..d8b0d0da 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -39,17 +39,10 @@ using namespace Hadrons; Application::Application(const std::string parameterFileName) : parameterFileName_(parameterFileName) , env_(Environment::getInstance()) -, actionFactory_(FermionActionFactory::getInstance()) , modFactory_(ModuleFactory::getInstance()) { - LOG(Message) << "Fermion actions available:" << std::endl; - auto list = actionFactory_.getBuilderList(); - for (auto &m: list) - { - LOG(Message) << " " << m << std::endl; - } LOG(Message) << "Modules available:" << std::endl; - list = modFactory_.getBuilderList(); + auto list = modFactory_.getBuilderList(); for (auto &m: list) { LOG(Message) << " " << m << std::endl; @@ -84,18 +77,6 @@ void Application::parseParameterFile(void) LOG(Message) << "Reading '" << parameterFileName_ << "'..." << std::endl; read(reader, "parameters", par_); - push(reader, "actions"); - push(reader, "action"); - do - { - read(reader, "id", id); - env_.addFermionAction(actionFactory_.create(id.type, id.name)); - auto &action = *env_.getFermionAction(id.name); - action.parseParameters(reader, "options"); - action.create(env_); - } while (reader.nextElement("action")); - pop(reader); - pop(reader); push(reader, "modules"); push(reader, "module"); do @@ -190,7 +171,6 @@ void Application::configLoop(void) { LOG(Message) << "Starting measurement for trajectory " << t << std::endl; - env_.loadUnitGauge(); execute(program_); env_.freeAll(); } @@ -219,8 +199,8 @@ unsigned int Application::execute(const std::vector &program) } for (unsigned int i = 0; i < program.size(); ++i) { - LOG(Message) << "Measurement step (" << i+1 << "/" << program.size() - << ")" << std::endl; + LOG(Message) << "Measurement step " << i+1 << "/" << program.size() + << " (module '" << program[i] << "')" << std::endl; (*module_[program[i]])(env_); LOG(Message) << "allocated propagators: " << env_.nProp() << std::endl; if (env_.nProp() > memPeak) diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index a5e0e3c4..de788956 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -29,7 +29,6 @@ directory. #define Hadrons_Application_hpp_ #include -#include #include #include @@ -90,7 +89,6 @@ private: std::string parameterFileName_; GlobalPar par_; Environment &env_; - FermionActionFactory &actionFactory_; ModuleFactory &modFactory_; std::map> module_; std::map associatedModule_; diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index a6e958f9..eb746061 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -45,7 +45,7 @@ void CMeson::parseParameters(XmlReader &reader, const std::string name) read(reader, name, par_); } -// dependency relation ///////////////////////////////////////////////////////// +// dependencies/products /////////////////////////////////////////////////////// std::vector CMeson::getInput(void) { std::vector input = {par_.q1, par_.q2}; diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp index 5e18cfbf..29620726 100644 --- a/programs/Hadrons/CMeson.hpp +++ b/programs/Hadrons/CMeson.hpp @@ -61,7 +61,7 @@ public: virtual ~CMeson(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); - // dependency relation + // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); // execution diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index ebd8d010..c72e1fca 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -42,8 +42,6 @@ Environment::Environment(void) GridDefaultMpi())); gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get())); rng4d_.reset(new GridParallelRNG(grid4d_.get())); - gauge_.reset(new LatticeGaugeField(grid4d_.get())); - loadUnitGauge(); } // dry run ///////////////////////////////////////////////////////////////////// @@ -97,22 +95,22 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const } // fermion actions ///////////////////////////////////////////////////////////// -void Environment::addFermionAction(FActionPt action) +void Environment::addFermionMatrix(const std::string name, FMat *fMat) { - fAction_[action->getName()] = std::move(action); + fMat_[name].reset(fMat); } -FermionAction * Environment::getFermionAction(const std::string name) const +Environment::FMat * Environment::getFermionMatrix(const std::string name) const { try { - return fAction_.at(name).get(); + return fMat_.at(name).get(); } catch(std::out_of_range &) { try { - return fAction_.at(solverAction_.at(name)).get(); + return fMat_.at(solverAction_.at(name)).get(); } catch (std::out_of_range &) { @@ -143,9 +141,9 @@ void Environment::callSolver(const std::string name, LatticeFermion &sol, } // quark propagators /////////////////////////////////////////////////////////// -void Environment::addProp(const std::string name, const unsigned int Ls) +void Environment::createProp(const std::string name, const unsigned int Ls) { - GridCartesian *p4 = grid4d_.get(); + GridCartesian *g4 = getGrid(); if (propExists(name)) { @@ -153,21 +151,21 @@ void Environment::addProp(const std::string name, const unsigned int Ls) } if (Ls > 1) { - GridCartesian *p; + GridCartesian *g; try { - p = grid5d_.at(Ls).get(); + g = grid5d_.at(Ls).get(); } catch(std::out_of_range &) { - grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, p4)); - gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, p4)); - p = grid5d_[Ls].get(); + grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g4)); + gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g4)); + g = grid5d_[Ls].get(); } if (!isDryRun()) { - prop_[name].reset(new LatticePropagator(p)); + prop_[name].reset(new LatticePropagator(g)); } else { @@ -179,7 +177,7 @@ void Environment::addProp(const std::string name, const unsigned int Ls) { if (!isDryRun()) { - prop_[name].reset(new LatticePropagator(p4)); + prop_[name].reset(new LatticePropagator(g4)); } else { @@ -269,19 +267,44 @@ unsigned int Environment::nProp(void) const } // gauge configuration ///////////////////////////////////////////////////////// -LatticeGaugeField * Environment::getGauge(void) const +void Environment::createGauge(const std::string name) { - return gauge_.get(); + if (gaugeExists(name)) + { + HADRON_ERROR("gauge field '" + name + "' already exists"); + } + gauge_[name].reset(new LatticeGaugeField(getGrid())); } -void Environment::loadUnitGauge(void) +void Environment::freeGauge(const std::string name) { - SU3::ColdConfiguration(*rng4d_, *gauge_); + if (gaugeExists(name)) + { + gauge_.erase(name); + } + else + { + HADRON_ERROR("trying to free unknown gauge field '" + name + "'"); + } } -void Environment::loadRandomGauge(void) +LatticeGaugeField * Environment::getGauge(const std::string name) const { - SU3::HotConfiguration(*rng4d_, *gauge_); + if (gaugeExists(name)) + { + return gauge_.at(name).get(); + } + else + { + HADRON_ERROR("gauge field '" + name + "' unknown"); + + return nullptr; + } +} + +bool Environment::gaugeExists(const std::string name) const +{ + return (gauge_.find(name) != gauge_.end()); } // random number generator ///////////////////////////////////////////////////// @@ -300,13 +323,19 @@ void Environment::free(const std::string name) { if (propExists(name)) { - LOG(Message) << "freeing '" << name << "'" << std::endl; + LOG(Message) << "freeing propagator '" << name << "'" << std::endl; freeProp(name); } + else if (gaugeExists(name)) + { + LOG(Message) << "freeing gauge field '" << name << "'" << std::endl; + freeGauge(name); + } } void Environment::freeAll(void) { prop_.clear(); propSize_.clear(); + gauge_.clear(); } diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 906c5aa1..91f0ec23 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -29,7 +29,6 @@ directory. #define Hadrons_Environment_hpp_ #include -#include BEGIN_HADRONS_NAMESPACE @@ -40,12 +39,13 @@ class Environment { SINGLETON(Environment); public: + typedef FermionOperator FMat; typedef std::function Solver; typedef std::unique_ptr GridPt; typedef std::unique_ptr GridRbPt; typedef std::unique_ptr RngPt; - typedef std::unique_ptr FActionPt; + typedef std::unique_ptr FMatPt; typedef std::unique_ptr PropPt; typedef std::unique_ptr GaugePt; public: @@ -56,8 +56,8 @@ public: GridCartesian * getGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; // fermion actions - void addFermionAction(FActionPt action); - FermionAction * getFermionAction(const std::string name) const; + void addFermionMatrix(const std::string name, FMat *mat); + FMat * getFermionMatrix(const std::string name) const; // solvers void addSolver(const std::string name, Solver s, const std::string actionName); @@ -65,18 +65,19 @@ public: LatticeFermion &sol, const LatticeFermion &src) const; // quark propagators - void addProp(const std::string name, - const unsigned int Ls = 1); + void createProp(const std::string name, + const unsigned int Ls = 1); void freeProp(const std::string name); bool isProp5d(const std::string name) const; unsigned int getPropLs(const std::string name) const; LatticePropagator * getProp(const std::string name) const; bool propExists(const std::string name) const; unsigned int nProp(void) const; - // gauge configuration - LatticeGaugeField * getGauge(void) const; - void loadUnitGauge(void); - void loadRandomGauge(void); + // gauge configurations + void createGauge(const std::string name); + void freeGauge(const std::string name); + LatticeGaugeField * getGauge(const std::string name) const; + bool gaugeExists(const std::string name) const; // random number generator void setSeed(const std::vector &seed); GridParallelRNG * get4dRng(void) const; @@ -90,13 +91,12 @@ private: GridRbPt gridRb4d_; std::map gridRb5d_; RngPt rng4d_; - std::map fAction_; + std::map fMat_; std::map solver_; std::map solverAction_; std::map prop_; std::map propSize_; - GaugePt gauge_; - + std::map gauge_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/FermionAction.hpp b/programs/Hadrons/FermionAction.hpp deleted file mode 100644 index f3cd1cf7..00000000 --- a/programs/Hadrons/FermionAction.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/FermionAction.hpp - -Copyright (C) 2016 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#ifndef Hadrons_FermionAction_hpp_ -#define Hadrons_FermionAction_hpp_ - -#include - -BEGIN_HADRONS_NAMESPACE - -// action registration macro -#define ACTION_REGISTER(action)\ -class action##ActionRegistrar\ -{\ -public:\ - action##ActionRegistrar(void)\ - {\ - FermionActionFactory &actionFac = FermionActionFactory::getInstance();\ - actionFac.registerBuilder(#action, [&](const std::string name)\ - {\ - return std::unique_ptr(\ - new action(name));\ - });\ - }\ -};\ -static action##ActionRegistrar action##ActionRegistrarInstance; - -/****************************************************************************** - * FermionAction * - ******************************************************************************/ -class Environment; - -class FermionAction -{ -public: - typedef FermionOperator FMat; - typedef std::unique_ptr FMatPt; -public: - // constructor - FermionAction(const std::string name); - // destructor - virtual ~FermionAction(void) = default; - // access - std::string getName(void) const; - virtual unsigned int getLs(void) const; - void setFMat(FMat *fMat); - FMat * getFMat(void); - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name) = 0; - // create operator - virtual void create(Environment &env) = 0; -private: - std::string name_; - FMatPt fMat_; -}; - -END_HADRONS_NAMESPACE - -#endif // Hadrons_FermionAction_hpp_ diff --git a/programs/Hadrons/FermionAction.cc b/programs/Hadrons/GUnit.cc similarity index 59% rename from programs/Hadrons/FermionAction.cc rename to programs/Hadrons/GUnit.cc index fdd9530c..ce406612 100644 --- a/programs/Hadrons/FermionAction.cc +++ b/programs/Hadrons/GUnit.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/FermionAction.cc +Source file: programs/Hadrons/GUnit.cc Copyright (C) 2016 @@ -25,37 +25,41 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; -using namespace QCD; using namespace Hadrons; /****************************************************************************** - * FermionAction implementation * - ******************************************************************************/ +* GUnit implementation * +******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -FermionAction::FermionAction(const std::string name) -: name_(name) +GUnit::GUnit(const std::string name) +: Module(name) {} -// access ////////////////////////////////////////////////////////////////////// -std::string FermionAction::getName(void) const +// dependencies/products /////////////////////////////////////////////////////// +std::vector GUnit::getInput(void) { - return name_; + return std::vector(); } -unsigned int FermionAction::getLs(void) const +std::vector GUnit::getOutput(void) { - return 1; + std::vector out = {getName()}; + + return out; } -void FermionAction::setFMat(FMat *fMat) +// allocation ////////////////////////////////////////////////////////////////// +void GUnit::allocate(Environment &env) { - fMat_.reset(fMat); + env.createGauge(getName()); + gauge_ = env.getGauge(getName()); } -FermionAction::FMat * FermionAction::getFMat(void) +// execution /////////////////////////////////////////////////////////////////// +void GUnit::execute(Environment &env) { - return fMat_.get(); + SU3::ColdConfiguration(*env.get4dRng(), *gauge_); } diff --git a/programs/Hadrons/FermionActionFactory.hpp b/programs/Hadrons/GUnit.hpp similarity index 64% rename from programs/Hadrons/FermionActionFactory.hpp rename to programs/Hadrons/GUnit.hpp index d9522c31..21e9a15f 100644 --- a/programs/Hadrons/FermionActionFactory.hpp +++ b/programs/Hadrons/GUnit.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/FermionActionFactory.hpp +Source file: programs/Hadrons/GUnit.hpp Copyright (C) 2016 @@ -25,23 +25,38 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_FermionActionFactory_hpp_ -#define Hadrons_FermionActionFactory_hpp_ +#ifndef Hadrons_GUnit_hpp_ +#define Hadrons_GUnit_hpp_ #include -#include -#include +#include +#include BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * FermionActionFactory * + * Unit gauge * ******************************************************************************/ -class FermionActionFactory: public Factory +class GUnit: public Module { - SINGLETON_DEFCTOR(FermionActionFactory) +public: + // constructor + GUnit(const std::string name); + // destructor + virtual ~GUnit(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // allocation + virtual void allocate(Environment &env); + // execution + virtual void execute(Environment &env); +private: + LatticeGaugeField *gauge_ = nullptr; }; +MODULE_REGISTER(GUnit); + END_HADRONS_NAMESPACE -#endif // Hadrons_FermionActionFactory_hpp_ +#endif // Hadrons_GUnit_hpp_ diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index 04f9042d..b95493e7 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -39,13 +39,13 @@ MQuark::MQuark(const std::string name) : Module(name) {} -// parse parameters +// parse parameters //////////////////////////////////////////////////////////// void MQuark::parseParameters(XmlReader &reader, const std::string name) { read(reader, name, par_); } -// dependency relation +// dependencies/products /////////////////////////////////////////////////////// std::vector MQuark::getInput(void) { std::vector in = {par_.source, par_.solver}; @@ -63,22 +63,31 @@ std::vector MQuark::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void MQuark::setup(Environment &env) { - Ls_ = env.getFermionAction(par_.solver)->getLs(); + auto dim = env.getFermionMatrix(par_.solver)->Grid()->GlobalDimensions(); + + if (dim.size() == Nd) + { + Ls_ = 1; + } + else + { + Ls_ = dim[0]; + } } // allocation ////////////////////////////////////////////////////////////////// void MQuark::allocate(Environment &env) { - env.addProp(getName()); + env.createProp(getName()); quark_ = env.getProp(getName()); if (Ls_ > 1) { - env.addProp(getName() + "_5d", Ls_); + env.createProp(getName() + "_5d", Ls_); quark5d_ = env.getProp(getName() + "_5d"); } } -// execution +// execution /////////////////////////////////////////////////////////////////// void MQuark::execute(Environment &env) { LatticePropagator *fullSource; diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/MQuark.hpp index 90e5f0e4..5b14d0aa 100644 --- a/programs/Hadrons/MQuark.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -53,7 +53,7 @@ public: virtual ~MQuark(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); - // dependency relation + // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); // setup diff --git a/programs/Hadrons/MSource.cc b/programs/Hadrons/MSource.cc index 3897db7c..923d5e94 100644 --- a/programs/Hadrons/MSource.cc +++ b/programs/Hadrons/MSource.cc @@ -41,13 +41,13 @@ MSource::MSource(const std::string name) : Module(name) {} -// parse parameters +// parse parameters //////////////////////////////////////////////////////////// void MSource::parseParameters(XmlReader &reader, const std::string name) { read(reader, name, par_); } -// dependency relation +// dependencies/products /////////////////////////////////////////////////////// std::vector MSource::getInput(void) { return std::vector(); @@ -68,7 +68,7 @@ void MSource::allocate(Environment &env) // 4D sources case Grid::SourceType::point: case Grid::SourceType::z2Band: - env.addProp(getName()); + env.createProp(getName()); src_ = env.getProp(getName()); break; // error diff --git a/programs/Hadrons/MSource.hpp b/programs/Hadrons/MSource.hpp index 3bc901ad..490be342 100644 --- a/programs/Hadrons/MSource.hpp +++ b/programs/Hadrons/MSource.hpp @@ -84,7 +84,7 @@ public: virtual ~MSource(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); - // dependency relation + // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); // allocation diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 41da337e..499122ac 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -3,30 +3,33 @@ AM_LDFLAGS = -L$(top_builddir)/lib bin_PROGRAMS = Hadrons -## general sources +# general sources Hadrons_SOURCES = \ Application.cc \ Environment.cc \ - FermionAction.cc\ Global.cc \ Hadrons.cc \ Module.cc -## fermion actions -Hadrons_SOURCES += \ - AWilson.cc - -## general modules +# general modules Hadrons_SOURCES += \ MQuark.cc \ MSource.cc -## solver modules +# fermion actions Hadrons_SOURCES += \ - SRBPrecCG.cc + AWilson.cc -## contraction modules +# contraction modules Hadrons_SOURCES += \ CMeson.cc +# gauge modules +Hadrons_SOURCES += \ + GUnit.cc + +# solver modules +Hadrons_SOURCES += \ + SRBPrecCG.cc + Hadrons_LDADD = -lGrid diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 4153e77b..1f529944 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -62,8 +62,8 @@ public: // access std::string getName(void) const; // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name) = 0; - // dependency relation + virtual void parseParameters(XmlReader &reader, const std::string name) {}; + // dependencies/products virtual std::vector getInput(void) = 0; virtual std::vector getOutput(void) = 0; // setup diff --git a/programs/Hadrons/SRBPrecCG.cc b/programs/Hadrons/SRBPrecCG.cc index ff4a50d5..42ee332f 100644 --- a/programs/Hadrons/SRBPrecCG.cc +++ b/programs/Hadrons/SRBPrecCG.cc @@ -39,16 +39,18 @@ SRBPrecCG::SRBPrecCG(const std::string name) : Module(name) {} -// parse parameters +// parse parameters //////////////////////////////////////////////////////////// void SRBPrecCG::parseParameters(XmlReader &reader, const std::string name) { read(reader, name, par_); } -// dependency relation +// dependencies/products /////////////////////////////////////////////////////// std::vector SRBPrecCG::getInput(void) { - return std::vector(); + std::vector in = {par_.action}; + + return in; } std::vector SRBPrecCG::getOutput(void) @@ -61,7 +63,7 @@ std::vector SRBPrecCG::getOutput(void) // execution /////////////////////////////////////////////////////////////////// void SRBPrecCG::execute(Environment &env) { - auto &mat = *(env.getFermionAction(par_.action)->getFMat()); + auto &mat = *(env.getFermionMatrix(par_.action)); auto solver = [&mat, this](LatticeFermion &sol, const LatticeFermion &source) { diff --git a/programs/Hadrons/SRBPrecCG.hpp b/programs/Hadrons/SRBPrecCG.hpp index 1b072c37..f657bd50 100644 --- a/programs/Hadrons/SRBPrecCG.hpp +++ b/programs/Hadrons/SRBPrecCG.hpp @@ -35,7 +35,7 @@ directory. BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * SRBPrecCG * + * Schur red-black preconditioned CG * ******************************************************************************/ class SRBPrecCG: public Module { @@ -53,7 +53,7 @@ public: virtual ~SRBPrecCG(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); - // dependency relation + // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); // execution From 8b313a35ac76d0fe03460e4974bf64dc13ea7615 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 May 2016 17:07:00 -0700 Subject: [PATCH 027/106] Hadrons: random and NERSC gauge configurations --- programs/Hadrons/Application.cc | 1 + programs/Hadrons/Environment.cc | 11 +++++ programs/Hadrons/Environment.hpp | 4 ++ programs/Hadrons/GLoad.cc | 77 ++++++++++++++++++++++++++++++++ programs/Hadrons/GLoad.hpp | 71 +++++++++++++++++++++++++++++ programs/Hadrons/GRandom.cc | 65 +++++++++++++++++++++++++++ programs/Hadrons/GRandom.hpp | 62 +++++++++++++++++++++++++ programs/Hadrons/Makefile.am | 2 + 8 files changed, 293 insertions(+) create mode 100644 programs/Hadrons/GLoad.cc create mode 100644 programs/Hadrons/GLoad.hpp create mode 100644 programs/Hadrons/GRandom.cc create mode 100644 programs/Hadrons/GRandom.hpp diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index d8b0d0da..980a4cf5 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -171,6 +171,7 @@ void Application::configLoop(void) { LOG(Message) << "Starting measurement for trajectory " << t << std::endl; + env_.setTrajectory(t); execute(program_); env_.freeAll(); } diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index c72e1fca..9f572f17 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -55,6 +55,17 @@ bool Environment::isDryRun(void) const return dryRun_; } +// trajectory number /////////////////////////////////////////////////////////// +void Environment::setTrajectory(const unsigned int traj) +{ + traj_ = traj; +} + +unsigned int Environment::getTrajectory(void) const +{ + return traj_; +} + // grids /////////////////////////////////////////////////////////////////////// GridCartesian * Environment::getGrid(const unsigned int Ls) const { diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 91f0ec23..5a4c1e3f 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -52,6 +52,9 @@ public: // dry run void dryRun(const bool isDry); bool isDryRun(void) const; + // trajectory number + void setTrajectory(const unsigned int traj); + unsigned int getTrajectory(void) const; // grids GridCartesian * getGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; @@ -86,6 +89,7 @@ public: void freeAll(void); private: bool dryRun_{false}; + unsigned int traj_; GridPt grid4d_; std::map grid5d_; GridRbPt gridRb4d_; diff --git a/programs/Hadrons/GLoad.cc b/programs/Hadrons/GLoad.cc new file mode 100644 index 00000000..2add8a11 --- /dev/null +++ b/programs/Hadrons/GLoad.cc @@ -0,0 +1,77 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/GLoad.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* GLoad implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +GLoad::GLoad(const std::string name) +: Module(name) +{} + +// parse parameters //////////////////////////////////////////////////////////// +void GLoad::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_); +} + +// dependencies/products /////////////////////////////////////////////////////// +std::vector GLoad::getInput(void) +{ + std::vector in; + + return in; +} + +std::vector GLoad::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// allocation ////////////////////////////////////////////////////////////////// +void GLoad::allocate(Environment &env) +{ + env.createGauge(getName()); + gauge_ = env.getGauge(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +void GLoad::execute(Environment &env) +{ + NerscField header; + std::string fileName = par_.file + "." + + std::to_string(env.getTrajectory()); + + NerscIO::readConfiguration(*gauge_, header, fileName); +} diff --git a/programs/Hadrons/GLoad.hpp b/programs/Hadrons/GLoad.hpp new file mode 100644 index 00000000..a40ed2c2 --- /dev/null +++ b/programs/Hadrons/GLoad.hpp @@ -0,0 +1,71 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/GLoad.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_GLoad_hpp_ +#define Hadrons_GLoad_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Load a NERSC configuration * + ******************************************************************************/ +class GLoad: public Module +{ +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, file); + }; +public: + // constructor + GLoad(const std::string name); + // destructor + virtual ~GLoad(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // allocation + virtual void allocate(Environment &env); + // execution + virtual void execute(Environment &env); +private: + Par par_; + LatticeGaugeField *gauge_ = nullptr; +}; + +MODULE_REGISTER(GLoad); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_GLoad_hpp_ diff --git a/programs/Hadrons/GRandom.cc b/programs/Hadrons/GRandom.cc new file mode 100644 index 00000000..d39769a9 --- /dev/null +++ b/programs/Hadrons/GRandom.cc @@ -0,0 +1,65 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/GRandom.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* GRandom implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +GRandom::GRandom(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +std::vector GRandom::getInput(void) +{ + return std::vector(); +} + +std::vector GRandom::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// allocation ////////////////////////////////////////////////////////////////// +void GRandom::allocate(Environment &env) +{ + env.createGauge(getName()); + gauge_ = env.getGauge(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +void GRandom::execute(Environment &env) +{ + SU3::HotConfiguration(*env.get4dRng(), *gauge_); +} diff --git a/programs/Hadrons/GRandom.hpp b/programs/Hadrons/GRandom.hpp new file mode 100644 index 00000000..18660bf9 --- /dev/null +++ b/programs/Hadrons/GRandom.hpp @@ -0,0 +1,62 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/GRandom.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_GRandom_hpp_ +#define Hadrons_GRandom_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Random gauge * + ******************************************************************************/ +class GRandom: public Module +{ +public: + // constructor + GRandom(const std::string name); + // destructor + virtual ~GRandom(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // allocation + virtual void allocate(Environment &env); + // execution + virtual void execute(Environment &env); +private: + LatticeGaugeField *gauge_ = nullptr; +}; + +MODULE_REGISTER(GRandom); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_GRandom_hpp_ diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 499122ac..72f04612 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -26,6 +26,8 @@ Hadrons_SOURCES += \ # gauge modules Hadrons_SOURCES += \ + GLoad.cc \ + GRandom.cc \ GUnit.cc # solver modules From b865dd9da8bcb7d63649cffa1de2cb675dd4f163 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 May 2016 18:16:57 -0700 Subject: [PATCH 028/106] Hadrons: solver renaming --- programs/Hadrons/Makefile.am | 2 +- .../Hadrons/{SRBPrecCG.cc => SolRBPrecCG.cc} | 19 +++++++++++-------- .../{SRBPrecCG.hpp => SolRBPrecCG.hpp} | 16 ++++++++-------- 3 files changed, 20 insertions(+), 17 deletions(-) rename programs/Hadrons/{SRBPrecCG.cc => SolRBPrecCG.cc} (78%) rename programs/Hadrons/{SRBPrecCG.hpp => SolRBPrecCG.hpp} (87%) diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 72f04612..1c97305a 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -32,6 +32,6 @@ Hadrons_SOURCES += \ # solver modules Hadrons_SOURCES += \ - SRBPrecCG.cc + SolRBPrecCG.cc Hadrons_LDADD = -lGrid diff --git a/programs/Hadrons/SRBPrecCG.cc b/programs/Hadrons/SolRBPrecCG.cc similarity index 78% rename from programs/Hadrons/SRBPrecCG.cc rename to programs/Hadrons/SolRBPrecCG.cc index 42ee332f..250c81e6 100644 --- a/programs/Hadrons/SRBPrecCG.cc +++ b/programs/Hadrons/SolRBPrecCG.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SRBPrecCG.cc +Source file: programs/Hadrons/SolRBPrecCG.cc Copyright (C) 2016 @@ -25,35 +25,35 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; using namespace Hadrons; /****************************************************************************** -* SRBPrecCG implementation * +* SolRBPrecCG implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -SRBPrecCG::SRBPrecCG(const std::string name) +SolRBPrecCG::SolRBPrecCG(const std::string name) : Module(name) {} // parse parameters //////////////////////////////////////////////////////////// -void SRBPrecCG::parseParameters(XmlReader &reader, const std::string name) +void SolRBPrecCG::parseParameters(XmlReader &reader, const std::string name) { read(reader, name, par_); } // dependencies/products /////////////////////////////////////////////////////// -std::vector SRBPrecCG::getInput(void) +std::vector SolRBPrecCG::getInput(void) { std::vector in = {par_.action}; return in; } -std::vector SRBPrecCG::getOutput(void) +std::vector SolRBPrecCG::getOutput(void) { std::vector out = {getName()}; @@ -61,7 +61,7 @@ std::vector SRBPrecCG::getOutput(void) } // execution /////////////////////////////////////////////////////////////////// -void SRBPrecCG::execute(Environment &env) +void SolRBPrecCG::execute(Environment &env) { auto &mat = *(env.getFermionMatrix(par_.action)); auto solver = [&mat, this](LatticeFermion &sol, @@ -73,5 +73,8 @@ void SRBPrecCG::execute(Environment &env) schurSolver(mat, source, sol); }; + LOG(Message) << "setting up Schur red-black preconditioned CG for" + << " action '" << par_.action << "' with residual " + << par_.residual << std::endl; env.addSolver(getName(), solver, par_.action); } diff --git a/programs/Hadrons/SRBPrecCG.hpp b/programs/Hadrons/SolRBPrecCG.hpp similarity index 87% rename from programs/Hadrons/SRBPrecCG.hpp rename to programs/Hadrons/SolRBPrecCG.hpp index f657bd50..ca046efa 100644 --- a/programs/Hadrons/SRBPrecCG.hpp +++ b/programs/Hadrons/SolRBPrecCG.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SRBPrecCG.hpp +Source file: programs/Hadrons/SolRBPrecCG.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_SRBPrecCG_hpp_ -#define Hadrons_SRBPrecCG_hpp_ +#ifndef Hadrons_SolRBPrecCG_hpp_ +#define Hadrons_SolRBPrecCG_hpp_ #include #include @@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Schur red-black preconditioned CG * ******************************************************************************/ -class SRBPrecCG: public Module +class SolRBPrecCG: public Module { public: class Par: Serializable @@ -48,9 +48,9 @@ public: }; public: // constructor - SRBPrecCG(const std::string name); + SolRBPrecCG(const std::string name); // destructor - virtual ~SRBPrecCG(void) = default; + virtual ~SolRBPrecCG(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); // dependencies/products @@ -62,8 +62,8 @@ private: Par par_; }; -MODULE_REGISTER(SRBPrecCG); +MODULE_REGISTER(SolRBPrecCG); END_HADRONS_NAMESPACE -#endif // Hadrons_SRBPrecCG_hpp_ +#endif // Hadrons_SolRBPrecCG_hpp_ From ba878724ce068cd8ed21acadea72312035307efe Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 May 2016 18:17:28 -0700 Subject: [PATCH 029/106] Hadrons: sources are now independent modules --- programs/Hadrons/MSource.cc | 144 ------------------ programs/Hadrons/Makefile.am | 8 +- programs/Hadrons/SrcPoint.cc | 80 ++++++++++ .../Hadrons/{MSource.hpp => SrcPoint.hpp} | 65 +++----- programs/Hadrons/SrcZ2.cc | 93 +++++++++++ programs/Hadrons/SrcZ2.hpp | 84 ++++++++++ 6 files changed, 285 insertions(+), 189 deletions(-) delete mode 100644 programs/Hadrons/MSource.cc create mode 100644 programs/Hadrons/SrcPoint.cc rename programs/Hadrons/{MSource.hpp => SrcPoint.hpp} (61%) create mode 100644 programs/Hadrons/SrcZ2.cc create mode 100644 programs/Hadrons/SrcZ2.hpp diff --git a/programs/Hadrons/MSource.cc b/programs/Hadrons/MSource.cc deleted file mode 100644 index 923d5e94..00000000 --- a/programs/Hadrons/MSource.cc +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/MSource.cc - -Copyright (C) 2016 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -#define ERROR_SUF " (source '" << getName() << "')" - -using namespace Grid; -using namespace QCD; -using namespace Hadrons; - -/****************************************************************************** -* MSource implementation * -******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -MSource::MSource(const std::string name) -: Module(name) -{} - -// parse parameters //////////////////////////////////////////////////////////// -void MSource::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - -// dependencies/products /////////////////////////////////////////////////////// -std::vector MSource::getInput(void) -{ - return std::vector(); -} - -std::vector MSource::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// allocation ////////////////////////////////////////////////////////////////// -void MSource::allocate(Environment &env) -{ - switch (par_.sourceType) - { - // 4D sources - case Grid::SourceType::point: - case Grid::SourceType::z2Band: - env.createProp(getName()); - src_ = env.getProp(getName()); - break; - // error - default: - HADRON_ERROR("no allocation implemented for source type '" - << par_.sourceType << "'" << ERROR_SUF); - break; - } -} - -// execution -#define ARG_CHECK(n)\ -if (par_.arguments.size() != (n))\ -{\ - HADRON_ERROR("source type '" << par_.sourceType << "' expect "\ - << (n) << " arguments (got "\ - << par_.arguments.size() << ")" << ERROR_SUF);\ -} - -void MSource::execute(Environment &env) -{ - LOG(Message) << "generating source '" << getName() << "' of type '" - << par_.sourceType << "'" << std::endl; - switch (par_.sourceType) - { - // point source - case Grid::SourceType::point: - { - ARG_CHECK(1); - - std::vector origin = strToVec(par_.arguments[0]); - SpinColourMatrix id(1.); - - if (origin.size() != Nd) - { - HADRON_ERROR("point source origin dimension different from " - << Nd << ERROR_SUF); - } - *src_ = zero; - pokeSite(id, *src_, origin); - - break; - } - // z2Band source - case Grid::SourceType::z2Band: - { - ARG_CHECK(2); - - int ta = std::stoi(par_.arguments[0]); - int tb = std::stoi(par_.arguments[1]); - Lattice> t(env.getGrid()); - LatticeComplex eta(env.getGrid()); - LatticeFermion phi(env.getGrid()); - Complex shift(1., 1.); - - LatticeCoordinate(t, Tp); - bernoulli(*env.get4dRng(), eta); - eta = (2.*eta - shift)*(1./::sqrt(2.)); - eta = where((t >= ta) and (t <= tb), eta, 0.*eta); - *src_ = 1.; - *src_ = (*src_)*eta; - - break; - } - // error - default: - { - HADRON_ERROR("no definition implemented for source type '" - << par_.sourceType << "'" << ERROR_SUF); - break; - } - } -} diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 1c97305a..2d1b5980 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -13,8 +13,7 @@ Hadrons_SOURCES = \ # general modules Hadrons_SOURCES += \ - MQuark.cc \ - MSource.cc + MQuark.cc # fermion actions Hadrons_SOURCES += \ @@ -34,4 +33,9 @@ Hadrons_SOURCES += \ Hadrons_SOURCES += \ SolRBPrecCG.cc +# source modules +Hadrons_SOURCES += \ + SrcPoint.cc \ + SrcZ2.cc + Hadrons_LDADD = -lGrid diff --git a/programs/Hadrons/SrcPoint.cc b/programs/Hadrons/SrcPoint.cc new file mode 100644 index 00000000..b5329091 --- /dev/null +++ b/programs/Hadrons/SrcPoint.cc @@ -0,0 +1,80 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/SrcPoint.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* SrcPoint implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +SrcPoint::SrcPoint(const std::string name) +: Module(name) +{} + +// parse parameters //////////////////////////////////////////////////////////// +void SrcPoint::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_); +} + +// dependencies/products /////////////////////////////////////////////////////// +std::vector SrcPoint::getInput(void) +{ + std::vector in; + + return in; +} + +std::vector SrcPoint::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// allocation ////////////////////////////////////////////////////////////////// +void SrcPoint::allocate(Environment &env) +{ + env.createProp(getName()); + src_ = env.getProp(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +void SrcPoint::execute(Environment &env) +{ + std::vector position = strToVec(par_.position); + SpinColourMatrix id; + + LOG(Message) << "creating point source at position [" << par_.position + << "]" << std::endl; + id = 1.; + *src_ = zero; + pokeSite(id, *src_, position); +} diff --git a/programs/Hadrons/MSource.hpp b/programs/Hadrons/SrcPoint.hpp similarity index 61% rename from programs/Hadrons/MSource.hpp rename to programs/Hadrons/SrcPoint.hpp index 490be342..5cde676e 100644 --- a/programs/Hadrons/MSource.hpp +++ b/programs/Hadrons/SrcPoint.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/MSource.hpp +Source file: programs/Hadrons/SrcPoint.hpp Copyright (C) 2016 @@ -25,66 +25,45 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -/************ - * Sources * - ************ - - Description of all source types. - Convention: the discrete Heavyside function verifies theta(0) = 1. - - point: Point source - ------------------- - * src(x) = delta_x,o - - * arguments: o - - o: origin, space-separated integer sequence (e.g. "0 1 1 0") - - z2Band: Z_2 stochastic source - ----------------------------- - * src(x) = eta_x * theta(x_0 - ta) * theta(tb - x_0) - - * arguments: ta tb - - ta: begin timeslice (integer) - - tb: end timesilce (integer) - - */ - - -#ifndef Hadrons_MSource_hpp_ -#define Hadrons_MSource_hpp_ +#ifndef Hadrons_SrcPoint_hpp_ +#define Hadrons_SrcPoint_hpp_ #include #include #include -namespace Grid{ - GRID_SERIALIZABLE_ENUM(SourceType, undef, - point, 1, - z2Band, 2); -} - BEGIN_HADRONS_NAMESPACE +/* + + Point source + ------------ + * src_x = delta_x,o + + * options: o + - position: space-separated integer sequence (e.g. "0 1 1 0") + + */ + /****************************************************************************** - * Source module * + * SrcPoint * ******************************************************************************/ -class MSource: public Module +class SrcPoint: public Module { public: class Par: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, SourceType, sourceType, - std::vector, arguments); + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, position); }; public: // constructor - MSource(const std::string name); + SrcPoint(const std::string name); // destructor - virtual ~MSource(void) = default; + virtual ~SrcPoint(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); - // dependencies/products + // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); // allocation @@ -96,8 +75,8 @@ private: LatticePropagator *src_{nullptr}; }; -MODULE_REGISTER(MSource); +MODULE_REGISTER(SrcPoint); END_HADRONS_NAMESPACE -#endif // Hadrons_MSource_hpp_ +#endif // Hadrons_SrcPoint_hpp_ diff --git a/programs/Hadrons/SrcZ2.cc b/programs/Hadrons/SrcZ2.cc new file mode 100644 index 00000000..e050d6c4 --- /dev/null +++ b/programs/Hadrons/SrcZ2.cc @@ -0,0 +1,93 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/SrcZ2.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* SrcZ2 implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +SrcZ2::SrcZ2(const std::string name) +: Module(name) +{} + +// parse parameters //////////////////////////////////////////////////////////// +void SrcZ2::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_); +} + +// dependencies/products /////////////////////////////////////////////////////// +std::vector SrcZ2::getInput(void) +{ + std::vector in; + + return in; +} + +std::vector SrcZ2::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// allocation ////////////////////////////////////////////////////////////////// +void SrcZ2::allocate(Environment &env) +{ + env.createProp(getName()); + src_ = env.getProp(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +void SrcZ2::execute(Environment &env) +{ + Lattice> t(env.getGrid()); + LatticeComplex eta(env.getGrid()); + LatticeFermion phi(env.getGrid()); + Complex shift(1., 1.); + + if (par_.tA == par_.tB) + { + LOG(Message) << "generating Z_2 wall source at t= " << par_.tA + << std::endl; + } + else + { + LOG(Message) << "generating Z_2 band for " << par_.tA << " <= t <= " + << par_.tB << std::endl; + } + LatticeCoordinate(t, Tp); + bernoulli(*env.get4dRng(), eta); + eta = (2.*eta - shift)*(1./::sqrt(2.)); + eta = where((t >= par_.tA) and (t <= par_.tB), eta, 0.*eta); + *src_ = 1.; + *src_ = (*src_)*eta; +} diff --git a/programs/Hadrons/SrcZ2.hpp b/programs/Hadrons/SrcZ2.hpp new file mode 100644 index 00000000..09248e66 --- /dev/null +++ b/programs/Hadrons/SrcZ2.hpp @@ -0,0 +1,84 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/SrcZ2.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_SrcZ2_hpp_ +#define Hadrons_SrcZ2_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + + Z_2 stochastic source + ----------------------------- + * src_x = eta_x * theta(x_3 - ta) * theta(tb - x_3) + + * options: + - tA: begin timeslice (integer) + - tB: end timesilce (integer) + + */ + +/****************************************************************************** + * SrcZ2 * + ******************************************************************************/ +class SrcZ2: public Module +{ +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, tA, + unsigned int, tB); + }; +public: + // constructor + SrcZ2(const std::string name); + // destructor + virtual ~SrcZ2(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // allocation + virtual void allocate(Environment &env); + // execution + virtual void execute(Environment &env); +private: + Par par_; + LatticePropagator *src_; +}; + +MODULE_REGISTER(SrcZ2); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_SrcZ2_hpp_ From 798d8f7340b3d2050fc1066c2938480668217165 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 May 2016 18:17:58 -0700 Subject: [PATCH 030/106] Hadrons: Modules: better log messages --- programs/Hadrons/AWilson.cc | 2 ++ programs/Hadrons/CMeson.cc | 3 ++- programs/Hadrons/GLoad.cc | 2 ++ programs/Hadrons/GRandom.cc | 1 + programs/Hadrons/GUnit.cc | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc index ad5cae2a..c9ecc701 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/AWilson.cc @@ -66,6 +66,8 @@ void AWilson::execute(Environment &env) auto &grid = *env.getGrid(); auto &gridRb = *env.getRbGrid(); + LOG(Message) << "setting up Wilson fermion matrix with m= " << par_.mass + << " using gauge field '" << par_.gauge << "'" << std::endl; env.addFermionMatrix(getName(), new WilsonFermionR(U, grid, gridRb, par_.mass)); } diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index eb746061..3683d8e8 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -63,7 +63,8 @@ std::vector CMeson::getOutput(void) // execution /////////////////////////////////////////////////////////////////// void CMeson::execute(Environment &env) { - LOG(Message) << "computing meson contraction '" << getName() << "'" + LOG(Message) << "computing meson contraction '" << getName() << "' using" + << " quarks '" << par_.q1 << " and '" << par_.q2 << "'" << std::endl; XmlWriter writer(par_.output); diff --git a/programs/Hadrons/GLoad.cc b/programs/Hadrons/GLoad.cc index 2add8a11..756c4f29 100644 --- a/programs/Hadrons/GLoad.cc +++ b/programs/Hadrons/GLoad.cc @@ -73,5 +73,7 @@ void GLoad::execute(Environment &env) std::string fileName = par_.file + "." + std::to_string(env.getTrajectory()); + LOG(Message) << "loading NERSC configuration from file '" << fileName + << "'" << std::endl; NerscIO::readConfiguration(*gauge_, header, fileName); } diff --git a/programs/Hadrons/GRandom.cc b/programs/Hadrons/GRandom.cc index d39769a9..d6bb381f 100644 --- a/programs/Hadrons/GRandom.cc +++ b/programs/Hadrons/GRandom.cc @@ -61,5 +61,6 @@ void GRandom::allocate(Environment &env) // execution /////////////////////////////////////////////////////////////////// void GRandom::execute(Environment &env) { + LOG(Message) << "generating random gauge configuration" << std::endl; SU3::HotConfiguration(*env.get4dRng(), *gauge_); } diff --git a/programs/Hadrons/GUnit.cc b/programs/Hadrons/GUnit.cc index ce406612..330b09e4 100644 --- a/programs/Hadrons/GUnit.cc +++ b/programs/Hadrons/GUnit.cc @@ -61,5 +61,6 @@ void GUnit::allocate(Environment &env) // execution /////////////////////////////////////////////////////////////////// void GUnit::execute(Environment &env) { + LOG(Message) << "creating unit gauge configuration" << std::endl; SU3::ColdConfiguration(*env.get4dRng(), *gauge_); } From 3aa6463ede21b9f74429653c9261de400d02b113 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 4 May 2016 12:17:27 -0700 Subject: [PATCH 031/106] Hadrons: general lattice store & a lot of code cleaning --- programs/Hadrons/AWilson.cc | 5 +- programs/Hadrons/Application.cc | 60 ++++++- programs/Hadrons/Application.hpp | 3 + programs/Hadrons/CMeson.cc | 6 +- programs/Hadrons/Environment.cc | 262 ++++++++++--------------------- programs/Hadrons/Environment.hpp | 104 +++++++++--- programs/Hadrons/GLoad.cc | 8 +- programs/Hadrons/GRandom.cc | 6 +- programs/Hadrons/GUnit.cc | 6 +- programs/Hadrons/MQuark.cc | 20 +-- programs/Hadrons/SrcPoint.cc | 6 +- programs/Hadrons/SrcZ2.cc | 8 +- 12 files changed, 256 insertions(+), 238 deletions(-) diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc index c9ecc701..f4fb3dc9 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/AWilson.cc @@ -62,12 +62,13 @@ std::vector AWilson::getOutput(void) // execution /////////////////////////////////////////////////////////////////// void AWilson::execute(Environment &env) { - auto &U = *env.getGauge(par_.gauge); + auto &U = *env.get(par_.gauge); auto &grid = *env.getGrid(); auto &gridRb = *env.getRbGrid(); - LOG(Message) << "setting up Wilson fermion matrix with m= " << par_.mass + LOG(Message) << "Setting up Wilson fermion matrix with m= " << par_.mass << " using gauge field '" << par_.gauge << "'" << std::endl; env.addFermionMatrix(getName(), new WilsonFermionR(U, grid, gridRb, par_.mass)); + LOG(Message) << sizeof(*env.getFermionMatrix(getName())) << std::endl; } diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 980a4cf5..531ad875 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -47,6 +47,16 @@ Application::Application(const std::string parameterFileName) { LOG(Message) << " " << m << std::endl; } + auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim); + locVol_ = 1; + for (unsigned int d = 0; d < dim.size(); ++d) + { + loc[d] /= mpi[d]; + locVol_ *= loc[d]; + } + LOG(Message) << "Global lattice: " << dim << std::endl; + LOG(Message) << "MPI partition : " << mpi << std::endl; + LOG(Message) << "Local lattice : " << loc << std::endl; } // destructor ////////////////////////////////////////////////////////////////// @@ -169,8 +179,8 @@ void Application::configLoop(void) for (unsigned int t = range.start; t < range.end; t += range.step) { - LOG(Message) << "Starting measurement for trajectory " << t - << std::endl; + LOG(Message) << "========== Starting measurement for trajectory " << t + << " ==========" << std::endl; env_.setTrajectory(t); execute(program_); env_.freeAll(); @@ -179,7 +189,7 @@ void Application::configLoop(void) unsigned int Application::execute(const std::vector &program) { - unsigned int memPeak = 0; + unsigned int memPeak = 0, size; std::vector> freeProg; freeProg.resize(program.size()); @@ -200,19 +210,53 @@ unsigned int Application::execute(const std::vector &program) } for (unsigned int i = 0; i < program.size(); ++i) { - LOG(Message) << "Measurement step " << i+1 << "/" << program.size() - << " (module '" << program[i] << "')" << std::endl; + LOG(Message) << "---------- Measurement step " << i+1 << "/" + << program.size() << " (module '" << program[i] << "')" + << " ----------" << std::endl; (*module_[program[i]])(env_); - LOG(Message) << "allocated propagators: " << env_.nProp() << std::endl; - if (env_.nProp() > memPeak) + size = env_.getTotalSize(); + LOG(Message) << "Allocated objects: " << sizeString(size*locVol_) + << " (" << sizeString(size) << "/site)" << std::endl; + if (size > memPeak) { - memPeak = env_.nProp(); + memPeak = size; } + LOG(Message) << "Garbage collection..." << std::endl; for (auto &n: freeProg[i]) { env_.free(n); } + size = env_.getTotalSize(); + LOG(Message) << "Allocated objects: " << sizeString(size*locVol_) + << " (" << sizeString(size) << "/site)" << std::endl; } return memPeak; } + +// pretty size formatting ////////////////////////////////////////////////////// +std::string Application::sizeString(long unsigned int bytes) + +{ + constexpr unsigned int bufSize = 256; + const char *suffixes[7] = {"", "K", "M", "G", "T", "P", "E"}; + char buf[256]; + long unsigned int s = 0; + double count = bytes; + + while (count >= 1024 && s < 7) + { + s++; + count /= 1024; + } + if (count - floor(count) == 0.0) + { + snprintf(buf, bufSize, "%d %sB", (int)count, suffixes[s]); + } + else + { + snprintf(buf, bufSize, "%.1f %sB", count, suffixes[s]); + } + + return std::string(buf); +} diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index de788956..518b29ca 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -85,7 +85,10 @@ private: // program execution void configLoop(void); unsigned int execute(const std::vector &program); + // pretty size formatting + std::string sizeString(long unsigned int bytes); private: + long unsigned int locVol_; std::string parameterFileName_; GlobalPar par_; Environment &env_; diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index 3683d8e8..194da413 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -63,13 +63,13 @@ std::vector CMeson::getOutput(void) // execution /////////////////////////////////////////////////////////////////// void CMeson::execute(Environment &env) { - LOG(Message) << "computing meson contraction '" << getName() << "' using" + LOG(Message) << "Computing meson contraction '" << getName() << "' using" << " quarks '" << par_.q1 << " and '" << par_.q2 << "'" << std::endl; XmlWriter writer(par_.output); - LatticePropagator &q1 = *env.getProp(par_.q1); - LatticePropagator &q2 = *env.getProp(par_.q2); + LatticePropagator &q1 = *env.get(par_.q1); + LatticePropagator &q2 = *env.get(par_.q2); LatticeComplex c(env.getGrid()); SpinMatrix g[Ns*Ns], g5; std::vector buf; diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 9f572f17..a82e4c80 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -151,173 +151,6 @@ void Environment::callSolver(const std::string name, LatticeFermion &sol, } } -// quark propagators /////////////////////////////////////////////////////////// -void Environment::createProp(const std::string name, const unsigned int Ls) -{ - GridCartesian *g4 = getGrid(); - - if (propExists(name)) - { - HADRON_ERROR("propagator '" + name + "' already exists"); - } - if (Ls > 1) - { - GridCartesian *g; - - try - { - g = grid5d_.at(Ls).get(); - } - catch(std::out_of_range &) - { - grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g4)); - gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g4)); - g = grid5d_[Ls].get(); - } - if (!isDryRun()) - { - prop_[name].reset(new LatticePropagator(g)); - } - else - { - prop_[name].reset(nullptr); - } - propSize_[name] = Ls; - } - else - { - if (!isDryRun()) - { - prop_[name].reset(new LatticePropagator(g4)); - } - else - { - prop_[name].reset(nullptr); - } - propSize_[name] = 1; - } -} - -void Environment::freeProp(const std::string name) -{ - if (propExists(name)) - { - prop_.erase(name); - propSize_.erase(name); - } - else - { - HADRON_ERROR("trying to free unknown propagator '" + name + "'"); - } -} - -bool Environment::isProp5d(const std::string name) const -{ - if (propExists(name)) - { - return (getProp(name)->_grid->GlobalDimensions().size() == Nd + 1); - } - else - { - HADRON_ERROR("propagator '" + name + "' unknown"); - - return false; - } -} - -unsigned int Environment::getPropLs(const std::string name) const -{ - if (propExists(name)) - { - if (isProp5d(name)) - { - return getProp(name)->_grid->GlobalDimensions()[0]; - } - else - { - return 1; - } - } - else - { - HADRON_ERROR("propagator '" + name + "' unknown"); - - return 0; - } -} - -LatticePropagator * Environment::getProp(const std::string name) const -{ - if (propExists(name)) - { - return prop_.at(name).get(); - } - else - { - HADRON_ERROR("propagator '" + name + "' unknown"); - - return nullptr; - } -} - -bool Environment::propExists(const std::string name) const -{ - return (prop_.find(name) != prop_.end()); -} - -unsigned int Environment::nProp(void) const -{ - unsigned int size = 0; - - for (auto &s: propSize_) - { - size += s.second; - } - - return size; -} - -// gauge configuration ///////////////////////////////////////////////////////// -void Environment::createGauge(const std::string name) -{ - if (gaugeExists(name)) - { - HADRON_ERROR("gauge field '" + name + "' already exists"); - } - gauge_[name].reset(new LatticeGaugeField(getGrid())); -} - -void Environment::freeGauge(const std::string name) -{ - if (gaugeExists(name)) - { - gauge_.erase(name); - } - else - { - HADRON_ERROR("trying to free unknown gauge field '" + name + "'"); - } -} - -LatticeGaugeField * Environment::getGauge(const std::string name) const -{ - if (gaugeExists(name)) - { - return gauge_.at(name).get(); - } - else - { - HADRON_ERROR("gauge field '" + name + "' unknown"); - - return nullptr; - } -} - -bool Environment::gaugeExists(const std::string name) const -{ - return (gauge_.find(name) != gauge_.end()); -} - // random number generator ///////////////////////////////////////////////////// void Environment::setSeed(const std::vector &seed) { @@ -329,24 +162,95 @@ GridParallelRNG * Environment::get4dRng(void) const return rng4d_.get(); } -// general free //////////////////////////////////////////////////////////////// +// data store ////////////////////////////////////////////////////////////////// +void Environment::freeLattice(const std::string name) +{ + if (hasLattice(name)) + { + LOG(Message) << "freeing lattice '" << name << "'" << std::endl; + lattice_.erase(name); + objectSize_.erase(name); + } + else + { + HADRON_ERROR("trying to free undefined lattice '" + name + "'"); + } +} + +bool Environment::hasLattice(const std::string name) const +{ + return (lattice_.find(name) != lattice_.end()); +} + + +bool Environment::isLattice5d(const std::string name) const +{ + if (hasLattice(name)) + { + return (lattice_.at(name)->_grid->GlobalDimensions().size() == Nd + 1); + } + else + { + HADRON_ERROR("object '" + name + "' undefined"); + + return false; + } +} + +unsigned int Environment::getLatticeLs(const std::string name) const +{ + if (isLattice5d(name)) + { + return lattice_.at(name)->_grid->GlobalDimensions()[0]; + } + else + { + return 1; + } +} + +// general memory management /////////////////////////////////////////////////// void Environment::free(const std::string name) { - if (propExists(name)) + if (hasLattice(name)) { - LOG(Message) << "freeing propagator '" << name << "'" << std::endl; - freeProp(name); - } - else if (gaugeExists(name)) - { - LOG(Message) << "freeing gauge field '" << name << "'" << std::endl; - freeGauge(name); + freeLattice(name); } } void Environment::freeAll(void) { - prop_.clear(); - propSize_.clear(); - gauge_.clear(); + lattice_.clear(); + objectSize_.clear(); +} + +void Environment::addSize(const std::string name, const unsigned int size) +{ + objectSize_[name] = size; +} + +unsigned int Environment::getSize(const std::string name) const +{ + if (hasLattice(name)) + { + return objectSize_.at(name); + } + else + { + HADRON_ERROR("object '" + name + "' undefined"); + + return 0; + } +} + +long unsigned int Environment::getTotalSize(void) const +{ + long unsigned int size = 0; + + for (auto &s: objectSize_) + { + size += s.second; + } + + return size; } diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 5a4c1e3f..628d9831 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -46,8 +46,7 @@ public: typedef std::unique_ptr GridRbPt; typedef std::unique_ptr RngPt; typedef std::unique_ptr FMatPt; - typedef std::unique_ptr PropPt; - typedef std::unique_ptr GaugePt; + typedef std::unique_ptr LatticePt; public: // dry run void dryRun(const bool isDry); @@ -67,26 +66,27 @@ public: void callSolver(const std::string name, LatticeFermion &sol, const LatticeFermion &src) const; - // quark propagators - void createProp(const std::string name, - const unsigned int Ls = 1); - void freeProp(const std::string name); - bool isProp5d(const std::string name) const; - unsigned int getPropLs(const std::string name) const; - LatticePropagator * getProp(const std::string name) const; - bool propExists(const std::string name) const; - unsigned int nProp(void) const; - // gauge configurations - void createGauge(const std::string name); - void freeGauge(const std::string name); - LatticeGaugeField * getGauge(const std::string name) const; - bool gaugeExists(const std::string name) const; // random number generator void setSeed(const std::vector &seed); GridParallelRNG * get4dRng(void) const; - // general free + // lattice store + template + void create(const std::string name, + const unsigned int Ls = 1); + template + T * get(const std::string name) const; + void freeLattice(const std::string name); + bool hasLattice(const std::string name) const; + + bool isLattice5d(const std::string name) const; + unsigned int getLatticeLs(const std::string name) const; + // general memory management void free(const std::string name); void freeAll(void); + void addSize(const std::string name, + const unsigned int size); + unsigned int getSize(const std::string name) const; + long unsigned int getTotalSize(void) const; private: bool dryRun_{false}; unsigned int traj_; @@ -98,11 +98,75 @@ private: std::map fMat_; std::map solver_; std::map solverAction_; - std::map prop_; - std::map propSize_; - std::map gauge_; + std::map lattice_; + std::map objectSize_; }; +/****************************************************************************** + * template implementation * + ******************************************************************************/ +template +void Environment::create(const std::string name, const unsigned int Ls) +{ + GridCartesian *g4 = getGrid(); + GridCartesian *g; + + if (hasLattice(name)) + { + HADRON_ERROR("object '" + name + "' already exists"); + } + if (Ls > 1) + { + try + { + g = grid5d_.at(Ls).get(); + } + catch(std::out_of_range &) + { + grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g4)); + gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g4)); + g = grid5d_[Ls].get(); + } + } + else + { + g = g4; + } + if (!isDryRun()) + { + lattice_[name].reset(new T(g)); + } + else + { + lattice_[name].reset(nullptr); + } + objectSize_[name] = sizeof(typename T::vector_object)/g->Nsimd()*Ls; +} + +template +T * Environment::get(const std::string name) const +{ + if (hasLattice(name)) + { + try + { + return dynamic_cast(lattice_.at(name).get()); + } + catch (std::bad_cast &) + { + HADRON_ERROR("object '" + name + "' does not have type " + + typeid(T *).name() + "(object type: " + + typeid(lattice_.at(name).get()).name() + ")"); + } + } + else + { + HADRON_ERROR("object '" + name + "' undefined"); + + return nullptr; + } +} + END_HADRONS_NAMESPACE #endif // Hadrons_Environment_hpp_ diff --git a/programs/Hadrons/GLoad.cc b/programs/Hadrons/GLoad.cc index 756c4f29..f35fef54 100644 --- a/programs/Hadrons/GLoad.cc +++ b/programs/Hadrons/GLoad.cc @@ -62,8 +62,8 @@ std::vector GLoad::getOutput(void) // allocation ////////////////////////////////////////////////////////////////// void GLoad::allocate(Environment &env) { - env.createGauge(getName()); - gauge_ = env.getGauge(getName()); + env.create(getName()); + gauge_ = env.get(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -73,7 +73,9 @@ void GLoad::execute(Environment &env) std::string fileName = par_.file + "." + std::to_string(env.getTrajectory()); - LOG(Message) << "loading NERSC configuration from file '" << fileName + LOG(Message) << "Loading NERSC configuration from file '" << fileName << "'" << std::endl; NerscIO::readConfiguration(*gauge_, header, fileName); + LOG(Message) << "NERSC header:" << std::endl; + dump_nersc_header(header, LOG(Message)); } diff --git a/programs/Hadrons/GRandom.cc b/programs/Hadrons/GRandom.cc index d6bb381f..0490d3e7 100644 --- a/programs/Hadrons/GRandom.cc +++ b/programs/Hadrons/GRandom.cc @@ -54,13 +54,13 @@ std::vector GRandom::getOutput(void) // allocation ////////////////////////////////////////////////////////////////// void GRandom::allocate(Environment &env) { - env.createGauge(getName()); - gauge_ = env.getGauge(getName()); + env.create(getName()); + gauge_ = env.get(getName()); } // execution /////////////////////////////////////////////////////////////////// void GRandom::execute(Environment &env) { - LOG(Message) << "generating random gauge configuration" << std::endl; + LOG(Message) << "Generating random gauge configuration" << std::endl; SU3::HotConfiguration(*env.get4dRng(), *gauge_); } diff --git a/programs/Hadrons/GUnit.cc b/programs/Hadrons/GUnit.cc index 330b09e4..5c19a259 100644 --- a/programs/Hadrons/GUnit.cc +++ b/programs/Hadrons/GUnit.cc @@ -54,13 +54,13 @@ std::vector GUnit::getOutput(void) // allocation ////////////////////////////////////////////////////////////////// void GUnit::allocate(Environment &env) { - env.createGauge(getName()); - gauge_ = env.getGauge(getName()); + env.create(getName()); + gauge_ = env.get(getName()); } // execution /////////////////////////////////////////////////////////////////// void GUnit::execute(Environment &env) { - LOG(Message) << "creating unit gauge configuration" << std::endl; + LOG(Message) << "Creating unit gauge configuration" << std::endl; SU3::ColdConfiguration(*env.get4dRng(), *gauge_); } diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index b95493e7..2ec3d4a6 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -78,12 +78,12 @@ void MQuark::setup(Environment &env) // allocation ////////////////////////////////////////////////////////////////// void MQuark::allocate(Environment &env) { - env.createProp(getName()); - quark_ = env.getProp(getName()); + env.create(getName()); + quark_ = env.get(getName()); if (Ls_ > 1) { - env.createProp(getName() + "_5d", Ls_); - quark5d_ = env.getProp(getName() + "_5d"); + env.create(getName() + "_5d", Ls_); + quark5d_ = env.get(getName() + "_5d"); } } @@ -93,13 +93,13 @@ void MQuark::execute(Environment &env) LatticePropagator *fullSource; LatticeFermion source(env.getGrid(Ls_)), sol(env.getGrid(Ls_)); - LOG(Message) << "computing quark propagator '" << getName() << "'" + LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; - if (!env.isProp5d(par_.source)) + if (!env.isLattice5d(par_.source)) { if (Ls_ == 1) { - fullSource = env.getProp(par_.source); + fullSource = env.get(par_.source); } else { @@ -112,17 +112,17 @@ void MQuark::execute(Environment &env) { HADRON_ERROR("MQuark not implemented with 5D actions"); } - else if (Ls_ != env.getPropLs(par_.source)) + else if (Ls_ != env.getLatticeLs(par_.source)) { HADRON_ERROR("MQuark not implemented with 5D actions"); } else { - fullSource = env.getProp(par_.source); + fullSource = env.get(par_.source); } } - LOG(Message) << "inverting using solver '" << par_.solver + LOG(Message) << "Inverting using solver '" << par_.solver << "' on source '" << par_.source << "'" << std::endl; for (unsigned int s = 0; s < Ns; ++s) for (unsigned int c = 0; c < Nc; ++c) diff --git a/programs/Hadrons/SrcPoint.cc b/programs/Hadrons/SrcPoint.cc index b5329091..4360385c 100644 --- a/programs/Hadrons/SrcPoint.cc +++ b/programs/Hadrons/SrcPoint.cc @@ -62,8 +62,8 @@ std::vector SrcPoint::getOutput(void) // allocation ////////////////////////////////////////////////////////////////// void SrcPoint::allocate(Environment &env) { - env.createProp(getName()); - src_ = env.getProp(getName()); + env.create(getName()); + src_ = env.get(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -72,7 +72,7 @@ void SrcPoint::execute(Environment &env) std::vector position = strToVec(par_.position); SpinColourMatrix id; - LOG(Message) << "creating point source at position [" << par_.position + LOG(Message) << "Creating point source at position [" << par_.position << "]" << std::endl; id = 1.; *src_ = zero; diff --git a/programs/Hadrons/SrcZ2.cc b/programs/Hadrons/SrcZ2.cc index e050d6c4..56a4ea6e 100644 --- a/programs/Hadrons/SrcZ2.cc +++ b/programs/Hadrons/SrcZ2.cc @@ -62,8 +62,8 @@ std::vector SrcZ2::getOutput(void) // allocation ////////////////////////////////////////////////////////////////// void SrcZ2::allocate(Environment &env) { - env.createProp(getName()); - src_ = env.getProp(getName()); + env.create(getName()); + src_ = env.get(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -76,12 +76,12 @@ void SrcZ2::execute(Environment &env) if (par_.tA == par_.tB) { - LOG(Message) << "generating Z_2 wall source at t= " << par_.tA + LOG(Message) << "Generating Z_2 wall source at t= " << par_.tA << std::endl; } else { - LOG(Message) << "generating Z_2 band for " << par_.tA << " <= t <= " + LOG(Message) << "Generating Z_2 band for " << par_.tA << " <= t <= " << par_.tB << std::endl; } LatticeCoordinate(t, Tp); From cbe52b065948ff16b20abad3146d205a97d3976c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 4 May 2016 12:19:58 -0700 Subject: [PATCH 032/106] Hadrons: debug message removed --- programs/Hadrons/AWilson.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc index f4fb3dc9..5e08ae12 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/AWilson.cc @@ -70,5 +70,4 @@ void AWilson::execute(Environment &env) << " using gauge field '" << par_.gauge << "'" << std::endl; env.addFermionMatrix(getName(), new WilsonFermionR(U, grid, gridRb, par_.mass)); - LOG(Message) << sizeof(*env.getFermionMatrix(getName())) << std::endl; } From 75cd72a4211b8cccc4ac3b207de546d2d163f898 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 4 May 2016 19:11:03 -0700 Subject: [PATCH 033/106] Hadrons: memory management for fermion matrices, dynamic ownership in garbage collector --- programs/Hadrons/AWilson.cc | 14 ++-- programs/Hadrons/AWilson.hpp | 2 +- programs/Hadrons/Application.cc | 41 ++++++++++-- programs/Hadrons/CMeson.cc | 10 +-- programs/Hadrons/CMeson.hpp | 2 +- programs/Hadrons/Environment.cc | 107 ++++++++++++++++++++++++++----- programs/Hadrons/Environment.hpp | 29 +++++++-- programs/Hadrons/GLoad.cc | 10 +-- programs/Hadrons/GLoad.hpp | 4 +- programs/Hadrons/GRandom.cc | 10 +-- programs/Hadrons/GRandom.hpp | 4 +- programs/Hadrons/GUnit.cc | 10 +-- programs/Hadrons/GUnit.hpp | 4 +- programs/Hadrons/MQuark.cc | 29 ++++----- programs/Hadrons/MQuark.hpp | 10 +-- programs/Hadrons/Module.cc | 17 +++-- programs/Hadrons/Module.hpp | 10 +-- programs/Hadrons/SolRBPrecCG.cc | 15 +++-- programs/Hadrons/SolRBPrecCG.hpp | 4 +- programs/Hadrons/SrcPoint.cc | 8 +-- programs/Hadrons/SrcPoint.hpp | 4 +- programs/Hadrons/SrcZ2.cc | 16 ++--- programs/Hadrons/SrcZ2.hpp | 4 +- 23 files changed, 253 insertions(+), 111 deletions(-) diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc index 5e08ae12..0be43ee7 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/AWilson.cc @@ -60,14 +60,16 @@ std::vector AWilson::getOutput(void) } // execution /////////////////////////////////////////////////////////////////// -void AWilson::execute(Environment &env) +void AWilson::execute() { - auto &U = *env.get(par_.gauge); - auto &grid = *env.getGrid(); - auto &gridRb = *env.getRbGrid(); + auto &U = *env().get(par_.gauge); + auto &grid = *env().getGrid(); + auto &gridRb = *env().getRbGrid(); + auto fMatPt = new WilsonFermionR(U, grid, gridRb, par_.mass); + unsigned int size; LOG(Message) << "Setting up Wilson fermion matrix with m= " << par_.mass << " using gauge field '" << par_.gauge << "'" << std::endl; - env.addFermionMatrix(getName(), - new WilsonFermionR(U, grid, gridRb, par_.mass)); + size = 3*env().lattice4dSize(); + env().addFermionMatrix(getName(), fMatPt, size); } diff --git a/programs/Hadrons/AWilson.hpp b/programs/Hadrons/AWilson.hpp index cf21eff3..df2d6f41 100644 --- a/programs/Hadrons/AWilson.hpp +++ b/programs/Hadrons/AWilson.hpp @@ -57,7 +57,7 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: Par par_; }; diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 531ad875..7fb69ab1 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -189,9 +189,11 @@ void Application::configLoop(void) unsigned int Application::execute(const std::vector &program) { - unsigned int memPeak = 0, size; - std::vector> freeProg; + unsigned int memPeak = 0, size; + std::vector> freeProg; + bool continueCollect; + // build garbage collection schedule freeProg.resize(program.size()); for (auto &n: associatedModule_) { @@ -205,27 +207,54 @@ unsigned int Application::execute(const std::vector &program) auto it = std::find_if(program.rbegin(), program.rend(), pred); if (it != program.rend()) { - freeProg[program.rend() - it - 1].push_back(n.first); + freeProg[program.rend() - it - 1].insert(n.first); } } + // program execution for (unsigned int i = 0; i < program.size(); ++i) { + // execute module LOG(Message) << "---------- Measurement step " << i+1 << "/" << program.size() << " (module '" << program[i] << "')" << " ----------" << std::endl; - (*module_[program[i]])(env_); + (*module_[program[i]])(); size = env_.getTotalSize(); + // print used memory after execution LOG(Message) << "Allocated objects: " << sizeString(size*locVol_) << " (" << sizeString(size) << "/site)" << std::endl; if (size > memPeak) { memPeak = size; } + // garbage collection for step i LOG(Message) << "Garbage collection..." << std::endl; - for (auto &n: freeProg[i]) + do { - env_.free(n); + continueCollect = false; + auto toFree = freeProg[i]; + for (auto &n: toFree) + { + // continue garbage collection while there are still + // objects without owners + continueCollect = continueCollect or !env_.hasOwners(n); + if(env_.free(n)) + { + // if an object has been freed, remove it from + // the garbage collection schedule + freeProg[i].erase(n); + } + } + } while (continueCollect); + // any remaining objects in step i garbage collection schedule + // is scheduled for step i + 1 + if (i + 1 < program.size()) + { + for (auto &n: freeProg[i]) + { + freeProg[i + 1].insert(n); + } } + // print used memory after garbage collection size = env_.getTotalSize(); LOG(Message) << "Allocated objects: " << sizeString(size*locVol_) << " (" << sizeString(size) << "/site)" << std::endl; diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index 194da413..4e3e6b68 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -61,20 +61,20 @@ std::vector CMeson::getOutput(void) } // execution /////////////////////////////////////////////////////////////////// -void CMeson::execute(Environment &env) +void CMeson::execute(void) { LOG(Message) << "Computing meson contraction '" << getName() << "' using" << " quarks '" << par_.q1 << " and '" << par_.q2 << "'" << std::endl; XmlWriter writer(par_.output); - LatticePropagator &q1 = *env.get(par_.q1); - LatticePropagator &q2 = *env.get(par_.q2); - LatticeComplex c(env.getGrid()); + LatticePropagator &q1 = *env().get(par_.q1); + LatticePropagator &q2 = *env().get(par_.q2); + LatticeComplex c(env().getGrid()); SpinMatrix g[Ns*Ns], g5; std::vector buf; Result result; - unsigned int nt = env.getGrid()->GlobalDimensions()[Tp]; + unsigned int nt = env().getGrid()->GlobalDimensions()[Tp]; g5 = makeGammaProd(Ns*Ns - 1); result.corr.resize(Ns*Ns); diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/CMeson.hpp index 29620726..bc9f3177 100644 --- a/programs/Hadrons/CMeson.hpp +++ b/programs/Hadrons/CMeson.hpp @@ -65,7 +65,7 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: Par par_; }; diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index a82e4c80..ec61c40d 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -106,18 +106,20 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const } // fermion actions ///////////////////////////////////////////////////////////// -void Environment::addFermionMatrix(const std::string name, FMat *fMat) +void Environment::addFermionMatrix(const std::string name, FMat *fMat, + const unsigned int size) { fMat_[name].reset(fMat); + addSize(name, size); } Environment::FMat * Environment::getFermionMatrix(const std::string name) const { - try + if (hasFermionMatrix(name)) { return fMat_.at(name).get(); } - catch(std::out_of_range &) + else { try { @@ -130,6 +132,25 @@ Environment::FMat * Environment::getFermionMatrix(const std::string name) const } } +void Environment::freeFermionMatrix(const std::string name) +{ + if (hasFermionMatrix(name)) + { + LOG(Message) << "freeing fermion matrix '" << name << "'" << std::endl; + fMat_.erase(name); + objectSize_.erase(name); + } + else + { + HADRON_ERROR("trying to free undefined fermion matrix '" + name + "'"); + } +} + +bool Environment::hasFermionMatrix(const std::string name) const +{ + return (fMat_.find(name) != fMat_.end()); +} + // solvers ///////////////////////////////////////////////////////////////////// void Environment::addSolver(const std::string name, Solver s, const std::string actionName) @@ -138,14 +159,31 @@ void Environment::addSolver(const std::string name, Solver s, solverAction_[name] = actionName; } +bool Environment::hasSolver(const std::string name) const +{ + return (solver_.find(name) != solver_.end()); +} + +std::string Environment::getSolverAction(const std::string name) const +{ + if (hasSolver(name)) + { + return solverAction_.at(name); + } + else + { + HADRON_ERROR("no solver with name '" << name << "'"); + } +} + void Environment::callSolver(const std::string name, LatticeFermion &sol, const LatticeFermion &source) const { - try + if (hasSolver(name)) { solver_.at(name)(sol, source); } - catch(std::out_of_range &) + else { HADRON_ERROR("no solver with name '" << name << "'"); } @@ -162,7 +200,7 @@ GridParallelRNG * Environment::get4dRng(void) const return rng4d_.get(); } -// data store ////////////////////////////////////////////////////////////////// +// lattice store /////////////////////////////////////////////////////////////// void Environment::freeLattice(const std::string name) { if (hasLattice(name)) @@ -210,28 +248,62 @@ unsigned int Environment::getLatticeLs(const std::string name) const } // general memory management /////////////////////////////////////////////////// -void Environment::free(const std::string name) +void Environment::addOwnership(const std::string owner, + const std::string property) { - if (hasLattice(name)) + owners_[property].insert(owner); + properties_[owner].insert(property); +} + +bool Environment::hasOwners(const std::string name) const +{ + try { - freeLattice(name); + return (!owners_.at(name).empty()); + } + catch (std::out_of_range &) + { + return false; + } +} + +bool Environment::free(const std::string name) +{ + if (!hasOwners(name)) + { + for (auto &p: properties_[name]) + { + owners_[p].erase(name); + } + properties_[name].clear(); + if (hasLattice(name)) + { + freeLattice(name); + } + else if (hasFermionMatrix(name)) + { + freeFermionMatrix(name); + } + + return true; + } + else + { + return false; } } void Environment::freeAll(void) { lattice_.clear(); + fMat_.clear(); + solver_.clear(); objectSize_.clear(); } -void Environment::addSize(const std::string name, const unsigned int size) -{ - objectSize_[name] = size; -} - unsigned int Environment::getSize(const std::string name) const { - if (hasLattice(name)) + if (hasLattice(name) or hasFermionMatrix(name)) { return objectSize_.at(name); } @@ -254,3 +326,8 @@ long unsigned int Environment::getTotalSize(void) const return size; } + +void Environment::addSize(const std::string name, const unsigned int size) +{ + objectSize_[name] = size; +} diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 628d9831..f5265181 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -58,11 +58,16 @@ public: GridCartesian * getGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; // fermion actions - void addFermionMatrix(const std::string name, FMat *mat); + void addFermionMatrix(const std::string name, FMat *mat, + const unsigned int size); FMat * getFermionMatrix(const std::string name) const; + void freeFermionMatrix(const std::string name); + bool hasFermionMatrix(const std::string name) const; // solvers void addSolver(const std::string name, Solver s, const std::string actionName); + bool hasSolver(const std::string name) const; + std::string getSolverAction(const std::string name) const; void callSolver(const std::string name, LatticeFermion &sol, const LatticeFermion &src) const; @@ -71,22 +76,26 @@ public: GridParallelRNG * get4dRng(void) const; // lattice store template + unsigned int lattice4dSize(void) const; + template void create(const std::string name, const unsigned int Ls = 1); template T * get(const std::string name) const; void freeLattice(const std::string name); bool hasLattice(const std::string name) const; - bool isLattice5d(const std::string name) const; unsigned int getLatticeLs(const std::string name) const; // general memory management - void free(const std::string name); + void addOwnership(const std::string owner, + const std::string property); + bool hasOwners(const std::string name) const; + bool free(const std::string name); void freeAll(void); - void addSize(const std::string name, - const unsigned int size); unsigned int getSize(const std::string name) const; long unsigned int getTotalSize(void) const; +private: + void addSize(const std::string name, const unsigned int size); private: bool dryRun_{false}; unsigned int traj_; @@ -100,11 +109,19 @@ private: std::map solverAction_; std::map lattice_; std::map objectSize_; + std::map> owners_; + std::map> properties_; }; /****************************************************************************** * template implementation * ******************************************************************************/ +template +unsigned int Environment::lattice4dSize(void) const +{ + return sizeof(typename T::vector_object)/getGrid()->Nsimd(); +} + template void Environment::create(const std::string name, const unsigned int Ls) { @@ -140,7 +157,7 @@ void Environment::create(const std::string name, const unsigned int Ls) { lattice_[name].reset(nullptr); } - objectSize_[name] = sizeof(typename T::vector_object)/g->Nsimd()*Ls; + addSize(name, lattice4dSize()*Ls); } template diff --git a/programs/Hadrons/GLoad.cc b/programs/Hadrons/GLoad.cc index f35fef54..55715fbb 100644 --- a/programs/Hadrons/GLoad.cc +++ b/programs/Hadrons/GLoad.cc @@ -60,18 +60,18 @@ std::vector GLoad::getOutput(void) } // allocation ////////////////////////////////////////////////////////////////// -void GLoad::allocate(Environment &env) +void GLoad::allocate(void) { - env.create(getName()); - gauge_ = env.get(getName()); + env().create(getName()); + gauge_ = env().get(getName()); } // execution /////////////////////////////////////////////////////////////////// -void GLoad::execute(Environment &env) +void GLoad::execute(void) { NerscField header; std::string fileName = par_.file + "." - + std::to_string(env.getTrajectory()); + + std::to_string(env().getTrajectory()); LOG(Message) << "Loading NERSC configuration from file '" << fileName << "'" << std::endl; diff --git a/programs/Hadrons/GLoad.hpp b/programs/Hadrons/GLoad.hpp index a40ed2c2..4527c33c 100644 --- a/programs/Hadrons/GLoad.hpp +++ b/programs/Hadrons/GLoad.hpp @@ -56,9 +56,9 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // allocation - virtual void allocate(Environment &env); + virtual void allocate(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: Par par_; LatticeGaugeField *gauge_ = nullptr; diff --git a/programs/Hadrons/GRandom.cc b/programs/Hadrons/GRandom.cc index 0490d3e7..53007045 100644 --- a/programs/Hadrons/GRandom.cc +++ b/programs/Hadrons/GRandom.cc @@ -52,15 +52,15 @@ std::vector GRandom::getOutput(void) } // allocation ////////////////////////////////////////////////////////////////// -void GRandom::allocate(Environment &env) +void GRandom::allocate(void) { - env.create(getName()); - gauge_ = env.get(getName()); + env().create(getName()); + gauge_ = env().get(getName()); } // execution /////////////////////////////////////////////////////////////////// -void GRandom::execute(Environment &env) +void GRandom::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; - SU3::HotConfiguration(*env.get4dRng(), *gauge_); + SU3::HotConfiguration(*env().get4dRng(), *gauge_); } diff --git a/programs/Hadrons/GRandom.hpp b/programs/Hadrons/GRandom.hpp index 18660bf9..12d5be5f 100644 --- a/programs/Hadrons/GRandom.hpp +++ b/programs/Hadrons/GRandom.hpp @@ -48,9 +48,9 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // allocation - virtual void allocate(Environment &env); + virtual void allocate(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: LatticeGaugeField *gauge_ = nullptr; }; diff --git a/programs/Hadrons/GUnit.cc b/programs/Hadrons/GUnit.cc index 5c19a259..5a86aa00 100644 --- a/programs/Hadrons/GUnit.cc +++ b/programs/Hadrons/GUnit.cc @@ -52,15 +52,15 @@ std::vector GUnit::getOutput(void) } // allocation ////////////////////////////////////////////////////////////////// -void GUnit::allocate(Environment &env) +void GUnit::allocate(void) { - env.create(getName()); - gauge_ = env.get(getName()); + env().create(getName()); + gauge_ = env().get(getName()); } // execution /////////////////////////////////////////////////////////////////// -void GUnit::execute(Environment &env) +void GUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; - SU3::ColdConfiguration(*env.get4dRng(), *gauge_); + SU3::ColdConfiguration(*env().get4dRng(), *gauge_); } diff --git a/programs/Hadrons/GUnit.hpp b/programs/Hadrons/GUnit.hpp index 21e9a15f..4dfc268d 100644 --- a/programs/Hadrons/GUnit.hpp +++ b/programs/Hadrons/GUnit.hpp @@ -48,9 +48,9 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // allocation - virtual void allocate(Environment &env); + virtual void allocate(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: LatticeGaugeField *gauge_ = nullptr; }; diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index 2ec3d4a6..d27a545e 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -61,9 +61,9 @@ std::vector MQuark::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void MQuark::setup(Environment &env) +void MQuark::setup(void) { - auto dim = env.getFermionMatrix(par_.solver)->Grid()->GlobalDimensions(); + auto dim = env().getFermionMatrix(par_.solver)->Grid()->GlobalDimensions(); if (dim.size() == Nd) { @@ -76,30 +76,30 @@ void MQuark::setup(Environment &env) } // allocation ////////////////////////////////////////////////////////////////// -void MQuark::allocate(Environment &env) +void MQuark::allocate(void) { - env.create(getName()); - quark_ = env.get(getName()); + env().create(getName()); + quark_ = env().get(getName()); if (Ls_ > 1) { - env.create(getName() + "_5d", Ls_); - quark5d_ = env.get(getName() + "_5d"); + env().create(getName() + "_5d", Ls_); + quark5d_ = env().get(getName() + "_5d"); } } // execution /////////////////////////////////////////////////////////////////// -void MQuark::execute(Environment &env) +void MQuark::execute(void) { LatticePropagator *fullSource; - LatticeFermion source(env.getGrid(Ls_)), sol(env.getGrid(Ls_)); + LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)); LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; - if (!env.isLattice5d(par_.source)) + if (!env().isLattice5d(par_.source)) { if (Ls_ == 1) { - fullSource = env.get(par_.source); + fullSource = env().get(par_.source); } else { @@ -112,16 +112,15 @@ void MQuark::execute(Environment &env) { HADRON_ERROR("MQuark not implemented with 5D actions"); } - else if (Ls_ != env.getLatticeLs(par_.source)) + else if (Ls_ != env().getLatticeLs(par_.source)) { HADRON_ERROR("MQuark not implemented with 5D actions"); } else { - fullSource = env.get(par_.source); + fullSource = env().get(par_.source); } } - LOG(Message) << "Inverting using solver '" << par_.solver << "' on source '" << par_.source << "'" << std::endl; for (unsigned int s = 0; s < Ns; ++s) @@ -129,7 +128,7 @@ void MQuark::execute(Environment &env) { PropToFerm(source, *fullSource, s, c); sol = zero; - env.callSolver(par_.solver, sol, source); + env().callSolver(par_.solver, sol, source); if (Ls_ == 1) { FermToProp(*quark_, sol, s, c); diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/MQuark.hpp index 5b14d0aa..aaa3864e 100644 --- a/programs/Hadrons/MQuark.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -43,8 +43,8 @@ public: class Par: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string , source, - std::string , solver); + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, source, + std::string, solver); }; public: // constructor @@ -57,11 +57,11 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // setup - virtual void setup(Environment &env); + virtual void setup(void); // allocation - virtual void allocate(Environment &env); + virtual void allocate(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: Par par_; unsigned int Ls_; diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index a590b81a..3233c210 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -37,6 +37,7 @@ using namespace Hadrons; // constructor ///////////////////////////////////////////////////////////////// Module::Module(const std::string name) : name_(name) +, env_(Environment::getInstance()) {} // access ////////////////////////////////////////////////////////////////////// @@ -45,12 +46,18 @@ std::string Module::getName(void) const return name_; } -void Module::operator()(Environment &env) +Environment & Module::env(void) const { - setup(env); - allocate(env); - if (!env.isDryRun()) + return env_; +} + +// execution /////////////////////////////////////////////////////////////////// +void Module::operator()(void) +{ + setup(); + allocate(); + if (!env().isDryRun()) { - execute(env); + execute(); } } diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 1f529944..605aec06 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -61,20 +61,22 @@ public: virtual ~Module(void) = default; // access std::string getName(void) const; + Environment &env(void) const; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name) {}; // dependencies/products virtual std::vector getInput(void) = 0; virtual std::vector getOutput(void) = 0; // setup - virtual void setup(Environment &env) {}; + virtual void setup(void) {}; // allocation - virtual void allocate(Environment &env) {}; + virtual void allocate(void) {}; // execution - void operator()(Environment &env); - virtual void execute(Environment &env) = 0; + void operator()(void); + virtual void execute(void) = 0; private: std::string name_; + Environment &env_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/SolRBPrecCG.cc b/programs/Hadrons/SolRBPrecCG.cc index 250c81e6..3984ea35 100644 --- a/programs/Hadrons/SolRBPrecCG.cc +++ b/programs/Hadrons/SolRBPrecCG.cc @@ -60,10 +60,17 @@ std::vector SolRBPrecCG::getOutput(void) return out; } -// execution /////////////////////////////////////////////////////////////////// -void SolRBPrecCG::execute(Environment &env) +// setup /////////////////////////////////////////////////////////////////////// +void SolRBPrecCG::setup(void) { - auto &mat = *(env.getFermionMatrix(par_.action)); + env().addOwnership(getName(), par_.action); +} + +// execution /////////////////////////////////////////////////////////////////// +void SolRBPrecCG::execute(void) +{ + auto &mat = *(env().getFermionMatrix(par_.action)); + auto solver = [&mat, this](LatticeFermion &sol, const LatticeFermion &source) { @@ -76,5 +83,5 @@ void SolRBPrecCG::execute(Environment &env) LOG(Message) << "setting up Schur red-black preconditioned CG for" << " action '" << par_.action << "' with residual " << par_.residual << std::endl; - env.addSolver(getName(), solver, par_.action); + env().addSolver(getName(), solver, par_.action); } diff --git a/programs/Hadrons/SolRBPrecCG.hpp b/programs/Hadrons/SolRBPrecCG.hpp index ca046efa..82784666 100644 --- a/programs/Hadrons/SolRBPrecCG.hpp +++ b/programs/Hadrons/SolRBPrecCG.hpp @@ -56,8 +56,10 @@ public: // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); + // setup + virtual void setup(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: Par par_; }; diff --git a/programs/Hadrons/SrcPoint.cc b/programs/Hadrons/SrcPoint.cc index 4360385c..40046cd0 100644 --- a/programs/Hadrons/SrcPoint.cc +++ b/programs/Hadrons/SrcPoint.cc @@ -60,14 +60,14 @@ std::vector SrcPoint::getOutput(void) } // allocation ////////////////////////////////////////////////////////////////// -void SrcPoint::allocate(Environment &env) +void SrcPoint::allocate(void) { - env.create(getName()); - src_ = env.get(getName()); + env().create(getName()); + src_ = env().get(getName()); } // execution /////////////////////////////////////////////////////////////////// -void SrcPoint::execute(Environment &env) +void SrcPoint::execute(void) { std::vector position = strToVec(par_.position); SpinColourMatrix id; diff --git a/programs/Hadrons/SrcPoint.hpp b/programs/Hadrons/SrcPoint.hpp index 5cde676e..75cd9aa6 100644 --- a/programs/Hadrons/SrcPoint.hpp +++ b/programs/Hadrons/SrcPoint.hpp @@ -67,9 +67,9 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // allocation - virtual void allocate(Environment &env); + virtual void allocate(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: Par par_; LatticePropagator *src_{nullptr}; diff --git a/programs/Hadrons/SrcZ2.cc b/programs/Hadrons/SrcZ2.cc index 56a4ea6e..42d5dbb2 100644 --- a/programs/Hadrons/SrcZ2.cc +++ b/programs/Hadrons/SrcZ2.cc @@ -60,18 +60,18 @@ std::vector SrcZ2::getOutput(void) } // allocation ////////////////////////////////////////////////////////////////// -void SrcZ2::allocate(Environment &env) +void SrcZ2::allocate(void) { - env.create(getName()); - src_ = env.get(getName()); + env().create(getName()); + src_ = env().get(getName()); } // execution /////////////////////////////////////////////////////////////////// -void SrcZ2::execute(Environment &env) +void SrcZ2::execute(void) { - Lattice> t(env.getGrid()); - LatticeComplex eta(env.getGrid()); - LatticeFermion phi(env.getGrid()); + Lattice> t(env().getGrid()); + LatticeComplex eta(env().getGrid()); + LatticeFermion phi(env().getGrid()); Complex shift(1., 1.); if (par_.tA == par_.tB) @@ -85,7 +85,7 @@ void SrcZ2::execute(Environment &env) << par_.tB << std::endl; } LatticeCoordinate(t, Tp); - bernoulli(*env.get4dRng(), eta); + bernoulli(*env().get4dRng(), eta); eta = (2.*eta - shift)*(1./::sqrt(2.)); eta = where((t >= par_.tA) and (t <= par_.tB), eta, 0.*eta); *src_ = 1.; diff --git a/programs/Hadrons/SrcZ2.hpp b/programs/Hadrons/SrcZ2.hpp index 09248e66..dc4c35c6 100644 --- a/programs/Hadrons/SrcZ2.hpp +++ b/programs/Hadrons/SrcZ2.hpp @@ -69,9 +69,9 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); // allocation - virtual void allocate(Environment &env); + virtual void allocate(void); // execution - virtual void execute(Environment &env); + virtual void execute(void); private: Par par_; LatticePropagator *src_; From ea0cea668e42ced2443dfe230600b9bf98225cb5 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 5 May 2016 16:13:14 -0700 Subject: [PATCH 034/106] Hadrons: minor code cleaning --- programs/Hadrons/Environment.cc | 8 +++++--- programs/Hadrons/SolRBPrecCG.cc | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index ec61c40d..0f870ba2 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -121,13 +121,13 @@ Environment::FMat * Environment::getFermionMatrix(const std::string name) const } else { - try + if (hasSolver(name)) { return fMat_.at(solverAction_.at(name)).get(); } - catch (std::out_of_range &) + else { - HADRON_ERROR("no action with name '" << name << "'"); + HADRON_ERROR("no action/solver with name '" << name << "'"); } } } @@ -299,6 +299,8 @@ void Environment::freeAll(void) fMat_.clear(); solver_.clear(); objectSize_.clear(); + owners_.clear(); + properties_.clear(); } unsigned int Environment::getSize(const std::string name) const diff --git a/programs/Hadrons/SolRBPrecCG.cc b/programs/Hadrons/SolRBPrecCG.cc index 3984ea35..8487991e 100644 --- a/programs/Hadrons/SolRBPrecCG.cc +++ b/programs/Hadrons/SolRBPrecCG.cc @@ -70,7 +70,6 @@ void SolRBPrecCG::setup(void) void SolRBPrecCG::execute(void) { auto &mat = *(env().getFermionMatrix(par_.action)); - auto solver = [&mat, this](LatticeFermion &sol, const LatticeFermion &source) { From 2c226753ab56ab3f2d66686ff689f89c79f458b4 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 6 May 2016 06:35:11 -0700 Subject: [PATCH 035/106] Hadrons: comments on graph theory algorithm complexity --- programs/Hadrons/Graph.hpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index c7591350..e43f98d1 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -116,14 +116,20 @@ makeDependencyMatrix(const std::vector> &topSort); /****************************************************************************** * template implementation * - ******************************************************************************/ + ****************************************************************************** + * in all the following V is the number of vertex and E is the number of edge + * in the worst case E = V^2 + */ + // access ////////////////////////////////////////////////////////////////////// +// complexity: log(V) template void Graph::addVertex(const T &value) { isMarked_[value] = false; } +// complexity: O(log(V)) template void Graph::addEdge(const Edge &e) { @@ -132,12 +138,14 @@ void Graph::addEdge(const Edge &e) edgeSet_.insert(e); } +// complexity: O(log(V)) template void Graph::addEdge(const T &start, const T &end) { addEdge(Edge(start, end)); } +// complexity: O(V*log(V)) template void Graph::removeVertex(const T &value) { @@ -167,6 +175,7 @@ void Graph::removeVertex(const T &value) } } +// complexity: O(log(V)) template void Graph::removeEdge(const Edge &e) { @@ -182,12 +191,14 @@ void Graph::removeEdge(const Edge &e) } } +// complexity: O(log(V)) template void Graph::removeEdge(const T &start, const T &end) { removeEdge(Edge(start, end)); } +// complexity: O(1) template unsigned int Graph::size(void) const { @@ -195,6 +206,7 @@ unsigned int Graph::size(void) const } // tests /////////////////////////////////////////////////////////////////////// +// complexity: O(log(V)) template bool Graph::gotValue(const T &value) const { @@ -211,6 +223,7 @@ bool Graph::gotValue(const T &value) const } // vertex marking ////////////////////////////////////////////////////////////// +// complexity: O(log(V)) template void Graph::mark(const T &value, const bool doMark) { @@ -224,6 +237,7 @@ void Graph::mark(const T &value, const bool doMark) } } +// complexity: O(V*log(V)) template void Graph::markAll(const bool doMark) { @@ -233,18 +247,21 @@ void Graph::markAll(const bool doMark) } } +// complexity: O(log(V)) template void Graph::unmark(const T &value) { mark(value, false); } +// complexity: O(V*log(V)) template void Graph::unmarkAll(void) { markAll(false); } +// complexity: O(log(V)) template bool Graph::isMarked(const T &value) const { @@ -260,6 +277,7 @@ bool Graph::isMarked(const T &value) const } } +// complexity: O(log(V)) template const T * Graph::getFirstMarked(const bool isMarked) const { @@ -279,6 +297,7 @@ const T * Graph::getFirstMarked(const bool isMarked) const } } +// complexity: O(log(V)) template const T * Graph::getFirstUnmarked(void) const { @@ -286,6 +305,7 @@ const T * Graph::getFirstUnmarked(void) const } // prune marked/unmarked vertices ////////////////////////////////////////////// +// complexity: O(V^2*log(V)) template void Graph::removeMarked(const bool isMarked) { @@ -300,6 +320,7 @@ void Graph::removeMarked(const bool isMarked) } } +// complexity: O(V^2*log(V)) template void Graph::removeUnmarked(void) { @@ -307,12 +328,14 @@ void Graph::removeUnmarked(void) } // depth-first search marking ////////////////////////////////////////////////// +// complexity: O(V*log(V)) template void Graph::depthFirstSearch(void) { depthFirstSearch(isMarked_.begin()->first); } +// complexity: O(V*log(V)) template void Graph::depthFirstSearch(const T &root) { @@ -330,6 +353,7 @@ void Graph::depthFirstSearch(const T &root) } // graph topological manipulations ///////////////////////////////////////////// +// complexity: O(V*log(V)) template std::vector Graph::getAdjacentVertices(const T &value) const { @@ -357,6 +381,7 @@ std::vector Graph::getAdjacentVertices(const T &value) const return adjacentVertex; } +// complexity: O(V*log(V)) template std::vector Graph::getChildren(const T &value) const { @@ -377,6 +402,7 @@ std::vector Graph::getChildren(const T &value) const return child; } +// complexity: O(V*log(V)) template std::vector Graph::getParents(const T &value) const { @@ -397,6 +423,7 @@ std::vector Graph::getParents(const T &value) const return parent; } +// complexity: O(V^2*log(V)) template std::vector Graph::getRoots(void) const { @@ -415,6 +442,7 @@ std::vector Graph::getRoots(void) const return root; } +// complexity: O(V^2*log(V)) template std::vector> Graph::getConnectedComponents(void) const { @@ -435,6 +463,7 @@ std::vector> Graph::getConnectedComponents(void) const } // topological sort using Tarjan's algorithm +// complexity: O(V*log(V)) template std::vector Graph::topoSort(void) { @@ -493,6 +522,7 @@ std::vector Graph::topoSort(void) // generate all possible topological sorts // Y. L. Varol & D. Rotem, Comput. J. 24(1), pp. 83–84, 1981 // http://comjnl.oupjournals.org/cgi/doi/10.1093/comjnl/24.1.83 +// complexity: O(V*log(V)) template std::vector> Graph::allTopoSort(void) { @@ -570,6 +600,7 @@ std::vector> Graph::allTopoSort(void) } // build depedency matrix from topological sorts /////////////////////////////// +// complexity: can be V! template std::map> makeDependencyMatrix(const std::vector> &topSort) From bb580ae077493b656e8ef3e5caf08016d6edb987 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 7 May 2016 13:19:38 -0700 Subject: [PATCH 036/106] Hadrons: significant overhaul of the object registration system, previous version didn't allow dry runs --- programs/Hadrons/AWilson.cc | 12 +- programs/Hadrons/AWilson.hpp | 2 + programs/Hadrons/Application.cc | 38 ++++-- programs/Hadrons/Environment.cc | 204 +++++++++++++++++++------------ programs/Hadrons/Environment.hpp | 113 ++++++++--------- programs/Hadrons/GLoad.cc | 10 +- programs/Hadrons/GLoad.hpp | 7 +- programs/Hadrons/GRandom.cc | 10 +- programs/Hadrons/GRandom.hpp | 6 +- programs/Hadrons/GUnit.cc | 10 +- programs/Hadrons/GUnit.hpp | 6 +- programs/Hadrons/Graph.hpp | 95 ++++++++++++-- programs/Hadrons/MQuark.cc | 46 +++---- programs/Hadrons/MQuark.hpp | 3 - programs/Hadrons/Module.cc | 1 - programs/Hadrons/Module.hpp | 2 - programs/Hadrons/SolRBPrecCG.cc | 4 +- programs/Hadrons/SrcPoint.cc | 14 +-- programs/Hadrons/SrcPoint.hpp | 7 +- programs/Hadrons/SrcZ2.cc | 16 +-- programs/Hadrons/SrcZ2.hpp | 7 +- 21 files changed, 364 insertions(+), 249 deletions(-) diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/AWilson.cc index 0be43ee7..5a75a257 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/AWilson.cc @@ -59,6 +59,15 @@ std::vector AWilson::getOutput(void) return out; } +// setup /////////////////////////////////////////////////////////////////////// +void AWilson::setup(void) +{ + unsigned int size; + + size = 3*env().lattice4dSize(); + env().registerObject(getName(), size); +} + // execution /////////////////////////////////////////////////////////////////// void AWilson::execute() { @@ -70,6 +79,5 @@ void AWilson::execute() LOG(Message) << "Setting up Wilson fermion matrix with m= " << par_.mass << " using gauge field '" << par_.gauge << "'" << std::endl; - size = 3*env().lattice4dSize(); - env().addFermionMatrix(getName(), fMatPt, size); + env().addFermionMatrix(getName(), fMatPt); } diff --git a/programs/Hadrons/AWilson.hpp b/programs/Hadrons/AWilson.hpp index df2d6f41..1eaf0a36 100644 --- a/programs/Hadrons/AWilson.hpp +++ b/programs/Hadrons/AWilson.hpp @@ -56,6 +56,8 @@ public: // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); + // setup + virtual void setup(void); // execution virtual void execute(void); private: diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 7fb69ab1..aa7e66bc 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -107,9 +107,33 @@ void Application::parseParameterFile(void) } // schedule computation //////////////////////////////////////////////////////// +#define MEM_MSG(size)\ +sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" + void Application::schedule(void) { - Graph moduleGraph; + // memory peak and invers memory peak functions + auto memPeak = [this](const std::vector &program) + { + unsigned int memPeak; + bool msg; + + msg = HadronsLogMessage.isActive(); + HadronsLogMessage.Active(false); + env_.dryRun(true); + memPeak = execute(program); + env_.dryRun(false); + env_.freeAll(); + HadronsLogMessage.Active(true); + + return memPeak; + }; + auto invMemPeak = [&memPeak](const std::vector &program) + { + return 1./memPeak(program); + }; + + Graph moduleGraph; LOG(Message) << "Scheduling computation..." << std::endl; @@ -161,7 +185,8 @@ void Application::schedule(void) // } // env_.dryRun(false); std::vector t = con[i].topoSort(); - LOG(Message) << "Program " << i + 1 << ":" << std::endl; + LOG(Message) << "Program " << i + 1 << " (memory peak: " + << MEM_MSG(memPeak(t)) << "):" << std::endl; for (unsigned int j = 0; j < t.size(); ++j) { program_.push_back(t[j]); @@ -210,6 +235,7 @@ unsigned int Application::execute(const std::vector &program) freeProg[program.rend() - it - 1].insert(n.first); } } + // program execution for (unsigned int i = 0; i < program.size(); ++i) { @@ -220,8 +246,7 @@ unsigned int Application::execute(const std::vector &program) (*module_[program[i]])(); size = env_.getTotalSize(); // print used memory after execution - LOG(Message) << "Allocated objects: " << sizeString(size*locVol_) - << " (" << sizeString(size) << "/site)" << std::endl; + LOG(Message) << "Allocated objects: " << MEM_MSG(size) << std::endl; if (size > memPeak) { memPeak = size; @@ -237,7 +262,7 @@ unsigned int Application::execute(const std::vector &program) // continue garbage collection while there are still // objects without owners continueCollect = continueCollect or !env_.hasOwners(n); - if(env_.free(n)) + if(env_.freeObject(n)) { // if an object has been freed, remove it from // the garbage collection schedule @@ -256,8 +281,7 @@ unsigned int Application::execute(const std::vector &program) } // print used memory after garbage collection size = env_.getTotalSize(); - LOG(Message) << "Allocated objects: " << sizeString(size*locVol_) - << " (" << sizeString(size) << "/site)" << std::endl; + LOG(Message) << "Allocated objects: " << MEM_MSG(size) << std::endl; } return memPeak; diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 0f870ba2..ee0b842d 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -67,6 +67,14 @@ unsigned int Environment::getTrajectory(void) const } // grids /////////////////////////////////////////////////////////////////////// +void Environment::createGrid(const unsigned int Ls) +{ + auto g = getGrid(); + + grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g)); + gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g)); +} + GridCartesian * Environment::getGrid(const unsigned int Ls) const { try @@ -82,7 +90,7 @@ GridCartesian * Environment::getGrid(const unsigned int Ls) const } catch(std::out_of_range &) { - HADRON_ERROR("no 5D grid with Ls= " << Ls); + HADRON_ERROR("no grid with Ls= " << Ls); } } @@ -106,11 +114,16 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const } // fermion actions ///////////////////////////////////////////////////////////// -void Environment::addFermionMatrix(const std::string name, FMat *fMat, - const unsigned int size) +void Environment::addFermionMatrix(const std::string name, FMat *fMat) { - fMat_[name].reset(fMat); - addSize(name, size); + if (hasObject(name)) + { + fMat_[name].reset(fMat); + } + else + { + HADRON_ERROR("no object named '" << name << "'"); + } } Environment::FMat * Environment::getFermionMatrix(const std::string name) const @@ -138,41 +151,66 @@ void Environment::freeFermionMatrix(const std::string name) { LOG(Message) << "freeing fermion matrix '" << name << "'" << std::endl; fMat_.erase(name); - objectSize_.erase(name); + object_.erase(name); } else { - HADRON_ERROR("trying to free undefined fermion matrix '" + name + "'"); + HADRON_ERROR("trying to free unknown fermion matrix '" + name + "'"); } } bool Environment::hasFermionMatrix(const std::string name) const { - return (fMat_.find(name) != fMat_.end()); + return (hasObject(name) and (fMat_.find(name) != fMat_.end())); } // solvers ///////////////////////////////////////////////////////////////////// -void Environment::addSolver(const std::string name, Solver s, - const std::string actionName) +void Environment::addSolver(const std::string name, Solver s) { - solver_[name] = s; - solverAction_[name] = actionName; + if (hasObject(name)) + { + solver_[name] = s; + } + else + { + HADRON_ERROR("no object named '" << name << "'"); + } } bool Environment::hasSolver(const std::string name) const { - return (solver_.find(name) != solver_.end()); + return (hasObject(name) and (solver_.find(name) != solver_.end())); +} + +void Environment::setSolverAction(const std::string name, + const std::string actionName) +{ + if (hasObject(name)) + { + solverAction_[name] = actionName; + } + else + { + HADRON_ERROR("no object named '" << name << "'"); + } } std::string Environment::getSolverAction(const std::string name) const { - if (hasSolver(name)) + if (hasObject(name)) { - return solverAction_.at(name); + try + { + return solverAction_.at(name); + } + catch (std::out_of_range &) + { + HADRON_ERROR("no action registered for solver '" << name << "'") + } } else { - HADRON_ERROR("no solver with name '" << name << "'"); + HADRON_ERROR("no object with name '" << name << "'"); } } @@ -207,47 +245,81 @@ void Environment::freeLattice(const std::string name) { LOG(Message) << "freeing lattice '" << name << "'" << std::endl; lattice_.erase(name); - objectSize_.erase(name); + object_.erase(name); } else { - HADRON_ERROR("trying to free undefined lattice '" + name + "'"); + HADRON_ERROR("trying to free unknown lattice '" + name + "'"); } } bool Environment::hasLattice(const std::string name) const { - return (lattice_.find(name) != lattice_.end()); -} - - -bool Environment::isLattice5d(const std::string name) const -{ - if (hasLattice(name)) - { - return (lattice_.at(name)->_grid->GlobalDimensions().size() == Nd + 1); - } - else - { - HADRON_ERROR("object '" + name + "' undefined"); - - return false; - } -} - -unsigned int Environment::getLatticeLs(const std::string name) const -{ - if (isLattice5d(name)) - { - return lattice_.at(name)->_grid->GlobalDimensions()[0]; - } - else - { - return 1; - } + return (hasObject(name) and (lattice_.find(name) != lattice_.end())); } // general memory management /////////////////////////////////////////////////// +bool Environment::hasObject(const std::string name) const +{ + return (object_.find(name) != object_.end()); +} + +void Environment::registerObject(const std::string name, + const unsigned int size, const unsigned int Ls) +{ + if (!hasObject(name)) + { + ObjInfo info{size, Ls}; + + object_[name] = info; + } + else + { + HADRON_ERROR("object '" + name + "' already exists"); + } +} + +unsigned int Environment::getObjectSize(const std::string name) const +{ + if (hasObject(name)) + { + return object_.at(name).size; + } + else + { + HADRON_ERROR("no object named '" + name + "'"); + } +} + +long unsigned int Environment::getTotalSize(void) const +{ + long unsigned int size = 0; + + for (auto &s: object_) + { + size += s.second.size; + } + + return size; +} + +unsigned int Environment::getObjectLs(const std::string name) const +{ + if (hasObject(name)) + { + return object_.at(name).Ls; + } + else + { + HADRON_ERROR("no object named '" + name + "'"); + } +} + +bool Environment::isObject5d(const std::string name) const +{ + return (getObjectLs(name) > 1); +} + void Environment::addOwnership(const std::string owner, const std::string property) { @@ -267,7 +339,7 @@ bool Environment::hasOwners(const std::string name) const } } -bool Environment::free(const std::string name) +bool Environment::freeObject(const std::string name) { if (!hasOwners(name)) { @@ -284,6 +356,10 @@ bool Environment::free(const std::string name) { freeFermionMatrix(name); } + else if (hasObject(name)) + { + object_.erase(name); + } return true; } @@ -295,41 +371,11 @@ bool Environment::free(const std::string name) void Environment::freeAll(void) { + object_.clear(); lattice_.clear(); fMat_.clear(); solver_.clear(); - objectSize_.clear(); + solverAction_.clear(); owners_.clear(); properties_.clear(); } - -unsigned int Environment::getSize(const std::string name) const -{ - if (hasLattice(name) or hasFermionMatrix(name)) - { - return objectSize_.at(name); - } - else - { - HADRON_ERROR("object '" + name + "' undefined"); - - return 0; - } -} - -long unsigned int Environment::getTotalSize(void) const -{ - long unsigned int size = 0; - - for (auto &s: objectSize_) - { - size += s.second; - } - - return size; -} - -void Environment::addSize(const std::string name, const unsigned int size) -{ - objectSize_[name] = size; -} diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index f5265181..7f55308a 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -47,6 +47,11 @@ public: typedef std::unique_ptr RngPt; typedef std::unique_ptr FMatPt; typedef std::unique_ptr LatticePt; +private: + struct ObjInfo + { + unsigned int size, Ls; + }; public: // dry run void dryRun(const bool isDry); @@ -55,18 +60,19 @@ public: void setTrajectory(const unsigned int traj); unsigned int getTrajectory(void) const; // grids + void createGrid(const unsigned int Ls); GridCartesian * getGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; // fermion actions - void addFermionMatrix(const std::string name, FMat *mat, - const unsigned int size); + void addFermionMatrix(const std::string name, FMat *mat); FMat * getFermionMatrix(const std::string name) const; void freeFermionMatrix(const std::string name); bool hasFermionMatrix(const std::string name) const; // solvers - void addSolver(const std::string name, Solver s, - const std::string actionName); + void addSolver(const std::string name, Solver s); bool hasSolver(const std::string name) const; + void setSolverAction(const std::string name, + const std::string actionName); std::string getSolverAction(const std::string name) const; void callSolver(const std::string name, LatticeFermion &sol, @@ -76,39 +82,45 @@ public: GridParallelRNG * get4dRng(void) const; // lattice store template - unsigned int lattice4dSize(void) const; - template - void create(const std::string name, - const unsigned int Ls = 1); + T * create(const std::string name); template T * get(const std::string name) const; - void freeLattice(const std::string name); bool hasLattice(const std::string name) const; - bool isLattice5d(const std::string name) const; - unsigned int getLatticeLs(const std::string name) const; + void freeLattice(const std::string name); + template + unsigned int lattice4dSize(void) const; // general memory management + bool hasObject(const std::string name) const; + void registerObject(const std::string name, + const unsigned int size, + const unsigned int Ls = 1); + template + void registerLattice(const std::string name, + const unsigned int Ls = 1); + unsigned int getObjectSize(const std::string name) const; + long unsigned int getTotalSize(void) const; + unsigned int getObjectLs(const std::string name) const; + bool isObject5d(const std::string name) const; void addOwnership(const std::string owner, const std::string property); bool hasOwners(const std::string name) const; - bool free(const std::string name); + bool freeObject(const std::string name); void freeAll(void); - unsigned int getSize(const std::string name) const; - long unsigned int getTotalSize(void) const; private: - void addSize(const std::string name, const unsigned int size); + private: - bool dryRun_{false}; - unsigned int traj_; - GridPt grid4d_; - std::map grid5d_; - GridRbPt gridRb4d_; - std::map gridRb5d_; - RngPt rng4d_; - std::map fMat_; - std::map solver_; - std::map solverAction_; - std::map lattice_; - std::map objectSize_; + bool dryRun_{false}; + unsigned int traj_; + GridPt grid4d_; + std::map grid5d_; + GridRbPt gridRb4d_; + std::map gridRb5d_; + RngPt rng4d_; + std::map object_; + std::map lattice_; + std::map fMat_; + std::map solver_; + std::map solverAction_; std::map> owners_; std::map> properties_; }; @@ -123,41 +135,13 @@ unsigned int Environment::lattice4dSize(void) const } template -void Environment::create(const std::string name, const unsigned int Ls) +T * Environment::create(const std::string name) { - GridCartesian *g4 = getGrid(); - GridCartesian *g; + GridCartesian *g = getGrid(getObjectLs(name)); - if (hasLattice(name)) - { - HADRON_ERROR("object '" + name + "' already exists"); - } - if (Ls > 1) - { - try - { - g = grid5d_.at(Ls).get(); - } - catch(std::out_of_range &) - { - grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g4)); - gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g4)); - g = grid5d_[Ls].get(); - } - } - else - { - g = g4; - } - if (!isDryRun()) - { - lattice_[name].reset(new T(g)); - } - else - { - lattice_[name].reset(nullptr); - } - addSize(name, lattice4dSize()*Ls); + lattice_[name].reset(new T(g)); + + return dynamic_cast(lattice_[name].get()); } template @@ -178,12 +162,19 @@ T * Environment::get(const std::string name) const } else { - HADRON_ERROR("object '" + name + "' undefined"); + HADRON_ERROR("no lattice name '" + name + "'"); return nullptr; } } +template +void Environment::registerLattice(const std::string name, const unsigned int Ls) +{ + createGrid(Ls); + registerObject(name, Ls*lattice4dSize()); +} + END_HADRONS_NAMESPACE #endif // Hadrons_Environment_hpp_ diff --git a/programs/Hadrons/GLoad.cc b/programs/Hadrons/GLoad.cc index 55715fbb..cff9f3ed 100644 --- a/programs/Hadrons/GLoad.cc +++ b/programs/Hadrons/GLoad.cc @@ -59,11 +59,10 @@ std::vector GLoad::getOutput(void) return out; } -// allocation ////////////////////////////////////////////////////////////////// -void GLoad::allocate(void) +// setup /////////////////////////////////////////////////////////////////////// +void GLoad::setup(void) { - env().create(getName()); - gauge_ = env().get(getName()); + env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -75,7 +74,8 @@ void GLoad::execute(void) LOG(Message) << "Loading NERSC configuration from file '" << fileName << "'" << std::endl; - NerscIO::readConfiguration(*gauge_, header, fileName); + LatticeGaugeField &U = *env().create(getName()); + NerscIO::readConfiguration(U, header, fileName); LOG(Message) << "NERSC header:" << std::endl; dump_nersc_header(header, LOG(Message)); } diff --git a/programs/Hadrons/GLoad.hpp b/programs/Hadrons/GLoad.hpp index 4527c33c..cb076bb5 100644 --- a/programs/Hadrons/GLoad.hpp +++ b/programs/Hadrons/GLoad.hpp @@ -55,13 +55,12 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); - // allocation - virtual void allocate(void); + // setup + virtual void setup(void); // execution virtual void execute(void); private: - Par par_; - LatticeGaugeField *gauge_ = nullptr; + Par par_; }; MODULE_REGISTER(GLoad); diff --git a/programs/Hadrons/GRandom.cc b/programs/Hadrons/GRandom.cc index 53007045..7f81624c 100644 --- a/programs/Hadrons/GRandom.cc +++ b/programs/Hadrons/GRandom.cc @@ -51,16 +51,16 @@ std::vector GRandom::getOutput(void) return out; } -// allocation ////////////////////////////////////////////////////////////////// -void GRandom::allocate(void) +// setup /////////////////////////////////////////////////////////////////////// +void GRandom::setup(void) { - env().create(getName()); - gauge_ = env().get(getName()); + env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// void GRandom::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; - SU3::HotConfiguration(*env().get4dRng(), *gauge_); + LatticeGaugeField &U = *env().create(getName()); + SU3::HotConfiguration(*env().get4dRng(), U); } diff --git a/programs/Hadrons/GRandom.hpp b/programs/Hadrons/GRandom.hpp index 12d5be5f..5d0f4197 100644 --- a/programs/Hadrons/GRandom.hpp +++ b/programs/Hadrons/GRandom.hpp @@ -47,12 +47,10 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); - // allocation - virtual void allocate(void); + // setup + virtual void setup(void); // execution virtual void execute(void); -private: - LatticeGaugeField *gauge_ = nullptr; }; MODULE_REGISTER(GRandom); diff --git a/programs/Hadrons/GUnit.cc b/programs/Hadrons/GUnit.cc index 5a86aa00..75bdc597 100644 --- a/programs/Hadrons/GUnit.cc +++ b/programs/Hadrons/GUnit.cc @@ -51,16 +51,16 @@ std::vector GUnit::getOutput(void) return out; } -// allocation ////////////////////////////////////////////////////////////////// -void GUnit::allocate(void) +// setup /////////////////////////////////////////////////////////////////////// +void GUnit::setup(void) { - env().create(getName()); - gauge_ = env().get(getName()); + env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// void GUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; - SU3::ColdConfiguration(*env().get4dRng(), *gauge_); + LatticeGaugeField &U = *env().create(getName()); + SU3::ColdConfiguration(*env().get4dRng(), U); } diff --git a/programs/Hadrons/GUnit.hpp b/programs/Hadrons/GUnit.hpp index 4dfc268d..3c72bd07 100644 --- a/programs/Hadrons/GUnit.hpp +++ b/programs/Hadrons/GUnit.hpp @@ -47,12 +47,10 @@ public: // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); - // allocation - virtual void allocate(void); + // setup + virtual void setup(void); // execution virtual void execute(void); -private: - LatticeGaugeField *gauge_ = nullptr; }; MODULE_REGISTER(GUnit); diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index e43f98d1..6022dd3a 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -52,7 +52,7 @@ public: typedef std::pair Edge; public: // constructor - Graph(void) = default; + Graph(void); // destructor virtual ~Graph(void) = default; // access @@ -71,7 +71,7 @@ public: std::vector getParents(const T &value) const; std::vector getRoots(void) const; std::vector> getConnectedComponents(void) const; - std::vector topoSort(void); + std::vector topoSort(const bool randomize = false); std::vector> allTopoSort(void); // I/O friend std::ostream & operator<<(std::ostream &out, const Graph &g) @@ -97,7 +97,9 @@ private: void unmarkAll(void); bool isMarked(const T &value) const; const T * getFirstMarked(const bool isMarked = true) const; + const T * getRandomMarked(const bool isMarked = true); const T * getFirstUnmarked(void) const; + const T * getRandomUnmarked(void); // prune marked/unmarked vertices void removeMarked(const bool isMarked = true); void removeUnmarked(void); @@ -105,8 +107,9 @@ private: void depthFirstSearch(void); void depthFirstSearch(const T &root); private: - std::map isMarked_; - std::set edgeSet_; + std::map isMarked_; + std::set edgeSet_; + std::mt19937 gen_; }; // build depedency matrix from topological sorts @@ -121,6 +124,15 @@ makeDependencyMatrix(const std::vector> &topSort); * in the worst case E = V^2 */ +// constructor ///////////////////////////////////////////////////////////////// +template +Graph::Graph(void) +{ + std::random_device rd; + + gen_.seed(rd()); +} + // access ////////////////////////////////////////////////////////////////////// // complexity: log(V) template @@ -297,6 +309,37 @@ const T * Graph::getFirstMarked(const bool isMarked) const } } +// complexity: O(log(V)) +template +const T * Graph::getRandomMarked(const bool isMarked) +{ + auto pred = [&isMarked](const std::pair &v) + { + return (v.second == isMarked); + }; + std::uniform_int_distribution dis(0, size() - 1); + auto rIt = isMarked_.begin(); + + std::advance(rIt, dis(gen_)); + auto vIt = std::find_if(rIt, isMarked_.end(), pred); + if (vIt != isMarked_.end()) + { + return &(vIt->first); + } + else + { + vIt = std::find_if(isMarked_.begin(), rIt, pred); + if (vIt != rIt) + { + return &(vIt->first); + } + else + { + return nullptr; + } + } +} + // complexity: O(log(V)) template const T * Graph::getFirstUnmarked(void) const @@ -304,6 +347,13 @@ const T * Graph::getFirstUnmarked(void) const return getFirstMarked(false); } +// complexity: O(log(V)) +template +const T * Graph::getRandomUnmarked(void) +{ + return getRandomMarked(false); +} + // prune marked/unmarked vertices ////////////////////////////////////////////// // complexity: O(V^2*log(V)) template @@ -462,10 +512,10 @@ std::vector> Graph::getConnectedComponents(void) const return res; } -// topological sort using Tarjan's algorithm +// topological sort using a directed DFS algorithm // complexity: O(V*log(V)) template -std::vector Graph::topoSort(void) +std::vector Graph::topoSort(const bool randomize) { std::stack buf; std::vector res; @@ -479,16 +529,20 @@ std::vector Graph::topoSort(void) { HADRON_ERROR("cannot topologically sort a cyclic graph"); } - if (!this->isMarked(v)) + if (!isMarked(v)) { - std::vector child = this->getChildren(v); - + std::vector child = getChildren(v); + tmpMarked[v] = true; + if (randomize) + { + std::shuffle(child.begin(), child.end(), gen_); + } for (auto &c: child) { visit(c); } - this->mark(v); + mark(v); tmpMarked[v] = false; buf.push(v); } @@ -501,11 +555,26 @@ std::vector Graph::topoSort(void) } // loop on unmarked vertices - vPt = getFirstUnmarked(); + unmarkAll(); + if (randomize) + { + vPt = getRandomUnmarked(); + } + else + { + vPt = getFirstUnmarked(); + } while (vPt) { visit(*vPt); - vPt = getFirstUnmarked(); + if (randomize) + { + vPt = getRandomUnmarked(); + } + else + { + vPt = getFirstUnmarked(); + } } unmarkAll(); @@ -522,7 +591,7 @@ std::vector Graph::topoSort(void) // generate all possible topological sorts // Y. L. Varol & D. Rotem, Comput. J. 24(1), pp. 83–84, 1981 // http://comjnl.oupjournals.org/cgi/doi/10.1093/comjnl/24.1.83 -// complexity: O(V*log(V)) +// complexity: O(V*log(V)) (from the paper, but really ?) template std::vector> Graph::allTopoSort(void) { diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/MQuark.cc index d27a545e..c6af53f4 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/MQuark.cc @@ -63,27 +63,11 @@ std::vector MQuark::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void MQuark::setup(void) { - auto dim = env().getFermionMatrix(par_.solver)->Grid()->GlobalDimensions(); - - if (dim.size() == Nd) - { - Ls_ = 1; - } - else - { - Ls_ = dim[0]; - } -} - -// allocation ////////////////////////////////////////////////////////////////// -void MQuark::allocate(void) -{ - env().create(getName()); - quark_ = env().get(getName()); + Ls_ = env().getObjectLs(env().getSolverAction(par_.solver)); + env().registerLattice(getName()); if (Ls_ > 1) { - env().create(getName() + "_5d", Ls_); - quark5d_ = env().get(getName() + "_5d"); + env().registerLattice(getName() + "_5d", Ls_); } } @@ -92,10 +76,13 @@ void MQuark::execute(void) { LatticePropagator *fullSource; LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)); + std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; - if (!env().isLattice5d(par_.source)) + LatticePropagator &prop = *env().create(propName); + // source conversion for 4D sources + if (!env().isObject5d(par_.source)) { if (Ls_ == 1) { @@ -106,15 +93,16 @@ void MQuark::execute(void) HADRON_ERROR("MQuark not implemented with 5D actions"); } } + // source conversion for 5D sources else { if (Ls_ == 1) { HADRON_ERROR("MQuark not implemented with 5D actions"); } - else if (Ls_ != env().getLatticeLs(par_.source)) + else if (Ls_ != env().getObjectLs(par_.source)) { - HADRON_ERROR("MQuark not implemented with 5D actions"); + HADRON_ERROR("Ls mismatch between quark action and source"); } else { @@ -129,13 +117,11 @@ void MQuark::execute(void) PropToFerm(source, *fullSource, s, c); sol = zero; env().callSolver(par_.solver, sol, source); - if (Ls_ == 1) - { - FermToProp(*quark_, sol, s, c); - } - else - { - HADRON_ERROR("MQuark not implemented with 5D actions"); - } + FermToProp(prop, sol, s, c); + } + // create 4D propagators from 5D one if necessary + if (Ls_ > 1) + { + HADRON_ERROR("MQuark not implemented with 5D actions"); } } diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/MQuark.hpp index aaa3864e..14ced177 100644 --- a/programs/Hadrons/MQuark.hpp +++ b/programs/Hadrons/MQuark.hpp @@ -58,14 +58,11 @@ public: virtual std::vector getOutput(void); // setup virtual void setup(void); - // allocation - virtual void allocate(void); // execution virtual void execute(void); private: Par par_; unsigned int Ls_; - LatticePropagator *source_{nullptr}, *quark_{nullptr}, *quark5d_{nullptr}; Environment::Solver *solver_{nullptr}; }; diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index 3233c210..a2dedb52 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -55,7 +55,6 @@ Environment & Module::env(void) const void Module::operator()(void) { setup(); - allocate(); if (!env().isDryRun()) { execute(); diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 605aec06..2b4bfabe 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -69,8 +69,6 @@ public: virtual std::vector getOutput(void) = 0; // setup virtual void setup(void) {}; - // allocation - virtual void allocate(void) {}; // execution void operator()(void); virtual void execute(void) = 0; diff --git a/programs/Hadrons/SolRBPrecCG.cc b/programs/Hadrons/SolRBPrecCG.cc index 8487991e..fc1d00aa 100644 --- a/programs/Hadrons/SolRBPrecCG.cc +++ b/programs/Hadrons/SolRBPrecCG.cc @@ -63,7 +63,9 @@ std::vector SolRBPrecCG::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void SolRBPrecCG::setup(void) { + env().registerObject(getName(), 0); env().addOwnership(getName(), par_.action); + env().setSolverAction(getName(), par_.action); } // execution /////////////////////////////////////////////////////////////////// @@ -82,5 +84,5 @@ void SolRBPrecCG::execute(void) LOG(Message) << "setting up Schur red-black preconditioned CG for" << " action '" << par_.action << "' with residual " << par_.residual << std::endl; - env().addSolver(getName(), solver, par_.action); + env().addSolver(getName(), solver); } diff --git a/programs/Hadrons/SrcPoint.cc b/programs/Hadrons/SrcPoint.cc index 40046cd0..559e56d3 100644 --- a/programs/Hadrons/SrcPoint.cc +++ b/programs/Hadrons/SrcPoint.cc @@ -59,11 +59,10 @@ std::vector SrcPoint::getOutput(void) return out; } -// allocation ////////////////////////////////////////////////////////////////// -void SrcPoint::allocate(void) +// setup /////////////////////////////////////////////////////////////////////// +void SrcPoint::setup(void) { - env().create(getName()); - src_ = env().get(getName()); + env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -74,7 +73,8 @@ void SrcPoint::execute(void) LOG(Message) << "Creating point source at position [" << par_.position << "]" << std::endl; - id = 1.; - *src_ = zero; - pokeSite(id, *src_, position); + LatticePropagator &src = *env().create(getName()); + id = 1.; + src = zero; + pokeSite(id, src, position); } diff --git a/programs/Hadrons/SrcPoint.hpp b/programs/Hadrons/SrcPoint.hpp index 75cd9aa6..8cfa89c9 100644 --- a/programs/Hadrons/SrcPoint.hpp +++ b/programs/Hadrons/SrcPoint.hpp @@ -66,13 +66,12 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); - // allocation - virtual void allocate(void); + // setup + virtual void setup(void); // execution virtual void execute(void); private: - Par par_; - LatticePropagator *src_{nullptr}; + Par par_; }; MODULE_REGISTER(SrcPoint); diff --git a/programs/Hadrons/SrcZ2.cc b/programs/Hadrons/SrcZ2.cc index 42d5dbb2..0ed6227d 100644 --- a/programs/Hadrons/SrcZ2.cc +++ b/programs/Hadrons/SrcZ2.cc @@ -59,11 +59,10 @@ std::vector SrcZ2::getOutput(void) return out; } -// allocation ////////////////////////////////////////////////////////////////// -void SrcZ2::allocate(void) +// setup /////////////////////////////////////////////////////////////////////// +void SrcZ2::setup(void) { - env().create(getName()); - src_ = env().get(getName()); + env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -84,10 +83,11 @@ void SrcZ2::execute(void) LOG(Message) << "Generating Z_2 band for " << par_.tA << " <= t <= " << par_.tB << std::endl; } + LatticePropagator &src = *env().create(getName()); LatticeCoordinate(t, Tp); bernoulli(*env().get4dRng(), eta); - eta = (2.*eta - shift)*(1./::sqrt(2.)); - eta = where((t >= par_.tA) and (t <= par_.tB), eta, 0.*eta); - *src_ = 1.; - *src_ = (*src_)*eta; + eta = (2.*eta - shift)*(1./::sqrt(2.)); + eta = where((t >= par_.tA) and (t <= par_.tB), eta, 0.*eta); + src = 1.; + src = src*eta; } diff --git a/programs/Hadrons/SrcZ2.hpp b/programs/Hadrons/SrcZ2.hpp index dc4c35c6..a1458693 100644 --- a/programs/Hadrons/SrcZ2.hpp +++ b/programs/Hadrons/SrcZ2.hpp @@ -68,13 +68,12 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); - // allocation - virtual void allocate(void); + // setup + virtual void setup(void); // execution virtual void execute(void); private: - Par par_; - LatticePropagator *src_; + Par par_; }; MODULE_REGISTER(SrcZ2); From df3fbc477ef15410f9b42f2bd88804e5b85ffaf3 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 7 May 2016 13:26:56 -0700 Subject: [PATCH 037/106] Hadrons: code cleaning --- programs/Hadrons/Application.cc | 13 ++++++++----- programs/Hadrons/Application.hpp | 2 +- programs/Hadrons/Environment.cc | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index aa7e66bc..3b1564c0 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -32,6 +32,9 @@ using namespace Grid; using namespace QCD; using namespace Hadrons; +#define BIG_SEP "===============" +#define SEP "---------------" + /****************************************************************************** * Application implementation * ******************************************************************************/ @@ -204,8 +207,8 @@ void Application::configLoop(void) for (unsigned int t = range.start; t < range.end; t += range.step) { - LOG(Message) << "========== Starting measurement for trajectory " << t - << " ==========" << std::endl; + LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t + << " " << BIG_SEP << std::endl; env_.setTrajectory(t); execute(program_); env_.freeAll(); @@ -240,9 +243,9 @@ unsigned int Application::execute(const std::vector &program) for (unsigned int i = 0; i < program.size(); ++i) { // execute module - LOG(Message) << "---------- Measurement step " << i+1 << "/" - << program.size() << " (module '" << program[i] << "')" - << " ----------" << std::endl; + LOG(Message) << SEP << " Measurement step " << i+1 << "/" + << program.size() << " (module '" << program[i] << "') " + << SEP << std::endl; (*module_[program[i]])(); size = env_.getTotalSize(); // print used memory after execution diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 518b29ca..6b7e54c5 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -86,7 +86,7 @@ private: void configLoop(void); unsigned int execute(const std::vector &program); // pretty size formatting - std::string sizeString(long unsigned int bytes); + static std::string sizeString(long unsigned int bytes); private: long unsigned int locVol_; std::string parameterFileName_; diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index ee0b842d..3390893d 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -149,7 +149,7 @@ void Environment::freeFermionMatrix(const std::string name) { if (hasFermionMatrix(name)) { - LOG(Message) << "freeing fermion matrix '" << name << "'" << std::endl; + LOG(Message) << "Freeing fermion matrix '" << name << "'" << std::endl; fMat_.erase(name); object_.erase(name); } @@ -243,7 +243,7 @@ void Environment::freeLattice(const std::string name) { if (hasLattice(name)) { - LOG(Message) << "freeing lattice '" << name << "'" << std::endl; + LOG(Message) << "Freeing lattice '" << name << "'" << std::endl; lattice_.erase(name); object_.erase(name); } From 9e986654e695ecf131a5ce200678255e3558f38f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 9 May 2016 14:49:06 +0100 Subject: [PATCH 038/106] Hadrons: first version of the genetic scheduler --- programs/Hadrons/Application.cc | 111 ++++++------ programs/Hadrons/CMeson.cc | 2 +- programs/Hadrons/Environment.cc | 20 ++- programs/Hadrons/GeneticScheduler.hpp | 233 ++++++++++++++++++++++++++ programs/Hadrons/Global.cc | 1 + programs/Hadrons/Global.hpp | 1 + programs/Hadrons/Graph.hpp | 131 +++++++++++---- programs/Hadrons/Hadrons.cc | 1 + 8 files changed, 407 insertions(+), 93 deletions(-) create mode 100644 programs/Hadrons/GeneticScheduler.hpp diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 3b1564c0..7bcc9959 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -26,7 +26,7 @@ directory. *******************************************************************************/ #include -#include +#include using namespace Grid; using namespace QCD; @@ -115,7 +115,7 @@ sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" void Application::schedule(void) { - // memory peak and invers memory peak functions + // memory peak function auto memPeak = [this](const std::vector &program) { unsigned int memPeak; @@ -131,16 +131,11 @@ void Application::schedule(void) return memPeak; }; - auto invMemPeak = [&memPeak](const std::vector &program) - { - return 1./memPeak(program); - }; - - Graph moduleGraph; - - LOG(Message) << "Scheduling computation..." << std::endl; // create dependency graph + Graph moduleGraph; + + LOG(Message) << "Scheduling computation..." << std::endl; for (auto &m: module_) { std::vector input = m.second->getInput(); @@ -157,39 +152,47 @@ void Application::schedule(void) } } - // topological sort - unsigned int k = 0; - + // constrained topological sort using a genetic algorithm + constexpr unsigned int maxGen = 200, maxCstGen = 50; + unsigned int k = 0, gen, prevPeak, nCstPeak = 0; std::vector> con = moduleGraph.getConnectedComponents(); - + GeneticScheduler::Parameters par; + std::random_device rd; + + par.popSize = 20; + par.mutationRate = .1; + par.seed = rd(); + CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); for (unsigned int i = 0; i < con.size(); ++i) { -// std::vector> t = con[i].allTopoSort(); -// int memPeak, minMemPeak = -1; -// unsigned int bestInd; -// bool msg; -// -// LOG(Message) << "analyzing " << t.size() << " possible programs..." -// << std::endl; -// env_.dryRun(true); -// for (unsigned int p = 0; p < t.size(); ++p) -// { -// msg = HadronsLogMessage.isActive(); -// HadronsLogMessage.Active(false); -// -// memPeak = execute(t[p]); -// if ((memPeak < minMemPeak) or (minMemPeak < 0)) -// { -// minMemPeak = memPeak; -// bestInd = p; -// } -// HadronsLogMessage.Active(msg); -// env_.freeAll(); -// } -// env_.dryRun(false); - std::vector t = con[i].topoSort(); + GeneticScheduler scheduler(con[i], memPeak, par); + + gen = 0; + do + { + scheduler.nextGeneration(); + if (gen != 0) + { + if (prevPeak == scheduler.getMinValue()) + { + nCstPeak++; + } + else + { + nCstPeak = 0; + } + } + prevPeak = scheduler.getMinValue(); + if (gen % 10 == 0) + { + LOG(Iterative) << "Generation " << gen << ": " + << MEM_MSG(scheduler.getMinValue()) << std::endl; + } + gen++; + } while ((gen < maxGen) and (nCstPeak < maxCstGen)); + auto &t = scheduler.getMinSchedule(); LOG(Message) << "Program " << i + 1 << " (memory peak: " - << MEM_MSG(memPeak(t)) << "):" << std::endl; + << MEM_MSG(scheduler.getMinValue()) << "):" << std::endl; for (unsigned int j = 0; j < t.size(); ++j) { program_.push_back(t[j]); @@ -213,13 +216,14 @@ void Application::configLoop(void) execute(program_); env_.freeAll(); } + LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; } unsigned int Application::execute(const std::vector &program) { - unsigned int memPeak = 0, size; + unsigned int memPeak = 0, sizeBefore, sizeAfter; std::vector> freeProg; - bool continueCollect; + bool continueCollect, nothingFreed; // build garbage collection schedule freeProg.resize(program.size()); @@ -247,15 +251,17 @@ unsigned int Application::execute(const std::vector &program) << program.size() << " (module '" << program[i] << "') " << SEP << std::endl; (*module_[program[i]])(); - size = env_.getTotalSize(); + sizeBefore = env_.getTotalSize(); // print used memory after execution - LOG(Message) << "Allocated objects: " << MEM_MSG(size) << std::endl; - if (size > memPeak) + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) + << std::endl; + if (sizeBefore > memPeak) { - memPeak = size; + memPeak = sizeBefore; } // garbage collection for step i LOG(Message) << "Garbage collection..." << std::endl; + nothingFreed = true; do { continueCollect = false; @@ -270,6 +276,7 @@ unsigned int Application::execute(const std::vector &program) // if an object has been freed, remove it from // the garbage collection schedule freeProg[i].erase(n); + nothingFreed = false; } } } while (continueCollect); @@ -282,9 +289,17 @@ unsigned int Application::execute(const std::vector &program) freeProg[i + 1].insert(n); } } - // print used memory after garbage collection - size = env_.getTotalSize(); - LOG(Message) << "Allocated objects: " << MEM_MSG(size) << std::endl; + // print used memory after garbage collection if necessary + sizeAfter = env_.getTotalSize(); + if (sizeBefore != sizeAfter) + { + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) + << std::endl; + } + else + { + LOG(Message) << "Nothing to free" << std::endl; + } } return memPeak; diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/CMeson.cc index 4e3e6b68..6cd627bd 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/CMeson.cc @@ -64,7 +64,7 @@ std::vector CMeson::getOutput(void) void CMeson::execute(void) { LOG(Message) << "Computing meson contraction '" << getName() << "' using" - << " quarks '" << par_.q1 << " and '" << par_.q2 << "'" + << " quarks '" << par_.q1 << "' and '" << par_.q2 << "'" << std::endl; XmlWriter writer(par_.output); diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 3390893d..bdb8d0d2 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -69,10 +69,13 @@ unsigned int Environment::getTrajectory(void) const // grids /////////////////////////////////////////////////////////////////////// void Environment::createGrid(const unsigned int Ls) { - auto g = getGrid(); - - grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g)); - gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g)); + if (grid5d_.find(Ls) == grid5d_.end()) + { + auto g = getGrid(); + + grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g)); + gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g)); + } } GridCartesian * Environment::getGrid(const unsigned int Ls) const @@ -329,11 +332,14 @@ void Environment::addOwnership(const std::string owner, bool Environment::hasOwners(const std::string name) const { - try + + auto it = owners_.find(name); + + if (it != owners_.end()) { - return (!owners_.at(name).empty()); + return (!it->second.empty()); } - catch (std::out_of_range &) + else { return false; } diff --git a/programs/Hadrons/GeneticScheduler.hpp b/programs/Hadrons/GeneticScheduler.hpp new file mode 100644 index 00000000..8d9bbf40 --- /dev/null +++ b/programs/Hadrons/GeneticScheduler.hpp @@ -0,0 +1,233 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/GeneticScheduler.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_GeneticScheduler_hpp_ +#define Hadrons_GeneticScheduler_hpp_ + +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Scheduler based on a genetic algorithm * + ******************************************************************************/ +template +class GeneticScheduler +{ +public: + typedef std::function &)> ObjFunc; + struct Parameters + { + double mutationRate; + unsigned int popSize, seed; + }; +public: + // constructor + GeneticScheduler(Graph &graph, const ObjFunc &func, + const Parameters &par); + // destructor + virtual ~GeneticScheduler(void) = default; + // access + const std::vector & getMinSchedule(void); + int getMinValue(void); + // breed a new generation + void nextGeneration(void); + // print population + friend std::ostream & operator<<(std::ostream &out, + const GeneticScheduler &s) + { + for (auto &p: s.population_) + { + out << p.second << ": " << p.first << std::endl; + } + + return out; + } +private: + // randomly initialize population + void initPopulation(void); + // genetic operators + const std::vector & selection(void); + void crossover(const std::vector &c1, + const std::vector &c2); + void mutation(std::vector &c); +private: + Graph &graph_; + const ObjFunc &func_; + const Parameters par_; + std::multimap> population_; + std::mt19937 gen_; +}; + +/****************************************************************************** + * template implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +GeneticScheduler::GeneticScheduler(Graph &graph, const ObjFunc &func, + const Parameters &par) +: graph_(graph) +, func_(func) +, par_(par) +{ + gen_.seed(par_.seed); +} + +// access ////////////////////////////////////////////////////////////////////// +template +const std::vector & GeneticScheduler::getMinSchedule(void) +{ + return population_.begin()->second; +} + +template +int GeneticScheduler::getMinValue(void) +{ + return population_.begin()->first; +} + +// breed a new generation ////////////////////////////////////////////////////// +template +void GeneticScheduler::nextGeneration(void) +{ + std::uniform_real_distribution dis(0., 1.); + + // random initialization of the population if necessary + if (population_.size() != par_.popSize) + { + initPopulation(); + } + + // mating + for (unsigned int i = 0; i < par_.popSize/2; ++i) + { + auto &p1 = selection(), &p2 = selection(); + crossover(p1, p2); + } + + // random mutations + auto buf = population_; + population_.clear(); + for (auto &c: buf) + { + if (dis(gen_) < par_.mutationRate) + { + mutation(c.second); + } + population_.emplace(func_(c.second), c.second); + } + + // grim reaper + auto it = population_.begin(); + + std::advance(it, par_.popSize); + population_.erase(it, population_.end()); +} + +// randomly initialize population ////////////////////////////////////////////// +template +void GeneticScheduler::initPopulation(void) +{ + population_.clear(); + for (unsigned int i = 0; i < par_.popSize; ++i) + { + auto p = graph_.topoSort(gen_); + + population_.emplace(func_(p), p); + } +} + +// genetic operators /////////////////////////////////////////////////////////// +template +const std::vector & GeneticScheduler::selection(void) +{ + std::vector prob; + + for (auto &c: population_) + { + prob.push_back(1./c.first); + } + std::discrete_distribution dis(prob.begin(), prob.end()); + auto rIt = population_.begin(); + std::advance(rIt, dis(gen_)); + + return rIt->second; +} + +template +void GeneticScheduler::crossover(const std::vector &p1, + const std::vector &p2) +{ + std::uniform_int_distribution dis(1, p1.size() - 2); + unsigned int cut = dis(gen_); + std::vector c1, c2, buf; + + auto cross = [&buf, cut](std::vector &c, const std::vector &p1, + const std::vector &p2) + { + buf = p2; + for (unsigned int i = 0; i < cut; ++i) + { + c.push_back(p1[i]); + buf.erase(std::find(buf.begin(), buf.end(), p1[i])); + } + for (unsigned int i = 0; i < buf.size(); ++i) + { + c.push_back(buf[i]); + } + }; + + cross(c1, p1, p2); + cross(c2, p2, p1); + population_.emplace(func_(c1), c1); + population_.emplace(func_(c2), c2); +} + +template +void GeneticScheduler::mutation(std::vector &c) +{ + std::uniform_int_distribution dis(1, c.size() - 2); + unsigned int cut = dis(gen_); + Graph g = graph_; + std::vector buf; + + for (unsigned int i = cut; i < c.size(); ++i) + { + g.removeVertex(c[i]); + } + buf = g.topoSort(gen_); + for (unsigned int i = cut; i < c.size(); ++i) + { + buf.push_back(c[i]); + } + c = buf; +} + +END_HADRONS_NAMESPACE + +#endif // Hadrons_GeneticScheduler_hpp_ diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc index 6b855cda..ec5e8f51 100644 --- a/programs/Hadrons/Global.cc +++ b/programs/Hadrons/Global.cc @@ -34,4 +34,5 @@ using namespace Hadrons; HadronsLogger Hadrons::HadronsLogError(1,"Error"); HadronsLogger Hadrons::HadronsLogWarning(1,"Warning"); HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); +HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index f5a5c144..38bdcc0f 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -63,6 +63,7 @@ abort(); extern HadronsLogger HadronsLogError; extern HadronsLogger HadronsLogWarning; extern HadronsLogger HadronsLogMessage; +extern HadronsLogger HadronsLogIterative; extern HadronsLogger HadronsLogDebug; // singleton pattern diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 6022dd3a..5f71f31b 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -56,13 +56,14 @@ public: // destructor virtual ~Graph(void) = default; // access - void addVertex(const T &value); - void addEdge(const Edge &e); - void addEdge(const T &start, const T &end); - void removeVertex(const T &value); - void removeEdge(const Edge &e); - void removeEdge(const T &start, const T &end); - unsigned int size(void) const; + void addVertex(const T &value); + void addEdge(const Edge &e); + void addEdge(const T &start, const T &end); + std::vector getVertices(void) const; + void removeVertex(const T &value); + void removeEdge(const Edge &e); + void removeEdge(const T &start, const T &end); + unsigned int size(void) const; // tests bool gotValue(const T &value) const; // graph topological manipulations @@ -71,7 +72,9 @@ public: std::vector getParents(const T &value) const; std::vector getRoots(void) const; std::vector> getConnectedComponents(void) const; - std::vector topoSort(const bool randomize = false); + std::vector topoSort(void); + template + std::vector topoSort(Gen &gen); std::vector> allTopoSort(void); // I/O friend std::ostream & operator<<(std::ostream &out, const Graph &g) @@ -97,9 +100,11 @@ private: void unmarkAll(void); bool isMarked(const T &value) const; const T * getFirstMarked(const bool isMarked = true) const; - const T * getRandomMarked(const bool isMarked = true); + template + const T * getRandomMarked(const bool isMarked, Gen &gen); const T * getFirstUnmarked(void) const; - const T * getRandomUnmarked(void); + template + const T * getRandomUnmarked(Gen &gen); // prune marked/unmarked vertices void removeMarked(const bool isMarked = true); void removeUnmarked(void); @@ -109,7 +114,6 @@ private: private: std::map isMarked_; std::set edgeSet_; - std::mt19937 gen_; }; // build depedency matrix from topological sorts @@ -127,11 +131,7 @@ makeDependencyMatrix(const std::vector> &topSort); // constructor ///////////////////////////////////////////////////////////////// template Graph::Graph(void) -{ - std::random_device rd; - - gen_.seed(rd()); -} +{} // access ////////////////////////////////////////////////////////////////////// // complexity: log(V) @@ -157,6 +157,19 @@ void Graph::addEdge(const T &start, const T &end) addEdge(Edge(start, end)); } +template +std::vector Graph::getVertices(void) const +{ + std::vector vertex; + + for (auto &v: isMarked_) + { + vertex.push_back(v.first); + } + + return vertex; +} + // complexity: O(V*log(V)) template void Graph::removeVertex(const T &value) @@ -311,7 +324,8 @@ const T * Graph::getFirstMarked(const bool isMarked) const // complexity: O(log(V)) template -const T * Graph::getRandomMarked(const bool isMarked) +template +const T * Graph::getRandomMarked(const bool isMarked, Gen &gen) { auto pred = [&isMarked](const std::pair &v) { @@ -320,7 +334,7 @@ const T * Graph::getRandomMarked(const bool isMarked) std::uniform_int_distribution dis(0, size() - 1); auto rIt = isMarked_.begin(); - std::advance(rIt, dis(gen_)); + std::advance(rIt, dis(gen)); auto vIt = std::find_if(rIt, isMarked_.end(), pred); if (vIt != isMarked_.end()) { @@ -349,9 +363,10 @@ const T * Graph::getFirstUnmarked(void) const // complexity: O(log(V)) template -const T * Graph::getRandomUnmarked(void) +template +const T * Graph::getRandomUnmarked(Gen &gen) { - return getRandomMarked(false); + return getRandomMarked(false, gen); } // prune marked/unmarked vertices ////////////////////////////////////////////// @@ -515,7 +530,7 @@ std::vector> Graph::getConnectedComponents(void) const // topological sort using a directed DFS algorithm // complexity: O(V*log(V)) template -std::vector Graph::topoSort(const bool randomize) +std::vector Graph::topoSort(void) { std::stack buf; std::vector res; @@ -534,10 +549,6 @@ std::vector Graph::topoSort(const bool randomize) std::vector child = getChildren(v); tmpMarked[v] = true; - if (randomize) - { - std::shuffle(child.begin(), child.end(), gen_); - } for (auto &c: child) { visit(c); @@ -556,25 +567,71 @@ std::vector Graph::topoSort(const bool randomize) // loop on unmarked vertices unmarkAll(); - if (randomize) - { - vPt = getRandomUnmarked(); - } - else - { - vPt = getFirstUnmarked(); - } + vPt = getFirstUnmarked(); while (vPt) { visit(*vPt); - if (randomize) + vPt = getFirstUnmarked(); + } + unmarkAll(); + + // create result vector + while (!buf.empty()) + { + res.push_back(buf.top()); + buf.pop(); + } + + return res; +} + +// random version of the topological sort +// complexity: O(V*log(V)) +template +template +std::vector Graph::topoSort(Gen &gen) +{ + std::stack buf; + std::vector res; + const T *vPt; + std::map tmpMarked(isMarked_); + + // visit function + std::function visit = [&](const T &v) + { + if (tmpMarked.at(v)) { - vPt = getRandomUnmarked(); + HADRON_ERROR("cannot topologically sort a cyclic graph"); } - else + if (!isMarked(v)) { - vPt = getFirstUnmarked(); + std::vector child = getChildren(v); + + tmpMarked[v] = true; + std::shuffle(child.begin(), child.end(), gen); + for (auto &c: child) + { + visit(c); + } + mark(v); + tmpMarked[v] = false; + buf.push(v); } + }; + + // reset temporary marks + for (auto &v: tmpMarked) + { + tmpMarked.at(v.first) = false; + } + + // loop on unmarked vertices + unmarkAll(); + vPt = getRandomUnmarked(gen); + while (vPt) + { + visit(*vPt); + vPt = getRandomUnmarked(gen); } unmarkAll(); diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc index da5e02b1..97b8686c 100644 --- a/programs/Hadrons/Hadrons.cc +++ b/programs/Hadrons/Hadrons.cc @@ -49,6 +49,7 @@ int main(int argc, char *argv[]) HadronsLogError.Active(GridLogError.isActive()); HadronsLogWarning.Active(GridLogWarning.isActive()); HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); HadronsLogDebug.Active(GridLogDebug.isActive()); LOG(Message) << "Grid initialized" << std::endl; From 7dfdc9baa0581eacfcdc910467cfce5304deed2e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 10 May 2016 10:41:20 +0100 Subject: [PATCH 039/106] Hadrons: lattice dynamic cast fix --- programs/Hadrons/Environment.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 7f55308a..65f870ee 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -149,11 +149,11 @@ T * Environment::get(const std::string name) const { if (hasLattice(name)) { - try + if (auto pt = dynamic_cast(lattice_.at(name).get())) { - return dynamic_cast(lattice_.at(name).get()); + return pt; } - catch (std::bad_cast &) + else { HADRON_ERROR("object '" + name + "' does not have type " + typeid(T *).name() + "(object type: " From d604580e5a6ff7fd92010fd662834c7bfbfaad5c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 10 May 2016 19:07:41 +0100 Subject: [PATCH 040/106] Hadrons: all objects/modules mapped to an integer address system to remove string operations from scheduling --- programs/Hadrons/Application.cc | 166 +------- programs/Hadrons/Application.hpp | 14 +- programs/Hadrons/Environment.cc | 662 ++++++++++++++++++++++++++----- programs/Hadrons/Environment.hpp | 156 ++++++-- programs/Hadrons/Global.cc | 27 ++ programs/Hadrons/Global.hpp | 20 + 6 files changed, 734 insertions(+), 311 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 7bcc9959..6381a9e1 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -42,10 +42,9 @@ using namespace Hadrons; Application::Application(const std::string parameterFileName) : parameterFileName_(parameterFileName) , env_(Environment::getInstance()) -, modFactory_(ModuleFactory::getInstance()) { LOG(Message) << "Modules available:" << std::endl; - auto list = modFactory_.getBuilderList(); + auto list = ModuleFactory::getInstance().getBuilderList(); for (auto &m: list) { LOG(Message) << " " << m << std::endl; @@ -95,18 +94,12 @@ void Application::parseParameterFile(void) do { read(reader, "id", id); - module_[id.name] = modFactory_.create(id.type, id.name); - module_[id.name]->parseParameters(reader, "options"); - std::vector output = module_[id.name]->getOutput(); - for (auto &n: output) - { - associatedModule_[n] = id.name; - } - input_[id.name] = module_[id.name]->getInput(); + env_.createModule(id.name, id.type, reader); } while (reader.nextElement("module")); pop(reader); pop(reader); env_.setSeed(strToVec(par_.seed)); + env_.printContent(); } // schedule computation //////////////////////////////////////////////////////// @@ -116,7 +109,7 @@ sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" void Application::schedule(void) { // memory peak function - auto memPeak = [this](const std::vector &program) + auto memPeak = [this](const std::vector &program) { unsigned int memPeak; bool msg; @@ -124,7 +117,7 @@ void Application::schedule(void) msg = HadronsLogMessage.isActive(); HadronsLogMessage.Active(false); env_.dryRun(true); - memPeak = execute(program); + memPeak = env_.executeProgram(program); env_.dryRun(false); env_.freeAll(); HadronsLogMessage.Active(true); @@ -132,32 +125,14 @@ void Application::schedule(void) return memPeak; }; - // create dependency graph - Graph moduleGraph; - - LOG(Message) << "Scheduling computation..." << std::endl; - for (auto &m: module_) - { - std::vector input = m.second->getInput(); - for (auto &n: input) - { - try - { - moduleGraph.addEdge(associatedModule_.at(n), m.first); - } - catch (std::out_of_range &) - { - HADRON_ERROR("unknown object '" + n + "'"); - } - } - } - // constrained topological sort using a genetic algorithm + LOG(Message) << "Scheduling computation..." << std::endl; constexpr unsigned int maxGen = 200, maxCstGen = 50; unsigned int k = 0, gen, prevPeak, nCstPeak = 0; - std::vector> con = moduleGraph.getConnectedComponents(); - GeneticScheduler::Parameters par; - std::random_device rd; + auto graph = env_.makeModuleGraph(); + auto con = graph.getConnectedComponents(); + std::random_device rd; + GeneticScheduler::Parameters par; par.popSize = 20; par.mutationRate = .1; @@ -165,7 +140,7 @@ void Application::schedule(void) CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); for (unsigned int i = 0; i < con.size(); ++i) { - GeneticScheduler scheduler(con[i], memPeak, par); + GeneticScheduler scheduler(con[i], memPeak, par); gen = 0; do @@ -197,13 +172,13 @@ void Application::schedule(void) { program_.push_back(t[j]); LOG(Message) << std::setw(4) << std::right << k + 1 << ": " - << program_[k] << std::endl; + << env_.getModuleName(program_[k]) << std::endl; k++; } } } -// program execution /////////////////////////////////////////////////////////// +// loop on configurations ////////////////////////////////////////////////////// void Application::configLoop(void) { auto range = par_.configs.range; @@ -213,121 +188,8 @@ void Application::configLoop(void) LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t << " " << BIG_SEP << std::endl; env_.setTrajectory(t); - execute(program_); + env_.executeProgram(program_); env_.freeAll(); } LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; } - -unsigned int Application::execute(const std::vector &program) -{ - unsigned int memPeak = 0, sizeBefore, sizeAfter; - std::vector> freeProg; - bool continueCollect, nothingFreed; - - // build garbage collection schedule - freeProg.resize(program.size()); - for (auto &n: associatedModule_) - { - auto pred = [&n, this](const std::string &s) - { - auto &in = input_[s]; - auto it = std::find(in.begin(), in.end(), n.first); - - return (it != in.end()) or (s == n.second); - }; - auto it = std::find_if(program.rbegin(), program.rend(), pred); - if (it != program.rend()) - { - freeProg[program.rend() - it - 1].insert(n.first); - } - } - - // program execution - for (unsigned int i = 0; i < program.size(); ++i) - { - // execute module - LOG(Message) << SEP << " Measurement step " << i+1 << "/" - << program.size() << " (module '" << program[i] << "') " - << SEP << std::endl; - (*module_[program[i]])(); - sizeBefore = env_.getTotalSize(); - // print used memory after execution - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) - << std::endl; - if (sizeBefore > memPeak) - { - memPeak = sizeBefore; - } - // garbage collection for step i - LOG(Message) << "Garbage collection..." << std::endl; - nothingFreed = true; - do - { - continueCollect = false; - auto toFree = freeProg[i]; - for (auto &n: toFree) - { - // continue garbage collection while there are still - // objects without owners - continueCollect = continueCollect or !env_.hasOwners(n); - if(env_.freeObject(n)) - { - // if an object has been freed, remove it from - // the garbage collection schedule - freeProg[i].erase(n); - nothingFreed = false; - } - } - } while (continueCollect); - // any remaining objects in step i garbage collection schedule - // is scheduled for step i + 1 - if (i + 1 < program.size()) - { - for (auto &n: freeProg[i]) - { - freeProg[i + 1].insert(n); - } - } - // print used memory after garbage collection if necessary - sizeAfter = env_.getTotalSize(); - if (sizeBefore != sizeAfter) - { - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) - << std::endl; - } - else - { - LOG(Message) << "Nothing to free" << std::endl; - } - } - - return memPeak; -} - -// pretty size formatting ////////////////////////////////////////////////////// -std::string Application::sizeString(long unsigned int bytes) - -{ - constexpr unsigned int bufSize = 256; - const char *suffixes[7] = {"", "K", "M", "G", "T", "P", "E"}; - char buf[256]; - long unsigned int s = 0; - double count = bytes; - - while (count >= 1024 && s < 7) - { - s++; - count /= 1024; - } - if (count - floor(count) == 0.0) - { - snprintf(buf, bufSize, "%d %sB", (int)count, suffixes[s]); - } - else - { - snprintf(buf, bufSize, "%.1f %sB", count, suffixes[s]); - } - - return std::string(buf); -} diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 6b7e54c5..67b8d7a0 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -82,22 +82,14 @@ private: void parseParameterFile(void); // schedule computation void schedule(void); - // program execution - void configLoop(void); - unsigned int execute(const std::vector &program); - // pretty size formatting - static std::string sizeString(long unsigned int bytes); + // loop on configurations + void configLoop(void); private: long unsigned int locVol_; std::string parameterFileName_; GlobalPar par_; Environment &env_; - ModuleFactory &modFactory_; - std::map> module_; - std::map associatedModule_; - std::map> input_; - std::vector program_; - std::vector> freeProg_; + std::vector program_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index bdb8d0d2..4c7ce023 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -26,6 +26,8 @@ directory. *******************************************************************************/ #include +#include +#include using namespace Grid; using namespace QCD; @@ -41,6 +43,12 @@ Environment::Environment(void) GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), GridDefaultMpi())); gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get())); + auto loc = getGrid()->LocalDimensions(); + locVol_ = 1; + for (unsigned int d = 0; d < loc.size(); ++d) + { + locVol_ *= loc[d]; + } rng4d_.reset(new GridParallelRNG(grid4d_.get())); } @@ -116,12 +124,312 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const } } -// fermion actions ///////////////////////////////////////////////////////////// -void Environment::addFermionMatrix(const std::string name, FMat *fMat) +// random number generator ///////////////////////////////////////////////////// +void Environment::setSeed(const std::vector &seed) +{ + rng4d_->SeedFixedIntegers(seed); +} + +GridParallelRNG * Environment::get4dRng(void) const +{ + return rng4d_.get(); +} + +// module management /////////////////////////////////////////////////////////// +void Environment::createModule(const std::string name, const std::string type, + XmlReader &reader) +{ + auto addObject = [this](const std::string name, const int moduleAddress) + { + ObjInfo info; + + object_.push_back(info); + objectName_.push_back(name); + objectAddress_[name] = object_.size() - 1; + objectModule_.push_back(moduleAddress); + owners_.push_back(std::set()); + properties_.push_back(std::set()); + }; + + if (!hasModule(name)) + { + auto &factory = ModuleFactory::getInstance(); + std::vector inputAddress; + + module_.push_back(factory.create(type, name)); + moduleType_.push_back(type); + moduleName_.push_back(name); + moduleAddress_[name] = module_.size() - 1; + module_.back()->parseParameters(reader, "options"); + auto input = module_.back()->getInput(); + for (auto &in: input) + { + if (!hasObject(in)) + { + addObject(in , -1); + } + inputAddress.push_back(objectAddress_[in]); + } + moduleInput_.push_back(inputAddress); + auto output = module_.back()->getOutput(); + for (auto &out: output) + { + if (!hasObject(out)) + { + addObject(out , module_.size() - 1); + } + else + { + if (objectModule_[objectAddress_[out]] < 0) + { + objectModule_[objectAddress_[out]] = module_.size() - 1; + } + else + { + HADRON_ERROR("object '" + out + + "' is already produced by module '" + + moduleName_[objectModule_[getObjectAddress(out)]] + + "' (while creating module '" + name + "')"); + } + } + } + } + else + { + HADRON_ERROR("module '" + name + "' already exists"); + } +} + +Module * Environment::getModule(const unsigned int address) const +{ + if (hasModule(address)) + { + return module_[address].get(); + } + else + { + HADRON_ERROR("no module with address " + std::to_string(address)); + } +} + +Module * Environment::getModule(const std::string name) const +{ + return getModule(getModuleAddress(name)); +} + +unsigned int Environment::getModuleAddress(const std::string name) const +{ + if (hasModule(name)) + { + return moduleAddress_.at(name); + } + else + { + HADRON_ERROR("no module with name '" + name + "'"); + } +} + +std::string Environment::getModuleName(const unsigned int address) const +{ + if (hasModule(address)) + { + return moduleName_[address]; + } + else + { + HADRON_ERROR("no module with address " + std::to_string(address)); + } +} + +std::string Environment::getModuleType(const unsigned int address) const +{ + if (hasModule(address)) + { + return moduleType_[address]; + } + else + { + HADRON_ERROR("no module with address " + std::to_string(address)); + } +} + +std::string Environment::getModuleType(const std::string name) const +{ + return getModuleType(getModuleAddress(name)); +} + +bool Environment::hasModule(const unsigned int address) const +{ + return (address < module_.size()); +} + +bool Environment::hasModule(const std::string name) const +{ + return (moduleAddress_.find(name) != moduleAddress_.end()); +} + +Graph Environment::makeModuleGraph(void) const +{ + Graph moduleGraph; + + for (unsigned int i = 0; i < module_.size(); ++i) + { + for (auto &j: moduleInput_[i]) + { + moduleGraph.addEdge(objectModule_[j], i); + } + } + + return moduleGraph; +} + +#define BIG_SEP "===============" +#define SEP "---------------" +#define MEM_MSG(size)\ +sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" + +unsigned int Environment::executeProgram(const std::vector &p) +{ + unsigned int memPeak = 0, sizeBefore, sizeAfter; + std::vector> freeProg; + bool continueCollect, nothingFreed; + + // build garbage collection schedule + freeProg.resize(p.size()); + for (unsigned int i = 0; i < object_.size(); ++i) + { + auto pred = [i, this](const unsigned int j) + { + auto &in = moduleInput_[j]; + auto it = std::find(in.begin(), in.end(), i); + + return (it != in.end()) or (j == objectModule_[i]); + }; + auto it = std::find_if(p.rbegin(), p.rend(), pred); + if (it != p.rend()) + { + freeProg[p.rend() - it - 1].insert(i); + } + } + + // program execution + for (unsigned int i = 0; i < p.size(); ++i) + { + // execute module + LOG(Message) << SEP << " Measurement step " << i+1 << "/" + << p.size() << " (module '" << moduleName_[p[i]] << "') " + << SEP << std::endl; + (*module_[p[i]])(); + sizeBefore = getTotalSize(); + // print used memory after execution + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) + << std::endl; + if (sizeBefore > memPeak) + { + memPeak = sizeBefore; + } + // garbage collection for step i + LOG(Message) << "Garbage collection..." << std::endl; + nothingFreed = true; + do + { + continueCollect = false; + auto toFree = freeProg[i]; + for (auto &j: toFree) + { + // continue garbage collection while there are still + // objects without owners + continueCollect = continueCollect or !hasOwners(j); + if(freeObject(j)) + { + // if an object has been freed, remove it from + // the garbage collection schedule + freeProg[i].erase(j); + nothingFreed = false; + } + } + } while (continueCollect); + // any remaining objects in step i garbage collection schedule + // is scheduled for step i + 1 + if (i + 1 < p.size()) + { + for (auto &j: freeProg[i]) + { + freeProg[i + 1].insert(j); + } + } + // print used memory after garbage collection if necessary + sizeAfter = getTotalSize(); + if (sizeBefore != sizeAfter) + { + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) + << std::endl; + } + else + { + LOG(Message) << "Nothing to free" << std::endl; + } + } + + return memPeak; +} + +unsigned int Environment::executeProgram(const std::vector &p) +{ + std::vector pAddress; + + for (auto &n: p) + { + pAddress.push_back(getModuleAddress(n)); + } + + return executeProgram(pAddress); +} + +// lattice store /////////////////////////////////////////////////////////////// +void Environment::freeLattice(const unsigned int address) +{ + if (hasLattice(address)) + { + if (!isDryRun()) + { + LOG(Message) << "Freeing lattice '" << moduleName_[address] + << "'" << std::endl; + } + lattice_.erase(address); + object_[address] = ObjInfo(); + } + else + { + HADRON_ERROR("trying to free unknown lattice (address " + + std::to_string(address) + ")"); + } +} + +bool Environment::hasLattice(const unsigned int address) const +{ + return (hasRegisteredObject(address) + and (lattice_.find(address) != lattice_.end())); +} + +bool Environment::hasLattice(const std::string name) const { if (hasObject(name)) { - fMat_[name].reset(fMat); + return hasLattice(getObjectAddress(name)); + } + else + { + return false; + } +} + +// fermion actions ///////////////////////////////////////////////////////////// +void Environment::addFermionMatrix(const std::string name, FMat *fMat) +{ + if (hasRegisteredObject(name)) + { + fMat_[getObjectAddress(name)].reset(fMat); } else { @@ -131,15 +439,21 @@ void Environment::addFermionMatrix(const std::string name, FMat *fMat) Environment::FMat * Environment::getFermionMatrix(const std::string name) const { + unsigned int i; + if (hasFermionMatrix(name)) { - return fMat_.at(name).get(); + i = getObjectAddress(name); + + return fMat_.at(i).get(); } else { if (hasSolver(name)) { - return fMat_.at(solverAction_.at(name)).get(); + i = getObjectAddress(solverAction_.at(name)); + + return fMat_.at(i).get(); } else { @@ -148,41 +462,80 @@ Environment::FMat * Environment::getFermionMatrix(const std::string name) const } } -void Environment::freeFermionMatrix(const std::string name) +bool Environment::hasFermionMatrix(const unsigned int address) const { - if (hasFermionMatrix(name)) - { - LOG(Message) << "Freeing fermion matrix '" << name << "'" << std::endl; - fMat_.erase(name); - object_.erase(name); - } - else - { - HADRON_ERROR("trying to free unknown fermion matrix '" + name + "'"); - } + return (hasRegisteredObject(address) + and (fMat_.find(address) != fMat_.end())); } bool Environment::hasFermionMatrix(const std::string name) const { - return (hasObject(name) and (fMat_.find(name) != fMat_.end())); + if (hasObject(name)) + { + return hasFermionMatrix(getObjectAddress(name)); + } + else + { + return false; + } +} + +void Environment::freeFermionMatrix(const unsigned int address) +{ + if (hasFermionMatrix(address)) + { + if (!isDryRun()) + { + LOG(Message) << "Freeing fermion matrix '" << objectName_[address] + << "'" << std::endl; + } + fMat_.erase(address); + object_[address] = ObjInfo(); + } + else + { + HADRON_ERROR("trying to free unknown fermion matrix (address " + + std::to_string(address) + ")"); + } +} + +void Environment::freeFermionMatrix(const std::string name) +{ + freeFermionMatrix(getObjectAddress(name)); } // solvers ///////////////////////////////////////////////////////////////////// void Environment::addSolver(const std::string name, Solver s) { - if (hasObject(name)) + auto address = getObjectAddress(name); + + if (hasRegisteredObject(address)) { - solver_[name] = s; + solver_[address] = s; } else { - HADRON_ERROR("no object named '" << name << "'"); + HADRON_ERROR("object with name '" + name + + "' exsists but is not registered"); } } +bool Environment::hasSolver(const unsigned int address) const +{ + return (hasRegisteredObject(address) + and (solver_.find(address) != solver_.end())); +} + bool Environment::hasSolver(const std::string name) const { - return (hasObject(name) and (solver_.find(name) != solver_.end())); + if (hasObject(name)) + { + return hasSolver(getObjectAddress(name)); + } + else + { + return false; + } } void Environment::setSolverAction(const std::string name, @@ -222,7 +575,7 @@ void Environment::callSolver(const std::string name, LatticeFermion &sol, { if (hasSolver(name)) { - solver_.at(name)(sol, source); + solver_.at(getObjectAddress(name))(sol, source); } else { @@ -230,114 +583,124 @@ void Environment::callSolver(const std::string name, LatticeFermion &sol, } } -// random number generator ///////////////////////////////////////////////////// -void Environment::setSeed(const std::vector &seed) +// general memory management /////////////////////////////////////////////////// +void Environment::registerObject(const unsigned int address, + const unsigned int size, const unsigned int Ls) { - rng4d_->SeedFixedIntegers(seed); -} - -GridParallelRNG * Environment::get4dRng(void) const -{ - return rng4d_.get(); -} - -// lattice store /////////////////////////////////////////////////////////////// -void Environment::freeLattice(const std::string name) -{ - if (hasLattice(name)) + if (!hasRegisteredObject(address)) { - LOG(Message) << "Freeing lattice '" << name << "'" << std::endl; - lattice_.erase(name); - object_.erase(name); + if (hasObject(address)) + { + ObjInfo info; + + info.size = size; + info.Ls = Ls; + info.isRegistered = true; + object_[address] = info; + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); + } } else { - HADRON_ERROR("trying to free unknown lattice '" + name + "'"); + HADRON_ERROR("object with address " + std::to_string(address) + + " already registered"); } } -bool Environment::hasLattice(const std::string name) const -{ - return (hasObject(name) and (lattice_.find(name) != lattice_.end())); -} - -// general memory management /////////////////////////////////////////////////// -bool Environment::hasObject(const std::string name) const -{ - return (object_.find(name) != object_.end()); -} - void Environment::registerObject(const std::string name, const unsigned int size, const unsigned int Ls) { - if (!hasObject(name)) + registerObject(getObjectAddress(name), size, Ls); +} + +unsigned int Environment::getObjectAddress(const std::string name) const +{ + if (hasObject(name)) { - ObjInfo info{size, Ls}; - - object_[name] = info; + return objectAddress_.at(name); } else { - HADRON_ERROR("object '" + name + "' already exists"); + HADRON_ERROR("no object with name '" + name + "'"); + } +} + +std::string Environment::getObjectName(const unsigned int address) const +{ + if (hasObject(address)) + { + return objectName_[address]; + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); + } +} + +unsigned int Environment::getObjectSize(const unsigned int address) const +{ + if (hasRegisteredObject(address)) + { + return object_[address].size; + } + else if (hasObject(address)) + { + HADRON_ERROR("object with address " + std::to_string(address) + + " exsists but is not registered"); + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); } } unsigned int Environment::getObjectSize(const std::string name) const { - if (hasObject(name)) + return getObjectSize(getObjectAddress(name)); +} + +unsigned int Environment::getObjectLs(const unsigned int address) const +{ + if (hasRegisteredObject(address)) { - return object_.at(name).size; + return object_[address].Ls; + } + else if (hasObject(address)) + { + HADRON_ERROR("object with address " + std::to_string(address) + + " exsists but is not registered"); } else { - HADRON_ERROR("no object named '" + name + "'"); + HADRON_ERROR("no object with address " + std::to_string(address)); } } -long unsigned int Environment::getTotalSize(void) const -{ - long unsigned int size = 0; - - for (auto &s: object_) - { - size += s.second.size; - } - - return size; -} - unsigned int Environment::getObjectLs(const std::string name) const { - if (hasObject(name)) - { - return object_.at(name).Ls; - } - else - { - HADRON_ERROR("no object named '" + name + "'"); - } + return getObjectLs(getObjectAddress(name)); } -bool Environment::isObject5d(const std::string name) const +bool Environment::hasObject(const unsigned int address) const { - return (getObjectLs(name) > 1); + return (address < object_.size()); } -void Environment::addOwnership(const std::string owner, - const std::string property) -{ - owners_[property].insert(owner); - properties_[owner].insert(property); -} - -bool Environment::hasOwners(const std::string name) const +bool Environment::hasObject(const std::string name) const { + auto it = objectAddress_.find(name); - auto it = owners_.find(name); - - if (it != owners_.end()) + return ((it != objectAddress_.end()) and hasObject(it->second)); +} + +bool Environment::hasRegisteredObject(const unsigned int address) const +{ + if (hasObject(address)) { - return (!it->second.empty()); + return object_[address].isRegistered; } else { @@ -345,26 +708,94 @@ bool Environment::hasOwners(const std::string name) const } } -bool Environment::freeObject(const std::string name) +bool Environment::hasRegisteredObject(const std::string name) const { - if (!hasOwners(name)) + if (hasObject(name)) { - for (auto &p: properties_[name]) + return hasRegisteredObject(getObjectAddress(name)); + } + else + { + return false; + } +} + +bool Environment::isObject5d(const unsigned int address) const +{ + return (getObjectLs(address) > 1); +} + +bool Environment::isObject5d(const std::string name) const +{ + return (getObjectLs(name) > 1); +} + +long unsigned int Environment::getTotalSize(void) const +{ + long unsigned int size = 0; + + for (auto &o: object_) + { + if (o.isRegistered) { - owners_[p].erase(name); + size += o.size; } - properties_[name].clear(); - if (hasLattice(name)) + } + + return size; +} + +void Environment::addOwnership(const unsigned int owner, + const unsigned int property) +{ + owners_[property].insert(owner); + properties_[owner].insert(property); +} + +void Environment::addOwnership(const std::string owner, + const std::string property) +{ + addOwnership(getObjectAddress(owner), getObjectAddress(property)); +} + +bool Environment::hasOwners(const unsigned int address) const +{ + + if (hasObject(address)) + { + return (!owners_[address].empty()); + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); + } +} + +bool Environment::hasOwners(const std::string name) const +{ + return hasOwners(getObjectAddress(name)); +} + +bool Environment::freeObject(const unsigned int address) +{ + if (!hasOwners(address)) + { + for (auto &p: properties_[address]) { - freeLattice(name); + owners_[p].erase(address); } - else if (hasFermionMatrix(name)) + properties_[address].clear(); + if (hasLattice(address)) { - freeFermionMatrix(name); + freeLattice(address); } - else if (hasObject(name)) + else if (hasFermionMatrix(address)) { - object_.erase(name); + freeFermionMatrix(address); + } + else if (hasObject(address)) + { + object_[address] = ObjInfo(); } return true; @@ -375,9 +806,13 @@ bool Environment::freeObject(const std::string name) } } +bool Environment::freeObject(const std::string name) +{ + return freeObject(getObjectAddress(name)); +} + void Environment::freeAll(void) { - object_.clear(); lattice_.clear(); fMat_.clear(); solver_.clear(); @@ -385,3 +820,20 @@ void Environment::freeAll(void) owners_.clear(); properties_.clear(); } + +void Environment::printContent(void) +{ + LOG(Message) << "Modules: " << std::endl; + for (unsigned int i = 0; i < module_.size(); ++i) + { + LOG(Message) << std::setw(4) << std::right << i << ": " + << moduleName_[i] << " (" + << moduleType_[i] << ")" << std::endl; + } + LOG(Message) << "Objects: " << std::endl; + for (unsigned int i = 0; i < object_.size(); ++i) + { + LOG(Message) << std::setw(4) << std::right << i << ": " + << objectName_[i] << std::endl; + } +} diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 65f870ee..4cecf7da 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -29,28 +29,34 @@ directory. #define Hadrons_Environment_hpp_ #include +#include BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Global environment * ******************************************************************************/ +// forward declaration of Module +class Module; + class Environment { SINGLETON(Environment); public: - typedef FermionOperator FMat; - typedef std::function Solver; + typedef std::unique_ptr ModPt; typedef std::unique_ptr GridPt; typedef std::unique_ptr GridRbPt; - typedef std::unique_ptr RngPt; + typedef FermionOperator FMat; typedef std::unique_ptr FMatPt; + typedef std::function Solver; + typedef std::unique_ptr RngPt; typedef std::unique_ptr LatticePt; private: struct ObjInfo { - unsigned int size, Ls; + unsigned int size{0}, Ls{0}; + bool isRegistered{false}; }; public: // dry run @@ -63,13 +69,45 @@ public: void createGrid(const unsigned int Ls); GridCartesian * getGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; + // random number generator + void setSeed(const std::vector &seed); + GridParallelRNG * get4dRng(void) const; + // module management + void createModule(const std::string name, + const std::string type, + XmlReader &reader); + Module * getModule(const unsigned int address) const; + Module * getModule(const std::string name) const; + unsigned int getModuleAddress(const std::string name) const; + std::string getModuleName(const unsigned int address) const; + std::string getModuleType(const unsigned int address) const; + std::string getModuleType(const std::string name) const; + bool hasModule(const unsigned int address) const; + bool hasModule(const std::string name) const; + Graph makeModuleGraph(void) const; + unsigned int executeProgram(const std::vector &p); + unsigned int executeProgram(const std::vector &p); + // lattice store + template + T * create(const std::string name); + template + T * get(const std::string name) const; + bool hasLattice(const unsigned int address) const; + bool hasLattice(const std::string name) const; + void freeLattice(const unsigned int address); + void freeLattice(const std::string name); + template + unsigned int lattice4dSize(void) const; // fermion actions void addFermionMatrix(const std::string name, FMat *mat); FMat * getFermionMatrix(const std::string name) const; - void freeFermionMatrix(const std::string name); + bool hasFermionMatrix(const unsigned int address) const; bool hasFermionMatrix(const std::string name) const; + void freeFermionMatrix(const unsigned int address); + void freeFermionMatrix(const std::string name); // solvers void addSolver(const std::string name, Solver s); + bool hasSolver(const unsigned int address) const; bool hasSolver(const std::string name) const; void setSolverAction(const std::string name, const std::string actionName); @@ -77,52 +115,73 @@ public: void callSolver(const std::string name, LatticeFermion &sol, const LatticeFermion &src) const; - // random number generator - void setSeed(const std::vector &seed); - GridParallelRNG * get4dRng(void) const; - // lattice store - template - T * create(const std::string name); - template - T * get(const std::string name) const; - bool hasLattice(const std::string name) const; - void freeLattice(const std::string name); - template - unsigned int lattice4dSize(void) const; // general memory management - bool hasObject(const std::string name) const; + void registerObject(const unsigned int address, + const unsigned int size, + const unsigned int Ls = 1); void registerObject(const std::string name, const unsigned int size, const unsigned int Ls = 1); template + void registerLattice(const unsigned int address, + const unsigned int Ls = 1); + template void registerLattice(const std::string name, const unsigned int Ls = 1); + unsigned int getObjectAddress(const std::string name) const; + std::string getObjectName(const unsigned int address) const; + unsigned int getObjectSize(const unsigned int address) const; unsigned int getObjectSize(const std::string name) const; - long unsigned int getTotalSize(void) const; + unsigned int getObjectLs(const unsigned int address) const; unsigned int getObjectLs(const std::string name) const; + bool hasObject(const unsigned int address) const; + bool hasObject(const std::string name) const; + bool hasRegisteredObject(const unsigned int address) const; + bool hasRegisteredObject(const std::string name) const; + bool isObject5d(const unsigned int address) const; bool isObject5d(const std::string name) const; + long unsigned int getTotalSize(void) const; + void addOwnership(const unsigned int owner, + const unsigned int property); void addOwnership(const std::string owner, const std::string property); + bool hasOwners(const unsigned int address) const; bool hasOwners(const std::string name) const; + bool freeObject(const unsigned int address); bool freeObject(const std::string name); void freeAll(void); + void printContent(void); private: - -private: - bool dryRun_{false}; - unsigned int traj_; - GridPt grid4d_; - std::map grid5d_; - GridRbPt gridRb4d_; - std::map gridRb5d_; - RngPt rng4d_; - std::map object_; - std::map lattice_; - std::map fMat_; - std::map solver_; - std::map solverAction_; - std::map> owners_; - std::map> properties_; + // general + bool dryRun_{false}; + unsigned int traj_, locVol_; + // grids + GridPt grid4d_; + std::map grid5d_; + GridRbPt gridRb4d_; + std::map gridRb5d_; + // random number generator + RngPt rng4d_; + // module and related maps + std::vector module_; + std::vector moduleType_; + std::vector moduleName_; + std::map moduleAddress_; + std::vector> moduleInput_; + // lattice store + std::map lattice_; + // fermion matrix store + std::map fMat_; + // solver store & solver/action map + std::map solver_; + std::map solverAction_; + // object register + std::vector object_; + std::vector objectName_; + std::map objectAddress_; + std::vector objectModule_; + std::vector> owners_; + std::vector> properties_; }; /****************************************************************************** @@ -137,11 +196,12 @@ unsigned int Environment::lattice4dSize(void) const template T * Environment::create(const std::string name) { - GridCartesian *g = getGrid(getObjectLs(name)); + auto i = getObjectAddress(name); + GridCartesian *g = getGrid(getObjectLs(i)); - lattice_[name].reset(new T(g)); + lattice_[i].reset(new T(g)); - return dynamic_cast(lattice_[name].get()); + return dynamic_cast(lattice_[i].get()); } template @@ -149,25 +209,35 @@ T * Environment::get(const std::string name) const { if (hasLattice(name)) { - if (auto pt = dynamic_cast(lattice_.at(name).get())) + auto i = getObjectAddress(name); + + if (auto pt = dynamic_cast(lattice_.at(i).get())) { return pt; } else { HADRON_ERROR("object '" + name + "' does not have type " - + typeid(T *).name() + "(object type: " - + typeid(lattice_.at(name).get()).name() + ")"); + + typeName() + "(object type: " + + typeName(*lattice_.at(i).get()) + ")"); } } else { - HADRON_ERROR("no lattice name '" + name + "'"); + HADRON_ERROR("no lattice with name '" + name + "'"); return nullptr; } } +template +void Environment::registerLattice(const unsigned int address, + const unsigned int Ls) +{ + createGrid(Ls); + registerObject(address, Ls*lattice4dSize()); +} + template void Environment::registerLattice(const std::string name, const unsigned int Ls) { diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc index ec5e8f51..a13efec1 100644 --- a/programs/Hadrons/Global.cc +++ b/programs/Hadrons/Global.cc @@ -36,3 +36,30 @@ HadronsLogger Hadrons::HadronsLogWarning(1,"Warning"); HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); + +// pretty size formatting ////////////////////////////////////////////////////// +std::string Hadrons::sizeString(long unsigned int bytes) + +{ + constexpr unsigned int bufSize = 256; + const char *suffixes[7] = {"", "K", "M", "G", "T", "P", "E"}; + char buf[256]; + long unsigned int s = 0; + double count = bytes; + + while (count >= 1024 && s < 7) + { + s++; + count /= 1024; + } + if (count - floor(count) == 0.0) + { + snprintf(buf, bufSize, "%d %sB", (int)count, suffixes[s]); + } + else + { + snprintf(buf, bufSize, "%.1f %sB", count, suffixes[s]); + } + + return std::string(buf); +} diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 38bdcc0f..c42753c1 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -30,6 +30,7 @@ directory. #include #include +#include #include #define BEGIN_HADRONS_NAMESPACE \ @@ -91,6 +92,25 @@ public:\ private:\ name(void) = default; +// pretty size formating +std::string sizeString(long unsigned int bytes); + +template +std::string typeName(const T &x) +{ + std::string name(typeid(x).name()); + + return name; +} + +template +std::string typeName(void) +{ + std::string name(typeid(T).name()); + + return name; +} + END_HADRONS_NAMESPACE #endif // Hadrons_Global_hpp_ From 29dfe99e7ccbf128eaea50e37959aba17fdb8b3b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 10 May 2016 19:19:38 +0100 Subject: [PATCH 041/106] Hadrons: more scheduler optimizations --- programs/Hadrons/Environment.cc | 38 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 4c7ce023..45b16aa0 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -316,20 +316,29 @@ unsigned int Environment::executeProgram(const std::vector &p) for (unsigned int i = 0; i < p.size(); ++i) { // execute module - LOG(Message) << SEP << " Measurement step " << i+1 << "/" - << p.size() << " (module '" << moduleName_[p[i]] << "') " - << SEP << std::endl; + if (!isDryRun()) + { + LOG(Message) << SEP << " Measurement step " << i+1 << "/" + << p.size() << " (module '" << moduleName_[p[i]] + << "') " << SEP << std::endl; + } (*module_[p[i]])(); sizeBefore = getTotalSize(); // print used memory after execution - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) - << std::endl; + if (!isDryRun()) + { + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) + << std::endl; + } if (sizeBefore > memPeak) { memPeak = sizeBefore; } // garbage collection for step i - LOG(Message) << "Garbage collection..." << std::endl; + if (!isDryRun()) + { + LOG(Message) << "Garbage collection..." << std::endl; + } nothingFreed = true; do { @@ -360,14 +369,17 @@ unsigned int Environment::executeProgram(const std::vector &p) } // print used memory after garbage collection if necessary sizeAfter = getTotalSize(); - if (sizeBefore != sizeAfter) + if (!isDryRun()) { - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) - << std::endl; - } - else - { - LOG(Message) << "Nothing to free" << std::endl; + if (sizeBefore != sizeAfter) + { + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) + << std::endl; + } + else + { + LOG(Message) << "Nothing to free" << std::endl; + } } } From 84fa2bdce6a8d4b27bb02371eebd51be759dc363 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 10 May 2016 20:12:48 +0100 Subject: [PATCH 042/106] Hadrons: modules moved in their own directory & utility script to add new modules --- programs/Hadrons/Makefile.am | 31 ++----------- programs/Hadrons/Module.cc.template | 45 +++++++++++++++++++ programs/Hadrons/Module.hpp.template | 43 ++++++++++++++++++ programs/Hadrons/add_module.sh | 15 +++++++ programs/Hadrons/make_module_list.sh | 4 ++ programs/Hadrons/modules.inc | 10 +++++ programs/Hadrons/{ => modules}/AWilson.cc | 2 +- programs/Hadrons/{ => modules}/AWilson.hpp | 0 programs/Hadrons/{ => modules}/CMeson.cc | 2 +- programs/Hadrons/{ => modules}/CMeson.hpp | 0 programs/Hadrons/{ => modules}/GLoad.cc | 2 +- programs/Hadrons/{ => modules}/GLoad.hpp | 0 programs/Hadrons/{ => modules}/GRandom.cc | 4 +- programs/Hadrons/{ => modules}/GRandom.hpp | 0 programs/Hadrons/{ => modules}/GUnit.cc | 2 +- programs/Hadrons/{ => modules}/GUnit.hpp | 0 programs/Hadrons/{ => modules}/MQuark.cc | 2 +- programs/Hadrons/{ => modules}/MQuark.hpp | 0 programs/Hadrons/{ => modules}/SolRBPrecCG.cc | 2 +- .../Hadrons/{ => modules}/SolRBPrecCG.hpp | 0 programs/Hadrons/{ => modules}/SrcPoint.cc | 2 +- programs/Hadrons/{ => modules}/SrcPoint.hpp | 0 programs/Hadrons/{ => modules}/SrcZ2.cc | 2 +- programs/Hadrons/{ => modules}/SrcZ2.hpp | 0 24 files changed, 131 insertions(+), 37 deletions(-) create mode 100644 programs/Hadrons/Module.cc.template create mode 100644 programs/Hadrons/Module.hpp.template create mode 100755 programs/Hadrons/add_module.sh create mode 100755 programs/Hadrons/make_module_list.sh create mode 100644 programs/Hadrons/modules.inc rename programs/Hadrons/{ => modules}/AWilson.cc (98%) rename programs/Hadrons/{ => modules}/AWilson.hpp (100%) rename programs/Hadrons/{ => modules}/CMeson.cc (98%) rename programs/Hadrons/{ => modules}/CMeson.hpp (100%) rename programs/Hadrons/{ => modules}/GLoad.cc (98%) rename programs/Hadrons/{ => modules}/GLoad.hpp (100%) rename programs/Hadrons/{ => modules}/GRandom.cc (94%) rename programs/Hadrons/{ => modules}/GRandom.hpp (100%) rename programs/Hadrons/{ => modules}/GUnit.cc (98%) rename programs/Hadrons/{ => modules}/GUnit.hpp (100%) rename programs/Hadrons/{ => modules}/MQuark.cc (99%) rename programs/Hadrons/{ => modules}/MQuark.hpp (100%) rename programs/Hadrons/{ => modules}/SolRBPrecCG.cc (98%) rename programs/Hadrons/{ => modules}/SolRBPrecCG.hpp (100%) rename programs/Hadrons/{ => modules}/SrcPoint.cc (98%) rename programs/Hadrons/{ => modules}/SrcPoint.hpp (100%) rename programs/Hadrons/{ => modules}/SrcZ2.cc (98%) rename programs/Hadrons/{ => modules}/SrcZ2.hpp (100%) diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 2d1b5980..19bc9515 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -1,4 +1,4 @@ -AM_CXXFLAGS = -I$(top_srcdir)/programs -I$(top_srcdir)/lib +AM_CXXFLAGS = -I$(top_srcdir)/programs -I../$(top_srcdir)/programs -I$(top_srcdir)/lib AM_LDFLAGS = -L$(top_builddir)/lib bin_PROGRAMS = Hadrons @@ -11,31 +11,8 @@ Hadrons_SOURCES = \ Hadrons.cc \ Module.cc -# general modules -Hadrons_SOURCES += \ - MQuark.cc - -# fermion actions -Hadrons_SOURCES += \ - AWilson.cc - -# contraction modules -Hadrons_SOURCES += \ - CMeson.cc - -# gauge modules -Hadrons_SOURCES += \ - GLoad.cc \ - GRandom.cc \ - GUnit.cc - -# solver modules -Hadrons_SOURCES += \ - SolRBPrecCG.cc - -# source modules -Hadrons_SOURCES += \ - SrcPoint.cc \ - SrcZ2.cc +# modules +include modules.inc +Hadrons_SOURCES += $(modules) Hadrons_LDADD = -lGrid diff --git a/programs/Hadrons/Module.cc.template b/programs/Hadrons/Module.cc.template new file mode 100644 index 00000000..f2533d80 --- /dev/null +++ b/programs/Hadrons/Module.cc.template @@ -0,0 +1,45 @@ +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* ___FILEBASENAME___ implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +___FILEBASENAME___::___FILEBASENAME___(const std::string name) +: Module(name) +{} + +// parse parameters //////////////////////////////////////////////////////////// +void ___FILEBASENAME___::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_); +} + +// dependencies/products /////////////////////////////////////////////////////// +std::vector ___FILEBASENAME___::getInput(void) +{ + std::vector in; + + return in; +} + +std::vector ___FILEBASENAME___::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +void ___FILEBASENAME___::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +void ___FILEBASENAME___::execute(void) +{ + +} diff --git a/programs/Hadrons/Module.hpp.template b/programs/Hadrons/Module.hpp.template new file mode 100644 index 00000000..002d93b9 --- /dev/null +++ b/programs/Hadrons/Module.hpp.template @@ -0,0 +1,43 @@ +#ifndef Hadrons____FILEBASENAME____hpp_ +#define Hadrons____FILEBASENAME____hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * ___FILEBASENAME___ * + ******************************************************************************/ +class ___FILEBASENAME___: public Module +{ +public: + class Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, i); + }; +public: + // constructor + ___FILEBASENAME___(const std::string name); + // destructor + virtual ~___FILEBASENAME___(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +private: + Par par_; +}; + +MODULE_REGISTER(___FILEBASENAME___); + +END_HADRONS_NAMESPACE + +#endif // Hadrons____FILEBASENAME____hpp_ diff --git a/programs/Hadrons/add_module.sh b/programs/Hadrons/add_module.sh new file mode 100755 index 00000000..e412e0e7 --- /dev/null +++ b/programs/Hadrons/add_module.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +if (( $# != 1 )); then + echo "usage: `basename $0` " 1>&2 + exit 1 +fi +NAME=$1 + +if [ -e "Modules/${NAME}.cc" ] || [ -e "Modules/${NAME}.hpp" ]; then + echo "error: files Modules/${NAME}.* already exists" 1>&2 + exit 1 +fi +sed "s/___FILEBASENAME___/${NAME}/g" Module.cc.template > Modules/${NAME}.cc +sed "s/___FILEBASENAME___/${NAME}/g" Module.hpp.template > Modules/${NAME}.hpp +./make_module_list.sh diff --git a/programs/Hadrons/make_module_list.sh b/programs/Hadrons/make_module_list.sh new file mode 100755 index 00000000..78ed8040 --- /dev/null +++ b/programs/Hadrons/make_module_list.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +echo 'modules =\' > modules.inc +find Modules -name '*.cc' -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> modules.inc \ No newline at end of file diff --git a/programs/Hadrons/modules.inc b/programs/Hadrons/modules.inc new file mode 100644 index 00000000..c0da727a --- /dev/null +++ b/programs/Hadrons/modules.inc @@ -0,0 +1,10 @@ +modules =\ + Modules/AWilson.cc \ + Modules/CMeson.cc \ + Modules/GLoad.cc \ + Modules/GRandom.cc \ + Modules/GUnit.cc \ + Modules/MQuark.cc \ + Modules/SolRBPrecCG.cc \ + Modules/SrcPoint.cc \ + Modules/SrcZ2.cc diff --git a/programs/Hadrons/AWilson.cc b/programs/Hadrons/modules/AWilson.cc similarity index 98% rename from programs/Hadrons/AWilson.cc rename to programs/Hadrons/modules/AWilson.cc index 5a75a257..77f9cc25 100644 --- a/programs/Hadrons/AWilson.cc +++ b/programs/Hadrons/modules/AWilson.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/AWilson.hpp b/programs/Hadrons/modules/AWilson.hpp similarity index 100% rename from programs/Hadrons/AWilson.hpp rename to programs/Hadrons/modules/AWilson.hpp diff --git a/programs/Hadrons/CMeson.cc b/programs/Hadrons/modules/CMeson.cc similarity index 98% rename from programs/Hadrons/CMeson.cc rename to programs/Hadrons/modules/CMeson.cc index 6cd627bd..28b2dd81 100644 --- a/programs/Hadrons/CMeson.cc +++ b/programs/Hadrons/modules/CMeson.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/CMeson.hpp b/programs/Hadrons/modules/CMeson.hpp similarity index 100% rename from programs/Hadrons/CMeson.hpp rename to programs/Hadrons/modules/CMeson.hpp diff --git a/programs/Hadrons/GLoad.cc b/programs/Hadrons/modules/GLoad.cc similarity index 98% rename from programs/Hadrons/GLoad.cc rename to programs/Hadrons/modules/GLoad.cc index cff9f3ed..8f1b4d95 100644 --- a/programs/Hadrons/GLoad.cc +++ b/programs/Hadrons/modules/GLoad.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/GLoad.hpp b/programs/Hadrons/modules/GLoad.hpp similarity index 100% rename from programs/Hadrons/GLoad.hpp rename to programs/Hadrons/modules/GLoad.hpp diff --git a/programs/Hadrons/GRandom.cc b/programs/Hadrons/modules/GRandom.cc similarity index 94% rename from programs/Hadrons/GRandom.cc rename to programs/Hadrons/modules/GRandom.cc index 7f81624c..34b1d57e 100644 --- a/programs/Hadrons/GRandom.cc +++ b/programs/Hadrons/modules/GRandom.cc @@ -25,13 +25,13 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; /****************************************************************************** -* GRandom implementation * +* GRandom implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// GRandom::GRandom(const std::string name) diff --git a/programs/Hadrons/GRandom.hpp b/programs/Hadrons/modules/GRandom.hpp similarity index 100% rename from programs/Hadrons/GRandom.hpp rename to programs/Hadrons/modules/GRandom.hpp diff --git a/programs/Hadrons/GUnit.cc b/programs/Hadrons/modules/GUnit.cc similarity index 98% rename from programs/Hadrons/GUnit.cc rename to programs/Hadrons/modules/GUnit.cc index 75bdc597..d61f5551 100644 --- a/programs/Hadrons/GUnit.cc +++ b/programs/Hadrons/modules/GUnit.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/GUnit.hpp b/programs/Hadrons/modules/GUnit.hpp similarity index 100% rename from programs/Hadrons/GUnit.hpp rename to programs/Hadrons/modules/GUnit.hpp diff --git a/programs/Hadrons/MQuark.cc b/programs/Hadrons/modules/MQuark.cc similarity index 99% rename from programs/Hadrons/MQuark.cc rename to programs/Hadrons/modules/MQuark.cc index c6af53f4..ffb91791 100644 --- a/programs/Hadrons/MQuark.cc +++ b/programs/Hadrons/modules/MQuark.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/MQuark.hpp b/programs/Hadrons/modules/MQuark.hpp similarity index 100% rename from programs/Hadrons/MQuark.hpp rename to programs/Hadrons/modules/MQuark.hpp diff --git a/programs/Hadrons/SolRBPrecCG.cc b/programs/Hadrons/modules/SolRBPrecCG.cc similarity index 98% rename from programs/Hadrons/SolRBPrecCG.cc rename to programs/Hadrons/modules/SolRBPrecCG.cc index fc1d00aa..3db4a4d1 100644 --- a/programs/Hadrons/SolRBPrecCG.cc +++ b/programs/Hadrons/modules/SolRBPrecCG.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/SolRBPrecCG.hpp b/programs/Hadrons/modules/SolRBPrecCG.hpp similarity index 100% rename from programs/Hadrons/SolRBPrecCG.hpp rename to programs/Hadrons/modules/SolRBPrecCG.hpp diff --git a/programs/Hadrons/SrcPoint.cc b/programs/Hadrons/modules/SrcPoint.cc similarity index 98% rename from programs/Hadrons/SrcPoint.cc rename to programs/Hadrons/modules/SrcPoint.cc index 559e56d3..b668f7bb 100644 --- a/programs/Hadrons/SrcPoint.cc +++ b/programs/Hadrons/modules/SrcPoint.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/SrcPoint.hpp b/programs/Hadrons/modules/SrcPoint.hpp similarity index 100% rename from programs/Hadrons/SrcPoint.hpp rename to programs/Hadrons/modules/SrcPoint.hpp diff --git a/programs/Hadrons/SrcZ2.cc b/programs/Hadrons/modules/SrcZ2.cc similarity index 98% rename from programs/Hadrons/SrcZ2.cc rename to programs/Hadrons/modules/SrcZ2.cc index 0ed6227d..2c9bb403 100644 --- a/programs/Hadrons/SrcZ2.cc +++ b/programs/Hadrons/modules/SrcZ2.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/SrcZ2.hpp b/programs/Hadrons/modules/SrcZ2.hpp similarity index 100% rename from programs/Hadrons/SrcZ2.hpp rename to programs/Hadrons/modules/SrcZ2.hpp From 78198d1b04b48ae80ad22f3788c346bb8b2a1414 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 10 May 2016 20:13:28 +0100 Subject: [PATCH 043/106] Hadrons: size fix for module graph with one vertex --- programs/Hadrons/Environment.cc | 1 + programs/Hadrons/GeneticScheduler.hpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 45b16aa0..98724035 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -274,6 +274,7 @@ Graph Environment::makeModuleGraph(void) const for (unsigned int i = 0; i < module_.size(); ++i) { + moduleGraph.addVertex(i); for (auto &j: moduleInput_[i]) { moduleGraph.addEdge(objectModule_[j], i); diff --git a/programs/Hadrons/GeneticScheduler.hpp b/programs/Hadrons/GeneticScheduler.hpp index 8d9bbf40..026ee303 100644 --- a/programs/Hadrons/GeneticScheduler.hpp +++ b/programs/Hadrons/GeneticScheduler.hpp @@ -183,7 +183,7 @@ template void GeneticScheduler::crossover(const std::vector &p1, const std::vector &p2) { - std::uniform_int_distribution dis(1, p1.size() - 2); + std::uniform_int_distribution dis(0, p1.size() - 1); unsigned int cut = dis(gen_); std::vector c1, c2, buf; @@ -211,7 +211,7 @@ void GeneticScheduler::crossover(const std::vector &p1, template void GeneticScheduler::mutation(std::vector &c) { - std::uniform_int_distribution dis(1, c.size() - 2); + std::uniform_int_distribution dis(0, c.size() - 1); unsigned int cut = dis(gen_); Graph g = graph_; std::vector buf; @@ -220,7 +220,10 @@ void GeneticScheduler::mutation(std::vector &c) { g.removeVertex(c[i]); } - buf = g.topoSort(gen_); + if (g.size() > 0) + { + buf = g.topoSort(gen_); + } for (unsigned int i = cut; i < c.size(); ++i) { buf.push_back(c[i]); From 56a8d7a5bcd5bf08d40282d0d0463c013b29c505 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 11 May 2016 10:27:14 +0100 Subject: [PATCH 044/106] Hadrons: build system fix --- programs/Hadrons/Makefile.am | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 19bc9515..64ad5252 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -3,16 +3,14 @@ AM_LDFLAGS = -L$(top_builddir)/lib bin_PROGRAMS = Hadrons -# general sources +include modules.inc + Hadrons_SOURCES = \ + $(modules) \ Application.cc \ Environment.cc \ Global.cc \ Hadrons.cc \ Module.cc -# modules -include modules.inc -Hadrons_SOURCES += $(modules) - Hadrons_LDADD = -lGrid From 328d213c9ec62cb1741de81fd0e841392d20c794 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 11 May 2016 14:44:14 +0100 Subject: [PATCH 045/106] Hadrons: FS case sensitivity fix --- programs/Hadrons/{modules => Modules}/AWilson.cc | 0 programs/Hadrons/{modules => Modules}/AWilson.hpp | 0 programs/Hadrons/{modules => Modules}/CMeson.cc | 0 programs/Hadrons/{modules => Modules}/CMeson.hpp | 0 programs/Hadrons/{modules => Modules}/GLoad.cc | 0 programs/Hadrons/{modules => Modules}/GLoad.hpp | 0 programs/Hadrons/{modules => Modules}/GRandom.cc | 0 programs/Hadrons/{modules => Modules}/GRandom.hpp | 0 programs/Hadrons/{modules => Modules}/GUnit.cc | 0 programs/Hadrons/{modules => Modules}/GUnit.hpp | 0 programs/Hadrons/{modules => Modules}/MQuark.cc | 0 programs/Hadrons/{modules => Modules}/MQuark.hpp | 0 programs/Hadrons/{modules => Modules}/SolRBPrecCG.cc | 0 programs/Hadrons/{modules => Modules}/SolRBPrecCG.hpp | 0 programs/Hadrons/{modules => Modules}/SrcPoint.cc | 0 programs/Hadrons/{modules => Modules}/SrcPoint.hpp | 0 programs/Hadrons/{modules => Modules}/SrcZ2.cc | 0 programs/Hadrons/{modules => Modules}/SrcZ2.hpp | 0 18 files changed, 0 insertions(+), 0 deletions(-) rename programs/Hadrons/{modules => Modules}/AWilson.cc (100%) rename programs/Hadrons/{modules => Modules}/AWilson.hpp (100%) rename programs/Hadrons/{modules => Modules}/CMeson.cc (100%) rename programs/Hadrons/{modules => Modules}/CMeson.hpp (100%) rename programs/Hadrons/{modules => Modules}/GLoad.cc (100%) rename programs/Hadrons/{modules => Modules}/GLoad.hpp (100%) rename programs/Hadrons/{modules => Modules}/GRandom.cc (100%) rename programs/Hadrons/{modules => Modules}/GRandom.hpp (100%) rename programs/Hadrons/{modules => Modules}/GUnit.cc (100%) rename programs/Hadrons/{modules => Modules}/GUnit.hpp (100%) rename programs/Hadrons/{modules => Modules}/MQuark.cc (100%) rename programs/Hadrons/{modules => Modules}/MQuark.hpp (100%) rename programs/Hadrons/{modules => Modules}/SolRBPrecCG.cc (100%) rename programs/Hadrons/{modules => Modules}/SolRBPrecCG.hpp (100%) rename programs/Hadrons/{modules => Modules}/SrcPoint.cc (100%) rename programs/Hadrons/{modules => Modules}/SrcPoint.hpp (100%) rename programs/Hadrons/{modules => Modules}/SrcZ2.cc (100%) rename programs/Hadrons/{modules => Modules}/SrcZ2.hpp (100%) diff --git a/programs/Hadrons/modules/AWilson.cc b/programs/Hadrons/Modules/AWilson.cc similarity index 100% rename from programs/Hadrons/modules/AWilson.cc rename to programs/Hadrons/Modules/AWilson.cc diff --git a/programs/Hadrons/modules/AWilson.hpp b/programs/Hadrons/Modules/AWilson.hpp similarity index 100% rename from programs/Hadrons/modules/AWilson.hpp rename to programs/Hadrons/Modules/AWilson.hpp diff --git a/programs/Hadrons/modules/CMeson.cc b/programs/Hadrons/Modules/CMeson.cc similarity index 100% rename from programs/Hadrons/modules/CMeson.cc rename to programs/Hadrons/Modules/CMeson.cc diff --git a/programs/Hadrons/modules/CMeson.hpp b/programs/Hadrons/Modules/CMeson.hpp similarity index 100% rename from programs/Hadrons/modules/CMeson.hpp rename to programs/Hadrons/Modules/CMeson.hpp diff --git a/programs/Hadrons/modules/GLoad.cc b/programs/Hadrons/Modules/GLoad.cc similarity index 100% rename from programs/Hadrons/modules/GLoad.cc rename to programs/Hadrons/Modules/GLoad.cc diff --git a/programs/Hadrons/modules/GLoad.hpp b/programs/Hadrons/Modules/GLoad.hpp similarity index 100% rename from programs/Hadrons/modules/GLoad.hpp rename to programs/Hadrons/Modules/GLoad.hpp diff --git a/programs/Hadrons/modules/GRandom.cc b/programs/Hadrons/Modules/GRandom.cc similarity index 100% rename from programs/Hadrons/modules/GRandom.cc rename to programs/Hadrons/Modules/GRandom.cc diff --git a/programs/Hadrons/modules/GRandom.hpp b/programs/Hadrons/Modules/GRandom.hpp similarity index 100% rename from programs/Hadrons/modules/GRandom.hpp rename to programs/Hadrons/Modules/GRandom.hpp diff --git a/programs/Hadrons/modules/GUnit.cc b/programs/Hadrons/Modules/GUnit.cc similarity index 100% rename from programs/Hadrons/modules/GUnit.cc rename to programs/Hadrons/Modules/GUnit.cc diff --git a/programs/Hadrons/modules/GUnit.hpp b/programs/Hadrons/Modules/GUnit.hpp similarity index 100% rename from programs/Hadrons/modules/GUnit.hpp rename to programs/Hadrons/Modules/GUnit.hpp diff --git a/programs/Hadrons/modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc similarity index 100% rename from programs/Hadrons/modules/MQuark.cc rename to programs/Hadrons/Modules/MQuark.cc diff --git a/programs/Hadrons/modules/MQuark.hpp b/programs/Hadrons/Modules/MQuark.hpp similarity index 100% rename from programs/Hadrons/modules/MQuark.hpp rename to programs/Hadrons/Modules/MQuark.hpp diff --git a/programs/Hadrons/modules/SolRBPrecCG.cc b/programs/Hadrons/Modules/SolRBPrecCG.cc similarity index 100% rename from programs/Hadrons/modules/SolRBPrecCG.cc rename to programs/Hadrons/Modules/SolRBPrecCG.cc diff --git a/programs/Hadrons/modules/SolRBPrecCG.hpp b/programs/Hadrons/Modules/SolRBPrecCG.hpp similarity index 100% rename from programs/Hadrons/modules/SolRBPrecCG.hpp rename to programs/Hadrons/Modules/SolRBPrecCG.hpp diff --git a/programs/Hadrons/modules/SrcPoint.cc b/programs/Hadrons/Modules/SrcPoint.cc similarity index 100% rename from programs/Hadrons/modules/SrcPoint.cc rename to programs/Hadrons/Modules/SrcPoint.cc diff --git a/programs/Hadrons/modules/SrcPoint.hpp b/programs/Hadrons/Modules/SrcPoint.hpp similarity index 100% rename from programs/Hadrons/modules/SrcPoint.hpp rename to programs/Hadrons/Modules/SrcPoint.hpp diff --git a/programs/Hadrons/modules/SrcZ2.cc b/programs/Hadrons/Modules/SrcZ2.cc similarity index 100% rename from programs/Hadrons/modules/SrcZ2.cc rename to programs/Hadrons/Modules/SrcZ2.cc diff --git a/programs/Hadrons/modules/SrcZ2.hpp b/programs/Hadrons/Modules/SrcZ2.hpp similarity index 100% rename from programs/Hadrons/modules/SrcZ2.hpp rename to programs/Hadrons/Modules/SrcZ2.hpp From 835003b3c5e72ea5e4aa581d750916236e32c9f1 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 11 May 2016 15:01:52 +0100 Subject: [PATCH 046/106] Hadrons: removed useless gauge global parameters --- programs/Hadrons/Application.cc | 2 +- programs/Hadrons/Application.hpp | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 6381a9e1..4bb300e9 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -181,7 +181,7 @@ void Application::schedule(void) // loop on configurations ////////////////////////////////////////////////////// void Application::configLoop(void) { - auto range = par_.configs.range; + auto range = par_.trajCounter; for (unsigned int t = range.start; t < range.end; t += range.step) { diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 67b8d7a0..20716adf 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -32,10 +32,6 @@ directory. #include #include -namespace Grid { - GRID_SERIALIZABLE_ENUM(ConfigType, undef, load, 1, unit, 2, gen, 3); -} - BEGIN_HADRONS_NAMESPACE class TrajRange: Serializable @@ -47,19 +43,11 @@ public: unsigned int, step); }; -class ConfigPar: Serializable -{ -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(ConfigPar, - std::string, ioStem, - TrajRange, range); -}; - class GlobalPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, - ConfigPar, configs, + TrajRange, trajCounter, std::string, seed); }; From 362f255100a159061e9d81ec2f02cee8d3c46174 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 11:59:28 +0100 Subject: [PATCH 047/106] Hadrons: module parameters can now be accessed from outside --- lib/serialisation/BaseIO.h | 24 ++++++- programs/Hadrons/Environment.cc | 4 +- programs/Hadrons/Environment.hpp | 8 +-- programs/Hadrons/Module.cc | 8 +-- programs/Hadrons/Module.hpp | 54 ++++++++++++-- programs/Hadrons/ModuleFactory.hpp | 2 +- programs/Hadrons/Modules/AWilson.cc | 18 ++--- programs/Hadrons/Modules/AWilson.hpp | 19 +++-- programs/Hadrons/Modules/CMeson.cc | 18 ++--- programs/Hadrons/Modules/CMeson.hpp | 23 +++--- programs/Hadrons/Modules/GLoad.cc | 10 +-- programs/Hadrons/Modules/GLoad.hpp | 17 ++--- programs/Hadrons/Modules/GRandom.cc | 2 +- programs/Hadrons/Modules/GRandom.hpp | 2 +- programs/Hadrons/Modules/GUnit.cc | 2 +- programs/Hadrons/Modules/GUnit.hpp | 2 +- programs/Hadrons/Modules/MQuark.cc | 89 ++++++++++++------------ programs/Hadrons/Modules/MQuark.hpp | 18 +++-- programs/Hadrons/Modules/SolRBPrecCG.cc | 20 ++---- programs/Hadrons/Modules/SolRBPrecCG.hpp | 19 +++-- programs/Hadrons/Modules/SrcPoint.cc | 12 +--- programs/Hadrons/Modules/SrcPoint.hpp | 17 ++--- programs/Hadrons/Modules/SrcZ2.cc | 18 ++--- programs/Hadrons/Modules/SrcZ2.hpp | 19 +++-- 24 files changed, 216 insertions(+), 209 deletions(-) diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 6deb17f5..7761a8e6 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -67,9 +67,8 @@ namespace Grid { return os; } - class Serializable {}; - // static polymorphism implemented using CRTP idiom + class Serializable; // Static abstract writer template @@ -122,6 +121,27 @@ namespace Grid { T *upcast; }; + // serializable base class + class Serializable + { + public: + template + static inline void write(Writer &WR,const std::string &s, + const Serializable &obj) + {} + + template + static inline void read(Reader &RD,const std::string &s, + Serializable &obj) + {} + + friend inline std::ostream & operator<<(std::ostream &os, + const Serializable &obj) + { + return os; + } + }; + // Generic writer interface template inline void push(Writer &w, const std::string &s) diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 98724035..f92ab9d4 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -200,7 +200,7 @@ void Environment::createModule(const std::string name, const std::string type, } } -Module * Environment::getModule(const unsigned int address) const +ModuleBase * Environment::getModule(const unsigned int address) const { if (hasModule(address)) { @@ -212,7 +212,7 @@ Module * Environment::getModule(const unsigned int address) const } } -Module * Environment::getModule(const std::string name) const +ModuleBase * Environment::getModule(const std::string name) const { return getModule(getModuleAddress(name)); } diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 4cecf7da..b56b1680 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -37,13 +37,13 @@ BEGIN_HADRONS_NAMESPACE * Global environment * ******************************************************************************/ // forward declaration of Module -class Module; +class ModuleBase; class Environment { SINGLETON(Environment); public: - typedef std::unique_ptr ModPt; + typedef std::unique_ptr ModPt; typedef std::unique_ptr GridPt; typedef std::unique_ptr GridRbPt; typedef FermionOperator FMat; @@ -76,8 +76,8 @@ public: void createModule(const std::string name, const std::string type, XmlReader &reader); - Module * getModule(const unsigned int address) const; - Module * getModule(const std::string name) const; + ModuleBase * getModule(const unsigned int address) const; + ModuleBase * getModule(const std::string name) const; unsigned int getModuleAddress(const std::string name) const; std::string getModuleName(const unsigned int address) const; std::string getModuleType(const unsigned int address) const; diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index a2dedb52..70fcd79f 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -35,24 +35,24 @@ using namespace Hadrons; * Module implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -Module::Module(const std::string name) +ModuleBase::ModuleBase(const std::string name) : name_(name) , env_(Environment::getInstance()) {} // access ////////////////////////////////////////////////////////////////////// -std::string Module::getName(void) const +std::string ModuleBase::getName(void) const { return name_; } -Environment & Module::env(void) const +Environment & ModuleBase::env(void) const { return env_; } // execution /////////////////////////////////////////////////////////////////// -void Module::operator()(void) +void ModuleBase::operator()(void) { setup(); if (!env().isDryRun()) diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 2b4bfabe..7260eee8 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -52,21 +52,21 @@ static mod##ModuleRegistrar mod##ModuleRegistrarInstance; /****************************************************************************** * Module * ******************************************************************************/ -class Module +class ModuleBase { public: // constructor - Module(const std::string name); + ModuleBase(const std::string name); // destructor - virtual ~Module(void) = default; + virtual ~ModuleBase(void) = default; // access std::string getName(void) const; Environment &env(void) const; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name) {}; // dependencies/products virtual std::vector getInput(void) = 0; virtual std::vector getOutput(void) = 0; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name) = 0; // setup virtual void setup(void) {}; // execution @@ -77,6 +77,50 @@ private: Environment &env_; }; +typedef Serializable NoPar; + +template +class Module: public ModuleBase +{ +public: + typedef P Par; +public: + // constructor + Module(const std::string name); + // destructor + virtual ~Module(void) = default; + // parse parameters + virtual void parseParameters(XmlReader &reader, const std::string name); + // parameter access + const P & par(void) const; + void setPar(const P &par); +private: + P par_; +}; + +template +Module

::Module(const std::string name) +: ModuleBase(name) +{} + +template +void Module

::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_);read(reader, name, par_); +} + +template +const P & Module

::par(void) const +{ + return par_; +} + +template +void Module

::setPar(const P &par) +{ + par_ = par; +} + END_HADRONS_NAMESPACE #endif // Hadrons_Module_hpp_ diff --git a/programs/Hadrons/ModuleFactory.hpp b/programs/Hadrons/ModuleFactory.hpp index 263a0828..0169ef94 100644 --- a/programs/Hadrons/ModuleFactory.hpp +++ b/programs/Hadrons/ModuleFactory.hpp @@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * ModuleFactory * ******************************************************************************/ -class ModuleFactory: public Factory +class ModuleFactory: public Factory { SINGLETON_DEFCTOR(ModuleFactory) }; diff --git a/programs/Hadrons/Modules/AWilson.cc b/programs/Hadrons/Modules/AWilson.cc index 77f9cc25..9b7c1b04 100644 --- a/programs/Hadrons/Modules/AWilson.cc +++ b/programs/Hadrons/Modules/AWilson.cc @@ -35,19 +35,13 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// AWilson::AWilson(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void AWilson::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector AWilson::getInput(void) { - std::vector in = {par_.gauge}; + std::vector in = {par().gauge}; return in; } @@ -71,13 +65,13 @@ void AWilson::setup(void) // execution /////////////////////////////////////////////////////////////////// void AWilson::execute() { - auto &U = *env().get(par_.gauge); + auto &U = *env().get(par().gauge); auto &grid = *env().getGrid(); auto &gridRb = *env().getRbGrid(); - auto fMatPt = new WilsonFermionR(U, grid, gridRb, par_.mass); + auto fMatPt = new WilsonFermionR(U, grid, gridRb, par().mass); unsigned int size; - LOG(Message) << "Setting up Wilson fermion matrix with m= " << par_.mass - << " using gauge field '" << par_.gauge << "'" << std::endl; + LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass + << " using gauge field '" << par().gauge << "'" << std::endl; env().addFermionMatrix(getName(), fMatPt); } diff --git a/programs/Hadrons/Modules/AWilson.hpp b/programs/Hadrons/Modules/AWilson.hpp index 1eaf0a36..cb35525e 100644 --- a/programs/Hadrons/Modules/AWilson.hpp +++ b/programs/Hadrons/Modules/AWilson.hpp @@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Wilson quark action * ******************************************************************************/ -class AWilson: public Module +class AWilsonPar: Serializable { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, gauge, - double , mass); - }; + GRID_SERIALIZABLE_CLASS_MEMBERS(AWilsonPar, + std::string, gauge, + double , mass); +}; + +class AWilson: public Module +{ public: // constructor AWilson(const std::string name); // destructor virtual ~AWilson(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -60,8 +59,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(AWilson); diff --git a/programs/Hadrons/Modules/CMeson.cc b/programs/Hadrons/Modules/CMeson.cc index 28b2dd81..53088c43 100644 --- a/programs/Hadrons/Modules/CMeson.cc +++ b/programs/Hadrons/Modules/CMeson.cc @@ -36,19 +36,13 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// CMeson::CMeson(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void CMeson::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector CMeson::getInput(void) { - std::vector input = {par_.q1, par_.q2}; + std::vector input = {par().q1, par().q2}; return input; } @@ -64,12 +58,12 @@ std::vector CMeson::getOutput(void) void CMeson::execute(void) { LOG(Message) << "Computing meson contraction '" << getName() << "' using" - << " quarks '" << par_.q1 << "' and '" << par_.q2 << "'" + << " quarks '" << par().q1 << "' and '" << par().q2 << "'" << std::endl; - XmlWriter writer(par_.output); - LatticePropagator &q1 = *env().get(par_.q1); - LatticePropagator &q2 = *env().get(par_.q2); + XmlWriter writer(par().output); + LatticePropagator &q1 = *env().get(par().q1); + LatticePropagator &q2 = *env().get(par().q2); LatticeComplex c(env().getGrid()); SpinMatrix g[Ns*Ns], g5; std::vector buf; diff --git a/programs/Hadrons/Modules/CMeson.hpp b/programs/Hadrons/Modules/CMeson.hpp index bc9f3177..1cbd6d86 100644 --- a/programs/Hadrons/Modules/CMeson.hpp +++ b/programs/Hadrons/Modules/CMeson.hpp @@ -37,17 +37,18 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * CMeson * ******************************************************************************/ -class CMeson: public Module +class CMesonPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(CMesonPar, + std::string, q1, + std::string, q2, + std::string, output); +}; + +class CMeson: public Module { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, - std::string, q1, - std::string, q2, - std::string, output); - }; class Result: Serializable { public: @@ -59,15 +60,11 @@ public: CMeson(const std::string name); // destructor virtual ~CMeson(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(CMeson); diff --git a/programs/Hadrons/Modules/GLoad.cc b/programs/Hadrons/Modules/GLoad.cc index 8f1b4d95..590c4135 100644 --- a/programs/Hadrons/Modules/GLoad.cc +++ b/programs/Hadrons/Modules/GLoad.cc @@ -35,15 +35,9 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// GLoad::GLoad(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void GLoad::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector GLoad::getInput(void) { @@ -69,7 +63,7 @@ void GLoad::setup(void) void GLoad::execute(void) { NerscField header; - std::string fileName = par_.file + "." + std::string fileName = par().file + "." + std::to_string(env().getTrajectory()); LOG(Message) << "Loading NERSC configuration from file '" << fileName diff --git a/programs/Hadrons/Modules/GLoad.hpp b/programs/Hadrons/Modules/GLoad.hpp index cb076bb5..af01e40e 100644 --- a/programs/Hadrons/Modules/GLoad.hpp +++ b/programs/Hadrons/Modules/GLoad.hpp @@ -37,21 +37,20 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Load a NERSC configuration * ******************************************************************************/ -class GLoad: public Module +class GLoadPar: Serializable { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, file); - }; + GRID_SERIALIZABLE_CLASS_MEMBERS(GLoadPar, + std::string, file); +}; + +class GLoad: public Module +{ public: // constructor GLoad(const std::string name); // destructor virtual ~GLoad(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -59,8 +58,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(GLoad); diff --git a/programs/Hadrons/Modules/GRandom.cc b/programs/Hadrons/Modules/GRandom.cc index 34b1d57e..f40c8121 100644 --- a/programs/Hadrons/Modules/GRandom.cc +++ b/programs/Hadrons/Modules/GRandom.cc @@ -35,7 +35,7 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// GRandom::GRandom(const std::string name) -: Module(name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// diff --git a/programs/Hadrons/Modules/GRandom.hpp b/programs/Hadrons/Modules/GRandom.hpp index 5d0f4197..a31028fd 100644 --- a/programs/Hadrons/Modules/GRandom.hpp +++ b/programs/Hadrons/Modules/GRandom.hpp @@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Random gauge * ******************************************************************************/ -class GRandom: public Module +class GRandom: public Module { public: // constructor diff --git a/programs/Hadrons/Modules/GUnit.cc b/programs/Hadrons/Modules/GUnit.cc index d61f5551..20d815f1 100644 --- a/programs/Hadrons/Modules/GUnit.cc +++ b/programs/Hadrons/Modules/GUnit.cc @@ -35,7 +35,7 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// GUnit::GUnit(const std::string name) -: Module(name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// diff --git a/programs/Hadrons/Modules/GUnit.hpp b/programs/Hadrons/Modules/GUnit.hpp index 3c72bd07..eff34020 100644 --- a/programs/Hadrons/Modules/GUnit.hpp +++ b/programs/Hadrons/Modules/GUnit.hpp @@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Unit gauge * ******************************************************************************/ -class GUnit: public Module +class GUnit: public Module { public: // constructor diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index ffb91791..aa8344ac 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -39,16 +39,10 @@ MQuark::MQuark(const std::string name) : Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void MQuark::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector MQuark::getInput(void) { - std::vector in = {par_.source, par_.solver}; + std::vector in = {par().source, par().solver}; return in; } @@ -63,7 +57,7 @@ std::vector MQuark::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void MQuark::setup(void) { - Ls_ = env().getObjectLs(env().getSolverAction(par_.solver)); + Ls_ = env().getObjectLs(env().getSolverAction(par().solver)); env().registerLattice(getName()); if (Ls_ > 1) { @@ -74,54 +68,59 @@ void MQuark::setup(void) // execution /////////////////////////////////////////////////////////////////// void MQuark::execute(void) { - LatticePropagator *fullSource; - LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)); - std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); + LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)), + tmp(env().getGrid()); + std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; - LatticePropagator &prop = *env().create(propName); - // source conversion for 4D sources - if (!env().isObject5d(par_.source)) - { - if (Ls_ == 1) - { - fullSource = env().get(par_.source); - } - else - { - HADRON_ERROR("MQuark not implemented with 5D actions"); - } - } - // source conversion for 5D sources - else - { - if (Ls_ == 1) - { - HADRON_ERROR("MQuark not implemented with 5D actions"); - } - else if (Ls_ != env().getObjectLs(par_.source)) - { - HADRON_ERROR("Ls mismatch between quark action and source"); - } - else - { - fullSource = env().get(par_.source); - } - } - LOG(Message) << "Inverting using solver '" << par_.solver - << "' on source '" << par_.source << "'" << std::endl; + LatticePropagator &prop = *env().create(propName); + LatticePropagator &fullSrc = *env().create(par().source); + + LOG(Message) << "Inverting using solver '" << par().solver + << "' on source '" << par().source << "'" << std::endl; for (unsigned int s = 0; s < Ns; ++s) for (unsigned int c = 0; c < Nc; ++c) { - PropToFerm(source, *fullSource, s, c); + // source conversion for 4D sources + if (!env().isObject5d(par().source)) + { + if (Ls_ == 1) + { + PropToFerm(source, fullSrc, s, c); + } + else + { + PropToFerm(tmp, fullSrc, s, c); + InsertSlice(source, tmp, 0, 0); + InsertSlice(source, tmp, Ls_ - 1, 0); + axpby_ssp_pplus(source, 0., source, 1., source, + 0, 0); + axpby_ssp_pminus(source, 0., source, 1., source, + Ls_ - 1, Ls_ - 1); + } + } + // source conversion for 5D sources + else + { + if (Ls_ != env().getObjectLs(par().source)) + { + HADRON_ERROR("Ls mismatch between quark action and source"); + } + else + { + PropToFerm(source, fullSrc, s, c); + } + } sol = zero; - env().callSolver(par_.solver, sol, source); + env().callSolver(par().solver, sol, source); FermToProp(prop, sol, s, c); } // create 4D propagators from 5D one if necessary if (Ls_ > 1) { - HADRON_ERROR("MQuark not implemented with 5D actions"); + LatticePropagator &prop4d = *env().create(getName()); + + } } diff --git a/programs/Hadrons/Modules/MQuark.hpp b/programs/Hadrons/Modules/MQuark.hpp index 14ced177..0080090b 100644 --- a/programs/Hadrons/Modules/MQuark.hpp +++ b/programs/Hadrons/Modules/MQuark.hpp @@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * MQuark * ******************************************************************************/ -class MQuark: public Module +class MQuarkPar: Serializable { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, source, - std::string, solver); - }; + GRID_SERIALIZABLE_CLASS_MEMBERS(MQuarkPar, + std::string, source, + std::string, solver); +}; + +class MQuark: public Module +{ public: // constructor MQuark(const std::string name); // destructor virtual ~MQuark(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -61,7 +60,6 @@ public: // execution virtual void execute(void); private: - Par par_; unsigned int Ls_; Environment::Solver *solver_{nullptr}; }; diff --git a/programs/Hadrons/Modules/SolRBPrecCG.cc b/programs/Hadrons/Modules/SolRBPrecCG.cc index 3db4a4d1..14a09be5 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.cc +++ b/programs/Hadrons/Modules/SolRBPrecCG.cc @@ -39,16 +39,10 @@ SolRBPrecCG::SolRBPrecCG(const std::string name) : Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void SolRBPrecCG::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector SolRBPrecCG::getInput(void) { - std::vector in = {par_.action}; + std::vector in = {par().action}; return in; } @@ -64,25 +58,25 @@ std::vector SolRBPrecCG::getOutput(void) void SolRBPrecCG::setup(void) { env().registerObject(getName(), 0); - env().addOwnership(getName(), par_.action); - env().setSolverAction(getName(), par_.action); + env().addOwnership(getName(), par().action); + env().setSolverAction(getName(), par().action); } // execution /////////////////////////////////////////////////////////////////// void SolRBPrecCG::execute(void) { - auto &mat = *(env().getFermionMatrix(par_.action)); + auto &mat = *(env().getFermionMatrix(par().action)); auto solver = [&mat, this](LatticeFermion &sol, const LatticeFermion &source) { - ConjugateGradient cg(par_.residual, 10000); + ConjugateGradient cg(par().residual, 10000); SchurRedBlackDiagMooeeSolve schurSolver(cg); schurSolver(mat, source, sol); }; LOG(Message) << "setting up Schur red-black preconditioned CG for" - << " action '" << par_.action << "' with residual " - << par_.residual << std::endl; + << " action '" << par().action << "' with residual " + << par().residual << std::endl; env().addSolver(getName(), solver); } diff --git a/programs/Hadrons/Modules/SolRBPrecCG.hpp b/programs/Hadrons/Modules/SolRBPrecCG.hpp index 82784666..b987eb95 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.hpp +++ b/programs/Hadrons/Modules/SolRBPrecCG.hpp @@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Schur red-black preconditioned CG * ******************************************************************************/ -class SolRBPrecCG: public Module +class SolRBPrecCGPar: Serializable { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, action, - double , residual); - }; + GRID_SERIALIZABLE_CLASS_MEMBERS(SolRBPrecCGPar, + std::string, action, + double , residual); +}; + +class SolRBPrecCG: public Module +{ public: // constructor SolRBPrecCG(const std::string name); // destructor virtual ~SolRBPrecCG(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -60,8 +59,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(SolRBPrecCG); diff --git a/programs/Hadrons/Modules/SrcPoint.cc b/programs/Hadrons/Modules/SrcPoint.cc index b668f7bb..3b7c3d10 100644 --- a/programs/Hadrons/Modules/SrcPoint.cc +++ b/programs/Hadrons/Modules/SrcPoint.cc @@ -35,15 +35,9 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// SrcPoint::SrcPoint(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void SrcPoint::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector SrcPoint::getInput(void) { @@ -68,10 +62,10 @@ void SrcPoint::setup(void) // execution /////////////////////////////////////////////////////////////////// void SrcPoint::execute(void) { - std::vector position = strToVec(par_.position); + std::vector position = strToVec(par().position); SpinColourMatrix id; - LOG(Message) << "Creating point source at position [" << par_.position + LOG(Message) << "Creating point source at position [" << par().position << "]" << std::endl; LatticePropagator &src = *env().create(getName()); id = 1.; diff --git a/programs/Hadrons/Modules/SrcPoint.hpp b/programs/Hadrons/Modules/SrcPoint.hpp index 8cfa89c9..75108319 100644 --- a/programs/Hadrons/Modules/SrcPoint.hpp +++ b/programs/Hadrons/Modules/SrcPoint.hpp @@ -48,21 +48,20 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * SrcPoint * ******************************************************************************/ -class SrcPoint: public Module +class SrcPointPar: Serializable { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, position); - }; + GRID_SERIALIZABLE_CLASS_MEMBERS(SrcPointPar, + std::string, position); +}; + +class SrcPoint: public Module +{ public: // constructor SrcPoint(const std::string name); // destructor virtual ~SrcPoint(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -70,8 +69,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(SrcPoint); diff --git a/programs/Hadrons/Modules/SrcZ2.cc b/programs/Hadrons/Modules/SrcZ2.cc index 2c9bb403..c77c2943 100644 --- a/programs/Hadrons/Modules/SrcZ2.cc +++ b/programs/Hadrons/Modules/SrcZ2.cc @@ -35,15 +35,9 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// SrcZ2::SrcZ2(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void SrcZ2::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector SrcZ2::getInput(void) { @@ -73,21 +67,21 @@ void SrcZ2::execute(void) LatticeFermion phi(env().getGrid()); Complex shift(1., 1.); - if (par_.tA == par_.tB) + if (par().tA == par().tB) { - LOG(Message) << "Generating Z_2 wall source at t= " << par_.tA + LOG(Message) << "Generating Z_2 wall source at t= " << par().tA << std::endl; } else { - LOG(Message) << "Generating Z_2 band for " << par_.tA << " <= t <= " - << par_.tB << std::endl; + LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " + << par().tB << std::endl; } LatticePropagator &src = *env().create(getName()); LatticeCoordinate(t, Tp); bernoulli(*env().get4dRng(), eta); eta = (2.*eta - shift)*(1./::sqrt(2.)); - eta = where((t >= par_.tA) and (t <= par_.tB), eta, 0.*eta); + eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta); src = 1.; src = src*eta; } diff --git a/programs/Hadrons/Modules/SrcZ2.hpp b/programs/Hadrons/Modules/SrcZ2.hpp index a1458693..a61f8688 100644 --- a/programs/Hadrons/Modules/SrcZ2.hpp +++ b/programs/Hadrons/Modules/SrcZ2.hpp @@ -49,22 +49,21 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * SrcZ2 * ******************************************************************************/ -class SrcZ2: public Module +class SrcZ2Par: Serializable { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, tA, - unsigned int, tB); - }; + GRID_SERIALIZABLE_CLASS_MEMBERS(SrcZ2Par, + unsigned int, tA, + unsigned int, tB); +}; + +class SrcZ2: public Module +{ public: // constructor SrcZ2(const std::string name); // destructor virtual ~SrcZ2(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -72,8 +71,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(SrcZ2); From 3d75e0f0d1f33d4b0578d289f51950d36fb949b7 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 12:02:15 +0100 Subject: [PATCH 048/106] Hadrons: MQuark fix --- programs/Hadrons/Modules/MQuark.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index aa8344ac..3a0e27f8 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -75,7 +75,7 @@ void MQuark::execute(void) LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; LatticePropagator &prop = *env().create(propName); - LatticePropagator &fullSrc = *env().create(par().source); + LatticePropagator &fullSrc = *env().get(par().source); LOG(Message) << "Inverting using solver '" << par().solver << "' on source '" << par().source << "'" << std::endl; @@ -121,6 +121,6 @@ void MQuark::execute(void) { LatticePropagator &prop4d = *env().create(getName()); - + HADRON_ERROR("5D implementation not finished"); } } From 5c06e89d6975d0c86ee5b35b4b1d706e1e075804 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 12:49:49 +0100 Subject: [PATCH 049/106] Hadrons: code cleaning --- programs/Hadrons/Graph.hpp | 2 +- programs/Hadrons/Module.cc | 2 +- programs/Hadrons/Module.hpp | 12 +++++++++--- programs/Hadrons/Modules/MQuark.cc | 8 +++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 5f71f31b..78b43452 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -726,7 +726,7 @@ std::vector> Graph::allTopoSort(void) } // build depedency matrix from topological sorts /////////////////////////////// -// complexity: can be V! +// complexity: something like O(V^2*log(V!)) template std::map> makeDependencyMatrix(const std::vector> &topSort) diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index 70fcd79f..6669a861 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -32,7 +32,7 @@ using namespace QCD; using namespace Hadrons; /****************************************************************************** - * Module implementation * + * ModuleBase implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// ModuleBase::ModuleBase(const std::string name) diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 7260eee8..c2bebd93 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -50,8 +50,9 @@ public:\ static mod##ModuleRegistrar mod##ModuleRegistrarInstance; /****************************************************************************** - * Module * + * Module class * ******************************************************************************/ +// base class class ModuleBase { public: @@ -77,8 +78,7 @@ private: Environment &env_; }; -typedef Serializable NoPar; - +// derived class, templating the parameter class template class Module: public ModuleBase { @@ -98,6 +98,12 @@ private: P par_; }; +// no parameter type +typedef Serializable NoPar; + +/****************************************************************************** + * Template implementation * + ******************************************************************************/ template Module

::Module(const std::string name) : ModuleBase(name) diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index 3a0e27f8..ced6d362 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -93,11 +93,9 @@ void MQuark::execute(void) { PropToFerm(tmp, fullSrc, s, c); InsertSlice(source, tmp, 0, 0); - InsertSlice(source, tmp, Ls_ - 1, 0); - axpby_ssp_pplus(source, 0., source, 1., source, - 0, 0); - axpby_ssp_pminus(source, 0., source, 1., source, - Ls_ - 1, Ls_ - 1); + InsertSlice(source, tmp, Ls_-1, 0); + axpby_ssp_pplus(source, 0., source, 1., source, 0, 0); + axpby_ssp_pminus(source, 0., source, 1., source, Ls_-1, Ls_-1); } } // source conversion for 5D sources From 7ae667c76779ba68d158462b1d41889be06c5758 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 18:33:08 +0100 Subject: [PATCH 050/106] Hadrons: module template update --- programs/Hadrons/Module.cc.template | 10 ++-------- programs/Hadrons/Module.hpp.template | 17 +++++++---------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/programs/Hadrons/Module.cc.template b/programs/Hadrons/Module.cc.template index f2533d80..1bcf53ca 100644 --- a/programs/Hadrons/Module.cc.template +++ b/programs/Hadrons/Module.cc.template @@ -1,4 +1,4 @@ -#include +#include using namespace Grid; using namespace Hadrons; @@ -8,15 +8,9 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// ___FILEBASENAME___::___FILEBASENAME___(const std::string name) -: Module(name) +: Module<___FILEBASENAME___Par>(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void ___FILEBASENAME___::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector ___FILEBASENAME___::getInput(void) { diff --git a/programs/Hadrons/Module.hpp.template b/programs/Hadrons/Module.hpp.template index 002d93b9..e8e6c4de 100644 --- a/programs/Hadrons/Module.hpp.template +++ b/programs/Hadrons/Module.hpp.template @@ -10,21 +10,20 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * ___FILEBASENAME___ * ******************************************************************************/ -class ___FILEBASENAME___: public Module +class ___FILEBASENAME___Par: Serializable { public: - class Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, i); - }; + GRID_SERIALIZABLE_CLASS_MEMBERS(___FILEBASENAME___Par, + unsigned int, i); +}; + +class ___FILEBASENAME___: public Module<___FILEBASENAME___Par> +{ public: // constructor ___FILEBASENAME___(const std::string name); // destructor virtual ~___FILEBASENAME___(void) = default; - // parse parameters - virtual void parseParameters(XmlReader &reader, const std::string name); // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -32,8 +31,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(___FILEBASENAME___); From afe5a947456d4ffc05b0e3c98110e93d3123b8fd Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 18:33:36 +0100 Subject: [PATCH 051/106] Hadrons: getModule with upcast --- programs/Hadrons/Environment.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index b56b1680..8c5c6021 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -78,6 +78,10 @@ public: XmlReader &reader); ModuleBase * getModule(const unsigned int address) const; ModuleBase * getModule(const std::string name) const; + template + M * getModule(const unsigned int address) const; + template + M * getModule(const std::string name) const; unsigned int getModuleAddress(const std::string name) const; std::string getModuleName(const unsigned int address) const; std::string getModuleType(const unsigned int address) const; @@ -187,6 +191,27 @@ private: /****************************************************************************** * template implementation * ******************************************************************************/ +template +M * Environment::getModule(const unsigned int address) const +{ + if (auto *pt = dynamic_cast(getModule(address))) + { + return pt; + } + else + { + HADRON_ERROR("module '" + moduleName_[address] + "' does not have type " + + typeName() + "(object type: " + + typeName(*module_.at(address).get()) + ")"); + } +} + +template +M * Environment::getModule(const std::string name) const +{ + return getModule(getModuleAddress(name)); +} + template unsigned int Environment::lattice4dSize(void) const { From 2b31bf61ff969d618d64c5a6e67bd056240ec5f1 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 18:33:49 +0100 Subject: [PATCH 052/106] Hadrons: message fix --- programs/Hadrons/Environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index f92ab9d4..cbdf678e 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -406,7 +406,7 @@ void Environment::freeLattice(const unsigned int address) { if (!isDryRun()) { - LOG(Message) << "Freeing lattice '" << moduleName_[address] + LOG(Message) << "Freeing lattice '" << objectName_[address] << "'" << std::endl; } lattice_.erase(address); From 232fda5fe1ceaaa801ec35f36daeb091cd45189a Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 18:34:10 +0100 Subject: [PATCH 053/106] Hadrons: DWF action --- programs/Hadrons/Modules/ADWF.cc | 83 +++++++++++++++++++++++++++++++ programs/Hadrons/Modules/ADWF.hpp | 70 ++++++++++++++++++++++++++ programs/Hadrons/modules.inc | 1 + 3 files changed, 154 insertions(+) create mode 100644 programs/Hadrons/Modules/ADWF.cc create mode 100644 programs/Hadrons/Modules/ADWF.hpp diff --git a/programs/Hadrons/Modules/ADWF.cc b/programs/Hadrons/Modules/ADWF.cc new file mode 100644 index 00000000..f579c0b7 --- /dev/null +++ b/programs/Hadrons/Modules/ADWF.cc @@ -0,0 +1,83 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/ADWF.cc + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +/****************************************************************************** +* ADWF implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +ADWF::ADWF(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +std::vector ADWF::getInput(void) +{ + std::vector in = {par().gauge}; + + return in; +} + +std::vector ADWF::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +void ADWF::setup(void) +{ + unsigned int size; + + size = 3*env().lattice4dSize(); + env().registerObject(getName(), size, par().Ls); +} + +// execution /////////////////////////////////////////////////////////////////// +void ADWF::execute(void) +{ + env().createGrid(par().Ls); + + auto &U = *env().get(par().gauge); + auto &g4 = *env().getGrid(); + auto &grb4 = *env().getRbGrid(); + auto &g5 = *env().getGrid(par().Ls); + auto &grb5 = *env().getRbGrid(par().Ls); + auto fMatPt = new DomainWallFermionR(U, g5, grb5, g4, grb4, + par().mass, par().M5); + + LOG(Message) << "Setting up domain wall fermion matrix with m= " + << par().mass << ", M5= " << par().M5 << " and Ls= " + << par().Ls << " using gauge field '" << par().gauge << "'" + << std::endl; + env().addFermionMatrix(getName(), fMatPt); +} diff --git a/programs/Hadrons/Modules/ADWF.hpp b/programs/Hadrons/Modules/ADWF.hpp new file mode 100644 index 00000000..0f4f5402 --- /dev/null +++ b/programs/Hadrons/Modules/ADWF.hpp @@ -0,0 +1,70 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/ADWF.hpp + +Copyright (C) 2016 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#ifndef Hadrons_ADWF_hpp_ +#define Hadrons_ADWF_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Domain wall quark action * + ******************************************************************************/ +class ADWFPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(ADWFPar, + std::string, gauge, + unsigned int, Ls, + double , mass, + double , M5); +}; + +class ADWF: public Module +{ +public: + // constructor + ADWF(const std::string name); + // destructor + virtual ~ADWF(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER(ADWF); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_ADWF_hpp_ diff --git a/programs/Hadrons/modules.inc b/programs/Hadrons/modules.inc index c0da727a..6ca8329e 100644 --- a/programs/Hadrons/modules.inc +++ b/programs/Hadrons/modules.inc @@ -1,4 +1,5 @@ modules =\ + Modules/ADWF.cc \ Modules/AWilson.cc \ Modules/CMeson.cc \ Modules/GLoad.cc \ From bb2125962bbb3e9484626f8daeeab5d399a71487 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 12 May 2016 18:34:42 +0100 Subject: [PATCH 054/106] Hadrons: finished implementation of 5D quarks --- programs/Hadrons/Modules/MQuark.cc | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index ced6d362..f3f1da06 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -76,6 +76,10 @@ void MQuark::execute(void) << std::endl; LatticePropagator &prop = *env().create(propName); LatticePropagator &fullSrc = *env().get(par().source); + if (Ls_ > 1) + { + env().create(getName()); + } LOG(Message) << "Inverting using solver '" << par().solver << "' on source '" << par().source << "'" << std::endl; @@ -91,9 +95,10 @@ void MQuark::execute(void) } else { + source = zero; PropToFerm(tmp, fullSrc, s, c); - InsertSlice(source, tmp, 0, 0); - InsertSlice(source, tmp, Ls_-1, 0); + InsertSlice(tmp, source, 0, 0); + InsertSlice(tmp, source, Ls_-1, 0); axpby_ssp_pplus(source, 0., source, 1., source, 0, 0); axpby_ssp_pminus(source, 0., source, 1., source, Ls_-1, Ls_-1); } @@ -113,12 +118,15 @@ void MQuark::execute(void) sol = zero; env().callSolver(par().solver, sol, source); FermToProp(prop, sol, s, c); - } - // create 4D propagators from 5D one if necessary - if (Ls_ > 1) - { - LatticePropagator &prop4d = *env().create(getName()); - - HADRON_ERROR("5D implementation not finished"); + // create 4D propagators from 5D one if necessary + if (Ls_ > 1) + { + LatticePropagator &p4d = *env().get(getName()); + + axpby_ssp_pminus(sol, 0., sol, 1., sol, 0, 0); + axpby_ssp_pplus(sol, 0., sol, 1., sol, 0, Ls_-1); + ExtractSlice(tmp, sol, 0, 0); + FermToProp(p4d, tmp, s, c); + } } } From 8e2078be7158e231ab9bd24c29c0d4ca33d618bf Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 6 Jun 2016 17:45:37 +0100 Subject: [PATCH 055/106] Hadrons: environment with fully generic object store --- programs/Hadrons/Application.cc | 2 +- programs/Hadrons/Environment.cc | 366 +++++++----------------- programs/Hadrons/Environment.hpp | 238 +++++++++------ programs/Hadrons/Global.hpp | 12 + programs/Hadrons/Module.hpp | 18 +- programs/Hadrons/Modules/ADWF.cc | 20 +- programs/Hadrons/Modules/AWilson.cc | 12 +- programs/Hadrons/Modules/CMeson.cc | 4 +- programs/Hadrons/Modules/GLoad.cc | 2 +- programs/Hadrons/Modules/GRandom.cc | 2 +- programs/Hadrons/Modules/GUnit.cc | 2 +- programs/Hadrons/Modules/MQuark.cc | 15 +- programs/Hadrons/Modules/SolRBPrecCG.cc | 9 +- programs/Hadrons/Modules/SrcPoint.cc | 2 +- programs/Hadrons/Modules/SrcZ2.cc | 2 +- 15 files changed, 321 insertions(+), 385 deletions(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 4bb300e9..f45ca066 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -127,7 +127,7 @@ void Application::schedule(void) // constrained topological sort using a genetic algorithm LOG(Message) << "Scheduling computation..." << std::endl; - constexpr unsigned int maxGen = 200, maxCstGen = 50; + constexpr unsigned int maxGen = 2000000, maxCstGen = 2000000; unsigned int k = 0, gen, prevPeak, nCstPeak = 0; auto graph = env_.makeModuleGraph(); auto con = graph.getConnectedComponents(); diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index cbdf678e..92a19e41 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -139,39 +139,28 @@ GridParallelRNG * Environment::get4dRng(void) const void Environment::createModule(const std::string name, const std::string type, XmlReader &reader) { - auto addObject = [this](const std::string name, const int moduleAddress) - { - ObjInfo info; - - object_.push_back(info); - objectName_.push_back(name); - objectAddress_[name] = object_.size() - 1; - objectModule_.push_back(moduleAddress); - owners_.push_back(std::set()); - properties_.push_back(std::set()); - }; - if (!hasModule(name)) { auto &factory = ModuleFactory::getInstance(); std::vector inputAddress; + ModuleInfo m; - module_.push_back(factory.create(type, name)); - moduleType_.push_back(type); - moduleName_.push_back(name); - moduleAddress_[name] = module_.size() - 1; - module_.back()->parseParameters(reader, "options"); - auto input = module_.back()->getInput(); + m.data = factory.create(type, name); + m.type = typeIdPt(*m.data.get()); + m.name = name; + m.data->parseParameters(reader, "options"); + auto input = m.data->getInput(); for (auto &in: input) { if (!hasObject(in)) { addObject(in , -1); } - inputAddress.push_back(objectAddress_[in]); + m.input.push_back(objectAddress_[in]); } - moduleInput_.push_back(inputAddress); - auto output = module_.back()->getOutput(); + auto output = m.data->getOutput(); + module_.push_back(std::move(m)); + moduleAddress_[name] = module_.size() - 1; for (auto &out: output) { if (!hasObject(out)) @@ -180,16 +169,16 @@ void Environment::createModule(const std::string name, const std::string type, } else { - if (objectModule_[objectAddress_[out]] < 0) + if (object_[objectAddress_[out]].module < 0) { - objectModule_[objectAddress_[out]] = module_.size() - 1; + object_[objectAddress_[out]].module = module_.size() - 1; } else { HADRON_ERROR("object '" + out - + "' is already produced by module '" - + moduleName_[objectModule_[getObjectAddress(out)]] - + "' (while creating module '" + name + "')"); + + "' is already produced by module '" + + module_[object_[getObjectAddress(out)].module].name + + "' (while creating module '" + name + "')"); } } } @@ -204,7 +193,7 @@ ModuleBase * Environment::getModule(const unsigned int address) const { if (hasModule(address)) { - return module_[address].get(); + return module_[address].data.get(); } else { @@ -233,7 +222,7 @@ std::string Environment::getModuleName(const unsigned int address) const { if (hasModule(address)) { - return moduleName_[address]; + return module_[address].name; } else { @@ -245,7 +234,7 @@ std::string Environment::getModuleType(const unsigned int address) const { if (hasModule(address)) { - return moduleType_[address]; + return module_[address].type->name(); } else { @@ -275,9 +264,9 @@ Graph Environment::makeModuleGraph(void) const for (unsigned int i = 0; i < module_.size(); ++i) { moduleGraph.addVertex(i); - for (auto &j: moduleInput_[i]) + for (auto &j: module_[i].input) { - moduleGraph.addEdge(objectModule_[j], i); + moduleGraph.addEdge(object_[j].module, i); } } @@ -301,10 +290,10 @@ unsigned int Environment::executeProgram(const std::vector &p) { auto pred = [i, this](const unsigned int j) { - auto &in = moduleInput_[j]; + auto &in = module_[j].input; auto it = std::find(in.begin(), in.end(), i); - return (it != in.end()) or (j == objectModule_[i]); + return (it != in.end()) or (j == object_[i].module); }; auto it = std::find_if(p.rbegin(), p.rend(), pred); if (it != p.rend()) @@ -320,10 +309,10 @@ unsigned int Environment::executeProgram(const std::vector &p) if (!isDryRun()) { LOG(Message) << SEP << " Measurement step " << i+1 << "/" - << p.size() << " (module '" << moduleName_[p[i]] + << p.size() << " (module '" << module_[p[i]].name << "') " << SEP << std::endl; } - (*module_[p[i]])(); + (*module_[p[i]].data)(); sizeBefore = getTotalSize(); // print used memory after execution if (!isDryRun()) @@ -369,9 +358,9 @@ unsigned int Environment::executeProgram(const std::vector &p) } } // print used memory after garbage collection if necessary - sizeAfter = getTotalSize(); if (!isDryRun()) { + sizeAfter = getTotalSize(); if (sizeBefore != sizeAfter) { LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) @@ -399,204 +388,17 @@ unsigned int Environment::executeProgram(const std::vector &p) return executeProgram(pAddress); } -// lattice store /////////////////////////////////////////////////////////////// -void Environment::freeLattice(const unsigned int address) -{ - if (hasLattice(address)) - { - if (!isDryRun()) - { - LOG(Message) << "Freeing lattice '" << objectName_[address] - << "'" << std::endl; - } - lattice_.erase(address); - object_[address] = ObjInfo(); - } - else - { - HADRON_ERROR("trying to free unknown lattice (address " - + std::to_string(address) + ")"); - } -} - -bool Environment::hasLattice(const unsigned int address) const -{ - return (hasRegisteredObject(address) - and (lattice_.find(address) != lattice_.end())); -} - -bool Environment::hasLattice(const std::string name) const -{ - if (hasObject(name)) - { - return hasLattice(getObjectAddress(name)); - } - else - { - return false; - } -} - -// fermion actions ///////////////////////////////////////////////////////////// -void Environment::addFermionMatrix(const std::string name, FMat *fMat) -{ - if (hasRegisteredObject(name)) - { - fMat_[getObjectAddress(name)].reset(fMat); - } - else - { - HADRON_ERROR("no object named '" << name << "'"); - } -} - -Environment::FMat * Environment::getFermionMatrix(const std::string name) const -{ - unsigned int i; - - if (hasFermionMatrix(name)) - { - i = getObjectAddress(name); - - return fMat_.at(i).get(); - } - else - { - if (hasSolver(name)) - { - i = getObjectAddress(solverAction_.at(name)); - - return fMat_.at(i).get(); - } - else - { - HADRON_ERROR("no action/solver with name '" << name << "'"); - } - } -} - -bool Environment::hasFermionMatrix(const unsigned int address) const -{ - return (hasRegisteredObject(address) - and (fMat_.find(address) != fMat_.end())); -} - -bool Environment::hasFermionMatrix(const std::string name) const -{ - if (hasObject(name)) - { - return hasFermionMatrix(getObjectAddress(name)); - } - else - { - return false; - } -} - -void Environment::freeFermionMatrix(const unsigned int address) -{ - if (hasFermionMatrix(address)) - { - if (!isDryRun()) - { - LOG(Message) << "Freeing fermion matrix '" << objectName_[address] - << "'" << std::endl; - } - fMat_.erase(address); - object_[address] = ObjInfo(); - } - else - { - HADRON_ERROR("trying to free unknown fermion matrix (address " - + std::to_string(address) + ")"); - } -} - -void Environment::freeFermionMatrix(const std::string name) -{ - freeFermionMatrix(getObjectAddress(name)); -} - -// solvers ///////////////////////////////////////////////////////////////////// -void Environment::addSolver(const std::string name, Solver s) -{ - auto address = getObjectAddress(name); - - if (hasRegisteredObject(address)) - { - solver_[address] = s; - } - else - { - HADRON_ERROR("object with name '" + name - + "' exsists but is not registered"); - } -} - -bool Environment::hasSolver(const unsigned int address) const -{ - return (hasRegisteredObject(address) - and (solver_.find(address) != solver_.end())); -} - -bool Environment::hasSolver(const std::string name) const -{ - if (hasObject(name)) - { - return hasSolver(getObjectAddress(name)); - } - else - { - return false; - } -} - -void Environment::setSolverAction(const std::string name, - const std::string actionName) -{ - if (hasObject(name)) - { - solverAction_[name] = actionName; - } - else - { - HADRON_ERROR("no object named '" << name << "'"); - } -} - -std::string Environment::getSolverAction(const std::string name) const -{ - if (hasObject(name)) - { - try - { - return solverAction_.at(name); - } - catch (std::out_of_range &) - { - HADRON_ERROR("no action registered for solver '" << name << "'") - } - } - else - { - HADRON_ERROR("no object with name '" << name << "'"); - } -} - -void Environment::callSolver(const std::string name, LatticeFermion &sol, - const LatticeFermion &source) const -{ - if (hasSolver(name)) - { - solver_.at(getObjectAddress(name))(sol, source); - } - else - { - HADRON_ERROR("no solver with name '" << name << "'"); - } -} - // general memory management /////////////////////////////////////////////////// +void Environment::addObject(const std::string name, const int moduleAddress) +{ + ObjInfo info; + + info.name = name; + info.module = moduleAddress; + object_.push_back(std::move(info)); + objectAddress_[name] = object_.size() - 1; +} + void Environment::registerObject(const unsigned int address, const unsigned int size, const unsigned int Ls) { @@ -604,12 +406,9 @@ void Environment::registerObject(const unsigned int address, { if (hasObject(address)) { - ObjInfo info; - - info.size = size; - info.Ls = Ls; - info.isRegistered = true; - object_[address] = info; + object_[address].size = size; + object_[address].Ls = Ls; + object_[address].isRegistered = true; } else { @@ -645,7 +444,7 @@ std::string Environment::getObjectName(const unsigned int address) const { if (hasObject(address)) { - return objectName_[address]; + return object_[address].name; } else { @@ -653,6 +452,28 @@ std::string Environment::getObjectName(const unsigned int address) const } } +std::string Environment::getObjectType(const unsigned int address) const +{ + if (hasRegisteredObject(address)) + { + return object_[address].type->name(); + } + else if (hasObject(address)) + { + HADRON_ERROR("object with address " + std::to_string(address) + + " exists but is not registered"); + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); + } +} + +std::string Environment::getObjectType(const std::string name) const +{ + return getObjectType(getObjectAddress(name)); +} + unsigned int Environment::getObjectSize(const unsigned int address) const { if (hasRegisteredObject(address)) @@ -662,7 +483,7 @@ unsigned int Environment::getObjectSize(const unsigned int address) const else if (hasObject(address)) { HADRON_ERROR("object with address " + std::to_string(address) - + " exsists but is not registered"); + + " exists but is not registered"); } else { @@ -684,7 +505,7 @@ unsigned int Environment::getObjectLs(const unsigned int address) const else if (hasObject(address)) { HADRON_ERROR("object with address " + std::to_string(address) - + " exsists but is not registered"); + + " exists but is not registered"); } else { @@ -761,8 +582,22 @@ long unsigned int Environment::getTotalSize(void) const void Environment::addOwnership(const unsigned int owner, const unsigned int property) { - owners_[property].insert(owner); - properties_[owner].insert(property); + if (hasObject(property)) + { + object_[property].owners.insert(owner); + } + else + { + HADRON_ERROR("no object with address " + std::to_string(property)); + } + if (hasObject(owner)) + { + object_[owner].properties.insert(property); + } + else + { + HADRON_ERROR("no object with address " + std::to_string(owner)); + } } void Environment::addOwnership(const std::string owner, @@ -776,7 +611,7 @@ bool Environment::hasOwners(const unsigned int address) const if (hasObject(address)) { - return (!owners_[address].empty()); + return (!object_[address].owners.empty()); } else { @@ -793,23 +628,22 @@ bool Environment::freeObject(const unsigned int address) { if (!hasOwners(address)) { - for (auto &p: properties_[address]) + if (!isDryRun()) { - owners_[p].erase(address); + LOG(Message) << "Destroying object '" << object_[address].name + << "'" << std::endl; } - properties_[address].clear(); - if (hasLattice(address)) + for (auto &p: object_[address].properties) { - freeLattice(address); - } - else if (hasFermionMatrix(address)) - { - freeFermionMatrix(address); - } - else if (hasObject(address)) - { - object_[address] = ObjInfo(); + object_[p].owners.erase(address); } + object_[address].size = 0; + object_[address].Ls = 0; + object_[address].isRegistered = false; + object_[address].type = nullptr; + object_[address].owners.clear(); + object_[address].properties.clear(); + object_[address].data.reset(nullptr); return true; } @@ -826,12 +660,10 @@ bool Environment::freeObject(const std::string name) void Environment::freeAll(void) { - lattice_.clear(); - fMat_.clear(); - solver_.clear(); - solverAction_.clear(); - owners_.clear(); - properties_.clear(); + for (unsigned int i = 0; i < object_.size(); ++i) + { + freeObject(i); + } } void Environment::printContent(void) @@ -840,13 +672,13 @@ void Environment::printContent(void) for (unsigned int i = 0; i < module_.size(); ++i) { LOG(Message) << std::setw(4) << std::right << i << ": " - << moduleName_[i] << " (" - << moduleType_[i] << ")" << std::endl; + << getModuleName(i) << " (" + << getModuleType(i) << ")" << std::endl; } LOG(Message) << "Objects: " << std::endl; for (unsigned int i = 0; i < object_.size(); ++i) { LOG(Message) << std::setw(4) << std::right << i << ": " - << objectName_[i] << std::endl; + << getObjectName(i) << std::endl; } } diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 8c5c6021..f7076b8c 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -39,6 +39,27 @@ BEGIN_HADRONS_NAMESPACE // forward declaration of Module class ModuleBase; +class Object +{ +public: + Object(void) = default; + virtual ~Object(void) = default; +}; + +template +class Holder: public Object +{ +public: + Holder(void) = default; + Holder(T *pt); + virtual ~Holder(void) = default; + T & get(void) const; + T * getPt(void) const; + void reset(T *pt); +private: + std::unique_ptr objPt_{nullptr}; +}; + class Environment { SINGLETON(Environment); @@ -53,10 +74,22 @@ public: typedef std::unique_ptr RngPt; typedef std::unique_ptr LatticePt; private: + struct ModuleInfo + { + const std::type_info *type{nullptr}; + std::string name; + std::unique_ptr data{nullptr}; + std::vector input; + }; struct ObjInfo { - unsigned int size{0}, Ls{0}; - bool isRegistered{false}; + unsigned int size{0}, Ls{0}; + bool isRegistered{false}; + const std::type_info *type{nullptr}; + std::string name; + int module{-1}; + std::set owners, properties; + std::unique_ptr data{nullptr}; }; public: // dry run @@ -91,35 +124,9 @@ public: Graph makeModuleGraph(void) const; unsigned int executeProgram(const std::vector &p); unsigned int executeProgram(const std::vector &p); - // lattice store - template - T * create(const std::string name); - template - T * get(const std::string name) const; - bool hasLattice(const unsigned int address) const; - bool hasLattice(const std::string name) const; - void freeLattice(const unsigned int address); - void freeLattice(const std::string name); - template - unsigned int lattice4dSize(void) const; - // fermion actions - void addFermionMatrix(const std::string name, FMat *mat); - FMat * getFermionMatrix(const std::string name) const; - bool hasFermionMatrix(const unsigned int address) const; - bool hasFermionMatrix(const std::string name) const; - void freeFermionMatrix(const unsigned int address); - void freeFermionMatrix(const std::string name); - // solvers - void addSolver(const std::string name, Solver s); - bool hasSolver(const unsigned int address) const; - bool hasSolver(const std::string name) const; - void setSolverAction(const std::string name, - const std::string actionName); - std::string getSolverAction(const std::string name) const; - void callSolver(const std::string name, - LatticeFermion &sol, - const LatticeFermion &src) const; // general memory management + void addObject(const std::string name, + const int moduleAddress); void registerObject(const unsigned int address, const unsigned int size, const unsigned int Ls = 1); @@ -127,13 +134,29 @@ public: const unsigned int size, const unsigned int Ls = 1); template + unsigned int lattice4dSize(void) const; + template void registerLattice(const unsigned int address, const unsigned int Ls = 1); template void registerLattice(const std::string name, const unsigned int Ls = 1); + template + void setObject(const unsigned int address, T *object); + template + void setObject(const std::string name, T *object); + template + T * getObject(const unsigned int address) const; + template + T * getObject(const std::string name) const; + template + T * createLattice(const unsigned int address); + template + T * createLattice(const std::string name); unsigned int getObjectAddress(const std::string name) const; std::string getObjectName(const unsigned int address) const; + std::string getObjectType(const unsigned int address) const; + std::string getObjectType(const std::string name) const; unsigned int getObjectSize(const unsigned int address) const; unsigned int getObjectSize(const std::string name) const; unsigned int getObjectLs(const unsigned int address) const; @@ -167,11 +190,8 @@ private: // random number generator RngPt rng4d_; // module and related maps - std::vector module_; - std::vector moduleType_; - std::vector moduleName_; + std::vector module_; std::map moduleAddress_; - std::vector> moduleInput_; // lattice store std::map lattice_; // fermion matrix store @@ -179,18 +199,37 @@ private: // solver store & solver/action map std::map solver_; std::map solverAction_; - // object register + // object store std::vector object_; - std::vector objectName_; std::map objectAddress_; - std::vector objectModule_; - std::vector> owners_; - std::vector> properties_; }; /****************************************************************************** * template implementation * ******************************************************************************/ +template +Holder::Holder(T *pt) +: objPt_(pt) +{} + +template +T & Holder::get(void) const +{ + return &objPt_.get(); +} + +template +T * Holder::getPt(void) const +{ + return objPt_.get(); +} + +template +void Holder::reset(T *pt) +{ + objPt_.reset(pt); +} + template M * Environment::getModule(const unsigned int address) const { @@ -200,9 +239,9 @@ M * Environment::getModule(const unsigned int address) const } else { - HADRON_ERROR("module '" + moduleName_[address] + "' does not have type " - + typeName() + "(object type: " - + typeName(*module_.at(address).get()) + ")"); + HADRON_ERROR("module '" + module_[address].name + + "' does not have type " + typeid(M).name() + + "(object type: " + getModuleType(address) + ")"); } } @@ -218,56 +257,93 @@ unsigned int Environment::lattice4dSize(void) const return sizeof(typename T::vector_object)/getGrid()->Nsimd(); } -template -T * Environment::create(const std::string name) -{ - auto i = getObjectAddress(name); - GridCartesian *g = getGrid(getObjectLs(i)); - - lattice_[i].reset(new T(g)); - - return dynamic_cast(lattice_[i].get()); -} - -template -T * Environment::get(const std::string name) const -{ - if (hasLattice(name)) - { - auto i = getObjectAddress(name); - - if (auto pt = dynamic_cast(lattice_.at(i).get())) - { - return pt; - } - else - { - HADRON_ERROR("object '" + name + "' does not have type " - + typeName() + "(object type: " - + typeName(*lattice_.at(i).get()) + ")"); - } - } - else - { - HADRON_ERROR("no lattice with name '" + name + "'"); - - return nullptr; - } -} - template void Environment::registerLattice(const unsigned int address, const unsigned int Ls) { createGrid(Ls); - registerObject(address, Ls*lattice4dSize()); + registerObject(address, Ls*lattice4dSize(), Ls); } template void Environment::registerLattice(const std::string name, const unsigned int Ls) { createGrid(Ls); - registerObject(name, Ls*lattice4dSize()); + registerObject(name, Ls*lattice4dSize(), Ls); +} + +template +void Environment::setObject(const unsigned int address, T *object) +{ + if (hasRegisteredObject(address)) + { + object_[address].data.reset(new Holder(object)); + object_[address].type = &typeid(T); + } + else if (hasObject(address)) + { + HADRON_ERROR("object with address " + std::to_string(address) + + " exists but is not registered"); + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); + } +} + +template +void Environment::setObject(const std::string name, T *object) +{ + setObject(getObjectAddress(name), object); +} + +template +T * Environment::getObject(const unsigned int address) const +{ + if (hasRegisteredObject(address)) + { + if (auto h = dynamic_cast *>(object_[address].data.get())) + { + return h->getPt(); + } + else + { + HADRON_ERROR("object with address " + std::to_string(address) + + " does not have type '" + typeid(T).name() + + "' (has type '" + getObjectType(address) + "')"); + } + } + else if (hasObject(address)) + { + HADRON_ERROR("object with address " + std::to_string(address) + + " exists but is not registered"); + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); + } +} + +template +T * Environment::getObject(const std::string name) const +{ + return getObject(getObjectAddress(name)); +} + +template +T * Environment::createLattice(const unsigned int address) +{ + GridCartesian *g = getGrid(getObjectLs(address)); + + setObject(address, new T(g)); + + return getObject(address); +} + +template +T * Environment::createLattice(const std::string name) +{ + return createLattice(getObjectAddress(name)); } END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index c42753c1..716aaed9 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -111,6 +111,18 @@ std::string typeName(void) return name; } +template +const std::type_info * typeIdPt(const T &x) +{ + return &typeid(x); +} + +template +const std::type_info * typeName(void) +{ + return &typeid(T); +} + END_HADRONS_NAMESPACE #endif // Hadrons_Global_hpp_ diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index c2bebd93..2ea1cf21 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -55,6 +55,10 @@ static mod##ModuleRegistrar mod##ModuleRegistrarInstance; // base class class ModuleBase { +public: + // convenient type shortcuts + typedef Environment::FMat FMat; + typedef Environment::Solver Solver; public: // constructor ModuleBase(const std::string name); @@ -99,7 +103,19 @@ private: }; // no parameter type -typedef Serializable NoPar; +class NoPar {}; + +template <> +class Module: public ModuleBase +{ +public: + // constructor + Module(const std::string name): ModuleBase(name) {}; + // destructor + virtual ~Module(void) = default; + // parse parameters (do nothing) + virtual void parseParameters(XmlReader &reader, const std::string name) {}; +}; /****************************************************************************** * Template implementation * diff --git a/programs/Hadrons/Modules/ADWF.cc b/programs/Hadrons/Modules/ADWF.cc index f579c0b7..a52caf40 100644 --- a/programs/Hadrons/Modules/ADWF.cc +++ b/programs/Hadrons/Modules/ADWF.cc @@ -65,19 +65,17 @@ void ADWF::setup(void) // execution /////////////////////////////////////////////////////////////////// void ADWF::execute(void) { - env().createGrid(par().Ls); - - auto &U = *env().get(par().gauge); - auto &g4 = *env().getGrid(); - auto &grb4 = *env().getRbGrid(); - auto &g5 = *env().getGrid(par().Ls); - auto &grb5 = *env().getRbGrid(par().Ls); - auto fMatPt = new DomainWallFermionR(U, g5, grb5, g4, grb4, - par().mass, par().M5); - LOG(Message) << "Setting up domain wall fermion matrix with m= " << par().mass << ", M5= " << par().M5 << " and Ls= " << par().Ls << " using gauge field '" << par().gauge << "'" << std::endl; - env().addFermionMatrix(getName(), fMatPt); + env().createGrid(par().Ls); + auto &U = *env().getObject(par().gauge); + auto &g4 = *env().getGrid(); + auto &grb4 = *env().getRbGrid(); + auto &g5 = *env().getGrid(par().Ls); + auto &grb5 = *env().getRbGrid(par().Ls); + FMat *fMatPt = new DomainWallFermionR(U, g5, grb5, g4, grb4, par().mass, + par().M5); + env().setObject(getName(), fMatPt); } diff --git a/programs/Hadrons/Modules/AWilson.cc b/programs/Hadrons/Modules/AWilson.cc index 9b7c1b04..e5a41bfd 100644 --- a/programs/Hadrons/Modules/AWilson.cc +++ b/programs/Hadrons/Modules/AWilson.cc @@ -65,13 +65,11 @@ void AWilson::setup(void) // execution /////////////////////////////////////////////////////////////////// void AWilson::execute() { - auto &U = *env().get(par().gauge); - auto &grid = *env().getGrid(); - auto &gridRb = *env().getRbGrid(); - auto fMatPt = new WilsonFermionR(U, grid, gridRb, par().mass); - unsigned int size; - LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass << " using gauge field '" << par().gauge << "'" << std::endl; - env().addFermionMatrix(getName(), fMatPt); + auto &U = *env().getObject(par().gauge); + auto &grid = *env().getGrid(); + auto &gridRb = *env().getRbGrid(); + FMat *fMatPt = new WilsonFermionR(U, grid, gridRb, par().mass); + env().setObject(getName(), fMatPt); } diff --git a/programs/Hadrons/Modules/CMeson.cc b/programs/Hadrons/Modules/CMeson.cc index 53088c43..5e8d6d0c 100644 --- a/programs/Hadrons/Modules/CMeson.cc +++ b/programs/Hadrons/Modules/CMeson.cc @@ -62,8 +62,8 @@ void CMeson::execute(void) << std::endl; XmlWriter writer(par().output); - LatticePropagator &q1 = *env().get(par().q1); - LatticePropagator &q2 = *env().get(par().q2); + LatticePropagator &q1 = *env().getObject(par().q1); + LatticePropagator &q2 = *env().getObject(par().q2); LatticeComplex c(env().getGrid()); SpinMatrix g[Ns*Ns], g5; std::vector buf; diff --git a/programs/Hadrons/Modules/GLoad.cc b/programs/Hadrons/Modules/GLoad.cc index 590c4135..69aa6c9b 100644 --- a/programs/Hadrons/Modules/GLoad.cc +++ b/programs/Hadrons/Modules/GLoad.cc @@ -68,7 +68,7 @@ void GLoad::execute(void) LOG(Message) << "Loading NERSC configuration from file '" << fileName << "'" << std::endl; - LatticeGaugeField &U = *env().create(getName()); + LatticeGaugeField &U = *env().createLattice(getName()); NerscIO::readConfiguration(U, header, fileName); LOG(Message) << "NERSC header:" << std::endl; dump_nersc_header(header, LOG(Message)); diff --git a/programs/Hadrons/Modules/GRandom.cc b/programs/Hadrons/Modules/GRandom.cc index f40c8121..57b4efa9 100644 --- a/programs/Hadrons/Modules/GRandom.cc +++ b/programs/Hadrons/Modules/GRandom.cc @@ -61,6 +61,6 @@ void GRandom::setup(void) void GRandom::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; - LatticeGaugeField &U = *env().create(getName()); + LatticeGaugeField &U = *env().createLattice(getName()); SU3::HotConfiguration(*env().get4dRng(), U); } diff --git a/programs/Hadrons/Modules/GUnit.cc b/programs/Hadrons/Modules/GUnit.cc index 20d815f1..9e660799 100644 --- a/programs/Hadrons/Modules/GUnit.cc +++ b/programs/Hadrons/Modules/GUnit.cc @@ -61,6 +61,6 @@ void GUnit::setup(void) void GUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; - LatticeGaugeField &U = *env().create(getName()); + LatticeGaugeField &U = *env().createLattice(getName()); SU3::ColdConfiguration(*env().get4dRng(), U); } diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index f3f1da06..a1940771 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -57,7 +57,7 @@ std::vector MQuark::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void MQuark::setup(void) { - Ls_ = env().getObjectLs(env().getSolverAction(par().solver)); + Ls_ = env().getObjectLs(par().solver); env().registerLattice(getName()); if (Ls_ > 1) { @@ -74,11 +74,12 @@ void MQuark::execute(void) LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; - LatticePropagator &prop = *env().create(propName); - LatticePropagator &fullSrc = *env().get(par().source); + LatticePropagator &prop = *env().createLattice(propName); + LatticePropagator &fullSrc = *env().getObject(par().source); + Environment::Solver &solver = *env().getObject(par().solver); if (Ls_ > 1) { - env().create(getName()); + env().createLattice(getName()); } LOG(Message) << "Inverting using solver '" << par().solver @@ -86,6 +87,8 @@ void MQuark::execute(void) for (unsigned int s = 0; s < Ns; ++s) for (unsigned int c = 0; c < Nc; ++c) { + LOG(Message) << "Inversion for spin= " << s << ", color= " << c + << std::endl; // source conversion for 4D sources if (!env().isObject5d(par().source)) { @@ -116,12 +119,12 @@ void MQuark::execute(void) } } sol = zero; - env().callSolver(par().solver, sol, source); + solver(sol, source); FermToProp(prop, sol, s, c); // create 4D propagators from 5D one if necessary if (Ls_ > 1) { - LatticePropagator &p4d = *env().get(getName()); + LatticePropagator &p4d = *env().getObject(getName()); axpby_ssp_pminus(sol, 0., sol, 1., sol, 0, 0); axpby_ssp_pplus(sol, 0., sol, 1., sol, 0, Ls_-1); diff --git a/programs/Hadrons/Modules/SolRBPrecCG.cc b/programs/Hadrons/Modules/SolRBPrecCG.cc index 14a09be5..8a1c7449 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.cc +++ b/programs/Hadrons/Modules/SolRBPrecCG.cc @@ -57,15 +57,16 @@ std::vector SolRBPrecCG::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void SolRBPrecCG::setup(void) { - env().registerObject(getName(), 0); + auto Ls = env().getObjectLs(par().action); + + env().registerObject(getName(), 0, Ls); env().addOwnership(getName(), par().action); - env().setSolverAction(getName(), par().action); } // execution /////////////////////////////////////////////////////////////////// void SolRBPrecCG::execute(void) { - auto &mat = *(env().getFermionMatrix(par().action)); + auto &mat = *(env().getObject(par().action)); auto solver = [&mat, this](LatticeFermion &sol, const LatticeFermion &source) { @@ -78,5 +79,5 @@ void SolRBPrecCG::execute(void) LOG(Message) << "setting up Schur red-black preconditioned CG for" << " action '" << par().action << "' with residual " << par().residual << std::endl; - env().addSolver(getName(), solver); + env().setObject(getName(), new Environment::Solver(solver)); } diff --git a/programs/Hadrons/Modules/SrcPoint.cc b/programs/Hadrons/Modules/SrcPoint.cc index 3b7c3d10..34f1825e 100644 --- a/programs/Hadrons/Modules/SrcPoint.cc +++ b/programs/Hadrons/Modules/SrcPoint.cc @@ -67,7 +67,7 @@ void SrcPoint::execute(void) LOG(Message) << "Creating point source at position [" << par().position << "]" << std::endl; - LatticePropagator &src = *env().create(getName()); + LatticePropagator &src = *env().createLattice(getName()); id = 1.; src = zero; pokeSite(id, src, position); diff --git a/programs/Hadrons/Modules/SrcZ2.cc b/programs/Hadrons/Modules/SrcZ2.cc index c77c2943..a614526d 100644 --- a/programs/Hadrons/Modules/SrcZ2.cc +++ b/programs/Hadrons/Modules/SrcZ2.cc @@ -77,7 +77,7 @@ void SrcZ2::execute(void) LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " << par().tB << std::endl; } - LatticePropagator &src = *env().create(getName()); + LatticePropagator &src = *env().createLattice(getName()); LatticeCoordinate(t, Tp); bernoulli(*env().get4dRng(), eta); eta = (2.*eta - shift)*(1./::sqrt(2.)); From 0b731b5d8030ea6f7287794cdc74d76096eef416 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 6 Jun 2016 17:46:53 +0100 Subject: [PATCH 056/106] Hadrons: genetic scheduler parameter fix --- programs/Hadrons/Application.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index f45ca066..4bb300e9 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -127,7 +127,7 @@ void Application::schedule(void) // constrained topological sort using a genetic algorithm LOG(Message) << "Scheduling computation..." << std::endl; - constexpr unsigned int maxGen = 2000000, maxCstGen = 2000000; + constexpr unsigned int maxGen = 200, maxCstGen = 50; unsigned int k = 0, gen, prevPeak, nCstPeak = 0; auto graph = env_.makeModuleGraph(); auto con = graph.getConnectedComponents(); From a2e9430abec0d82251b60c0afa8bc1f6cec605fe Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 3 Aug 2016 17:14:32 +0100 Subject: [PATCH 057/106] Hadrons: fix after build system update --- programs/Hadrons/Global.hpp | 5 ++--- programs/Hadrons/Makefile.am | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 716aaed9..21e7ac7c 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -30,8 +30,7 @@ directory. #include #include -#include -#include +#include #define BEGIN_HADRONS_NAMESPACE \ namespace Grid {\ @@ -50,7 +49,7 @@ class HadronsLogger: public Logger { public: HadronsLogger(int on, std::string nm): Logger("Hadrons", on, nm, - Logger::BLACK){}; + GridLogColours, "BLACK"){}; }; #define LOG(channel) std::cout << HadronsLog##channel diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 64ad5252..2372c025 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -1,5 +1,4 @@ -AM_CXXFLAGS = -I$(top_srcdir)/programs -I../$(top_srcdir)/programs -I$(top_srcdir)/lib -AM_LDFLAGS = -L$(top_builddir)/lib +AM_CXXFLAGS += -I$(top_srcdir)/programs -I../$(top_srcdir)/programs bin_PROGRAMS = Hadrons From 1aa695cd78839f15c968c131574bed620421bac8 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 10 Nov 2016 18:38:30 +0000 Subject: [PATCH 058/106] Hadrons: merge typo --- programs/Hadrons/Module.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 2ea1cf21..21f374e0 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -128,7 +128,7 @@ Module

::Module(const std::string name) template void Module

::parseParameters(XmlReader &reader, const std::string name) { - read(reader, name, par_);read(reader, name, par_); + read(reader, name, par_); } template From a8843c9af672013797624b79e873e5c64f6208f3 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 27 Nov 2016 16:47:22 +0900 Subject: [PATCH 059/106] Code cleaning, the fermion implementation can be sepcified using the macro FIMPL --- lib/Log.h | 4 ++-- programs/Hadrons/Application.cc | 2 +- programs/Hadrons/Environment.cc | 4 ++-- programs/Hadrons/Environment.hpp | 17 +++++++---------- programs/Hadrons/Global.hpp | 5 +++++ programs/Hadrons/Module.hpp | 4 ---- programs/Hadrons/Modules/ADWF.hpp | 2 ++ programs/Hadrons/Modules/AWilson.hpp | 2 ++ programs/Hadrons/Modules/MQuark.cc | 2 +- programs/Hadrons/Modules/MQuark.hpp | 7 +++++-- programs/Hadrons/Modules/SolRBPrecCG.cc | 4 ++-- programs/Hadrons/Modules/SolRBPrecCG.hpp | 4 ++++ 12 files changed, 33 insertions(+), 24 deletions(-) diff --git a/lib/Log.h b/lib/Log.h index d7422ca9..8dce0acd 100644 --- a/lib/Log.h +++ b/lib/Log.h @@ -110,8 +110,8 @@ public: friend std::ostream& operator<< (std::ostream& stream, Logger& log){ if ( log.active ) { - stream << log.background()<< log.topName << log.background()<< " : "; - stream << log.colour() < ModPt; typedef std::unique_ptr GridPt; typedef std::unique_ptr GridRbPt; - typedef FermionOperator FMat; - typedef std::unique_ptr FMatPt; - typedef std::function Solver; typedef std::unique_ptr RngPt; typedef std::unique_ptr LatticePt; private: @@ -194,24 +190,21 @@ private: std::map moduleAddress_; // lattice store std::map lattice_; - // fermion matrix store - std::map fMat_; - // solver store & solver/action map - std::map solver_; - std::map solverAction_; // object store std::vector object_; std::map objectAddress_; }; /****************************************************************************** - * template implementation * + * Holder template implementation * ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// template Holder::Holder(T *pt) : objPt_(pt) {} +// access ////////////////////////////////////////////////////////////////////// template T & Holder::get(void) const { @@ -230,6 +223,10 @@ void Holder::reset(T *pt) objPt_.reset(pt); } +/****************************************************************************** + * Environment template implementation * + ******************************************************************************/ +// module management /////////////////////////////////////////////////////////// template M * Environment::getModule(const unsigned int address) const { diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 21e7ac7c..3f60122c 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -43,6 +43,11 @@ using Grid::operator<<; * error with GCC (clang compiles fine without it). */ +// FIXME: find a way to do that in a more general fashion +#ifndef FIMPL +#define FIMPL WilsonImplR +#endif + BEGIN_HADRONS_NAMESPACE class HadronsLogger: public Logger diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 21f374e0..1a219c59 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -55,10 +55,6 @@ static mod##ModuleRegistrar mod##ModuleRegistrarInstance; // base class class ModuleBase { -public: - // convenient type shortcuts - typedef Environment::FMat FMat; - typedef Environment::Solver Solver; public: // constructor ModuleBase(const std::string name); diff --git a/programs/Hadrons/Modules/ADWF.hpp b/programs/Hadrons/Modules/ADWF.hpp index 0f4f5402..6e2da691 100644 --- a/programs/Hadrons/Modules/ADWF.hpp +++ b/programs/Hadrons/Modules/ADWF.hpp @@ -49,6 +49,8 @@ public: class ADWF: public Module { +public: + typedef FermionOperator FMat; public: // constructor ADWF(const std::string name); diff --git a/programs/Hadrons/Modules/AWilson.hpp b/programs/Hadrons/Modules/AWilson.hpp index cb35525e..dd5708ea 100644 --- a/programs/Hadrons/Modules/AWilson.hpp +++ b/programs/Hadrons/Modules/AWilson.hpp @@ -47,6 +47,8 @@ public: class AWilson: public Module { +public: + typedef FermionOperator FMat; public: // constructor AWilson(const std::string name); diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index a1940771..195b558f 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -76,7 +76,7 @@ void MQuark::execute(void) << std::endl; LatticePropagator &prop = *env().createLattice(propName); LatticePropagator &fullSrc = *env().getObject(par().source); - Environment::Solver &solver = *env().getObject(par().solver); + Solver &solver = *env().getObject(par().solver); if (Ls_ > 1) { env().createLattice(getName()); diff --git a/programs/Hadrons/Modules/MQuark.hpp b/programs/Hadrons/Modules/MQuark.hpp index 0080090b..f28a49a8 100644 --- a/programs/Hadrons/Modules/MQuark.hpp +++ b/programs/Hadrons/Modules/MQuark.hpp @@ -47,6 +47,9 @@ public: class MQuark: public Module { +public: + typedef FIMPL::FermionField FermionField; + typedef std::function Solver; public: // constructor MQuark(const std::string name); @@ -60,8 +63,8 @@ public: // execution virtual void execute(void); private: - unsigned int Ls_; - Environment::Solver *solver_{nullptr}; + unsigned int Ls_; + Solver *solver_{nullptr}; }; MODULE_REGISTER(MQuark); diff --git a/programs/Hadrons/Modules/SolRBPrecCG.cc b/programs/Hadrons/Modules/SolRBPrecCG.cc index 8a1c7449..d93b39a8 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.cc +++ b/programs/Hadrons/Modules/SolRBPrecCG.cc @@ -66,7 +66,7 @@ void SolRBPrecCG::setup(void) // execution /////////////////////////////////////////////////////////////////// void SolRBPrecCG::execute(void) { - auto &mat = *(env().getObject(par().action)); + auto &mat = *(env().getObject(par().action)); auto solver = [&mat, this](LatticeFermion &sol, const LatticeFermion &source) { @@ -79,5 +79,5 @@ void SolRBPrecCG::execute(void) LOG(Message) << "setting up Schur red-black preconditioned CG for" << " action '" << par().action << "' with residual " << par().residual << std::endl; - env().setObject(getName(), new Environment::Solver(solver)); + env().setObject(getName(), new Solver(solver)); } diff --git a/programs/Hadrons/Modules/SolRBPrecCG.hpp b/programs/Hadrons/Modules/SolRBPrecCG.hpp index b987eb95..39f241dc 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.hpp +++ b/programs/Hadrons/Modules/SolRBPrecCG.hpp @@ -47,6 +47,10 @@ public: class SolRBPrecCG: public Module { +public: + typedef FermionOperator FMat; + typedef FIMPL::FermionField FermionField; + typedef std::function Solver; public: // constructor SolRBPrecCG(const std::string name); From fabcd4179d49aff6f047b46445fba099dcc38094 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 28 Nov 2016 14:02:10 +0900 Subject: [PATCH 060/106] Hadrons: propagator type coming from the fermion implementation --- lib/qcd/action/fermion/FermionOperatorImpl.h | 17 +++++++++++++++-- programs/Hadrons/Global.hpp | 7 +++++++ programs/Hadrons/Modules/ADWF.hpp | 2 -- programs/Hadrons/Modules/AWilson.hpp | 2 -- programs/Hadrons/Modules/CMeson.cc | 4 ++-- programs/Hadrons/Modules/MQuark.hpp | 3 --- programs/Hadrons/Modules/SolRBPrecCG.hpp | 4 ---- programs/Hadrons/Modules/SrcPoint.cc | 4 ++-- programs/Hadrons/Modules/SrcZ2.cc | 4 ++-- 9 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/qcd/action/fermion/FermionOperatorImpl.h b/lib/qcd/action/fermion/FermionOperatorImpl.h index 0800dea6..07eee6be 100644 --- a/lib/qcd/action/fermion/FermionOperatorImpl.h +++ b/lib/qcd/action/fermion/FermionOperatorImpl.h @@ -48,8 +48,10 @@ namespace QCD { // typedef typename XXX GaugeField; // typedef typename XXX GaugeActField; // typedef typename XXX FermionField; + // typedef typename XXX PropagatorField; // typedef typename XXX DoubledGaugeField; // typedef typename XXX SiteSpinor; + // typedef typename XXX SitePropagator; // typedef typename XXX SiteHalfSpinor; // typedef typename XXX Compressor; // @@ -95,13 +97,15 @@ namespace QCD { #define INHERIT_FIMPL_TYPES(Impl)\ typedef typename Impl::FermionField FermionField; \ + typedef typename Impl::PropagatorField PropagatorField; \ typedef typename Impl::DoubledGaugeField DoubledGaugeField; \ typedef typename Impl::SiteSpinor SiteSpinor; \ + typedef typename Impl::SitePropagator SitePropagator; \ typedef typename Impl::SiteHalfSpinor SiteHalfSpinor; \ typedef typename Impl::Compressor Compressor; \ typedef typename Impl::StencilImpl StencilImpl; \ - typedef typename Impl::ImplParams ImplParams; \ - typedef typename Impl::Coeff_t Coeff_t; + typedef typename Impl::ImplParams ImplParams; \ + typedef typename Impl::Coeff_t Coeff_t; \ #define INHERIT_IMPL_TYPES(Base) \ INHERIT_GIMPL_TYPES(Base) \ @@ -127,14 +131,17 @@ namespace QCD { INHERIT_GIMPL_TYPES(Gimpl); template using iImplSpinor = iScalar, Ns> >; + template using iImplPropagator = iScalar, Ns> >; template using iImplHalfSpinor = iScalar, Nhs> >; template using iImplDoubledGaugeField = iVector >, Nds>; typedef iImplSpinor SiteSpinor; + typedef iImplPropagator SitePropagator; typedef iImplHalfSpinor SiteHalfSpinor; typedef iImplDoubledGaugeField SiteDoubledGaugeField; typedef Lattice FermionField; + typedef Lattice PropagatorField; typedef Lattice DoubledGaugeField; typedef WilsonCompressor Compressor; @@ -216,14 +223,17 @@ class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Nrepres INHERIT_GIMPL_TYPES(Gimpl); template using iImplSpinor = iScalar, Ns> >; + template using iImplPropagator = iScalar, Ns> >; template using iImplHalfSpinor = iScalar, Nhs> >; template using iImplDoubledGaugeField = iVector >, Nds>; template using iImplGaugeField = iVector >, Nd>; template using iImplGaugeLink = iScalar > >; typedef iImplSpinor SiteSpinor; + typedef iImplPropagator SitePropagator; typedef iImplHalfSpinor SiteHalfSpinor; typedef Lattice FermionField; + typedef Lattice PropagatorField; // Make the doubled gauge field a *scalar* typedef iImplDoubledGaugeField SiteDoubledGaugeField; // This is a scalar @@ -315,14 +325,17 @@ class GparityWilsonImpl : public ConjugateGaugeImpl using iImplSpinor = iVector, Ns>, Ngp>; + template using iImplPropagator = iVector, Ns>, Ngp >; template using iImplHalfSpinor = iVector, Nhs>, Ngp>; template using iImplDoubledGaugeField = iVector >, Nds>, Ngp>; typedef iImplSpinor SiteSpinor; + typedef iImplPropagator SitePropagator; typedef iImplHalfSpinor SiteHalfSpinor; typedef iImplDoubledGaugeField SiteDoubledGaugeField; typedef Lattice FermionField; + typedef Lattice PropagatorField; typedef Lattice DoubledGaugeField; typedef WilsonCompressor Compressor; diff --git a/programs/Hadrons/Global.hpp b/programs/Hadrons/Global.hpp index 3f60122c..0936f3ba 100644 --- a/programs/Hadrons/Global.hpp +++ b/programs/Hadrons/Global.hpp @@ -50,6 +50,13 @@ using Grid::operator<<; BEGIN_HADRONS_NAMESPACE +// type aliases +typedef FermionOperator FMat; +typedef FIMPL::FermionField FermionField; +typedef FIMPL::PropagatorField PropagatorField; +typedef std::function Solver; + +// logger class HadronsLogger: public Logger { public: diff --git a/programs/Hadrons/Modules/ADWF.hpp b/programs/Hadrons/Modules/ADWF.hpp index 6e2da691..0f4f5402 100644 --- a/programs/Hadrons/Modules/ADWF.hpp +++ b/programs/Hadrons/Modules/ADWF.hpp @@ -49,8 +49,6 @@ public: class ADWF: public Module { -public: - typedef FermionOperator FMat; public: // constructor ADWF(const std::string name); diff --git a/programs/Hadrons/Modules/AWilson.hpp b/programs/Hadrons/Modules/AWilson.hpp index dd5708ea..cb35525e 100644 --- a/programs/Hadrons/Modules/AWilson.hpp +++ b/programs/Hadrons/Modules/AWilson.hpp @@ -47,8 +47,6 @@ public: class AWilson: public Module { -public: - typedef FermionOperator FMat; public: // constructor AWilson(const std::string name); diff --git a/programs/Hadrons/Modules/CMeson.cc b/programs/Hadrons/Modules/CMeson.cc index 5e8d6d0c..c1cf153e 100644 --- a/programs/Hadrons/Modules/CMeson.cc +++ b/programs/Hadrons/Modules/CMeson.cc @@ -62,8 +62,8 @@ void CMeson::execute(void) << std::endl; XmlWriter writer(par().output); - LatticePropagator &q1 = *env().getObject(par().q1); - LatticePropagator &q2 = *env().getObject(par().q2); + PropagatorField &q1 = *env().getObject(par().q1); + PropagatorField &q2 = *env().getObject(par().q2); LatticeComplex c(env().getGrid()); SpinMatrix g[Ns*Ns], g5; std::vector buf; diff --git a/programs/Hadrons/Modules/MQuark.hpp b/programs/Hadrons/Modules/MQuark.hpp index f28a49a8..526815ef 100644 --- a/programs/Hadrons/Modules/MQuark.hpp +++ b/programs/Hadrons/Modules/MQuark.hpp @@ -47,9 +47,6 @@ public: class MQuark: public Module { -public: - typedef FIMPL::FermionField FermionField; - typedef std::function Solver; public: // constructor MQuark(const std::string name); diff --git a/programs/Hadrons/Modules/SolRBPrecCG.hpp b/programs/Hadrons/Modules/SolRBPrecCG.hpp index 39f241dc..b987eb95 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.hpp +++ b/programs/Hadrons/Modules/SolRBPrecCG.hpp @@ -47,10 +47,6 @@ public: class SolRBPrecCG: public Module { -public: - typedef FermionOperator FMat; - typedef FIMPL::FermionField FermionField; - typedef std::function Solver; public: // constructor SolRBPrecCG(const std::string name); diff --git a/programs/Hadrons/Modules/SrcPoint.cc b/programs/Hadrons/Modules/SrcPoint.cc index 34f1825e..ca9c1345 100644 --- a/programs/Hadrons/Modules/SrcPoint.cc +++ b/programs/Hadrons/Modules/SrcPoint.cc @@ -56,7 +56,7 @@ std::vector SrcPoint::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void SrcPoint::setup(void) { - env().registerLattice(getName()); + env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -67,7 +67,7 @@ void SrcPoint::execute(void) LOG(Message) << "Creating point source at position [" << par().position << "]" << std::endl; - LatticePropagator &src = *env().createLattice(getName()); + PropagatorField &src = *env().createLattice(getName()); id = 1.; src = zero; pokeSite(id, src, position); diff --git a/programs/Hadrons/Modules/SrcZ2.cc b/programs/Hadrons/Modules/SrcZ2.cc index a614526d..74e3add0 100644 --- a/programs/Hadrons/Modules/SrcZ2.cc +++ b/programs/Hadrons/Modules/SrcZ2.cc @@ -56,7 +56,7 @@ std::vector SrcZ2::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void SrcZ2::setup(void) { - env().registerLattice(getName()); + env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -77,7 +77,7 @@ void SrcZ2::execute(void) LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " << par().tB << std::endl; } - LatticePropagator &src = *env().createLattice(getName()); + PropagatorField &src = *env().createLattice(getName()); LatticeCoordinate(t, Tp); bernoulli(*env().get4dRng(), eta); eta = (2.*eta - shift)*(1./::sqrt(2.)); From 43928846f2512088625644af060d9c22f83ce77b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 28 Nov 2016 16:02:15 +0900 Subject: [PATCH 061/106] first steps to make Hadrons a library --- lib/Hadrons | 1 + programs/Hadrons/Application.cc | 36 ++++++++++++----- programs/Hadrons/Application.hpp | 50 ++++++++++++------------ programs/Hadrons/Environment.cc | 33 ++++++++++------ programs/Hadrons/Environment.hpp | 36 ++++++++++++++--- programs/Hadrons/Factory.hpp | 2 +- programs/Hadrons/GeneticScheduler.hpp | 4 +- programs/Hadrons/Global.cc | 2 +- programs/Hadrons/Graph.hpp | 2 +- programs/Hadrons/Hadrons.cc | 2 +- programs/Hadrons/Makefile.am | 27 +++++++++---- programs/Hadrons/Module.cc | 2 +- programs/Hadrons/Module.hpp | 4 +- programs/Hadrons/ModuleFactory.hpp | 6 +-- programs/Hadrons/Modules/ADWF.cc | 2 +- programs/Hadrons/Modules/ADWF.hpp | 6 +-- programs/Hadrons/Modules/AWilson.cc | 2 +- programs/Hadrons/Modules/AWilson.hpp | 6 +-- programs/Hadrons/Modules/CMeson.cc | 2 +- programs/Hadrons/Modules/CMeson.hpp | 6 +-- programs/Hadrons/Modules/GLoad.cc | 2 +- programs/Hadrons/Modules/GLoad.hpp | 6 +-- programs/Hadrons/Modules/GRandom.cc | 2 +- programs/Hadrons/Modules/GRandom.hpp | 6 +-- programs/Hadrons/Modules/GUnit.cc | 2 +- programs/Hadrons/Modules/GUnit.hpp | 6 +-- programs/Hadrons/Modules/MQuark.cc | 2 +- programs/Hadrons/Modules/MQuark.hpp | 6 +-- programs/Hadrons/Modules/SolRBPrecCG.cc | 2 +- programs/Hadrons/Modules/SolRBPrecCG.hpp | 6 +-- programs/Hadrons/Modules/SrcPoint.cc | 2 +- programs/Hadrons/Modules/SrcPoint.hpp | 6 +-- programs/Hadrons/Modules/SrcZ2.cc | 2 +- programs/Hadrons/Modules/SrcZ2.hpp | 6 +-- programs/Hadrons/make_module_list.sh | 8 +++- programs/Hadrons/modules.inc | 15 ++++++- 36 files changed, 194 insertions(+), 116 deletions(-) create mode 120000 lib/Hadrons diff --git a/lib/Hadrons b/lib/Hadrons new file mode 120000 index 00000000..5343d55a --- /dev/null +++ b/lib/Hadrons @@ -0,0 +1 @@ +../programs/Hadrons \ No newline at end of file diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index fe1c21a0..a89d7034 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include -#include +#include +#include using namespace Grid; using namespace QCD; @@ -38,10 +38,9 @@ using namespace Hadrons; /****************************************************************************** * Application implementation * ******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -Application::Application(const std::string parameterFileName) -: parameterFileName_(parameterFileName) -, env_(Environment::getInstance()) +// constructors //////////////////////////////////////////////////////////////// +Application::Application(void) +: env_(Environment::getInstance()) { LOG(Message) << "Modules available:" << std::endl; auto list = ModuleFactory::getInstance().getBuilderList(); @@ -61,14 +60,31 @@ Application::Application(const std::string parameterFileName) LOG(Message) << "Local lattice : " << loc << std::endl; } -// destructor ////////////////////////////////////////////////////////////////// -Application::~Application(void) -{} +Application::Application(const Application::GlobalPar &par) +: Application() +{ + setPar(par); +} + +Application::Application(const std::string parameterFileName) +: Application() +{ + parameterFileName_ = parameterFileName; +} + +// access ////////////////////////////////////////////////////////////////////// +void Application::setPar(const Application::GlobalPar &par) +{ + par_ = par; +} // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { - parseParameterFile(); + if (!parameterFileName_.empty()) + { + parseParameterFile(); + } schedule(); configLoop(); } diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 20716adf..2ce8d694 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -28,44 +28,44 @@ directory. #ifndef Hadrons_Application_hpp_ #define Hadrons_Application_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE -class TrajRange: Serializable -{ -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange, - unsigned int, start, - unsigned int, end, - unsigned int, step); -}; - -class GlobalPar: Serializable -{ -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, - TrajRange, trajCounter, - std::string, seed); -}; - /****************************************************************************** * Main program manager * ******************************************************************************/ class Application { public: - + class TrajRange: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange, + unsigned int, start, + unsigned int, end, + unsigned int, step); + }; + class GlobalPar: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, + TrajRange, trajCounter, + std::string, seed); + }; public: - // constructor + // constructors + Application(void); + Application(const GlobalPar &par); Application(const std::string parameterFileName); // destructor - virtual ~Application(void); + virtual ~Application(void) = default; + // access + void setPar(const GlobalPar &par); // execute void run(void); -private: // parse parameter file void parseParameterFile(void); // schedule computation @@ -74,7 +74,7 @@ private: void configLoop(void); private: long unsigned int locVol_; - std::string parameterFileName_; + std::string parameterFileName_{""}; GlobalPar par_; Environment &env_; std::vector program_; diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 402543df..e9c7c733 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -25,9 +25,9 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include -#include -#include +#include +#include +#include using namespace Grid; using namespace QCD; @@ -136,19 +136,18 @@ GridParallelRNG * Environment::get4dRng(void) const } // module management /////////////////////////////////////////////////////////// -void Environment::createModule(const std::string name, const std::string type, - XmlReader &reader) +void Environment::pushModule(Environment::ModPt &pt) { + std::string name = pt->getName(); + if (!hasModule(name)) { - auto &factory = ModuleFactory::getInstance(); std::vector inputAddress; ModuleInfo m; - - m.data = factory.create(type, name); + + m.data = std::move(pt); m.type = typeIdPt(*m.data.get()); m.name = name; - m.data->parseParameters(reader, "options"); auto input = m.data->getInput(); for (auto &in: input) { @@ -176,9 +175,9 @@ void Environment::createModule(const std::string name, const std::string type, else { HADRON_ERROR("object '" + out - + "' is already produced by module '" - + module_[object_[getObjectAddress(out)].module].name - + "' (while creating module '" + name + "')"); + + "' is already produced by module '" + + module_[object_[getObjectAddress(out)].module].name + + "' (while pushing module '" + name + "')"); } } } @@ -189,6 +188,16 @@ void Environment::createModule(const std::string name, const std::string type, } } +void Environment::createModule(const std::string name, const std::string type, + XmlReader &reader) +{ + auto &factory = ModuleFactory::getInstance(); + auto pt = factory.create(type, name); + + pt->parseParameters(reader, "options"); + pushModule(pt); +} + ModuleBase * Environment::getModule(const unsigned int address) const { if (hasModule(address)) diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 6d8d2b23..baea4550 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -28,8 +28,8 @@ directory. #ifndef Hadrons_Environment_hpp_ #define Hadrons_Environment_hpp_ -#include -#include +#include +#include BEGIN_HADRONS_NAMESPACE @@ -72,10 +72,10 @@ public: private: struct ModuleInfo { - const std::type_info *type{nullptr}; - std::string name; - std::unique_ptr data{nullptr}; - std::vector input; + const std::type_info *type{nullptr}; + std::string name; + ModPt data{nullptr}; + std::vector input; }; struct ObjInfo { @@ -102,6 +102,12 @@ public: void setSeed(const std::vector &seed); GridParallelRNG * get4dRng(void) const; // module management + void pushModule(ModPt &pt); + template + void createModule(const std::string name); + template + void createModule(const std::string name, + const typename M::Par &par); void createModule(const std::string name, const std::string type, XmlReader &reader); @@ -227,6 +233,24 @@ void Holder::reset(T *pt) * Environment template implementation * ******************************************************************************/ // module management /////////////////////////////////////////////////////////// +template +void Environment::createModule(const std::string name) +{ + ModPt pt(new M(name)); + + pushModule(pt); +} + +template +void Environment::createModule(const std::string name, + const typename M::Par &par) +{ + ModPt pt(new M(name)); + + pt->setPar(par); + pushModule(pt); +} + template M * Environment::getModule(const unsigned int address) const { diff --git a/programs/Hadrons/Factory.hpp b/programs/Hadrons/Factory.hpp index e609949a..ea358c21 100644 --- a/programs/Hadrons/Factory.hpp +++ b/programs/Hadrons/Factory.hpp @@ -28,7 +28,7 @@ directory. #ifndef Hadrons_Factory_hpp_ #define Hadrons_Factory_hpp_ -#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/GeneticScheduler.hpp b/programs/Hadrons/GeneticScheduler.hpp index 026ee303..3d75f2a4 100644 --- a/programs/Hadrons/GeneticScheduler.hpp +++ b/programs/Hadrons/GeneticScheduler.hpp @@ -28,8 +28,8 @@ directory. #ifndef Hadrons_GeneticScheduler_hpp_ #define Hadrons_GeneticScheduler_hpp_ -#include -#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Global.cc b/programs/Hadrons/Global.cc index a13efec1..62997e1f 100644 --- a/programs/Hadrons/Global.cc +++ b/programs/Hadrons/Global.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 78b43452..37ad077d 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -28,7 +28,7 @@ directory. #ifndef Hadrons_Graph_hpp_ #define Hadrons_Graph_hpp_ -#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Hadrons.cc b/programs/Hadrons/Hadrons.cc index 97b8686c..ad43b6cc 100644 --- a/programs/Hadrons/Hadrons.cc +++ b/programs/Hadrons/Hadrons.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am index 2372c025..cdf7a166 100644 --- a/programs/Hadrons/Makefile.am +++ b/programs/Hadrons/Makefile.am @@ -1,15 +1,26 @@ -AM_CXXFLAGS += -I$(top_srcdir)/programs -I../$(top_srcdir)/programs +lib_LIBRARIES = libHadrons.a bin_PROGRAMS = Hadrons include modules.inc -Hadrons_SOURCES = \ - $(modules) \ - Application.cc \ - Environment.cc \ - Global.cc \ - Hadrons.cc \ +libHadrons_a_SOURCES = \ + $(modules_cc) \ + Application.cc \ + Environment.cc \ + Global.cc \ Module.cc +libHadrons_adir = $(pkgincludedir)/Hadrons +nobase_libHadrons_a_HEADERS = \ + $(modules_hpp) \ + Application.hpp \ + Environment.hpp \ + Factory.hpp \ + GeneticScheduler.hpp \ + Global.hpp \ + Graph.hpp \ + Module.hpp \ + ModuleFactory.hpp -Hadrons_LDADD = -lGrid +Hadrons_SOURCES = Hadrons.cc +Hadrons_LDADD = libHadrons.a -lGrid diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index 6669a861..e8a80f07 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 1a219c59..60dcc936 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -28,8 +28,8 @@ directory. #ifndef Hadrons_Module_hpp_ #define Hadrons_Module_hpp_ -#include -#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/ModuleFactory.hpp b/programs/Hadrons/ModuleFactory.hpp index 0169ef94..01cc130c 100644 --- a/programs/Hadrons/ModuleFactory.hpp +++ b/programs/Hadrons/ModuleFactory.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_ModuleFactory_hpp_ #define Hadrons_ModuleFactory_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/ADWF.cc b/programs/Hadrons/Modules/ADWF.cc index a52caf40..c7fba722 100644 --- a/programs/Hadrons/Modules/ADWF.cc +++ b/programs/Hadrons/Modules/ADWF.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Modules/ADWF.hpp b/programs/Hadrons/Modules/ADWF.hpp index 0f4f5402..159d5b20 100644 --- a/programs/Hadrons/Modules/ADWF.hpp +++ b/programs/Hadrons/Modules/ADWF.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_ADWF_hpp_ #define Hadrons_ADWF_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/AWilson.cc b/programs/Hadrons/Modules/AWilson.cc index e5a41bfd..a27a258d 100644 --- a/programs/Hadrons/Modules/AWilson.cc +++ b/programs/Hadrons/Modules/AWilson.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Modules/AWilson.hpp b/programs/Hadrons/Modules/AWilson.hpp index cb35525e..93986315 100644 --- a/programs/Hadrons/Modules/AWilson.hpp +++ b/programs/Hadrons/Modules/AWilson.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_AWilson_hpp_ #define Hadrons_AWilson_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/CMeson.cc b/programs/Hadrons/Modules/CMeson.cc index c1cf153e..fef8179d 100644 --- a/programs/Hadrons/Modules/CMeson.cc +++ b/programs/Hadrons/Modules/CMeson.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/Modules/CMeson.hpp b/programs/Hadrons/Modules/CMeson.hpp index 1cbd6d86..2e9daa6d 100644 --- a/programs/Hadrons/Modules/CMeson.hpp +++ b/programs/Hadrons/Modules/CMeson.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_CMeson_hpp_ #define Hadrons_CMeson_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/GLoad.cc b/programs/Hadrons/Modules/GLoad.cc index 69aa6c9b..b81307cd 100644 --- a/programs/Hadrons/Modules/GLoad.cc +++ b/programs/Hadrons/Modules/GLoad.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Modules/GLoad.hpp b/programs/Hadrons/Modules/GLoad.hpp index af01e40e..9a089b61 100644 --- a/programs/Hadrons/Modules/GLoad.hpp +++ b/programs/Hadrons/Modules/GLoad.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_GLoad_hpp_ #define Hadrons_GLoad_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/GRandom.cc b/programs/Hadrons/Modules/GRandom.cc index 57b4efa9..7f5af2c2 100644 --- a/programs/Hadrons/Modules/GRandom.cc +++ b/programs/Hadrons/Modules/GRandom.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Modules/GRandom.hpp b/programs/Hadrons/Modules/GRandom.hpp index a31028fd..6c42372e 100644 --- a/programs/Hadrons/Modules/GRandom.hpp +++ b/programs/Hadrons/Modules/GRandom.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_GRandom_hpp_ #define Hadrons_GRandom_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/GUnit.cc b/programs/Hadrons/Modules/GUnit.cc index 9e660799..34f134fe 100644 --- a/programs/Hadrons/Modules/GUnit.cc +++ b/programs/Hadrons/Modules/GUnit.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Modules/GUnit.hpp b/programs/Hadrons/Modules/GUnit.hpp index eff34020..31b53a35 100644 --- a/programs/Hadrons/Modules/GUnit.hpp +++ b/programs/Hadrons/Modules/GUnit.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_GUnit_hpp_ #define Hadrons_GUnit_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index 195b558f..8f730b58 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/Modules/MQuark.hpp b/programs/Hadrons/Modules/MQuark.hpp index 526815ef..f217e338 100644 --- a/programs/Hadrons/Modules/MQuark.hpp +++ b/programs/Hadrons/Modules/MQuark.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_MQuark_hpp_ #define Hadrons_MQuark_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/SolRBPrecCG.cc b/programs/Hadrons/Modules/SolRBPrecCG.cc index d93b39a8..7a7aa69d 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.cc +++ b/programs/Hadrons/Modules/SolRBPrecCG.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; diff --git a/programs/Hadrons/Modules/SolRBPrecCG.hpp b/programs/Hadrons/Modules/SolRBPrecCG.hpp index b987eb95..7482a70c 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.hpp +++ b/programs/Hadrons/Modules/SolRBPrecCG.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_SolRBPrecCG_hpp_ #define Hadrons_SolRBPrecCG_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/SrcPoint.cc b/programs/Hadrons/Modules/SrcPoint.cc index ca9c1345..a060b5d7 100644 --- a/programs/Hadrons/Modules/SrcPoint.cc +++ b/programs/Hadrons/Modules/SrcPoint.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Modules/SrcPoint.hpp b/programs/Hadrons/Modules/SrcPoint.hpp index 75108319..8c1efce0 100644 --- a/programs/Hadrons/Modules/SrcPoint.hpp +++ b/programs/Hadrons/Modules/SrcPoint.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_SrcPoint_hpp_ #define Hadrons_SrcPoint_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules/SrcZ2.cc b/programs/Hadrons/Modules/SrcZ2.cc index 74e3add0..ec555a08 100644 --- a/programs/Hadrons/Modules/SrcZ2.cc +++ b/programs/Hadrons/Modules/SrcZ2.cc @@ -25,7 +25,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/programs/Hadrons/Modules/SrcZ2.hpp b/programs/Hadrons/Modules/SrcZ2.hpp index a61f8688..bf0aebc0 100644 --- a/programs/Hadrons/Modules/SrcZ2.hpp +++ b/programs/Hadrons/Modules/SrcZ2.hpp @@ -28,9 +28,9 @@ directory. #ifndef Hadrons_SrcZ2_hpp_ #define Hadrons_SrcZ2_hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/make_module_list.sh b/programs/Hadrons/make_module_list.sh index 78ed8040..0733efcb 100755 --- a/programs/Hadrons/make_module_list.sh +++ b/programs/Hadrons/make_module_list.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash -echo 'modules =\' > modules.inc -find Modules -name '*.cc' -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> modules.inc \ No newline at end of file +echo 'modules_cc =\' > modules.inc +find Modules -name '*.cc' -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> modules.inc +echo '' >> modules.inc +echo 'modules_hpp =\' >> modules.inc +find Modules -name '*.hpp' -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> modules.inc +echo '' >> modules.inc diff --git a/programs/Hadrons/modules.inc b/programs/Hadrons/modules.inc index 6ca8329e..9040c406 100644 --- a/programs/Hadrons/modules.inc +++ b/programs/Hadrons/modules.inc @@ -1,4 +1,4 @@ -modules =\ +modules_cc =\ Modules/ADWF.cc \ Modules/AWilson.cc \ Modules/CMeson.cc \ @@ -9,3 +9,16 @@ modules =\ Modules/SolRBPrecCG.cc \ Modules/SrcPoint.cc \ Modules/SrcZ2.cc + +modules_hpp =\ + Modules/ADWF.hpp \ + Modules/AWilson.hpp \ + Modules/CMeson.hpp \ + Modules/GLoad.hpp \ + Modules/GRandom.hpp \ + Modules/GUnit.hpp \ + Modules/MQuark.hpp \ + Modules/SolRBPrecCG.hpp \ + Modules/SrcPoint.hpp \ + Modules/SrcZ2.hpp + From d8b716d2cdc958d238c7f31a211decbef3cbe87f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 1 Dec 2016 15:43:16 +0900 Subject: [PATCH 062/106] Hadrons: static initialisation fixed --- programs/Hadrons/Application.hpp | 1 + programs/Hadrons/Modules.hpp | 10 ++++++++++ programs/Hadrons/make_module_list.sh | 4 ++++ 3 files changed, 15 insertions(+) create mode 100644 programs/Hadrons/Modules.hpp diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index 2ce8d694..dd26a5b8 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -31,6 +31,7 @@ directory. #include #include #include +#include BEGIN_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Modules.hpp b/programs/Hadrons/Modules.hpp new file mode 100644 index 00000000..a7a88710 --- /dev/null +++ b/programs/Hadrons/Modules.hpp @@ -0,0 +1,10 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/programs/Hadrons/make_module_list.sh b/programs/Hadrons/make_module_list.sh index 0733efcb..ddc56ff6 100755 --- a/programs/Hadrons/make_module_list.sh +++ b/programs/Hadrons/make_module_list.sh @@ -6,3 +6,7 @@ echo '' >> modules.inc echo 'modules_hpp =\' >> modules.inc find Modules -name '*.hpp' -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> modules.inc echo '' >> modules.inc +rm -f Modules.hpp +for f in `find Modules -name '*.hpp'`; do + echo "#include " >> Modules.hpp +done From 9ad3d3453e2b9b2c79fc11e2904236ed44422ddb Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 1 Dec 2016 21:36:29 +0900 Subject: [PATCH 063/106] Hadrons is now a library, the previous XML driven program is now a test --- Makefile.am | 2 +- configure.ac | 5 +- {programs => extras}/Hadrons/Application.cc | 0 {programs => extras}/Hadrons/Application.hpp | 0 {programs => extras}/Hadrons/Environment.cc | 0 {programs => extras}/Hadrons/Environment.hpp | 0 {programs => extras}/Hadrons/Factory.hpp | 0 .../Hadrons/GeneticScheduler.hpp | 0 {programs => extras}/Hadrons/Global.cc | 0 {programs => extras}/Hadrons/Global.hpp | 0 {programs => extras}/Hadrons/Graph.hpp | 0 {programs => extras}/Hadrons/Hadrons.cc | 0 extras/Hadrons/Makefile.am | 22 +++++++ {programs => extras}/Hadrons/Module.cc | 0 .../Hadrons/Module.cc.template | 0 {programs => extras}/Hadrons/Module.hpp | 0 .../Hadrons/Module.hpp.template | 0 .../Hadrons/ModuleFactory.hpp | 0 {programs => extras}/Hadrons/Modules.hpp | 0 {programs => extras}/Hadrons/Modules/ADWF.cc | 0 {programs => extras}/Hadrons/Modules/ADWF.hpp | 0 .../Hadrons/Modules/AWilson.cc | 0 .../Hadrons/Modules/AWilson.hpp | 0 .../Hadrons/Modules/CMeson.cc | 0 .../Hadrons/Modules/CMeson.hpp | 0 {programs => extras}/Hadrons/Modules/GLoad.cc | 0 .../Hadrons/Modules/GLoad.hpp | 0 .../Hadrons/Modules/GRandom.cc | 0 .../Hadrons/Modules/GRandom.hpp | 0 {programs => extras}/Hadrons/Modules/GUnit.cc | 0 .../Hadrons/Modules/GUnit.hpp | 0 .../Hadrons/Modules/MQuark.cc | 0 .../Hadrons/Modules/MQuark.hpp | 0 .../Hadrons/Modules/SolRBPrecCG.cc | 0 .../Hadrons/Modules/SolRBPrecCG.hpp | 0 .../Hadrons/Modules/SrcPoint.cc | 0 .../Hadrons/Modules/SrcPoint.hpp | 0 {programs => extras}/Hadrons/Modules/SrcZ2.cc | 0 .../Hadrons/Modules/SrcZ2.hpp | 0 {programs => extras}/Hadrons/add_module.sh | 0 .../Hadrons/make_module_list.sh | 0 {programs => extras}/Hadrons/modules.inc | 0 {programs => extras}/Makefile.am | 0 lib/Hadrons | 2 +- programs/Hadrons/Make.inc | 4 -- programs/Hadrons/Makefile.am | 26 -------- scripts/filelist | 5 +- tests/hadrons/Makefile.am | 3 + tests/hadrons/Test_hadrons_xmldriven.cc | 66 +++++++++++++++++++ 49 files changed, 99 insertions(+), 36 deletions(-) rename {programs => extras}/Hadrons/Application.cc (100%) rename {programs => extras}/Hadrons/Application.hpp (100%) rename {programs => extras}/Hadrons/Environment.cc (100%) rename {programs => extras}/Hadrons/Environment.hpp (100%) rename {programs => extras}/Hadrons/Factory.hpp (100%) rename {programs => extras}/Hadrons/GeneticScheduler.hpp (100%) rename {programs => extras}/Hadrons/Global.cc (100%) rename {programs => extras}/Hadrons/Global.hpp (100%) rename {programs => extras}/Hadrons/Graph.hpp (100%) rename {programs => extras}/Hadrons/Hadrons.cc (100%) create mode 100644 extras/Hadrons/Makefile.am rename {programs => extras}/Hadrons/Module.cc (100%) rename {programs => extras}/Hadrons/Module.cc.template (100%) rename {programs => extras}/Hadrons/Module.hpp (100%) rename {programs => extras}/Hadrons/Module.hpp.template (100%) rename {programs => extras}/Hadrons/ModuleFactory.hpp (100%) rename {programs => extras}/Hadrons/Modules.hpp (100%) rename {programs => extras}/Hadrons/Modules/ADWF.cc (100%) rename {programs => extras}/Hadrons/Modules/ADWF.hpp (100%) rename {programs => extras}/Hadrons/Modules/AWilson.cc (100%) rename {programs => extras}/Hadrons/Modules/AWilson.hpp (100%) rename {programs => extras}/Hadrons/Modules/CMeson.cc (100%) rename {programs => extras}/Hadrons/Modules/CMeson.hpp (100%) rename {programs => extras}/Hadrons/Modules/GLoad.cc (100%) rename {programs => extras}/Hadrons/Modules/GLoad.hpp (100%) rename {programs => extras}/Hadrons/Modules/GRandom.cc (100%) rename {programs => extras}/Hadrons/Modules/GRandom.hpp (100%) rename {programs => extras}/Hadrons/Modules/GUnit.cc (100%) rename {programs => extras}/Hadrons/Modules/GUnit.hpp (100%) rename {programs => extras}/Hadrons/Modules/MQuark.cc (100%) rename {programs => extras}/Hadrons/Modules/MQuark.hpp (100%) rename {programs => extras}/Hadrons/Modules/SolRBPrecCG.cc (100%) rename {programs => extras}/Hadrons/Modules/SolRBPrecCG.hpp (100%) rename {programs => extras}/Hadrons/Modules/SrcPoint.cc (100%) rename {programs => extras}/Hadrons/Modules/SrcPoint.hpp (100%) rename {programs => extras}/Hadrons/Modules/SrcZ2.cc (100%) rename {programs => extras}/Hadrons/Modules/SrcZ2.hpp (100%) rename {programs => extras}/Hadrons/add_module.sh (100%) rename {programs => extras}/Hadrons/make_module_list.sh (100%) rename {programs => extras}/Hadrons/modules.inc (100%) rename {programs => extras}/Makefile.am (100%) delete mode 100644 programs/Hadrons/Make.inc delete mode 100644 programs/Hadrons/Makefile.am create mode 100644 tests/hadrons/Makefile.am create mode 100644 tests/hadrons/Test_hadrons_xmldriven.cc diff --git a/Makefile.am b/Makefile.am index fd9671cc..d3401c48 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # additional include paths necessary to compile the C++ library -SUBDIRS = lib benchmarks tests programs +SUBDIRS = lib benchmarks tests extras include $(top_srcdir)/doxygen.inc diff --git a/configure.ac b/configure.ac index 00ef6fdc..19e3f105 100644 --- a/configure.ac +++ b/configure.ac @@ -381,12 +381,13 @@ AC_CONFIG_FILES(tests/IO/Makefile) AC_CONFIG_FILES(tests/core/Makefile) AC_CONFIG_FILES(tests/debug/Makefile) AC_CONFIG_FILES(tests/forces/Makefile) +AC_CONFIG_FILES(tests/hadrons/Makefile) AC_CONFIG_FILES(tests/hmc/Makefile) AC_CONFIG_FILES(tests/solver/Makefile) AC_CONFIG_FILES(tests/qdpxx/Makefile) AC_CONFIG_FILES(benchmarks/Makefile) -AC_CONFIG_FILES(programs/Makefile) -AC_CONFIG_FILES(programs/Hadrons/Makefile) +AC_CONFIG_FILES(extras/Makefile) +AC_CONFIG_FILES(extras/hadrons/Makefile) AC_OUTPUT echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/programs/Hadrons/Application.cc b/extras/Hadrons/Application.cc similarity index 100% rename from programs/Hadrons/Application.cc rename to extras/Hadrons/Application.cc diff --git a/programs/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp similarity index 100% rename from programs/Hadrons/Application.hpp rename to extras/Hadrons/Application.hpp diff --git a/programs/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc similarity index 100% rename from programs/Hadrons/Environment.cc rename to extras/Hadrons/Environment.cc diff --git a/programs/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp similarity index 100% rename from programs/Hadrons/Environment.hpp rename to extras/Hadrons/Environment.hpp diff --git a/programs/Hadrons/Factory.hpp b/extras/Hadrons/Factory.hpp similarity index 100% rename from programs/Hadrons/Factory.hpp rename to extras/Hadrons/Factory.hpp diff --git a/programs/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp similarity index 100% rename from programs/Hadrons/GeneticScheduler.hpp rename to extras/Hadrons/GeneticScheduler.hpp diff --git a/programs/Hadrons/Global.cc b/extras/Hadrons/Global.cc similarity index 100% rename from programs/Hadrons/Global.cc rename to extras/Hadrons/Global.cc diff --git a/programs/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp similarity index 100% rename from programs/Hadrons/Global.hpp rename to extras/Hadrons/Global.hpp diff --git a/programs/Hadrons/Graph.hpp b/extras/Hadrons/Graph.hpp similarity index 100% rename from programs/Hadrons/Graph.hpp rename to extras/Hadrons/Graph.hpp diff --git a/programs/Hadrons/Hadrons.cc b/extras/Hadrons/Hadrons.cc similarity index 100% rename from programs/Hadrons/Hadrons.cc rename to extras/Hadrons/Hadrons.cc diff --git a/extras/Hadrons/Makefile.am b/extras/Hadrons/Makefile.am new file mode 100644 index 00000000..6fd459dc --- /dev/null +++ b/extras/Hadrons/Makefile.am @@ -0,0 +1,22 @@ +lib_LIBRARIES = libHadrons.a + +include modules.inc + +libHadrons_a_SOURCES = \ + $(modules_cc) \ + Application.cc \ + Environment.cc \ + Global.cc \ + Module.cc +libHadrons_adir = $(pkgincludedir)/Hadrons +nobase_libHadrons_a_HEADERS = \ + $(modules_hpp) \ + Application.hpp \ + Environment.hpp \ + Factory.hpp \ + GeneticScheduler.hpp \ + Global.hpp \ + Graph.hpp \ + Module.hpp \ + Modules.hpp \ + ModuleFactory.hpp diff --git a/programs/Hadrons/Module.cc b/extras/Hadrons/Module.cc similarity index 100% rename from programs/Hadrons/Module.cc rename to extras/Hadrons/Module.cc diff --git a/programs/Hadrons/Module.cc.template b/extras/Hadrons/Module.cc.template similarity index 100% rename from programs/Hadrons/Module.cc.template rename to extras/Hadrons/Module.cc.template diff --git a/programs/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp similarity index 100% rename from programs/Hadrons/Module.hpp rename to extras/Hadrons/Module.hpp diff --git a/programs/Hadrons/Module.hpp.template b/extras/Hadrons/Module.hpp.template similarity index 100% rename from programs/Hadrons/Module.hpp.template rename to extras/Hadrons/Module.hpp.template diff --git a/programs/Hadrons/ModuleFactory.hpp b/extras/Hadrons/ModuleFactory.hpp similarity index 100% rename from programs/Hadrons/ModuleFactory.hpp rename to extras/Hadrons/ModuleFactory.hpp diff --git a/programs/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp similarity index 100% rename from programs/Hadrons/Modules.hpp rename to extras/Hadrons/Modules.hpp diff --git a/programs/Hadrons/Modules/ADWF.cc b/extras/Hadrons/Modules/ADWF.cc similarity index 100% rename from programs/Hadrons/Modules/ADWF.cc rename to extras/Hadrons/Modules/ADWF.cc diff --git a/programs/Hadrons/Modules/ADWF.hpp b/extras/Hadrons/Modules/ADWF.hpp similarity index 100% rename from programs/Hadrons/Modules/ADWF.hpp rename to extras/Hadrons/Modules/ADWF.hpp diff --git a/programs/Hadrons/Modules/AWilson.cc b/extras/Hadrons/Modules/AWilson.cc similarity index 100% rename from programs/Hadrons/Modules/AWilson.cc rename to extras/Hadrons/Modules/AWilson.cc diff --git a/programs/Hadrons/Modules/AWilson.hpp b/extras/Hadrons/Modules/AWilson.hpp similarity index 100% rename from programs/Hadrons/Modules/AWilson.hpp rename to extras/Hadrons/Modules/AWilson.hpp diff --git a/programs/Hadrons/Modules/CMeson.cc b/extras/Hadrons/Modules/CMeson.cc similarity index 100% rename from programs/Hadrons/Modules/CMeson.cc rename to extras/Hadrons/Modules/CMeson.cc diff --git a/programs/Hadrons/Modules/CMeson.hpp b/extras/Hadrons/Modules/CMeson.hpp similarity index 100% rename from programs/Hadrons/Modules/CMeson.hpp rename to extras/Hadrons/Modules/CMeson.hpp diff --git a/programs/Hadrons/Modules/GLoad.cc b/extras/Hadrons/Modules/GLoad.cc similarity index 100% rename from programs/Hadrons/Modules/GLoad.cc rename to extras/Hadrons/Modules/GLoad.cc diff --git a/programs/Hadrons/Modules/GLoad.hpp b/extras/Hadrons/Modules/GLoad.hpp similarity index 100% rename from programs/Hadrons/Modules/GLoad.hpp rename to extras/Hadrons/Modules/GLoad.hpp diff --git a/programs/Hadrons/Modules/GRandom.cc b/extras/Hadrons/Modules/GRandom.cc similarity index 100% rename from programs/Hadrons/Modules/GRandom.cc rename to extras/Hadrons/Modules/GRandom.cc diff --git a/programs/Hadrons/Modules/GRandom.hpp b/extras/Hadrons/Modules/GRandom.hpp similarity index 100% rename from programs/Hadrons/Modules/GRandom.hpp rename to extras/Hadrons/Modules/GRandom.hpp diff --git a/programs/Hadrons/Modules/GUnit.cc b/extras/Hadrons/Modules/GUnit.cc similarity index 100% rename from programs/Hadrons/Modules/GUnit.cc rename to extras/Hadrons/Modules/GUnit.cc diff --git a/programs/Hadrons/Modules/GUnit.hpp b/extras/Hadrons/Modules/GUnit.hpp similarity index 100% rename from programs/Hadrons/Modules/GUnit.hpp rename to extras/Hadrons/Modules/GUnit.hpp diff --git a/programs/Hadrons/Modules/MQuark.cc b/extras/Hadrons/Modules/MQuark.cc similarity index 100% rename from programs/Hadrons/Modules/MQuark.cc rename to extras/Hadrons/Modules/MQuark.cc diff --git a/programs/Hadrons/Modules/MQuark.hpp b/extras/Hadrons/Modules/MQuark.hpp similarity index 100% rename from programs/Hadrons/Modules/MQuark.hpp rename to extras/Hadrons/Modules/MQuark.hpp diff --git a/programs/Hadrons/Modules/SolRBPrecCG.cc b/extras/Hadrons/Modules/SolRBPrecCG.cc similarity index 100% rename from programs/Hadrons/Modules/SolRBPrecCG.cc rename to extras/Hadrons/Modules/SolRBPrecCG.cc diff --git a/programs/Hadrons/Modules/SolRBPrecCG.hpp b/extras/Hadrons/Modules/SolRBPrecCG.hpp similarity index 100% rename from programs/Hadrons/Modules/SolRBPrecCG.hpp rename to extras/Hadrons/Modules/SolRBPrecCG.hpp diff --git a/programs/Hadrons/Modules/SrcPoint.cc b/extras/Hadrons/Modules/SrcPoint.cc similarity index 100% rename from programs/Hadrons/Modules/SrcPoint.cc rename to extras/Hadrons/Modules/SrcPoint.cc diff --git a/programs/Hadrons/Modules/SrcPoint.hpp b/extras/Hadrons/Modules/SrcPoint.hpp similarity index 100% rename from programs/Hadrons/Modules/SrcPoint.hpp rename to extras/Hadrons/Modules/SrcPoint.hpp diff --git a/programs/Hadrons/Modules/SrcZ2.cc b/extras/Hadrons/Modules/SrcZ2.cc similarity index 100% rename from programs/Hadrons/Modules/SrcZ2.cc rename to extras/Hadrons/Modules/SrcZ2.cc diff --git a/programs/Hadrons/Modules/SrcZ2.hpp b/extras/Hadrons/Modules/SrcZ2.hpp similarity index 100% rename from programs/Hadrons/Modules/SrcZ2.hpp rename to extras/Hadrons/Modules/SrcZ2.hpp diff --git a/programs/Hadrons/add_module.sh b/extras/Hadrons/add_module.sh similarity index 100% rename from programs/Hadrons/add_module.sh rename to extras/Hadrons/add_module.sh diff --git a/programs/Hadrons/make_module_list.sh b/extras/Hadrons/make_module_list.sh similarity index 100% rename from programs/Hadrons/make_module_list.sh rename to extras/Hadrons/make_module_list.sh diff --git a/programs/Hadrons/modules.inc b/extras/Hadrons/modules.inc similarity index 100% rename from programs/Hadrons/modules.inc rename to extras/Hadrons/modules.inc diff --git a/programs/Makefile.am b/extras/Makefile.am similarity index 100% rename from programs/Makefile.am rename to extras/Makefile.am diff --git a/lib/Hadrons b/lib/Hadrons index 5343d55a..1f422592 120000 --- a/lib/Hadrons +++ b/lib/Hadrons @@ -1 +1 @@ -../programs/Hadrons \ No newline at end of file +../extras/Hadrons \ No newline at end of file diff --git a/programs/Hadrons/Make.inc b/programs/Hadrons/Make.inc deleted file mode 100644 index 13c13c4e..00000000 --- a/programs/Hadrons/Make.inc +++ /dev/null @@ -1,4 +0,0 @@ -bin_PROGRAMS = Hadrons - -Hadrons_SOURCES = Hadrons.cc -Hadrons_LDADD = -lGrid diff --git a/programs/Hadrons/Makefile.am b/programs/Hadrons/Makefile.am deleted file mode 100644 index cdf7a166..00000000 --- a/programs/Hadrons/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ -lib_LIBRARIES = libHadrons.a - -bin_PROGRAMS = Hadrons - -include modules.inc - -libHadrons_a_SOURCES = \ - $(modules_cc) \ - Application.cc \ - Environment.cc \ - Global.cc \ - Module.cc -libHadrons_adir = $(pkgincludedir)/Hadrons -nobase_libHadrons_a_HEADERS = \ - $(modules_hpp) \ - Application.hpp \ - Environment.hpp \ - Factory.hpp \ - GeneticScheduler.hpp \ - Global.hpp \ - Graph.hpp \ - Module.hpp \ - ModuleFactory.hpp - -Hadrons_SOURCES = Hadrons.cc -Hadrons_LDADD = libHadrons.a -lGrid diff --git a/scripts/filelist b/scripts/filelist index dddb605b..ca7425c0 100755 --- a/scripts/filelist +++ b/scripts/filelist @@ -24,10 +24,11 @@ for subdir in $dirs; do echo "tests: ${TESTLIST} ${SUB}" > Make.inc echo ${PREF}_PROGRAMS = ${TESTLIST} >> Make.inc echo >> Make.inc + HADLINK=`[ $subdir = './hadrons' ] && echo '-lHadrons'` for f in $TESTS; do BNAME=`basename $f .cc` - echo ${BNAME}_SOURCES=$f >> Make.inc - echo ${BNAME}_LDADD=-lGrid>> Make.inc + echo ${BNAME}_SOURCES=$f >> Make.inc + echo ${BNAME}_LDADD=-lGrid ${HADLINK} >> Make.inc echo >> Make.inc done if [ $subdir != '.' ]; then diff --git a/tests/hadrons/Makefile.am b/tests/hadrons/Makefile.am new file mode 100644 index 00000000..fae0d212 --- /dev/null +++ b/tests/hadrons/Makefile.am @@ -0,0 +1,3 @@ +AM_LDFLAGS += -L../../extras/hadrons + +include Make.inc diff --git a/tests/hadrons/Test_hadrons_xmldriven.cc b/tests/hadrons/Test_hadrons_xmldriven.cc new file mode 100644 index 00000000..ad43b6cc --- /dev/null +++ b/tests/hadrons/Test_hadrons_xmldriven.cc @@ -0,0 +1,66 @@ +/******************************************************************************* +Grid physics library, www.github.com/paboyle/Grid + +Source file: programs/Hadrons/Hadrons.cc + +Copyright (C) 2015 + +Author: Antonin Portelli + +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. +*******************************************************************************/ + +#include + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // parse command line + std::string parameterFileName; + + if (argc < 2) + { + std::cerr << "usage: " << argv[0] << " [Grid options]"; + std::cerr << std::endl; + std::exit(EXIT_FAILURE); + } + parameterFileName = argv[1]; + + // initialization + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + + // execution + Application application(parameterFileName); + + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} From b5555d85a706d29bcaf2ba5e527c117b3ae6f861 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 2 Dec 2016 11:04:15 +0900 Subject: [PATCH 064/106] Hadrons: generelalised FImpl for actions --- extras/Hadrons/Modules/ADWF.cc | 4 ++-- extras/Hadrons/Modules/AWilson.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extras/Hadrons/Modules/ADWF.cc b/extras/Hadrons/Modules/ADWF.cc index c7fba722..8f83f93f 100644 --- a/extras/Hadrons/Modules/ADWF.cc +++ b/extras/Hadrons/Modules/ADWF.cc @@ -75,7 +75,7 @@ void ADWF::execute(void) auto &grb4 = *env().getRbGrid(); auto &g5 = *env().getGrid(par().Ls); auto &grb5 = *env().getRbGrid(par().Ls); - FMat *fMatPt = new DomainWallFermionR(U, g5, grb5, g4, grb4, par().mass, - par().M5); + FMat *fMatPt = new DomainWallFermion(U, g5, grb5, g4, grb4, + par().mass, par().M5); env().setObject(getName(), fMatPt); } diff --git a/extras/Hadrons/Modules/AWilson.cc b/extras/Hadrons/Modules/AWilson.cc index a27a258d..e55fe988 100644 --- a/extras/Hadrons/Modules/AWilson.cc +++ b/extras/Hadrons/Modules/AWilson.cc @@ -70,6 +70,6 @@ void AWilson::execute() auto &U = *env().getObject(par().gauge); auto &grid = *env().getGrid(); auto &gridRb = *env().getRbGrid(); - FMat *fMatPt = new WilsonFermionR(U, grid, gridRb, par().mass); + FMat *fMatPt = new WilsonFermion(U, grid, gridRb, par().mass); env().setObject(getName(), fMatPt); } From 8190523e4c665023d03b71ad8b411e2530516caf Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 2 Dec 2016 11:04:34 +0900 Subject: [PATCH 065/106] Hadrons: type fix in module creation --- extras/Hadrons/Environment.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index baea4550..aa93eb79 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -245,7 +245,7 @@ template void Environment::createModule(const std::string name, const typename M::Par &par) { - ModPt pt(new M(name)); + std::unique_ptr pt(new M(name)); pt->setPar(par); pushModule(pt); From 1540616b22894574f1c6b5d021b7739b11458144 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 08:53:48 +0900 Subject: [PATCH 066/106] Hadrons: integer types cleanup --- extras/Hadrons/Environment.cc | 25 ++++++++++++++----------- extras/Hadrons/Environment.hpp | 28 +++++++++++++++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index e9c7c733..03f33366 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -143,6 +143,7 @@ void Environment::pushModule(Environment::ModPt &pt) if (!hasModule(name)) { std::vector inputAddress; + unsigned int address; ModuleInfo m; m.data = std::move(pt); @@ -159,18 +160,19 @@ void Environment::pushModule(Environment::ModPt &pt) } auto output = m.data->getOutput(); module_.push_back(std::move(m)); - moduleAddress_[name] = module_.size() - 1; + address = static_cast(module_.size() - 1); + moduleAddress_[name] = address; for (auto &out: output) { if (!hasObject(out)) { - addObject(out , module_.size() - 1); + addObject(out, address); } else { if (object_[objectAddress_[out]].module < 0) { - object_[objectAddress_[out]].module = module_.size() - 1; + object_[objectAddress_[out]].module = address; } else { @@ -287,9 +289,10 @@ Graph Environment::makeModuleGraph(void) const #define MEM_MSG(size)\ sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" -unsigned int Environment::executeProgram(const std::vector &p) +Environment::Size +Environment::executeProgram(const std::vector &p) { - unsigned int memPeak = 0, sizeBefore, sizeAfter; + Size memPeak = 0, sizeBefore, sizeAfter; std::vector> freeProg; bool continueCollect, nothingFreed; @@ -385,7 +388,7 @@ unsigned int Environment::executeProgram(const std::vector &p) return memPeak; } -unsigned int Environment::executeProgram(const std::vector &p) +Environment::Size Environment::executeProgram(const std::vector &p) { std::vector pAddress; @@ -405,7 +408,7 @@ void Environment::addObject(const std::string name, const int moduleAddress) info.name = name; info.module = moduleAddress; object_.push_back(std::move(info)); - objectAddress_[name] = object_.size() - 1; + objectAddress_[name] = static_cast(object_.size() - 1); } void Environment::registerObject(const unsigned int address, @@ -483,7 +486,7 @@ std::string Environment::getObjectType(const std::string name) const return getObjectType(getObjectAddress(name)); } -unsigned int Environment::getObjectSize(const unsigned int address) const +Environment::Size Environment::getObjectSize(const unsigned int address) const { if (hasRegisteredObject(address)) { @@ -500,7 +503,7 @@ unsigned int Environment::getObjectSize(const unsigned int address) const } } -unsigned int Environment::getObjectSize(const std::string name) const +Environment::Size Environment::getObjectSize(const std::string name) const { return getObjectSize(getObjectAddress(name)); } @@ -573,9 +576,9 @@ bool Environment::isObject5d(const std::string name) const return (getObjectLs(name) > 1); } -long unsigned int Environment::getTotalSize(void) const +Environment::Size Environment::getTotalSize(void) const { - long unsigned int size = 0; + Environment::Size size = 0; for (auto &o: object_) { diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index aa93eb79..002d5d9d 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -31,6 +31,10 @@ directory. #include #include +#ifndef SITE_SIZE_TYPE +#define SITE_SIZE_TYPE unsigned int +#endif + BEGIN_HADRONS_NAMESPACE /****************************************************************************** @@ -64,11 +68,12 @@ class Environment { SINGLETON(Environment); public: - typedef std::unique_ptr ModPt; - typedef std::unique_ptr GridPt; - typedef std::unique_ptr GridRbPt; - typedef std::unique_ptr RngPt; - typedef std::unique_ptr LatticePt; + typedef SITE_SIZE_TYPE Size; + typedef std::unique_ptr ModPt; + typedef std::unique_ptr GridPt; + typedef std::unique_ptr GridRbPt; + typedef std::unique_ptr RngPt; + typedef std::unique_ptr LatticePt; private: struct ModuleInfo { @@ -79,7 +84,8 @@ private: }; struct ObjInfo { - unsigned int size{0}, Ls{0}; + Size size{0}; + unsigned int Ls{0}; bool isRegistered{false}; const std::type_info *type{nullptr}; std::string name; @@ -124,8 +130,8 @@ public: bool hasModule(const unsigned int address) const; bool hasModule(const std::string name) const; Graph makeModuleGraph(void) const; - unsigned int executeProgram(const std::vector &p); - unsigned int executeProgram(const std::vector &p); + Size executeProgram(const std::vector &p); + Size executeProgram(const std::vector &p); // general memory management void addObject(const std::string name, const int moduleAddress); @@ -159,8 +165,8 @@ public: std::string getObjectName(const unsigned int address) const; std::string getObjectType(const unsigned int address) const; std::string getObjectType(const std::string name) const; - unsigned int getObjectSize(const unsigned int address) const; - unsigned int getObjectSize(const std::string name) const; + Size getObjectSize(const unsigned int address) const; + Size getObjectSize(const std::string name) const; unsigned int getObjectLs(const unsigned int address) const; unsigned int getObjectLs(const std::string name) const; bool hasObject(const unsigned int address) const; @@ -169,7 +175,7 @@ public: bool hasRegisteredObject(const std::string name) const; bool isObject5d(const unsigned int address) const; bool isObject5d(const std::string name) const; - long unsigned int getTotalSize(void) const; + Environment::Size getTotalSize(void) const; void addOwnership(const unsigned int owner, const unsigned int property); void addOwnership(const std::string owner, From ee5b1fe043e75510838607fe2b7050861ba5e53b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 09:08:45 +0900 Subject: [PATCH 067/106] Hadrons: freeing object message fix --- extras/Hadrons/Environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 03f33366..67880cd3 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -640,7 +640,7 @@ bool Environment::freeObject(const unsigned int address) { if (!hasOwners(address)) { - if (!isDryRun()) + if (!isDryRun() and object_[address].isRegistered) { LOG(Message) << "Destroying object '" << object_[address].name << "'" << std::endl; From 7433eed2740de714098c8aeca349a60a386dc4d9 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 11:44:16 +0900 Subject: [PATCH 068/106] Hadrons: module creation fix --- extras/Hadrons/Application.hpp | 22 ++++++++++++++++++++++ extras/Hadrons/Environment.hpp | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index dd26a5b8..b0c88030 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -65,6 +65,11 @@ public: virtual ~Application(void) = default; // access void setPar(const GlobalPar &par); + // module creation + template + void createModule(const std::string name); + template + void createModule(const std::string name, const typename M::Par &par); // execute void run(void); // parse parameter file @@ -81,6 +86,23 @@ private: std::vector program_; }; +/****************************************************************************** + * Application template implementation * + ******************************************************************************/ +// module creation ///////////////////////////////////////////////////////////// +template +void Application::createModule(const std::string name) +{ + env_.createModule(name); +} + +template +void Application::createModule(const std::string name, + const typename M::Par &par) +{ + env_.createModule(name, par); +} + END_HADRONS_NAMESPACE #endif // Hadrons_Application_hpp_ diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 002d5d9d..88661c2e 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -251,9 +251,9 @@ template void Environment::createModule(const std::string name, const typename M::Par &par) { - std::unique_ptr pt(new M(name)); + ModPt pt(new M(name)); - pt->setPar(par); + static_cast(pt.get())->setPar(par); pushModule(pt); } From a69086ba1f78305aa794959155888e7a2dee85c5 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 11:44:36 +0900 Subject: [PATCH 069/106] Hadrons: application run minor fixes --- extras/Hadrons/Application.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index a89d7034..21f84ad1 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -76,6 +76,7 @@ Application::Application(const std::string parameterFileName) void Application::setPar(const Application::GlobalPar &par) { par_ = par; + env_.setSeed(strToVec(par_.seed)); } // execute ///////////////////////////////////////////////////////////////////// @@ -101,10 +102,12 @@ public: void Application::parseParameterFile(void) { XmlReader reader(parameterFileName_); + GlobalPar par; ObjectId id; LOG(Message) << "Reading '" << parameterFileName_ << "'..." << std::endl; - read(reader, "parameters", par_); + read(reader, "parameters", par); + setPar(par); push(reader, "modules"); push(reader, "module"); do @@ -150,7 +153,7 @@ void Application::schedule(void) std::random_device rd; GeneticScheduler::Parameters par; - par.popSize = 20; + par.popSize = 10; par.mutationRate = .1; par.seed = rd(); CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); @@ -173,6 +176,7 @@ void Application::schedule(void) nCstPeak = 0; } } + LOG(Debug) << "generation " << gen << ":\n" << scheduler; prevPeak = scheduler.getMinValue(); if (gen % 10 == 0) { From 0b4f680d2836589c44b9d7abb49ec2fb52edb83f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 11:44:58 +0900 Subject: [PATCH 070/106] Hadrons: meson run test --- tests/hadrons/Test_hadrons_mesons.cc | 110 +++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/hadrons/Test_hadrons_mesons.cc diff --git a/tests/hadrons/Test_hadrons_mesons.cc b/tests/hadrons/Test_hadrons_mesons.cc new file mode 100644 index 00000000..9c062b39 --- /dev/null +++ b/tests/hadrons/Test_hadrons_mesons.cc @@ -0,0 +1,110 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: programs/Hadrons/Hadrons.cc + + Copyright (C) 2015 + + Author: Antonin Portelli + + 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. + *******************************************************************************/ + +#include + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + + // run setup /////////////////////////////////////////////////////////////// + Application application; + + std::vector flavour = {"l", "s", "c1", "c2", "c3"}; + std::vector mass = {.01, .04, .2 , .25 , .3 }; + + // global parameters + Application::GlobalPar globalPar; + globalPar.trajCounter.start = 1500; + globalPar.trajCounter.end = 1520; + globalPar.trajCounter.step = 20; + globalPar.seed = "1 2 3 4"; + application.setPar(globalPar); + // gauge field + application.createModule("gauge"); + // sources + SrcZ2::Par z2Par; + z2Par.tA = 0; + z2Par.tB = 0; + application.createModule("z2", z2Par); + SrcPoint::Par ptPar; + ptPar.position = "0 0 0 0"; + application.createModule("pt", ptPar); + for (unsigned int i = 0; i < flavour.size(); ++i) + { + // actions + ADWF::Par actionPar; + actionPar.gauge = "gauge"; + actionPar.Ls = 12; + actionPar.M5 = 1.8; + actionPar.mass = mass[i]; + application.createModule("DWF_" + flavour[i], actionPar); + + // solvers + SolRBPrecCG::Par solverPar; + solverPar.action = "DWF_" + flavour[i]; + solverPar.residual = 1.0e-8; + application.createModule("CG_" + flavour[i], solverPar); + + // propagators + MQuark::Par quarkPar; + quarkPar.solver = "CG_" + flavour[i]; + quarkPar.source = (flavour[i][0] == 'c') ? "z2" : "pt"; + application.createModule("Q_" + flavour[i], quarkPar); + } + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i + 1; j < flavour.size(); ++j) + { + CMeson::Par mesPar; + + mesPar.output = "mesons/" + flavour[i] + flavour[j]; + mesPar.q1 = "Q_" + flavour[i]; + mesPar.q2 = "Q_" + flavour[j]; + application.createModule("meson_" + flavour[i] + flavour[j], + mesPar); + } + + // execution + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} From dd6fb140c58bbc5c080e141510cea774798987ff Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 13:53:31 +0900 Subject: [PATCH 071/106] Hadrons: big module reorganisation --- extras/Hadrons/Global.hpp | 2 +- extras/Hadrons/Module.hpp | 17 ++++- extras/Hadrons/Modules.hpp | 18 ++--- .../Modules/{ADWF.cc => MAction/DWF.cc} | 19 +++--- .../Modules/{ADWF.hpp => MAction/DWF.hpp} | 61 ++++++++--------- .../Modules/{AWilson.cc => MAction/Wilson.cc} | 19 +++--- .../{AWilson.hpp => MAction/Wilson.hpp} | 55 ++++++++-------- .../{CMeson.cc => MContraction/Meson.cc} | 17 ++--- .../{CMeson.hpp => MContraction/Meson.hpp} | 65 ++++++++++--------- .../Modules/{GLoad.cc => MGauge/Load.cc} | 19 +++--- .../Modules/{GLoad.hpp => MGauge/Load.hpp} | 53 ++++++++------- .../Modules/{GRandom.cc => MGauge/Random.cc} | 17 ++--- .../{GRandom.hpp => MGauge/Random.hpp} | 41 ++++++------ .../Modules/{GUnit.cc => MGauge/Unit.cc} | 17 ++--- .../Modules/{GUnit.hpp => MGauge/Unit.hpp} | 41 ++++++------ extras/Hadrons/Modules/MQuark.cc | 2 +- extras/Hadrons/Modules/MQuark.hpp | 2 +- .../{SolRBPrecCG.cc => MSolver/RBPrecCG.cc} | 19 +++--- .../{SolRBPrecCG.hpp => MSolver/RBPrecCG.hpp} | 57 ++++++++-------- .../Modules/{SrcPoint.cc => MSource/Point.cc} | 19 +++--- .../{SrcPoint.hpp => MSource/Point.hpp} | 57 ++++++++-------- .../Modules/{SrcZ2.cc => MSource/Z2.cc} | 19 +++--- .../Modules/{SrcZ2.hpp => MSource/Z2.hpp} | 57 ++++++++-------- .../templates}/Module.cc.template | 2 +- .../templates}/Module.hpp.template | 6 +- .../templates/Module_in_NS.cc.template | 40 ++++++++++++ .../templates/Module_in_NS.hpp.template | 43 ++++++++++++ extras/Hadrons/add_module.sh | 30 +++++++-- extras/Hadrons/modules.inc | 36 +++++----- tests/hadrons/Test_hadrons_mesons.cc | 27 ++++---- 30 files changed, 514 insertions(+), 363 deletions(-) rename extras/Hadrons/Modules/{ADWF.cc => MAction/DWF.cc} (87%) rename extras/Hadrons/Modules/{ADWF.hpp => MAction/DWF.hpp} (60%) rename extras/Hadrons/Modules/{AWilson.cc => MAction/Wilson.cc} (85%) rename extras/Hadrons/Modules/{AWilson.hpp => MAction/Wilson.hpp} (62%) rename extras/Hadrons/Modules/{CMeson.cc => MContraction/Meson.cc} (88%) rename extras/Hadrons/Modules/{CMeson.hpp => MContraction/Meson.hpp} (55%) rename extras/Hadrons/Modules/{GLoad.cc => MGauge/Load.cc} (85%) rename extras/Hadrons/Modules/{GLoad.hpp => MGauge/Load.hpp} (65%) rename extras/Hadrons/Modules/{GRandom.cc => MGauge/Random.cc} (83%) rename extras/Hadrons/Modules/{GRandom.hpp => MGauge/Random.hpp} (70%) rename extras/Hadrons/Modules/{GUnit.cc => MGauge/Unit.cc} (84%) rename extras/Hadrons/Modules/{GUnit.hpp => MGauge/Unit.hpp} (70%) rename extras/Hadrons/Modules/{SolRBPrecCG.cc => MSolver/RBPrecCG.cc} (85%) rename extras/Hadrons/Modules/{SolRBPrecCG.hpp => MSolver/RBPrecCG.hpp} (61%) rename extras/Hadrons/Modules/{SrcPoint.cc => MSource/Point.cc} (84%) rename extras/Hadrons/Modules/{SrcPoint.hpp => MSource/Point.hpp} (64%) rename extras/Hadrons/Modules/{SrcZ2.cc => MSource/Z2.cc} (87%) rename extras/Hadrons/Modules/{SrcZ2.hpp => MSource/Z2.hpp} (64%) rename extras/Hadrons/{ => Modules/templates}/Module.cc.template (95%) rename extras/Hadrons/{ => Modules/templates}/Module.hpp.template (90%) create mode 100644 extras/Hadrons/Modules/templates/Module_in_NS.cc.template create mode 100644 extras/Hadrons/Modules/templates/Module_in_NS.hpp.template diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 0936f3ba..5f102328 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -54,7 +54,7 @@ BEGIN_HADRONS_NAMESPACE typedef FermionOperator FMat; typedef FIMPL::FermionField FermionField; typedef FIMPL::PropagatorField PropagatorField; -typedef std::function Solver; +typedef std::function SolverFn; // logger class HadronsLogger: public Logger diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 60dcc936..d7065650 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -33,7 +33,7 @@ directory. BEGIN_HADRONS_NAMESPACE -// module registration macro +// module registration macros #define MODULE_REGISTER(mod)\ class mod##ModuleRegistrar\ {\ @@ -49,6 +49,21 @@ public:\ };\ static mod##ModuleRegistrar mod##ModuleRegistrarInstance; +#define MODULE_REGISTER_NS(mod, ns)\ +class ns##mod##ModuleRegistrar\ +{\ +public:\ + ns##mod##ModuleRegistrar(void)\ + {\ + ModuleFactory &modFac = ModuleFactory::getInstance();\ + modFac.registerBuilder(#ns "::" #mod, [&](const std::string name)\ + {\ + return std::unique_ptr(new ns::mod(name));\ + });\ + }\ +};\ +static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; + /****************************************************************************** * Module class * ******************************************************************************/ diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index a7a88710..998c609f 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include +#include +#include +#include diff --git a/extras/Hadrons/Modules/ADWF.cc b/extras/Hadrons/Modules/MAction/DWF.cc similarity index 87% rename from extras/Hadrons/Modules/ADWF.cc rename to extras/Hadrons/Modules/MAction/DWF.cc index 8f83f93f..626ac69b 100644 --- a/extras/Hadrons/Modules/ADWF.cc +++ b/extras/Hadrons/Modules/MAction/DWF.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/ADWF.cc +Source file: programs/Hadrons/DWF.cc Copyright (C) 2016 @@ -25,28 +25,29 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; +using namespace MAction; /****************************************************************************** -* ADWF implementation * +* DWF implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -ADWF::ADWF(const std::string name) -: Module(name) +DWF::DWF(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector ADWF::getInput(void) +std::vector DWF::getInput(void) { std::vector in = {par().gauge}; return in; } -std::vector ADWF::getOutput(void) +std::vector DWF::getOutput(void) { std::vector out = {getName()}; @@ -54,7 +55,7 @@ std::vector ADWF::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void ADWF::setup(void) +void DWF::setup(void) { unsigned int size; @@ -63,7 +64,7 @@ void ADWF::setup(void) } // execution /////////////////////////////////////////////////////////////////// -void ADWF::execute(void) +void DWF::execute(void) { LOG(Message) << "Setting up domain wall fermion matrix with m= " << par().mass << ", M5= " << par().M5 << " and Ls= " diff --git a/extras/Hadrons/Modules/ADWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp similarity index 60% rename from extras/Hadrons/Modules/ADWF.hpp rename to extras/Hadrons/Modules/MAction/DWF.hpp index 159d5b20..15d3a0dc 100644 --- a/extras/Hadrons/Modules/ADWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/ADWF.hpp +Source file: programs/Hadrons/DWF.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_ADWF_hpp_ -#define Hadrons_ADWF_hpp_ +#ifndef Hadrons_DWF_hpp_ +#define Hadrons_DWF_hpp_ #include #include @@ -37,34 +37,37 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Domain wall quark action * ******************************************************************************/ -class ADWFPar: Serializable +namespace MAction { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(ADWFPar, - std::string, gauge, - unsigned int, Ls, - double , mass, - double , M5); -}; + class DWFPar: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(DWFPar, + std::string, gauge, + unsigned int, Ls, + double , mass, + double , M5); + }; + + class DWF: public Module + { + public: + // constructor + DWF(const std::string name); + // destructor + virtual ~DWF(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -class ADWF: public Module -{ -public: - // constructor - ADWF(const std::string name); - // destructor - virtual ~ADWF(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; - -MODULE_REGISTER(ADWF); +MODULE_REGISTER_NS(DWF, MAction); END_HADRONS_NAMESPACE -#endif // Hadrons_ADWF_hpp_ +#endif // Hadrons_DWF_hpp_ diff --git a/extras/Hadrons/Modules/AWilson.cc b/extras/Hadrons/Modules/MAction/Wilson.cc similarity index 85% rename from extras/Hadrons/Modules/AWilson.cc rename to extras/Hadrons/Modules/MAction/Wilson.cc index e55fe988..a07669e2 100644 --- a/extras/Hadrons/Modules/AWilson.cc +++ b/extras/Hadrons/Modules/MAction/Wilson.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/AWilson.cc +Source file: programs/Hadrons/Wilson.cc Copyright (C) 2016 @@ -25,28 +25,29 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; +using namespace MAction; /****************************************************************************** -* AWilson implementation * +* Wilson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -AWilson::AWilson(const std::string name) -: Module(name) +Wilson::Wilson(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector AWilson::getInput(void) +std::vector Wilson::getInput(void) { std::vector in = {par().gauge}; return in; } -std::vector AWilson::getOutput(void) +std::vector Wilson::getOutput(void) { std::vector out = {getName()}; @@ -54,7 +55,7 @@ std::vector AWilson::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void AWilson::setup(void) +void Wilson::setup(void) { unsigned int size; @@ -63,7 +64,7 @@ void AWilson::setup(void) } // execution /////////////////////////////////////////////////////////////////// -void AWilson::execute() +void Wilson::execute() { LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass << " using gauge field '" << par().gauge << "'" << std::endl; diff --git a/extras/Hadrons/Modules/AWilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp similarity index 62% rename from extras/Hadrons/Modules/AWilson.hpp rename to extras/Hadrons/Modules/MAction/Wilson.hpp index 93986315..d6644ea4 100644 --- a/extras/Hadrons/Modules/AWilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/AWilson.hpp +Source file: programs/Hadrons/Wilson.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_AWilson_hpp_ -#define Hadrons_AWilson_hpp_ +#ifndef Hadrons_Wilson_hpp_ +#define Hadrons_Wilson_hpp_ #include #include @@ -37,32 +37,35 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Wilson quark action * ******************************************************************************/ -class AWilsonPar: Serializable +namespace MAction { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(AWilsonPar, - std::string, gauge, - double , mass); -}; + class WilsonPar: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonPar, + std::string, gauge, + double , mass); + }; -class AWilson: public Module -{ -public: - // constructor - AWilson(const std::string name); - // destructor - virtual ~AWilson(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; + class Wilson: public Module + { + public: + // constructor + Wilson(const std::string name); + // destructor + virtual ~Wilson(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -MODULE_REGISTER(AWilson); +MODULE_REGISTER_NS(Wilson, MAction); END_HADRONS_NAMESPACE -#endif // Hadrons_AWilson_hpp_ +#endif // Hadrons_Wilson_hpp_ diff --git a/extras/Hadrons/Modules/CMeson.cc b/extras/Hadrons/Modules/MContraction/Meson.cc similarity index 88% rename from extras/Hadrons/Modules/CMeson.cc rename to extras/Hadrons/Modules/MContraction/Meson.cc index fef8179d..1707f00d 100644 --- a/extras/Hadrons/Modules/CMeson.cc +++ b/extras/Hadrons/Modules/MContraction/Meson.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/CMeson.cc +Source file: programs/Hadrons/Meson.cc Copyright (C) 2015 @@ -25,29 +25,30 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; using namespace Hadrons; +using namespace MContraction; /****************************************************************************** - * CMeson implementation * + * Meson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -CMeson::CMeson(const std::string name) -: Module(name) +Meson::Meson(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector CMeson::getInput(void) +std::vector Meson::getInput(void) { std::vector input = {par().q1, par().q2}; return input; } -std::vector CMeson::getOutput(void) +std::vector Meson::getOutput(void) { std::vector output = {getName()}; @@ -55,7 +56,7 @@ std::vector CMeson::getOutput(void) } // execution /////////////////////////////////////////////////////////////////// -void CMeson::execute(void) +void Meson::execute(void) { LOG(Message) << "Computing meson contraction '" << getName() << "' using" << " quarks '" << par().q1 << "' and '" << par().q2 << "'" diff --git a/extras/Hadrons/Modules/CMeson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp similarity index 55% rename from extras/Hadrons/Modules/CMeson.hpp rename to extras/Hadrons/Modules/MContraction/Meson.hpp index 2e9daa6d..a2cdf3db 100644 --- a/extras/Hadrons/Modules/CMeson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/CMeson.hpp +Source file: programs/Hadrons/Meson.hpp Copyright (C) 2015 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_CMeson_hpp_ -#define Hadrons_CMeson_hpp_ +#ifndef Hadrons_Meson_hpp_ +#define Hadrons_Meson_hpp_ #include #include @@ -35,40 +35,43 @@ directory. BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * CMeson * + * Meson * ******************************************************************************/ -class CMesonPar: Serializable +namespace MContraction { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(CMesonPar, - std::string, q1, - std::string, q2, - std::string, output); -}; - -class CMeson: public Module -{ -public: - class Result: Serializable + class MesonPar: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Result, - std::vector>>, corr); + GRID_SERIALIZABLE_CLASS_MEMBERS(MesonPar, + std::string, q1, + std::string, q2, + std::string, output); }; -public: - // constructor - CMeson(const std::string name); - // destructor - virtual ~CMeson(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // execution - virtual void execute(void); -}; + + class Meson: public Module + { + public: + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::vector>>, corr); + }; + public: + // constructor + Meson(const std::string name); + // destructor + virtual ~Meson(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // execution + virtual void execute(void); + }; +} -MODULE_REGISTER(CMeson); +MODULE_REGISTER_NS(Meson, MContraction); END_HADRONS_NAMESPACE -#endif // Hadrons_CMeson_hpp_ +#endif // Hadrons_Meson_hpp_ diff --git a/extras/Hadrons/Modules/GLoad.cc b/extras/Hadrons/Modules/MGauge/Load.cc similarity index 85% rename from extras/Hadrons/Modules/GLoad.cc rename to extras/Hadrons/Modules/MGauge/Load.cc index b81307cd..276c08b2 100644 --- a/extras/Hadrons/Modules/GLoad.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/GLoad.cc +Source file: programs/Hadrons/Load.cc Copyright (C) 2016 @@ -25,28 +25,29 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; +using namespace MGauge; /****************************************************************************** -* GLoad implementation * +* Load implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -GLoad::GLoad(const std::string name) -: Module(name) +Load::Load(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector GLoad::getInput(void) +std::vector Load::getInput(void) { std::vector in; return in; } -std::vector GLoad::getOutput(void) +std::vector Load::getOutput(void) { std::vector out = {getName()}; @@ -54,13 +55,13 @@ std::vector GLoad::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void GLoad::setup(void) +void Load::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void GLoad::execute(void) +void Load::execute(void) { NerscField header; std::string fileName = par().file + "." diff --git a/extras/Hadrons/Modules/GLoad.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp similarity index 65% rename from extras/Hadrons/Modules/GLoad.hpp rename to extras/Hadrons/Modules/MGauge/Load.hpp index 9a089b61..5cd98f0c 100644 --- a/extras/Hadrons/Modules/GLoad.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/GLoad.hpp +Source file: programs/Hadrons/Load.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_GLoad_hpp_ -#define Hadrons_GLoad_hpp_ +#ifndef Hadrons_Load_hpp_ +#define Hadrons_Load_hpp_ #include #include @@ -37,31 +37,34 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Load a NERSC configuration * ******************************************************************************/ -class GLoadPar: Serializable +namespace MGauge { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(GLoadPar, - std::string, file); -}; + class LoadPar: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(LoadPar, + std::string, file); + }; -class GLoad: public Module -{ -public: - // constructor - GLoad(const std::string name); - // destructor - virtual ~GLoad(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; + class Load: public Module + { + public: + // constructor + Load(const std::string name); + // destructor + virtual ~Load(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -MODULE_REGISTER(GLoad); +MODULE_REGISTER_NS(Load, MGauge); END_HADRONS_NAMESPACE -#endif // Hadrons_GLoad_hpp_ +#endif // Hadrons_Load_hpp_ diff --git a/extras/Hadrons/Modules/GRandom.cc b/extras/Hadrons/Modules/MGauge/Random.cc similarity index 83% rename from extras/Hadrons/Modules/GRandom.cc rename to extras/Hadrons/Modules/MGauge/Random.cc index 7f5af2c2..587c5c25 100644 --- a/extras/Hadrons/Modules/GRandom.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/GRandom.cc +Source file: programs/Hadrons/Random.cc Copyright (C) 2016 @@ -25,26 +25,27 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; +using namespace MGauge; /****************************************************************************** -* GRandom implementation * +* Random implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -GRandom::GRandom(const std::string name) +Random::Random(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector GRandom::getInput(void) +std::vector Random::getInput(void) { return std::vector(); } -std::vector GRandom::getOutput(void) +std::vector Random::getOutput(void) { std::vector out = {getName()}; @@ -52,13 +53,13 @@ std::vector GRandom::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void GRandom::setup(void) +void Random::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void GRandom::execute(void) +void Random::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); diff --git a/extras/Hadrons/Modules/GRandom.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp similarity index 70% rename from extras/Hadrons/Modules/GRandom.hpp rename to extras/Hadrons/Modules/MGauge/Random.hpp index 6c42372e..285357e3 100644 --- a/extras/Hadrons/Modules/GRandom.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/GRandom.hpp +Source file: programs/Hadrons/Random.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_GRandom_hpp_ -#define Hadrons_GRandom_hpp_ +#ifndef Hadrons_Random_hpp_ +#define Hadrons_Random_hpp_ #include #include @@ -37,24 +37,27 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Random gauge * ******************************************************************************/ -class GRandom: public Module +namespace MGauge { -public: - // constructor - GRandom(const std::string name); - // destructor - virtual ~GRandom(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; + class Random: public Module + { + public: + // constructor + Random(const std::string name); + // destructor + virtual ~Random(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -MODULE_REGISTER(GRandom); +MODULE_REGISTER_NS(Random, MGauge); END_HADRONS_NAMESPACE -#endif // Hadrons_GRandom_hpp_ +#endif // Hadrons_Random_hpp_ diff --git a/extras/Hadrons/Modules/GUnit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc similarity index 84% rename from extras/Hadrons/Modules/GUnit.cc rename to extras/Hadrons/Modules/MGauge/Unit.cc index 34f134fe..232bd835 100644 --- a/extras/Hadrons/Modules/GUnit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/GUnit.cc +Source file: programs/Hadrons/Unit.cc Copyright (C) 2016 @@ -25,26 +25,27 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; +using namespace MGauge; /****************************************************************************** -* GUnit implementation * +* Unit implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -GUnit::GUnit(const std::string name) +Unit::Unit(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector GUnit::getInput(void) +std::vector Unit::getInput(void) { return std::vector(); } -std::vector GUnit::getOutput(void) +std::vector Unit::getOutput(void) { std::vector out = {getName()}; @@ -52,13 +53,13 @@ std::vector GUnit::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void GUnit::setup(void) +void Unit::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void GUnit::execute(void) +void Unit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); diff --git a/extras/Hadrons/Modules/GUnit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp similarity index 70% rename from extras/Hadrons/Modules/GUnit.hpp rename to extras/Hadrons/Modules/MGauge/Unit.hpp index 31b53a35..4fa03f54 100644 --- a/extras/Hadrons/Modules/GUnit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/GUnit.hpp +Source file: programs/Hadrons/Unit.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_GUnit_hpp_ -#define Hadrons_GUnit_hpp_ +#ifndef Hadrons_Unit_hpp_ +#define Hadrons_Unit_hpp_ #include #include @@ -37,24 +37,27 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Unit gauge * ******************************************************************************/ -class GUnit: public Module +namespace MGauge { -public: - // constructor - GUnit(const std::string name); - // destructor - virtual ~GUnit(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; + class Unit: public Module + { + public: + // constructor + Unit(const std::string name); + // destructor + virtual ~Unit(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -MODULE_REGISTER(GUnit); +MODULE_REGISTER_NS(Unit, MGauge); END_HADRONS_NAMESPACE -#endif // Hadrons_GUnit_hpp_ +#endif // Hadrons_Unit_hpp_ diff --git a/extras/Hadrons/Modules/MQuark.cc b/extras/Hadrons/Modules/MQuark.cc index 8f730b58..07f25e1c 100644 --- a/extras/Hadrons/Modules/MQuark.cc +++ b/extras/Hadrons/Modules/MQuark.cc @@ -76,7 +76,7 @@ void MQuark::execute(void) << std::endl; LatticePropagator &prop = *env().createLattice(propName); LatticePropagator &fullSrc = *env().getObject(par().source); - Solver &solver = *env().getObject(par().solver); + SolverFn &solver = *env().getObject(par().solver); if (Ls_ > 1) { env().createLattice(getName()); diff --git a/extras/Hadrons/Modules/MQuark.hpp b/extras/Hadrons/Modules/MQuark.hpp index f217e338..ed6dfb0c 100644 --- a/extras/Hadrons/Modules/MQuark.hpp +++ b/extras/Hadrons/Modules/MQuark.hpp @@ -61,7 +61,7 @@ public: virtual void execute(void); private: unsigned int Ls_; - Solver *solver_{nullptr}; + SolverFn *solver_{nullptr}; }; MODULE_REGISTER(MQuark); diff --git a/extras/Hadrons/Modules/SolRBPrecCG.cc b/extras/Hadrons/Modules/MSolver/RBPrecCG.cc similarity index 85% rename from extras/Hadrons/Modules/SolRBPrecCG.cc rename to extras/Hadrons/Modules/MSolver/RBPrecCG.cc index 7a7aa69d..2c3d9f67 100644 --- a/extras/Hadrons/Modules/SolRBPrecCG.cc +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SolRBPrecCG.cc +Source file: programs/Hadrons/RBPrecCG.cc Copyright (C) 2016 @@ -25,29 +25,30 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace QCD; using namespace Hadrons; +using namespace MSolver; /****************************************************************************** -* SolRBPrecCG implementation * +* RBPrecCG implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -SolRBPrecCG::SolRBPrecCG(const std::string name) +RBPrecCG::RBPrecCG(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector SolRBPrecCG::getInput(void) +std::vector RBPrecCG::getInput(void) { std::vector in = {par().action}; return in; } -std::vector SolRBPrecCG::getOutput(void) +std::vector RBPrecCG::getOutput(void) { std::vector out = {getName()}; @@ -55,7 +56,7 @@ std::vector SolRBPrecCG::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void SolRBPrecCG::setup(void) +void RBPrecCG::setup(void) { auto Ls = env().getObjectLs(par().action); @@ -64,7 +65,7 @@ void SolRBPrecCG::setup(void) } // execution /////////////////////////////////////////////////////////////////// -void SolRBPrecCG::execute(void) +void RBPrecCG::execute(void) { auto &mat = *(env().getObject(par().action)); auto solver = [&mat, this](LatticeFermion &sol, @@ -79,5 +80,5 @@ void SolRBPrecCG::execute(void) LOG(Message) << "setting up Schur red-black preconditioned CG for" << " action '" << par().action << "' with residual " << par().residual << std::endl; - env().setObject(getName(), new Solver(solver)); + env().setObject(getName(), new SolverFn(solver)); } diff --git a/extras/Hadrons/Modules/SolRBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp similarity index 61% rename from extras/Hadrons/Modules/SolRBPrecCG.hpp rename to extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index 7482a70c..3d36c4c7 100644 --- a/extras/Hadrons/Modules/SolRBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SolRBPrecCG.hpp +Source file: programs/Hadrons/RBPrecCG.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_SolRBPrecCG_hpp_ -#define Hadrons_SolRBPrecCG_hpp_ +#ifndef Hadrons_RBPrecCG_hpp_ +#define Hadrons_RBPrecCG_hpp_ #include #include @@ -37,32 +37,35 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Schur red-black preconditioned CG * ******************************************************************************/ -class SolRBPrecCGPar: Serializable +namespace MSolver { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(SolRBPrecCGPar, - std::string, action, - double , residual); -}; + class RBPrecCGPar: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar, + std::string, action, + double , residual); + }; + + class RBPrecCG: public Module + { + public: + // constructor + RBPrecCG(const std::string name); + // destructor + virtual ~RBPrecCG(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -class SolRBPrecCG: public Module -{ -public: - // constructor - SolRBPrecCG(const std::string name); - // destructor - virtual ~SolRBPrecCG(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; - -MODULE_REGISTER(SolRBPrecCG); +MODULE_REGISTER_NS(RBPrecCG, MSolver); END_HADRONS_NAMESPACE -#endif // Hadrons_SolRBPrecCG_hpp_ +#endif // Hadrons_RBPrecCG_hpp_ diff --git a/extras/Hadrons/Modules/SrcPoint.cc b/extras/Hadrons/Modules/MSource/Point.cc similarity index 84% rename from extras/Hadrons/Modules/SrcPoint.cc rename to extras/Hadrons/Modules/MSource/Point.cc index a060b5d7..f22f41d9 100644 --- a/extras/Hadrons/Modules/SrcPoint.cc +++ b/extras/Hadrons/Modules/MSource/Point.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SrcPoint.cc +Source file: programs/Hadrons/Point.cc Copyright (C) 2016 @@ -25,28 +25,29 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; +using namespace MSource; /****************************************************************************** -* SrcPoint implementation * +* Point implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -SrcPoint::SrcPoint(const std::string name) -: Module(name) +Point::Point(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector SrcPoint::getInput(void) +std::vector Point::getInput(void) { std::vector in; return in; } -std::vector SrcPoint::getOutput(void) +std::vector Point::getOutput(void) { std::vector out = {getName()}; @@ -54,13 +55,13 @@ std::vector SrcPoint::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void SrcPoint::setup(void) +void Point::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void SrcPoint::execute(void) +void Point::execute(void) { std::vector position = strToVec(par().position); SpinColourMatrix id; diff --git a/extras/Hadrons/Modules/SrcPoint.hpp b/extras/Hadrons/Modules/MSource/Point.hpp similarity index 64% rename from extras/Hadrons/Modules/SrcPoint.hpp rename to extras/Hadrons/Modules/MSource/Point.hpp index 8c1efce0..4bebdfe0 100644 --- a/extras/Hadrons/Modules/SrcPoint.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SrcPoint.hpp +Source file: programs/Hadrons/Point.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_SrcPoint_hpp_ -#define Hadrons_SrcPoint_hpp_ +#ifndef Hadrons_Point_hpp_ +#define Hadrons_Point_hpp_ #include #include @@ -46,33 +46,36 @@ BEGIN_HADRONS_NAMESPACE */ /****************************************************************************** - * SrcPoint * + * Point * ******************************************************************************/ -class SrcPointPar: Serializable +namespace MSource { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(SrcPointPar, - std::string, position); -}; + class PointPar: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(PointPar, + std::string, position); + }; + + class Point: public Module + { + public: + // constructor + Point(const std::string name); + // destructor + virtual ~Point(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -class SrcPoint: public Module -{ -public: - // constructor - SrcPoint(const std::string name); - // destructor - virtual ~SrcPoint(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; - -MODULE_REGISTER(SrcPoint); +MODULE_REGISTER_NS(Point, MSource); END_HADRONS_NAMESPACE -#endif // Hadrons_SrcPoint_hpp_ +#endif // Hadrons_Point_hpp_ diff --git a/extras/Hadrons/Modules/SrcZ2.cc b/extras/Hadrons/Modules/MSource/Z2.cc similarity index 87% rename from extras/Hadrons/Modules/SrcZ2.cc rename to extras/Hadrons/Modules/MSource/Z2.cc index ec555a08..90f9f274 100644 --- a/extras/Hadrons/Modules/SrcZ2.cc +++ b/extras/Hadrons/Modules/MSource/Z2.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SrcZ2.cc +Source file: programs/Hadrons/Z2.cc Copyright (C) 2016 @@ -25,28 +25,29 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#include using namespace Grid; using namespace Hadrons; +using namespace MSource; /****************************************************************************** -* SrcZ2 implementation * +* Z2 implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -SrcZ2::SrcZ2(const std::string name) -: Module(name) +Z2::Z2(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector SrcZ2::getInput(void) +std::vector Z2::getInput(void) { std::vector in; return in; } -std::vector SrcZ2::getOutput(void) +std::vector Z2::getOutput(void) { std::vector out = {getName()}; @@ -54,13 +55,13 @@ std::vector SrcZ2::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void SrcZ2::setup(void) +void Z2::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void SrcZ2::execute(void) +void Z2::execute(void) { Lattice> t(env().getGrid()); LatticeComplex eta(env().getGrid()); diff --git a/extras/Hadrons/Modules/SrcZ2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp similarity index 64% rename from extras/Hadrons/Modules/SrcZ2.hpp rename to extras/Hadrons/Modules/MSource/Z2.hpp index bf0aebc0..0ff24b0c 100644 --- a/extras/Hadrons/Modules/SrcZ2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/SrcZ2.hpp +Source file: programs/Hadrons/Z2.hpp Copyright (C) 2016 @@ -25,8 +25,8 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#ifndef Hadrons_SrcZ2_hpp_ -#define Hadrons_SrcZ2_hpp_ +#ifndef Hadrons_Z2_hpp_ +#define Hadrons_Z2_hpp_ #include #include @@ -47,34 +47,37 @@ BEGIN_HADRONS_NAMESPACE */ /****************************************************************************** - * SrcZ2 * + * Z2 * ******************************************************************************/ -class SrcZ2Par: Serializable +namespace MSource { -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(SrcZ2Par, - unsigned int, tA, - unsigned int, tB); -}; + class Z2Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Z2Par, + unsigned int, tA, + unsigned int, tB); + }; -class SrcZ2: public Module -{ -public: - // constructor - SrcZ2(const std::string name); - // destructor - virtual ~SrcZ2(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; + class Z2: public Module + { + public: + // constructor + Z2(const std::string name); + // destructor + virtual ~Z2(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} -MODULE_REGISTER(SrcZ2); +MODULE_REGISTER_NS(Z2, MSource); END_HADRONS_NAMESPACE -#endif // Hadrons_SrcZ2_hpp_ +#endif // Hadrons_Z2_hpp_ diff --git a/extras/Hadrons/Module.cc.template b/extras/Hadrons/Modules/templates/Module.cc.template similarity index 95% rename from extras/Hadrons/Module.cc.template rename to extras/Hadrons/Modules/templates/Module.cc.template index 1bcf53ca..5cd7664d 100644 --- a/extras/Hadrons/Module.cc.template +++ b/extras/Hadrons/Modules/templates/Module.cc.template @@ -1,4 +1,4 @@ -#include +#include using namespace Grid; using namespace Hadrons; diff --git a/extras/Hadrons/Module.hpp.template b/extras/Hadrons/Modules/templates/Module.hpp.template similarity index 90% rename from extras/Hadrons/Module.hpp.template rename to extras/Hadrons/Modules/templates/Module.hpp.template index e8e6c4de..bee4e618 100644 --- a/extras/Hadrons/Module.hpp.template +++ b/extras/Hadrons/Modules/templates/Module.hpp.template @@ -1,9 +1,9 @@ #ifndef Hadrons____FILEBASENAME____hpp_ #define Hadrons____FILEBASENAME____hpp_ -#include -#include -#include +#include +#include +#include BEGIN_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.cc.template b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template new file mode 100644 index 00000000..64bc7aa9 --- /dev/null +++ b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template @@ -0,0 +1,40 @@ +#include + +using namespace Grid; +using namespace Hadrons; +using namespace ___NAMESPACE___; + +/****************************************************************************** +* ___FILEBASENAME___ implementation * +******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +___FILEBASENAME___::___FILEBASENAME___(const std::string name) +: Module<___FILEBASENAME___Par>(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +std::vector ___FILEBASENAME___::getInput(void) +{ + std::vector in; + + return in; +} + +std::vector ___FILEBASENAME___::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +void ___FILEBASENAME___::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +void ___FILEBASENAME___::execute(void) +{ + +} diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template new file mode 100644 index 00000000..bc43649b --- /dev/null +++ b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template @@ -0,0 +1,43 @@ +#ifndef Hadrons____FILEBASENAME____hpp_ +#define Hadrons____FILEBASENAME____hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * ___FILEBASENAME___ * + ******************************************************************************/ +namespace ___NAMESPACE___ +{ + class ___FILEBASENAME___Par: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(___FILEBASENAME___Par, + unsigned int, i); + }; + + class ___FILEBASENAME___: public Module<___FILEBASENAME___Par> + { + public: + // constructor + ___FILEBASENAME___(const std::string name); + // destructor + virtual ~___FILEBASENAME___(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); + }; +} + +MODULE_REGISTER_NS(___FILEBASENAME___, ___NAMESPACE___); + +END_HADRONS_NAMESPACE + +#endif // Hadrons____FILEBASENAME____hpp_ diff --git a/extras/Hadrons/add_module.sh b/extras/Hadrons/add_module.sh index e412e0e7..d5d23ea4 100755 --- a/extras/Hadrons/add_module.sh +++ b/extras/Hadrons/add_module.sh @@ -1,15 +1,31 @@ #!/usr/bin/env bash -if (( $# != 1 )); then - echo "usage: `basename $0` " 1>&2 +if (( $# != 1 && $# != 2)); then + echo "usage: `basename $0` []" 1>&2 exit 1 fi NAME=$1 +NS=$2 -if [ -e "Modules/${NAME}.cc" ] || [ -e "Modules/${NAME}.hpp" ]; then - echo "error: files Modules/${NAME}.* already exists" 1>&2 - exit 1 +if (( $# == 1 )); then + if [ -e "Modules/${NAME}.cc" ] || [ -e "Modules/${NAME}.hpp" ]; then + echo "error: files Modules/${NAME}.* already exists" 1>&2 + exit 1 + fi + sed "s/___FILEBASENAME___/${NAME}/g" Modules/templates/Module.cc.template > Modules/${NAME}.cc + sed "s/___FILEBASENAME___/${NAME}/g" Modules/templates/Module.hpp.template > Modules/${NAME}.hpp +elif (( $# == 2 )); then + mkdir -p Modules/${NS} + if [ -e "Modules/${NS}/${NAME}.cc" ] || [ -e "Modules/${NS}/${NAME}.hpp" ]; then + echo "error: files Modules/${NS}/${NAME}.* already exists" 1>&2 + exit 1 + fi + TMPCC=".${NS}.${NAME}.tmp.cc" + TMPHPP=".${NS}.${NAME}.tmp.hpp" + sed "s/___FILEBASENAME___/${NAME}/g" Modules/templates/Module_in_NS.cc.template > ${TMPCC} + sed "s/___FILEBASENAME___/${NAME}/g" Modules/templates/Module_in_NS.hpp.template > ${TMPHPP} + sed "s/___NAMESPACE___/${NS}/g" ${TMPCC} > Modules/${NS}/${NAME}.cc + sed "s/___NAMESPACE___/${NS}/g" ${TMPHPP} > Modules/${NS}/${NAME}.hpp + rm -f ${TMPCC} ${TMPHPP} fi -sed "s/___FILEBASENAME___/${NAME}/g" Module.cc.template > Modules/${NAME}.cc -sed "s/___FILEBASENAME___/${NAME}/g" Module.hpp.template > Modules/${NAME}.hpp ./make_module_list.sh diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 9040c406..a460ae86 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -1,24 +1,24 @@ modules_cc =\ - Modules/ADWF.cc \ - Modules/AWilson.cc \ - Modules/CMeson.cc \ - Modules/GLoad.cc \ - Modules/GRandom.cc \ - Modules/GUnit.cc \ + Modules/MAction/DWF.cc \ + Modules/MAction/Wilson.cc \ + Modules/MContraction/Meson.cc \ + Modules/MGauge/Load.cc \ + Modules/MGauge/Random.cc \ + Modules/MGauge/Unit.cc \ Modules/MQuark.cc \ - Modules/SolRBPrecCG.cc \ - Modules/SrcPoint.cc \ - Modules/SrcZ2.cc + Modules/MSolver/RBPrecCG.cc \ + Modules/MSource/Point.cc \ + Modules/MSource/Z2.cc modules_hpp =\ - Modules/ADWF.hpp \ - Modules/AWilson.hpp \ - Modules/CMeson.hpp \ - Modules/GLoad.hpp \ - Modules/GRandom.hpp \ - Modules/GUnit.hpp \ + Modules/MAction/DWF.hpp \ + Modules/MAction/Wilson.hpp \ + Modules/MContraction/Meson.hpp \ + Modules/MGauge/Load.hpp \ + Modules/MGauge/Random.hpp \ + Modules/MGauge/Unit.hpp \ Modules/MQuark.hpp \ - Modules/SolRBPrecCG.hpp \ - Modules/SrcPoint.hpp \ - Modules/SrcZ2.hpp + Modules/MSolver/RBPrecCG.hpp \ + Modules/MSource/Point.hpp \ + Modules/MSource/Z2.hpp diff --git a/tests/hadrons/Test_hadrons_mesons.cc b/tests/hadrons/Test_hadrons_mesons.cc index 9c062b39..b9561694 100644 --- a/tests/hadrons/Test_hadrons_mesons.cc +++ b/tests/hadrons/Test_hadrons_mesons.cc @@ -28,7 +28,6 @@ #include using namespace Grid; -using namespace QCD; using namespace Hadrons; int main(int argc, char *argv[]) @@ -56,30 +55,31 @@ int main(int argc, char *argv[]) globalPar.seed = "1 2 3 4"; application.setPar(globalPar); // gauge field - application.createModule("gauge"); + application.createModule("gauge"); // sources - SrcZ2::Par z2Par; + MSource::Z2::Par z2Par; z2Par.tA = 0; z2Par.tB = 0; - application.createModule("z2", z2Par); - SrcPoint::Par ptPar; + application.createModule("z2", z2Par); + MSource::Point::Par ptPar; ptPar.position = "0 0 0 0"; - application.createModule("pt", ptPar); + application.createModule("pt", ptPar); for (unsigned int i = 0; i < flavour.size(); ++i) { // actions - ADWF::Par actionPar; + MAction::DWF::Par actionPar; actionPar.gauge = "gauge"; actionPar.Ls = 12; actionPar.M5 = 1.8; actionPar.mass = mass[i]; - application.createModule("DWF_" + flavour[i], actionPar); + application.createModule("DWF_" + flavour[i], actionPar); // solvers - SolRBPrecCG::Par solverPar; + MSolver::RBPrecCG::Par solverPar; solverPar.action = "DWF_" + flavour[i]; solverPar.residual = 1.0e-8; - application.createModule("CG_" + flavour[i], solverPar); + application.createModule("CG_" + flavour[i], + solverPar); // propagators MQuark::Par quarkPar; @@ -90,13 +90,14 @@ int main(int argc, char *argv[]) for (unsigned int i = 0; i < flavour.size(); ++i) for (unsigned int j = i + 1; j < flavour.size(); ++j) { - CMeson::Par mesPar; + MContraction::Meson::Par mesPar; mesPar.output = "mesons/" + flavour[i] + flavour[j]; mesPar.q1 = "Q_" + flavour[i]; mesPar.q2 = "Q_" + flavour[j]; - application.createModule("meson_" + flavour[i] + flavour[j], - mesPar); + application.createModule("meson_" + + flavour[i] + flavour[j], + mesPar); } // execution From 320268fe93f40a17f31dc8c8b6674612eb41abfb Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 13:57:34 +0900 Subject: [PATCH 072/106] Hadrons: code cleaning --- extras/Hadrons/Modules/MAction/DWF.cc | 2 +- extras/Hadrons/Modules/MAction/Wilson.cc | 2 +- extras/Hadrons/Modules/MContraction/Meson.cc | 7 +++---- extras/Hadrons/Modules/MGauge/Load.cc | 2 +- extras/Hadrons/Modules/MGauge/Random.cc | 2 +- extras/Hadrons/Modules/MGauge/Unit.cc | 2 +- extras/Hadrons/Modules/MSolver/RBPrecCG.cc | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/extras/Hadrons/Modules/MAction/DWF.cc b/extras/Hadrons/Modules/MAction/DWF.cc index 626ac69b..36527b58 100644 --- a/extras/Hadrons/Modules/MAction/DWF.cc +++ b/extras/Hadrons/Modules/MAction/DWF.cc @@ -32,7 +32,7 @@ using namespace Hadrons; using namespace MAction; /****************************************************************************** -* DWF implementation * +* DWF implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// DWF::DWF(const std::string name) diff --git a/extras/Hadrons/Modules/MAction/Wilson.cc b/extras/Hadrons/Modules/MAction/Wilson.cc index a07669e2..3188a636 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.cc +++ b/extras/Hadrons/Modules/MAction/Wilson.cc @@ -32,7 +32,7 @@ using namespace Hadrons; using namespace MAction; /****************************************************************************** -* Wilson implementation * +* Wilson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// Wilson::Wilson(const std::string name) diff --git a/extras/Hadrons/Modules/MContraction/Meson.cc b/extras/Hadrons/Modules/MContraction/Meson.cc index 1707f00d..fbdfceb1 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.cc +++ b/extras/Hadrons/Modules/MContraction/Meson.cc @@ -33,7 +33,7 @@ using namespace Hadrons; using namespace MContraction; /****************************************************************************** - * Meson implementation * + * Meson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// Meson::Meson(const std::string name) @@ -63,13 +63,12 @@ void Meson::execute(void) << std::endl; XmlWriter writer(par().output); - PropagatorField &q1 = *env().getObject(par().q1); - PropagatorField &q2 = *env().getObject(par().q2); + PropagatorField &q1 = *env().getObject(par().q1); + PropagatorField &q2 = *env().getObject(par().q2); LatticeComplex c(env().getGrid()); SpinMatrix g[Ns*Ns], g5; std::vector buf; Result result; - unsigned int nt = env().getGrid()->GlobalDimensions()[Tp]; g5 = makeGammaProd(Ns*Ns - 1); result.corr.resize(Ns*Ns); diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MGauge/Load.cc index 276c08b2..1a6cec0a 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -32,7 +32,7 @@ using namespace Hadrons; using namespace MGauge; /****************************************************************************** -* Load implementation * +* Load implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// Load::Load(const std::string name) diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index 587c5c25..6d5e0ec9 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -32,7 +32,7 @@ using namespace Hadrons; using namespace MGauge; /****************************************************************************** -* Random implementation * +* Random implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// Random::Random(const std::string name) diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index 232bd835..b9cfeac7 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -32,7 +32,7 @@ using namespace Hadrons; using namespace MGauge; /****************************************************************************** -* Unit implementation * +* Unit implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// Unit::Unit(const std::string name) diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.cc b/extras/Hadrons/Modules/MSolver/RBPrecCG.cc index 2c3d9f67..9cdd05aa 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.cc +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.cc @@ -33,7 +33,7 @@ using namespace Hadrons; using namespace MSolver; /****************************************************************************** -* RBPrecCG implementation * +* RBPrecCG implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// RBPrecCG::RBPrecCG(const std::string name) From 7a1ac4567924cfd9e08cc73d98318b6f67611974 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 14:00:10 +0900 Subject: [PATCH 073/106] Hadrons: configure.ac Linux typo --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 19e3f105..97491d7e 100644 --- a/configure.ac +++ b/configure.ac @@ -387,7 +387,7 @@ AC_CONFIG_FILES(tests/solver/Makefile) AC_CONFIG_FILES(tests/qdpxx/Makefile) AC_CONFIG_FILES(benchmarks/Makefile) AC_CONFIG_FILES(extras/Makefile) -AC_CONFIG_FILES(extras/hadrons/Makefile) +AC_CONFIG_FILES(extras/Hadrons/Makefile) AC_OUTPUT echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 7ae734103eac3b0a5d88d516dbe2cec566048de7 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 14:29:32 +0900 Subject: [PATCH 074/106] Hadrons: namespace macro to tackle GCC 5 bug --- extras/Hadrons/Global.hpp | 7 ++- extras/Hadrons/Modules/MAction/DWF.hpp | 55 +++++++++--------- extras/Hadrons/Modules/MAction/Wilson.hpp | 51 +++++++++-------- extras/Hadrons/Modules/MContraction/Meson.hpp | 57 ++++++++++--------- extras/Hadrons/Modules/MGauge/Load.hpp | 49 ++++++++-------- extras/Hadrons/Modules/MGauge/Random.hpp | 35 ++++++------ extras/Hadrons/Modules/MGauge/Unit.hpp | 35 ++++++------ extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 51 +++++++++-------- extras/Hadrons/Modules/MSource/Point.hpp | 49 ++++++++-------- extras/Hadrons/Modules/MSource/Z2.hpp | 51 +++++++++-------- .../templates/Module_in_NS.hpp.template | 49 ++++++++-------- 11 files changed, 252 insertions(+), 237 deletions(-) diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 5f102328..1dc9164a 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -39,8 +39,13 @@ namespace Hadrons {\ using Grid::operator<<; #define END_HADRONS_NAMESPACE }} +#define BEGIN_MODULE_NAMESPACE(name)\ +namespace name {\ +using Grid::operator<<; +#define END_MODULE_NAMESPACE } + /* the 'using Grid::operator<<;' statement prevents a very nasty compilation - * error with GCC (clang compiles fine without it). + * error with GCC 5 (clang & GCC 6 compile fine without it). */ // FIXME: find a way to do that in a more general fashion diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 15d3a0dc..246fafd4 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -37,34 +37,35 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Domain wall quark action * ******************************************************************************/ -namespace MAction +BEGIN_MODULE_NAMESPACE(MAction) + +class DWFPar: Serializable { - class DWFPar: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(DWFPar, - std::string, gauge, - unsigned int, Ls, - double , mass, - double , M5); - }; - - class DWF: public Module - { - public: - // constructor - DWF(const std::string name); - // destructor - virtual ~DWF(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(DWFPar, + std::string, gauge, + unsigned int, Ls, + double , mass, + double , M5); +}; + +class DWF: public Module +{ +public: + // constructor + DWF(const std::string name); + // destructor + virtual ~DWF(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(DWF, MAction); diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index d6644ea4..d3965f09 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -37,32 +37,33 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Wilson quark action * ******************************************************************************/ -namespace MAction -{ - class WilsonPar: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonPar, - std::string, gauge, - double , mass); - }; +BEGIN_MODULE_NAMESPACE(MAction) - class Wilson: public Module - { - public: - // constructor - Wilson(const std::string name); - // destructor - virtual ~Wilson(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +class WilsonPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonPar, + std::string, gauge, + double , mass); +}; + +class Wilson: public Module +{ +public: + // constructor + Wilson(const std::string name); + // destructor + virtual ~Wilson(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(Wilson, MAction); diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index a2cdf3db..713c8631 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -37,38 +37,39 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Meson * ******************************************************************************/ -namespace MContraction +BEGIN_MODULE_NAMESPACE(MContraction) + +class MesonPar: Serializable { - class MesonPar: Serializable +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(MesonPar, + std::string, q1, + std::string, q2, + std::string, output); +}; + +class Meson: public Module +{ +public: + class Result: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(MesonPar, - std::string, q1, - std::string, q2, - std::string, output); + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::vector>>, corr); }; - - class Meson: public Module - { - public: - class Result: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Result, - std::vector>>, corr); - }; - public: - // constructor - Meson(const std::string name); - // destructor - virtual ~Meson(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // execution - virtual void execute(void); - }; -} +public: + // constructor + Meson(const std::string name); + // destructor + virtual ~Meson(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(Meson, MContraction); diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp index 5cd98f0c..ff7cc128 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -37,31 +37,32 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Load a NERSC configuration * ******************************************************************************/ -namespace MGauge -{ - class LoadPar: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(LoadPar, - std::string, file); - }; +BEGIN_MODULE_NAMESPACE(MGauge) - class Load: public Module - { - public: - // constructor - Load(const std::string name); - // destructor - virtual ~Load(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +class LoadPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(LoadPar, + std::string, file); +}; + +class Load: public Module +{ +public: + // constructor + Load(const std::string name); + // destructor + virtual ~Load(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(Load, MGauge); diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index 285357e3..afa03de8 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -37,24 +37,25 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Random gauge * ******************************************************************************/ -namespace MGauge +BEGIN_MODULE_NAMESPACE(MGauge) + +class Random: public Module { - class Random: public Module - { - public: - // constructor - Random(const std::string name); - // destructor - virtual ~Random(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +public: + // constructor + Random(const std::string name); + // destructor + virtual ~Random(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(Random, MGauge); diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index 4fa03f54..da26dd37 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -37,24 +37,25 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Unit gauge * ******************************************************************************/ -namespace MGauge +BEGIN_MODULE_NAMESPACE(MGauge) + +class Unit: public Module { - class Unit: public Module - { - public: - // constructor - Unit(const std::string name); - // destructor - virtual ~Unit(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +public: + // constructor + Unit(const std::string name); + // destructor + virtual ~Unit(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(Unit, MGauge); diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index 3d36c4c7..14d8c169 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -37,32 +37,33 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Schur red-black preconditioned CG * ******************************************************************************/ -namespace MSolver +BEGIN_MODULE_NAMESPACE(MSolver) + +class RBPrecCGPar: Serializable { - class RBPrecCGPar: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar, - std::string, action, - double , residual); - }; - - class RBPrecCG: public Module - { - public: - // constructor - RBPrecCG(const std::string name); - // destructor - virtual ~RBPrecCG(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar, + std::string, action, + double , residual); +}; + +class RBPrecCG: public Module +{ +public: + // constructor + RBPrecCG(const std::string name); + // destructor + virtual ~RBPrecCG(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(RBPrecCG, MSolver); diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 4bebdfe0..1245ed9a 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -48,31 +48,32 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Point * ******************************************************************************/ -namespace MSource +BEGIN_MODULE_NAMESPACE(MSource) + +class PointPar: Serializable { - class PointPar: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(PointPar, - std::string, position); - }; - - class Point: public Module - { - public: - // constructor - Point(const std::string name); - // destructor - virtual ~Point(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(PointPar, + std::string, position); +}; + +class Point: public Module +{ +public: + // constructor + Point(const std::string name); + // destructor + virtual ~Point(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(Point, MSource); diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index 0ff24b0c..ac569ced 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -49,32 +49,33 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Z2 * ******************************************************************************/ -namespace MSource -{ - class Z2Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(Z2Par, - unsigned int, tA, - unsigned int, tB); - }; +BEGIN_MODULE_NAMESPACE(MSource) - class Z2: public Module - { - public: - // constructor - Z2(const std::string name); - // destructor - virtual ~Z2(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +class Z2Par: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Z2Par, + unsigned int, tA, + unsigned int, tB); +}; + +class Z2: public Module +{ +public: + // constructor + Z2(const std::string name); + // destructor + virtual ~Z2(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(Z2, MSource); diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template index bc43649b..490e5a78 100644 --- a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template @@ -10,31 +10,32 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * ___FILEBASENAME___ * ******************************************************************************/ -namespace ___NAMESPACE___ +BEGIN_MODULE_NAMESPACE(___NAMESPACE___) + +class ___FILEBASENAME___Par: Serializable { - class ___FILEBASENAME___Par: Serializable - { - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(___FILEBASENAME___Par, - unsigned int, i); - }; - - class ___FILEBASENAME___: public Module<___FILEBASENAME___Par> - { - public: - // constructor - ___FILEBASENAME___(const std::string name); - // destructor - virtual ~___FILEBASENAME___(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); - }; -} +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(___FILEBASENAME___Par, + unsigned int, i); +}; + +class ___FILEBASENAME___: public Module<___FILEBASENAME___Par> +{ +public: + // constructor + ___FILEBASENAME___(const std::string name); + // destructor + virtual ~___FILEBASENAME___(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +END_MODULE_NAMESPACE MODULE_REGISTER_NS(___FILEBASENAME___, ___NAMESPACE___); From d1f7c6b94e732d7619c1e2862264e2dfe8884475 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 16:47:29 +0900 Subject: [PATCH 075/106] Hadrons: templatisation of the fermion implementation --- extras/Hadrons/Global.hpp | 17 +++- extras/Hadrons/Modules.hpp | 2 +- extras/Hadrons/Modules/MAction/DWF.cc | 82 ---------------- extras/Hadrons/Modules/MAction/DWF.hpp | 66 ++++++++++++- extras/Hadrons/Modules/MAction/Wilson.cc | 76 -------------- extras/Hadrons/Modules/MAction/Wilson.hpp | 64 +++++++++++- extras/Hadrons/Modules/MContraction/Meson.cc | 94 ------------------ extras/Hadrons/Modules/MContraction/Meson.hpp | 81 ++++++++++++++- extras/Hadrons/Modules/MQuark.hpp | 71 -------------- extras/Hadrons/Modules/MSolver/RBPrecCG.cc | 84 ---------------- extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 68 ++++++++++++- extras/Hadrons/Modules/MSource/Point.cc | 75 -------------- extras/Hadrons/Modules/MSource/Point.hpp | 63 +++++++++++- extras/Hadrons/Modules/MSource/Z2.cc | 88 ----------------- extras/Hadrons/Modules/MSource/Z2.hpp | 75 +++++++++++++- .../Hadrons/Modules/{MQuark.cc => Quark.hpp} | 98 ++++++++++++++----- extras/Hadrons/modules.inc | 13 +-- tests/hadrons/Test_hadrons_mesons.cc | 4 +- 18 files changed, 483 insertions(+), 638 deletions(-) delete mode 100644 extras/Hadrons/Modules/MAction/DWF.cc delete mode 100644 extras/Hadrons/Modules/MAction/Wilson.cc delete mode 100644 extras/Hadrons/Modules/MContraction/Meson.cc delete mode 100644 extras/Hadrons/Modules/MQuark.hpp delete mode 100644 extras/Hadrons/Modules/MSolver/RBPrecCG.cc delete mode 100644 extras/Hadrons/Modules/MSource/Point.cc delete mode 100644 extras/Hadrons/Modules/MSource/Z2.cc rename extras/Hadrons/Modules/{MQuark.cc => Quark.hpp} (58%) diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 1dc9164a..3107ef12 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -56,10 +56,19 @@ using Grid::operator<<; BEGIN_HADRONS_NAMESPACE // type aliases -typedef FermionOperator FMat; -typedef FIMPL::FermionField FermionField; -typedef FIMPL::PropagatorField PropagatorField; -typedef std::function SolverFn; +//typedef FermionOperator FMat; +//typedef FIMPL::FermionField FermionField; +//typedef FIMPL::PropagatorField PropagatorField; +//typedef std::function SolverFn; + +#define TYPE_ALIASES(FImpl, suffix)\ +typedef FermionOperator FMat##suffix; \ +typedef typename FImpl::FermionField FermionField##suffix; \ +typedef typename FImpl::PropagatorField PropagatorField##suffix; \ +typedef typename FImpl::SitePropagator SitePropagator##suffix; \ +typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;\ +typedef std::function SolverFn##suffix; // logger class HadronsLogger: public Logger diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 998c609f..e90d0313 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -4,7 +4,7 @@ #include #include #include -#include #include #include #include +#include diff --git a/extras/Hadrons/Modules/MAction/DWF.cc b/extras/Hadrons/Modules/MAction/DWF.cc deleted file mode 100644 index 36527b58..00000000 --- a/extras/Hadrons/Modules/MAction/DWF.cc +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/DWF.cc - -Copyright (C) 2016 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -using namespace Grid; -using namespace Hadrons; -using namespace MAction; - -/****************************************************************************** -* DWF implementation * -******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -DWF::DWF(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -std::vector DWF::getInput(void) -{ - std::vector in = {par().gauge}; - - return in; -} - -std::vector DWF::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// setup /////////////////////////////////////////////////////////////////////// -void DWF::setup(void) -{ - unsigned int size; - - size = 3*env().lattice4dSize(); - env().registerObject(getName(), size, par().Ls); -} - -// execution /////////////////////////////////////////////////////////////////// -void DWF::execute(void) -{ - LOG(Message) << "Setting up domain wall fermion matrix with m= " - << par().mass << ", M5= " << par().M5 << " and Ls= " - << par().Ls << " using gauge field '" << par().gauge << "'" - << std::endl; - env().createGrid(par().Ls); - auto &U = *env().getObject(par().gauge); - auto &g4 = *env().getGrid(); - auto &grb4 = *env().getRbGrid(); - auto &g5 = *env().getGrid(par().Ls); - auto &grb5 = *env().getRbGrid(par().Ls); - FMat *fMatPt = new DomainWallFermion(U, g5, grb5, g4, grb4, - par().mass, par().M5); - env().setObject(getName(), fMatPt); -} diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 246fafd4..ceec975c 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -49,13 +49,16 @@ public: double , M5); }; -class DWF: public Module +template +class TDWF: public Module { +public: + TYPE_ALIASES(FImpl,); public: // constructor - DWF(const std::string name); + TDWF(const std::string name); // destructor - virtual ~DWF(void) = default; + virtual ~TDWF(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -65,6 +68,63 @@ public: virtual void execute(void); }; +/****************************************************************************** + * DWF template implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TDWF::TDWF(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TDWF::getInput(void) +{ + std::vector in = {par().gauge}; + + return in; +} + +template +std::vector TDWF::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TDWF::setup(void) +{ + unsigned int size; + + size = 3*env().template lattice4dSize(); + env().registerObject(getName(), size, par().Ls); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TDWF::execute(void) +{ + LOG(Message) << "Setting up domain wall fermion matrix with m= " + << par().mass << ", M5= " << par().M5 << " and Ls= " + << par().Ls << " using gauge field '" << par().gauge << "'" + << std::endl; + env().createGrid(par().Ls); + auto &U = *env().template getObject(par().gauge); + auto &g4 = *env().getGrid(); + auto &grb4 = *env().getRbGrid(); + auto &g5 = *env().getGrid(par().Ls); + auto &grb5 = *env().getRbGrid(par().Ls); + FMat *fMatPt = new DomainWallFermion(U, g5, grb5, g4, grb4, + par().mass, par().M5); + env().setObject(getName(), fMatPt); +} + +typedef TDWF DWF; + END_MODULE_NAMESPACE MODULE_REGISTER_NS(DWF, MAction); diff --git a/extras/Hadrons/Modules/MAction/Wilson.cc b/extras/Hadrons/Modules/MAction/Wilson.cc deleted file mode 100644 index 3188a636..00000000 --- a/extras/Hadrons/Modules/MAction/Wilson.cc +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/Wilson.cc - -Copyright (C) 2016 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -using namespace Grid; -using namespace Hadrons; -using namespace MAction; - -/****************************************************************************** -* Wilson implementation * -******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -Wilson::Wilson(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -std::vector Wilson::getInput(void) -{ - std::vector in = {par().gauge}; - - return in; -} - -std::vector Wilson::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// setup /////////////////////////////////////////////////////////////////////// -void Wilson::setup(void) -{ - unsigned int size; - - size = 3*env().lattice4dSize(); - env().registerObject(getName(), size); -} - -// execution /////////////////////////////////////////////////////////////////// -void Wilson::execute() -{ - LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass - << " using gauge field '" << par().gauge << "'" << std::endl; - auto &U = *env().getObject(par().gauge); - auto &grid = *env().getGrid(); - auto &gridRb = *env().getRbGrid(); - FMat *fMatPt = new WilsonFermion(U, grid, gridRb, par().mass); - env().setObject(getName(), fMatPt); -} diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index d3965f09..6a4528ca 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Wilson.hpp +Source file: programs/Hadrons/TWilson.hpp Copyright (C) 2016 @@ -35,7 +35,7 @@ directory. BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * Wilson quark action * + * TWilson quark action * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MAction) @@ -47,13 +47,16 @@ public: double , mass); }; -class Wilson: public Module +template +class TWilson: public Module { +public: + TYPE_ALIASES(FImpl,); public: // constructor - Wilson(const std::string name); + TWilson(const std::string name); // destructor - virtual ~Wilson(void) = default; + virtual ~TWilson(void) = default; // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -63,6 +66,57 @@ public: virtual void execute(void); }; +/****************************************************************************** + * TWilson template implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TWilson::TWilson(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TWilson::getInput(void) +{ + std::vector in = {par().gauge}; + + return in; +} + +template +std::vector TWilson::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TWilson::setup(void) +{ + unsigned int size; + + size = 3*env().template lattice4dSize(); + env().registerObject(getName(), size); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TWilson::execute() +{ + LOG(Message) << "Setting up TWilson fermion matrix with m= " << par().mass + << " using gauge field '" << par().gauge << "'" << std::endl; + auto &U = *env().template getObject(par().gauge); + auto &grid = *env().getGrid(); + auto &gridRb = *env().getRbGrid(); + FMat *fMatPt = new WilsonFermion(U, grid, gridRb, par().mass); + env().setObject(getName(), fMatPt); +} + +typedef TWilson Wilson; + END_MODULE_NAMESPACE MODULE_REGISTER_NS(Wilson, MAction); diff --git a/extras/Hadrons/Modules/MContraction/Meson.cc b/extras/Hadrons/Modules/MContraction/Meson.cc deleted file mode 100644 index fbdfceb1..00000000 --- a/extras/Hadrons/Modules/MContraction/Meson.cc +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/Meson.cc - -Copyright (C) 2015 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -using namespace Grid; -using namespace QCD; -using namespace Hadrons; -using namespace MContraction; - -/****************************************************************************** - * Meson implementation * - ******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -Meson::Meson(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -std::vector Meson::getInput(void) -{ - std::vector input = {par().q1, par().q2}; - - return input; -} - -std::vector Meson::getOutput(void) -{ - std::vector output = {getName()}; - - return output; -} - -// execution /////////////////////////////////////////////////////////////////// -void Meson::execute(void) -{ - LOG(Message) << "Computing meson contraction '" << getName() << "' using" - << " quarks '" << par().q1 << "' and '" << par().q2 << "'" - << std::endl; - - XmlWriter writer(par().output); - PropagatorField &q1 = *env().getObject(par().q1); - PropagatorField &q2 = *env().getObject(par().q2); - LatticeComplex c(env().getGrid()); - SpinMatrix g[Ns*Ns], g5; - std::vector buf; - Result result; - - g5 = makeGammaProd(Ns*Ns - 1); - result.corr.resize(Ns*Ns); - for (unsigned int i = 0; i < Ns*Ns; ++i) - { - g[i] = makeGammaProd(i); - } - for (unsigned int iSink = 0; iSink < Ns*Ns; ++iSink) - { - result.corr[iSink].resize(Ns*Ns); - for (unsigned int iSrc = 0; iSrc < Ns*Ns; ++iSrc) - { - c = trace(g[iSink]*q1*g[iSrc]*g5*adj(q2)*g5); - sliceSum(c, buf, Tp); - result.corr[iSink][iSrc].resize(buf.size()); - for (unsigned int t = 0; t < buf.size(); ++t) - { - result.corr[iSink][iSrc][t] = TensorRemove(buf[t]); - } - } - } - write(writer, "meson", result); -} diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 713c8631..fde05fca 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Meson.hpp +Source file: programs/Hadrons/TMeson.hpp Copyright (C) 2015 @@ -35,7 +35,7 @@ directory. BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * Meson * + * TMeson * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MContraction) @@ -48,8 +48,12 @@ public: std::string, output); }; -class Meson: public Module +template +class TMeson: public Module { +public: + TYPE_ALIASES(FImpl1, 1); + TYPE_ALIASES(FImpl2, 2); public: class Result: Serializable { @@ -59,9 +63,9 @@ public: }; public: // constructor - Meson(const std::string name); + TMeson(const std::string name); // destructor - virtual ~Meson(void) = default; + virtual ~TMeson(void) = default; // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -69,6 +73,73 @@ public: virtual void execute(void); }; +/****************************************************************************** + * TMeson implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TMeson::TMeson(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TMeson::getInput(void) +{ + std::vector input = {par().q1, par().q2}; + + return input; +} + +template +std::vector TMeson::getOutput(void) +{ + std::vector output = {getName()}; + + return output; +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TMeson::execute(void) +{ + LOG(Message) << "Computing meson contraction '" << getName() << "' using" + << " quarks '" << par().q1 << "' and '" << par().q2 << "'" + << std::endl; + + XmlWriter writer(par().output); + PropagatorField1 &q1 = *env().template getObject(par().q1); + PropagatorField2 &q2 = *env().template getObject(par().q2); + LatticeComplex c(env().getGrid()); + SpinMatrix g[Ns*Ns], g5; + std::vector buf; + Result result; + + g5 = makeGammaProd(Ns*Ns - 1); + result.corr.resize(Ns*Ns); + for (unsigned int i = 0; i < Ns*Ns; ++i) + { + g[i] = makeGammaProd(i); + } + for (unsigned int iSink = 0; iSink < Ns*Ns; ++iSink) + { + result.corr[iSink].resize(Ns*Ns); + for (unsigned int iSrc = 0; iSrc < Ns*Ns; ++iSrc) + { + c = trace(g[iSink]*q1*g[iSrc]*g5*adj(q2)*g5); + sliceSum(c, buf, Tp); + result.corr[iSink][iSrc].resize(buf.size()); + for (unsigned int t = 0; t < buf.size(); ++t) + { + result.corr[iSink][iSrc][t] = TensorRemove(buf[t]); + } + } + } + write(writer, "meson", result); +} + +typedef TMeson Meson; + END_MODULE_NAMESPACE MODULE_REGISTER_NS(Meson, MContraction); diff --git a/extras/Hadrons/Modules/MQuark.hpp b/extras/Hadrons/Modules/MQuark.hpp deleted file mode 100644 index ed6dfb0c..00000000 --- a/extras/Hadrons/Modules/MQuark.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/MQuark.hpp - -Copyright (C) 2015 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#ifndef Hadrons_MQuark_hpp_ -#define Hadrons_MQuark_hpp_ - -#include -#include -#include - -BEGIN_HADRONS_NAMESPACE - -/****************************************************************************** - * MQuark * - ******************************************************************************/ -class MQuarkPar: Serializable -{ -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(MQuarkPar, - std::string, source, - std::string, solver); -}; - -class MQuark: public Module -{ -public: - // constructor - MQuark(const std::string name); - // destructor - virtual ~MQuark(void) = default; - // dependencies/products - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -private: - unsigned int Ls_; - SolverFn *solver_{nullptr}; -}; - -MODULE_REGISTER(MQuark); - -END_HADRONS_NAMESPACE - -#endif // Hadrons_MQuark_hpp_ diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.cc b/extras/Hadrons/Modules/MSolver/RBPrecCG.cc deleted file mode 100644 index 9cdd05aa..00000000 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.cc +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/RBPrecCG.cc - -Copyright (C) 2016 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -using namespace Grid; -using namespace QCD; -using namespace Hadrons; -using namespace MSolver; - -/****************************************************************************** -* RBPrecCG implementation * -******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -RBPrecCG::RBPrecCG(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -std::vector RBPrecCG::getInput(void) -{ - std::vector in = {par().action}; - - return in; -} - -std::vector RBPrecCG::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// setup /////////////////////////////////////////////////////////////////////// -void RBPrecCG::setup(void) -{ - auto Ls = env().getObjectLs(par().action); - - env().registerObject(getName(), 0, Ls); - env().addOwnership(getName(), par().action); -} - -// execution /////////////////////////////////////////////////////////////////// -void RBPrecCG::execute(void) -{ - auto &mat = *(env().getObject(par().action)); - auto solver = [&mat, this](LatticeFermion &sol, - const LatticeFermion &source) - { - ConjugateGradient cg(par().residual, 10000); - SchurRedBlackDiagMooeeSolve schurSolver(cg); - - schurSolver(mat, source, sol); - }; - - LOG(Message) << "setting up Schur red-black preconditioned CG for" - << " action '" << par().action << "' with residual " - << par().residual << std::endl; - env().setObject(getName(), new SolverFn(solver)); -} diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index 14d8c169..57ebb816 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/RBPrecCG.hpp +Source file: programs/Hadrons/TRBPrecCG.hpp Copyright (C) 2016 @@ -47,13 +47,16 @@ public: double , residual); }; -class RBPrecCG: public Module +template +class TRBPrecCG: public Module { +public: + TYPE_ALIASES(FImpl,); public: // constructor - RBPrecCG(const std::string name); + TRBPrecCG(const std::string name); // destructor - virtual ~RBPrecCG(void) = default; + virtual ~TRBPrecCG(void) = default; // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -63,6 +66,63 @@ public: virtual void execute(void); }; +/****************************************************************************** + * TRBPrecCG template implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TRBPrecCG::TRBPrecCG(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TRBPrecCG::getInput(void) +{ + std::vector in = {par().action}; + + return in; +} + +template +std::vector TRBPrecCG::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TRBPrecCG::setup(void) +{ + auto Ls = env().getObjectLs(par().action); + + env().registerObject(getName(), 0, Ls); + env().addOwnership(getName(), par().action); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TRBPrecCG::execute(void) +{ + auto &mat = *(env().template getObject(par().action)); + auto solver = [&mat, this](FermionField &sol, const FermionField &source) + { + ConjugateGradient cg(par().residual, 10000); + SchurRedBlackDiagMooeeSolve schurSolver(cg); + + schurSolver(mat, source, sol); + }; + + LOG(Message) << "setting up Schur red-black preconditioned CG for" + << " action '" << par().action << "' with residual " + << par().residual << std::endl; + env().setObject(getName(), new SolverFn(solver)); +} + +typedef TRBPrecCG RBPrecCG; + END_MODULE_NAMESPACE MODULE_REGISTER_NS(RBPrecCG, MSolver); diff --git a/extras/Hadrons/Modules/MSource/Point.cc b/extras/Hadrons/Modules/MSource/Point.cc deleted file mode 100644 index f22f41d9..00000000 --- a/extras/Hadrons/Modules/MSource/Point.cc +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/Point.cc - -Copyright (C) 2016 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -using namespace Grid; -using namespace Hadrons; -using namespace MSource; - -/****************************************************************************** -* Point implementation * -******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -Point::Point(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -std::vector Point::getInput(void) -{ - std::vector in; - - return in; -} - -std::vector Point::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// setup /////////////////////////////////////////////////////////////////////// -void Point::setup(void) -{ - env().registerLattice(getName()); -} - -// execution /////////////////////////////////////////////////////////////////// -void Point::execute(void) -{ - std::vector position = strToVec(par().position); - SpinColourMatrix id; - - LOG(Message) << "Creating point source at position [" << par().position - << "]" << std::endl; - PropagatorField &src = *env().createLattice(getName()); - id = 1.; - src = zero; - pokeSite(id, src, position); -} diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 1245ed9a..ad0a37b5 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Point.hpp +Source file: programs/Hadrons/TPoint.hpp Copyright (C) 2016 @@ -46,7 +46,7 @@ BEGIN_HADRONS_NAMESPACE */ /****************************************************************************** - * Point * + * TPoint * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MSource) @@ -57,13 +57,16 @@ public: std::string, position); }; -class Point: public Module +template +class TPoint: public Module { +public: + TYPE_ALIASES(FImpl,); public: // constructor - Point(const std::string name); + TPoint(const std::string name); // destructor - virtual ~Point(void) = default; + virtual ~TPoint(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -73,6 +76,56 @@ public: virtual void execute(void); }; +/****************************************************************************** + * TPoint template implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TPoint::TPoint(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TPoint::getInput(void) +{ + std::vector in; + + return in; +} + +template +std::vector TPoint::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TPoint::setup(void) +{ + env().template registerLattice(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TPoint::execute(void) +{ + std::vector position = strToVec(par().position); + typename SitePropagator::scalar_object id; + + LOG(Message) << "Creating point source at position [" << par().position + << "]" << std::endl; + PropagatorField &src = *env().template createLattice(getName()); + id = 1.; + src = zero; + pokeSite(id, src, position); +} + +typedef TPoint Point; + END_MODULE_NAMESPACE MODULE_REGISTER_NS(Point, MSource); diff --git a/extras/Hadrons/Modules/MSource/Z2.cc b/extras/Hadrons/Modules/MSource/Z2.cc deleted file mode 100644 index 90f9f274..00000000 --- a/extras/Hadrons/Modules/MSource/Z2.cc +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: programs/Hadrons/Z2.cc - -Copyright (C) 2016 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -using namespace Grid; -using namespace Hadrons; -using namespace MSource; - -/****************************************************************************** -* Z2 implementation * -******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -Z2::Z2(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -std::vector Z2::getInput(void) -{ - std::vector in; - - return in; -} - -std::vector Z2::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// setup /////////////////////////////////////////////////////////////////////// -void Z2::setup(void) -{ - env().registerLattice(getName()); -} - -// execution /////////////////////////////////////////////////////////////////// -void Z2::execute(void) -{ - Lattice> t(env().getGrid()); - LatticeComplex eta(env().getGrid()); - LatticeFermion phi(env().getGrid()); - Complex shift(1., 1.); - - if (par().tA == par().tB) - { - LOG(Message) << "Generating Z_2 wall source at t= " << par().tA - << std::endl; - } - else - { - LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " - << par().tB << std::endl; - } - PropagatorField &src = *env().createLattice(getName()); - LatticeCoordinate(t, Tp); - bernoulli(*env().get4dRng(), eta); - eta = (2.*eta - shift)*(1./::sqrt(2.)); - eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta); - src = 1.; - src = src*eta; -} diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index ac569ced..21d0b2bd 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Z2.hpp +Source file: programs/Hadrons/TZ2.hpp Copyright (C) 2016 @@ -47,7 +47,7 @@ BEGIN_HADRONS_NAMESPACE */ /****************************************************************************** - * Z2 * + * Z2 stochastic source * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MSource) @@ -59,13 +59,16 @@ public: unsigned int, tB); }; -class Z2: public Module +template +class TZ2: public Module { +public: + TYPE_ALIASES(FImpl,); public: // constructor - Z2(const std::string name); + TZ2(const std::string name); // destructor - virtual ~Z2(void) = default; + virtual ~TZ2(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -75,6 +78,68 @@ public: virtual void execute(void); }; +/****************************************************************************** + * TZ2 template implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TZ2::TZ2(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TZ2::getInput(void) +{ + std::vector in; + + return in; +} + +template +std::vector TZ2::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TZ2::setup(void) +{ + env().template registerLattice(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TZ2::execute(void) +{ + Lattice> t(env().getGrid()); + LatticeComplex eta(env().getGrid()); + Complex shift(1., 1.); + + if (par().tA == par().tB) + { + LOG(Message) << "Generating Z_2 wall source at t= " << par().tA + << std::endl; + } + else + { + LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " + << par().tB << std::endl; + } + PropagatorField &src = *env().template createLattice(getName()); + LatticeCoordinate(t, Tp); + bernoulli(*env().get4dRng(), eta); + eta = (2.*eta - shift)*(1./::sqrt(2.)); + eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta); + src = 1.; + src = src*eta; +} + +typedef TZ2 Z2; + END_MODULE_NAMESPACE MODULE_REGISTER_NS(Z2, MSource); diff --git a/extras/Hadrons/Modules/MQuark.cc b/extras/Hadrons/Modules/Quark.hpp similarity index 58% rename from extras/Hadrons/Modules/MQuark.cc rename to extras/Hadrons/Modules/Quark.hpp index 07f25e1c..59274546 100644 --- a/extras/Hadrons/Modules/MQuark.cc +++ b/extras/Hadrons/Modules/Quark.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/MQuark.cc +Source file: programs/Hadrons/TQuark.hpp Copyright (C) 2015 @@ -25,29 +25,68 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ -#include +#ifndef Hadrons_Quark_hpp_ +#define Hadrons_Quark_hpp_ -using namespace Grid; -using namespace QCD; -using namespace Hadrons; +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * MQuark implementation * + * TQuark * + ******************************************************************************/ +class QuarkPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(QuarkPar, + std::string, source, + std::string, solver); +}; + +template +class TQuark: public Module +{ +public: + TYPE_ALIASES(FImpl,); +public: + // constructor + TQuark(const std::string name); + // destructor + virtual ~TQuark(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +private: + unsigned int Ls_; + SolverFn *solver_{nullptr}; +}; + +/****************************************************************************** + * TQuark implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -MQuark::MQuark(const std::string name) +template +TQuark::TQuark(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector MQuark::getInput(void) +template +std::vector TQuark::getInput(void) { std::vector in = {par().source, par().solver}; return in; } -std::vector MQuark::getOutput(void) +template +std::vector TQuark::getOutput(void) { std::vector out = {getName(), getName() + "_5d"}; @@ -55,40 +94,42 @@ std::vector MQuark::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void MQuark::setup(void) +template +void TQuark::setup(void) { Ls_ = env().getObjectLs(par().solver); - env().registerLattice(getName()); + env().template registerLattice(getName()); if (Ls_ > 1) { - env().registerLattice(getName() + "_5d", Ls_); + env().template registerLattice(getName() + "_5d", Ls_); } } // execution /////////////////////////////////////////////////////////////////// -void MQuark::execute(void) +template +void TQuark::execute(void) { - LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)), - tmp(env().getGrid()); - std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); - LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; - LatticePropagator &prop = *env().createLattice(propName); - LatticePropagator &fullSrc = *env().getObject(par().source); - SolverFn &solver = *env().getObject(par().solver); + + FermionField source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)), + tmp(env().getGrid()); + std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); + PropagatorField &prop = *env().template createLattice(propName); + PropagatorField &fullSrc = *env().template getObject(par().source); + SolverFn &solver = *env().template getObject(par().solver); if (Ls_ > 1) { - env().createLattice(getName()); + env().template createLattice(getName()); } - + LOG(Message) << "Inverting using solver '" << par().solver << "' on source '" << par().source << "'" << std::endl; for (unsigned int s = 0; s < Ns; ++s) for (unsigned int c = 0; c < Nc; ++c) { LOG(Message) << "Inversion for spin= " << s << ", color= " << c - << std::endl; + << std::endl; // source conversion for 4D sources if (!env().isObject5d(par().source)) { @@ -124,7 +165,8 @@ void MQuark::execute(void) // create 4D propagators from 5D one if necessary if (Ls_ > 1) { - LatticePropagator &p4d = *env().getObject(getName()); + PropagatorField &p4d = + *env().template getObject(getName()); axpby_ssp_pminus(sol, 0., sol, 1., sol, 0, 0); axpby_ssp_pplus(sol, 0., sol, 1., sol, 0, Ls_-1); @@ -133,3 +175,11 @@ void MQuark::execute(void) } } } + +typedef TQuark Quark; + +MODULE_REGISTER(Quark); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Quark_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index a460ae86..aacbbf14 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -1,14 +1,7 @@ modules_cc =\ - Modules/MAction/DWF.cc \ - Modules/MAction/Wilson.cc \ - Modules/MContraction/Meson.cc \ Modules/MGauge/Load.cc \ Modules/MGauge/Random.cc \ - Modules/MGauge/Unit.cc \ - Modules/MQuark.cc \ - Modules/MSolver/RBPrecCG.cc \ - Modules/MSource/Point.cc \ - Modules/MSource/Z2.cc + Modules/MGauge/Unit.cc modules_hpp =\ Modules/MAction/DWF.hpp \ @@ -17,8 +10,8 @@ modules_hpp =\ Modules/MGauge/Load.hpp \ Modules/MGauge/Random.hpp \ Modules/MGauge/Unit.hpp \ - Modules/MQuark.hpp \ Modules/MSolver/RBPrecCG.hpp \ Modules/MSource/Point.hpp \ - Modules/MSource/Z2.hpp + Modules/MSource/Z2.hpp \ + Modules/Quark.hpp diff --git a/tests/hadrons/Test_hadrons_mesons.cc b/tests/hadrons/Test_hadrons_mesons.cc index b9561694..75d752b2 100644 --- a/tests/hadrons/Test_hadrons_mesons.cc +++ b/tests/hadrons/Test_hadrons_mesons.cc @@ -82,10 +82,10 @@ int main(int argc, char *argv[]) solverPar); // propagators - MQuark::Par quarkPar; + Quark::Par quarkPar; quarkPar.solver = "CG_" + flavour[i]; quarkPar.source = (flavour[i][0] == 'c') ? "z2" : "pt"; - application.createModule("Q_" + flavour[i], quarkPar); + application.createModule("Q_" + flavour[i], quarkPar); } for (unsigned int i = 0; i < flavour.size(); ++i) for (unsigned int j = i + 1; j < flavour.size(); ++j) From d292657ef74bb217edff4ab4581f205443eb27e6 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 17:26:17 +0900 Subject: [PATCH 076/106] Hadrons: more module templates --- .../Modules/templates/Module_tmp.hpp.template | 83 ++++++++++++++++++ .../templates/Module_tmp_in_NS.hpp.template | 87 +++++++++++++++++++ extras/Hadrons/add_module_template.sh | 28 ++++++ 3 files changed, 198 insertions(+) create mode 100644 extras/Hadrons/Modules/templates/Module_tmp.hpp.template create mode 100644 extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template create mode 100755 extras/Hadrons/add_module_template.sh diff --git a/extras/Hadrons/Modules/templates/Module_tmp.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template new file mode 100644 index 00000000..53bee52b --- /dev/null +++ b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template @@ -0,0 +1,83 @@ +#ifndef Hadrons____FILEBASENAME____hpp_ +#define Hadrons____FILEBASENAME____hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * ___FILEBASENAME___ * + ******************************************************************************/ +class ___FILEBASENAME___Par: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(___FILEBASENAME___Par, + unsigned int, i); +}; + +template +class T___FILEBASENAME___: public Module<___FILEBASENAME___Par> +{ +public: + // constructor + T___FILEBASENAME___(const std::string name); + // destructor + virtual ~T___FILEBASENAME___(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +typedef T___FILEBASENAME___ ___FILEBASENAME___; + +/****************************************************************************** + * T___FILEBASENAME___ implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +T___FILEBASENAME___::T___FILEBASENAME___(const std::string name) +: Module<___FILEBASENAME___Par>(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector T___FILEBASENAME___::getInput(void) +{ + std::vector in; + + return in; +} + +template +std::vector T___FILEBASENAME___::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void T___FILEBASENAME___::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +template +void T___FILEBASENAME___::execute(void) +{ + +} + +MODULE_REGISTER(___FILEBASENAME___); + +END_HADRONS_NAMESPACE + +#endif // Hadrons____FILEBASENAME____hpp_ diff --git a/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template new file mode 100644 index 00000000..e7ff8ace --- /dev/null +++ b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template @@ -0,0 +1,87 @@ +#ifndef Hadrons____FILEBASENAME____hpp_ +#define Hadrons____FILEBASENAME____hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * ___FILEBASENAME___ * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(___NAMESPACE___) + +class ___FILEBASENAME___Par: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(___FILEBASENAME___Par, + unsigned int, i); +}; + +template +class T___FILEBASENAME___: public Module<___FILEBASENAME___Par> +{ +public: + // constructor + T___FILEBASENAME___(const std::string name); + // destructor + virtual ~T___FILEBASENAME___(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +typedef T___FILEBASENAME___ ___FILEBASENAME___; + +/****************************************************************************** + * T___FILEBASENAME___ implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +T___FILEBASENAME___::T___FILEBASENAME___(const std::string name) +: Module<___FILEBASENAME___Par>(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector T___FILEBASENAME___::getInput(void) +{ + std::vector in; + + return in; +} + +template +std::vector T___FILEBASENAME___::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void T___FILEBASENAME___::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +template +void T___FILEBASENAME___::execute(void) +{ + +} + +END_MODULE_NAMESPACE + +MODULE_REGISTER_NS(___FILEBASENAME___, ___NAMESPACE___); + +END_HADRONS_NAMESPACE + +#endif // Hadrons____FILEBASENAME____hpp_ diff --git a/extras/Hadrons/add_module_template.sh b/extras/Hadrons/add_module_template.sh new file mode 100755 index 00000000..0069fcea --- /dev/null +++ b/extras/Hadrons/add_module_template.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +if (( $# != 1 && $# != 2)); then + echo "usage: `basename $0` []" 1>&2 + exit 1 +fi +NAME=$1 +NS=$2 + +if (( $# == 1 )); then + if [ -e "Modules/${NAME}.cc" ] || [ -e "Modules/${NAME}.hpp" ]; then + echo "error: files Modules/${NAME}.* already exists" 1>&2 + exit 1 + fi + sed "s/___FILEBASENAME___/${NAME}/g" Modules/templates/Module_tmp.hpp.template > Modules/${NAME}.hpp +elif (( $# == 2 )); then + mkdir -p Modules/${NS} + if [ -e "Modules/${NS}/${NAME}.cc" ] || [ -e "Modules/${NS}/${NAME}.hpp" ]; then + echo "error: files Modules/${NS}/${NAME}.* already exists" 1>&2 + exit 1 + fi + TMPCC=".${NS}.${NAME}.tmp.cc" + TMPHPP=".${NS}.${NAME}.tmp.hpp" + sed "s/___FILEBASENAME___/${NAME}/g" Modules/templates/Module_tmp_in_NS.hpp.template > ${TMPHPP} + sed "s/___NAMESPACE___/${NS}/g" ${TMPHPP} > Modules/${NS}/${NAME}.hpp + rm -f ${TMPCC} ${TMPHPP} +fi +./make_module_list.sh From d42a1b73c483e6f9a0464d701ca90ff9ac52483e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 17:26:36 +0900 Subject: [PATCH 077/106] Hadrons: code cleaning --- extras/Hadrons/Application.cc | 2 -- extras/Hadrons/Modules/MContraction/Meson.hpp | 7 +++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 21f84ad1..63fb3673 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -117,8 +117,6 @@ void Application::parseParameterFile(void) } while (reader.nextElement("module")); pop(reader); pop(reader); - env_.setSeed(strToVec(par_.seed)); - env_.printContent(); } // schedule computation //////////////////////////////////////////////////////// diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index fde05fca..517b509d 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -54,7 +54,6 @@ class TMeson: public Module public: TYPE_ALIASES(FImpl1, 1); TYPE_ALIASES(FImpl2, 2); -public: class Result: Serializable { public: @@ -103,9 +102,9 @@ std::vector TMeson::getOutput(void) template void TMeson::execute(void) { - LOG(Message) << "Computing meson contraction '" << getName() << "' using" - << " quarks '" << par().q1 << "' and '" << par().q2 << "'" - << std::endl; + LOG(Message) << "Computing meson contractions '" << getName() << "' using" + << " quarks '" << par().q1 << "' and '" << par().q2 << "'" + << std::endl; XmlWriter writer(par().output); PropagatorField1 &q1 = *env().template getObject(par().q1); From aa016f61b968b5cfabddc694ace3ee77967738b3 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 17:26:57 +0900 Subject: [PATCH 078/106] Hadrons: empty baryon contractions --- extras/Hadrons/Modules.hpp | 1 + .../Hadrons/Modules/MContraction/Baryon.hpp | 104 ++++++++++++++++++ extras/Hadrons/modules.inc | 1 + tests/hadrons/Test_hadrons_mesons.cc | 17 ++- 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 extras/Hadrons/Modules/MContraction/Baryon.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index e90d0313..b08a7468 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp new file mode 100644 index 00000000..e8191793 --- /dev/null +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -0,0 +1,104 @@ +#ifndef Hadrons_Baryon_hpp_ +#define Hadrons_Baryon_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Baryon * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MContraction) + +class BaryonPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(BaryonPar, + std::string, q1, + std::string, q2, + std::string, q3, + std::string, output); +}; + +template +class TBaryon: public Module +{ +public: + TYPE_ALIASES(FImpl1, 1); + TYPE_ALIASES(FImpl2, 2); + TYPE_ALIASES(FImpl3, 3); + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::vector>>, corr); + }; +public: + // constructor + TBaryon(const std::string name); + // destructor + virtual ~TBaryon(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // execution + virtual void execute(void); +}; + +typedef TBaryon Baryon; + +/****************************************************************************** + * TBaryon implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TBaryon::TBaryon(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TBaryon::getInput(void) +{ + std::vector input = {par().q1, par().q2, par().q3}; + + return input; +} + +template +std::vector TBaryon::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TBaryon::execute(void) +{ + LOG(Message) << "Computing baryon contractions '" << getName() << "' using" + << " quarks '" << par().q1 << "', '" << par().q2 << "', and '" + << par().q3 << "'" << std::endl; + + XmlWriter writer(par().output); + PropagatorField1 &q1 = *env().template getObject(par().q1); + PropagatorField2 &q2 = *env().template getObject(par().q2); + PropagatorField3 &q3 = *env().template getObject(par().q2); + LatticeComplex c(env().getGrid()); + Result result; + + // FIXME: do contractions + + write(writer, "meson", result); +} + +END_MODULE_NAMESPACE + +MODULE_REGISTER_NS(Baryon, MContraction); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Baryon_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index aacbbf14..aad6c73b 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -6,6 +6,7 @@ modules_cc =\ modules_hpp =\ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ + Modules/MContraction/Baryon.hpp \ Modules/MContraction/Meson.hpp \ Modules/MGauge/Load.hpp \ Modules/MGauge/Random.hpp \ diff --git a/tests/hadrons/Test_hadrons_mesons.cc b/tests/hadrons/Test_hadrons_mesons.cc index 75d752b2..620e6ba8 100644 --- a/tests/hadrons/Test_hadrons_mesons.cc +++ b/tests/hadrons/Test_hadrons_mesons.cc @@ -87,8 +87,8 @@ int main(int argc, char *argv[]) quarkPar.source = (flavour[i][0] == 'c') ? "z2" : "pt"; application.createModule("Q_" + flavour[i], quarkPar); } - for (unsigned int i = 0; i < flavour.size(); ++i) - for (unsigned int j = i + 1; j < flavour.size(); ++j) + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i; j < flavour.size(); ++j) { MContraction::Meson::Par mesPar; @@ -99,6 +99,19 @@ int main(int argc, char *argv[]) + flavour[i] + flavour[j], mesPar); } + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i; j < flavour.size(); ++j) + for (unsigned int k = j; k < flavour.size(); ++k) + { + MContraction::Baryon::Par barPar; + + barPar.output = "baryons/" + flavour[i] + flavour[j] + flavour[k]; + barPar.q1 = "Q_" + flavour[i]; + barPar.q2 = "Q_" + flavour[j]; + barPar.q3 = "Q_" + flavour[k]; + application.createModule( + "baryon_" + flavour[i] + flavour[j] + flavour[k], barPar); + } // execution application.run(); From e6effcfd950b80b671c5a456caece44a4fa78832 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 5 Dec 2016 17:41:58 +0900 Subject: [PATCH 079/106] Hadrons: more contractions in the spectrum test --- tests/hadrons/Test_hadrons_mesons.cc | 30 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tests/hadrons/Test_hadrons_mesons.cc b/tests/hadrons/Test_hadrons_mesons.cc index 620e6ba8..baf1cd38 100644 --- a/tests/hadrons/Test_hadrons_mesons.cc +++ b/tests/hadrons/Test_hadrons_mesons.cc @@ -84,18 +84,26 @@ int main(int argc, char *argv[]) // propagators Quark::Par quarkPar; quarkPar.solver = "CG_" + flavour[i]; - quarkPar.source = (flavour[i][0] == 'c') ? "z2" : "pt"; - application.createModule("Q_" + flavour[i], quarkPar); + quarkPar.source = "pt"; + application.createModule("Qpt_" + flavour[i], quarkPar); + quarkPar.source = "z2"; + application.createModule("QZ2_" + flavour[i], quarkPar); } for (unsigned int i = 0; i < flavour.size(); ++i) for (unsigned int j = i; j < flavour.size(); ++j) { MContraction::Meson::Par mesPar; - mesPar.output = "mesons/" + flavour[i] + flavour[j]; - mesPar.q1 = "Q_" + flavour[i]; - mesPar.q2 = "Q_" + flavour[j]; - application.createModule("meson_" + mesPar.output = "mesons/pt_" + flavour[i] + flavour[j]; + mesPar.q1 = "Qpt_" + flavour[i]; + mesPar.q2 = "Qpt_" + flavour[j]; + application.createModule("meson_pt_" + + flavour[i] + flavour[j], + mesPar); + mesPar.output = "mesons/Z2_" + flavour[i] + flavour[j]; + mesPar.q1 = "QZ2_" + flavour[i]; + mesPar.q2 = "QZ2_" + flavour[j]; + application.createModule("meson_Z2_" + flavour[i] + flavour[j], mesPar); } @@ -105,12 +113,12 @@ int main(int argc, char *argv[]) { MContraction::Baryon::Par barPar; - barPar.output = "baryons/" + flavour[i] + flavour[j] + flavour[k]; - barPar.q1 = "Q_" + flavour[i]; - barPar.q2 = "Q_" + flavour[j]; - barPar.q3 = "Q_" + flavour[k]; + barPar.output = "baryons/pt_" + flavour[i] + flavour[j] + flavour[k]; + barPar.q1 = "Qpt_" + flavour[i]; + barPar.q2 = "Qpt_" + flavour[j]; + barPar.q3 = "Qpt_" + flavour[k]; application.createModule( - "baryon_" + flavour[i] + flavour[j] + flavour[k], barPar); + "baryon_pt_" + flavour[i] + flavour[j] + flavour[k], barPar); } // execution From a683a0f55aa945b23af844e9cfeb28309d25fb0b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 6 Dec 2016 12:11:44 +0900 Subject: [PATCH 080/106] Hadrons: meson tests renamed spectrum --- .../{Test_hadrons_mesons.cc => Test_hadrons_spectrum.cc} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/hadrons/{Test_hadrons_mesons.cc => Test_hadrons_spectrum.cc} (98%) diff --git a/tests/hadrons/Test_hadrons_mesons.cc b/tests/hadrons/Test_hadrons_spectrum.cc similarity index 98% rename from tests/hadrons/Test_hadrons_mesons.cc rename to tests/hadrons/Test_hadrons_spectrum.cc index baf1cd38..93d31fed 100644 --- a/tests/hadrons/Test_hadrons_mesons.cc +++ b/tests/hadrons/Test_hadrons_spectrum.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid - Source file: programs/Hadrons/Hadrons.cc + Source file: tests/hadrons/Test_hadrons_spectrum.cc Copyright (C) 2015 From 646b11f5c246c4a09ad80f5901e9a21028afe933 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 6 Dec 2016 12:12:05 +0900 Subject: [PATCH 081/106] Hadrons: exposing scheduler settings --- extras/Hadrons/Application.cc | 9 +++++---- extras/Hadrons/Application.hpp | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 63fb3673..1b0c37f8 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -76,6 +76,7 @@ Application::Application(const std::string parameterFileName) void Application::setPar(const Application::GlobalPar &par) { par_ = par; + LOG(Message) << par_.seed << std::endl; env_.setSeed(strToVec(par_.seed)); } @@ -144,15 +145,14 @@ void Application::schedule(void) // constrained topological sort using a genetic algorithm LOG(Message) << "Scheduling computation..." << std::endl; - constexpr unsigned int maxGen = 200, maxCstGen = 50; unsigned int k = 0, gen, prevPeak, nCstPeak = 0; auto graph = env_.makeModuleGraph(); auto con = graph.getConnectedComponents(); std::random_device rd; GeneticScheduler::Parameters par; - par.popSize = 10; - par.mutationRate = .1; + par.popSize = par_.genetic.popSize; + par.mutationRate = par_.genetic.mutationRate; par.seed = rd(); CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); for (unsigned int i = 0; i < con.size(); ++i) @@ -182,7 +182,8 @@ void Application::schedule(void) << MEM_MSG(scheduler.getMinValue()) << std::endl; } gen++; - } while ((gen < maxGen) and (nCstPeak < maxCstGen)); + } while ((gen < par_.genetic.maxGen) + and (nCstPeak < par_.genetic.maxCstGen)); auto &t = scheduler.getMinSchedule(); LOG(Message) << "Program " << i + 1 << " (memory peak: " << MEM_MSG(scheduler.getMinValue()) << "):" << std::endl; diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index b0c88030..846b4dfa 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -49,11 +49,24 @@ public: unsigned int, end, unsigned int, step); }; + class GeneticPar: Serializable + { + public: + GeneticPar(void): + popSize{20}, maxGen{1000}, maxCstGen{100}, mutationRate{.1} {}; + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(GeneticPar, + unsigned int, popSize, + unsigned int, maxGen, + unsigned int, maxCstGen, + double , mutationRate); + }; class GlobalPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, TrajRange, trajCounter, + GeneticPar, genetic, std::string, seed); }; public: From bd1d1cca34e097e1ddced6f2106e0acfa58868a7 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 6 Dec 2016 12:12:59 +0900 Subject: [PATCH 082/106] Hadrons: code cleaning --- extras/Hadrons/Modules/MContraction/Meson.hpp | 2 +- extras/Hadrons/Modules/MSource/Point.hpp | 4 ++-- extras/Hadrons/Modules/MSource/Z2.hpp | 4 +++- tests/hadrons/Test_hadrons_xmldriven.cc | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 517b509d..b2625b3e 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -73,7 +73,7 @@ public: }; /****************************************************************************** - * TMeson implementation * + * TMeson implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index ad0a37b5..456de76c 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -38,9 +38,9 @@ BEGIN_HADRONS_NAMESPACE Point source ------------ - * src_x = delta_x,o + * src_x = delta_x,position - * options: o + * options: - position: space-separated integer sequence (e.g. "0 1 1 0") */ diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index 21d0b2bd..76fefc8f 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -38,7 +38,9 @@ BEGIN_HADRONS_NAMESPACE Z_2 stochastic source ----------------------------- - * src_x = eta_x * theta(x_3 - ta) * theta(tb - x_3) + * src_x = eta_x * theta(x_3 - tA) * theta(tB - x_3) + + the eta_x are independent uniform random numbers in {+/- 1 +/- i} * options: - tA: begin timeslice (integer) diff --git a/tests/hadrons/Test_hadrons_xmldriven.cc b/tests/hadrons/Test_hadrons_xmldriven.cc index ad43b6cc..feb547e9 100644 --- a/tests/hadrons/Test_hadrons_xmldriven.cc +++ b/tests/hadrons/Test_hadrons_xmldriven.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Hadrons.cc +Source file: tests/hadrons/Test_hadrons_xmldriven.cc Copyright (C) 2015 From 5b3edf08a405e80ebc9554532050720b767f891b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 6 Dec 2016 12:13:19 +0900 Subject: [PATCH 083/106] Hadrons: sequential gamma source --- extras/Hadrons/Modules.hpp | 1 + extras/Hadrons/Modules/MSource/SeqGamma.hpp | 137 ++++++++++++++++ extras/Hadrons/modules.inc | 1 + tests/hadrons/Test_hadrons_meson_3pt.cc | 171 ++++++++++++++++++++ 4 files changed, 310 insertions(+) create mode 100644 extras/Hadrons/Modules/MSource/SeqGamma.hpp create mode 100644 tests/hadrons/Test_hadrons_meson_3pt.cc diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index b08a7468..72807d8b 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -7,5 +7,6 @@ #include #include #include +#include #include #include diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp new file mode 100644 index 00000000..e3dad26a --- /dev/null +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -0,0 +1,137 @@ +#ifndef Hadrons_SeqGamma_hpp_ +#define Hadrons_SeqGamma_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + + Sequential source + ----------------------------- + * src_x = q_x * theta(x_3 - tA) * theta(tB - x_3) * gamma * exp(i x.mom) + + * options: + - q: input propagator (string) + - tA: begin timeslice (integer) + - tB: end timesilce (integer) + - gamma: gamma product to insert (integer) + - mom: momentum insertion, space-separated float sequence (e.g ".1 .2 1. 0.") + + */ + +/****************************************************************************** + * SeqGamma * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MSource) + +class SeqGammaPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(SeqGammaPar, + std::string, q, + unsigned int, tA, + unsigned int, tB, + unsigned int, gamma, + std::string, mom); +}; + +template +class TSeqGamma: public Module +{ +public: + TYPE_ALIASES(FImpl,); +public: + // constructor + TSeqGamma(const std::string name); + // destructor + virtual ~TSeqGamma(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +typedef TSeqGamma SeqGamma; + +/****************************************************************************** + * TSeqGamma implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TSeqGamma::TSeqGamma(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TSeqGamma::getInput(void) +{ + std::vector in = {par().q}; + + return in; +} + +template +std::vector TSeqGamma::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TSeqGamma::setup(void) +{ + env().template registerLattice(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TSeqGamma::execute(void) +{ + if (par().tA == par().tB) + { + LOG(Message) << "Generating gamma_" << par().gamma + << " sequential source at t= " << par().tA << std::endl; + } + else + { + LOG(Message) << "Generating gamma_" << par().gamma + << " sequential source for " + << par().tA << " <= t <= " << par().tB << std::endl; + } + PropagatorField &src = *env().template createLattice(getName()); + PropagatorField &q = *env().template getObject(par().q); + Lattice> t(env().getGrid()); + LatticeComplex ph(env().getGrid()), coor(env().getGrid()); + SpinMatrix g; + std::vector p; + Complex i(0.0,1.0); + + g = makeGammaProd(par().gamma); + p = strToVec(par().mom); + ph = zero; + for(unsigned int mu = 0; mu < Nd; mu++) + { + LatticeCoordinate(coor, mu); + ph = ph + p[mu]*coor; + } + ph = exp(i*ph); + LatticeCoordinate(t, Tp); + src = where((t >= par().tA) and (t <= par().tB), g*ph*q, 0.*q); +} + +END_MODULE_NAMESPACE + +MODULE_REGISTER_NS(SeqGamma, MSource); + +END_HADRONS_NAMESPACE + +#endif // Hadrons_SeqGamma_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index aad6c73b..4251ffa3 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -13,6 +13,7 @@ modules_hpp =\ Modules/MGauge/Unit.hpp \ Modules/MSolver/RBPrecCG.hpp \ Modules/MSource/Point.hpp \ + Modules/MSource/SeqGamma.hpp \ Modules/MSource/Z2.hpp \ Modules/Quark.hpp diff --git a/tests/hadrons/Test_hadrons_meson_3pt.cc b/tests/hadrons/Test_hadrons_meson_3pt.cc new file mode 100644 index 00000000..159981d0 --- /dev/null +++ b/tests/hadrons/Test_hadrons_meson_3pt.cc @@ -0,0 +1,171 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_meson_3pt.cc + + Copyright (C) 2015 + + Author: Antonin Portelli + + 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. + *******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + + // run setup /////////////////////////////////////////////////////////////// + Application application; + + std::vector flavour = {"l", "s", "c1", "c2", "c3"}; + std::vector mass = {.01, .04, .2 , .25 , .3 }; + unsigned int nt = GridDefaultLatt()[Tp]; + + // global parameters + Application::GlobalPar globalPar; + globalPar.trajCounter.start = 1500; + globalPar.trajCounter.end = 1520; + globalPar.trajCounter.step = 20; + globalPar.seed = "1 2 3 4"; + globalPar.genetic.maxGen = 5000; + globalPar.genetic.maxCstGen = 100; + globalPar.genetic.popSize = 50; + globalPar.genetic.mutationRate = .25; + application.setPar(globalPar); + + // gauge field + application.createModule("gauge"); + for (unsigned int i = 0; i < flavour.size(); ++i) + { + // actions + MAction::DWF::Par actionPar; + actionPar.gauge = "gauge"; + actionPar.Ls = 12; + actionPar.M5 = 1.8; + actionPar.mass = mass[i]; + application.createModule("DWF_" + flavour[i], actionPar); + + // solvers + MSolver::RBPrecCG::Par solverPar; + solverPar.action = "DWF_" + flavour[i]; + solverPar.residual = 1.0e-8; + application.createModule("CG_" + flavour[i], + solverPar); + } + for (unsigned int t = 0; t < nt; t += 8) + { + std::string srcName; + std::vector qName; + std::vector> seqName; + + // Z2 source + MSource::Z2::Par z2Par; + z2Par.tA = t; + z2Par.tB = t; + srcName = "z2_" + std::to_string(t); + application.createModule(srcName, z2Par); + for (unsigned int i = 0; i < flavour.size(); ++i) + { + // sequential sources + MSource::SeqGamma::Par seqPar; + qName.push_back("QZ2_" + flavour[i] + srcName); + seqPar.q = qName[i]; + seqPar.tA = (t + nt/4) % nt; + seqPar.tB = (t + nt/4) % nt; + seqPar.mom = "1. 0. 0. 0."; + seqName.push_back(std::vector(Nd)); + for (unsigned int mu = 0; mu < Nd; ++mu) + { + seqPar.gamma = 0x1 << mu; + seqName[i][mu] = "G" + std::to_string(seqPar.gamma) + + "_" + std::to_string(seqPar.tA) + "-" + + qName[i]; + application.createModule(seqName[i][mu], seqPar); + } + + // propagators + Quark::Par quarkPar; + quarkPar.solver = "CG_" + flavour[i]; + quarkPar.source = srcName; + application.createModule(qName[i], quarkPar); + for (unsigned int mu = 0; mu < Nd; ++mu) + { + quarkPar.source = seqName[i][mu]; + seqName[i][mu] = qName[i] + "-" + seqName[i][mu]; + application.createModule(seqName[i][mu], quarkPar); + } + } + + // contractions + MContraction::Meson::Par mesPar; + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i; j < flavour.size(); ++j) + { + mesPar.output = "mesons/Z2_" + flavour[i] + flavour[j]; + mesPar.q1 = qName[i]; + mesPar.q2 = qName[j]; + application.createModule("meson_Z2_" + + std::to_string(t) + + "_" + + flavour[i] + + flavour[j], + mesPar); + } + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = 0; j < flavour.size(); ++j) + for (unsigned int mu = 0; mu < Nd; ++mu) + { + MContraction::Meson::Par mesPar; + + mesPar.output = "3pt/Z2_" + flavour[i] + flavour[j] + "_" + + std::to_string(mu); + mesPar.q1 = qName[i]; + mesPar.q2 = seqName[j][mu]; + application.createModule("3pt_Z2_" + + std::to_string(t) + + "_" + + flavour[i] + + flavour[j] + + "_" + + std::to_string(mu), + mesPar); + } + } + + Environment::getInstance().printContent(); + // execution + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} From c56707e003e63c33404659d150b33dd8bcd05869 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 7 Dec 2016 08:59:20 +0900 Subject: [PATCH 084/106] useless debug message removed --- lib/stencil/Lebesgue.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stencil/Lebesgue.cc b/lib/stencil/Lebesgue.cc index c30c14c7..c83975a9 100644 --- a/lib/stencil/Lebesgue.cc +++ b/lib/stencil/Lebesgue.cc @@ -65,7 +65,7 @@ void LebesgueOrder::CartesianBlocking(void) { _LebesgueReorder.resize(0); - std::cout << GridLogDebug << " CartesianBlocking "; + // std::cout << GridLogDebug << " CartesianBlocking "; // for(int d=0;d Date: Wed, 7 Dec 2016 08:59:58 +0900 Subject: [PATCH 085/106] Hadrons: more verbose genetic parameters --- extras/Hadrons/Application.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 1b0c37f8..62c69230 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -76,7 +76,6 @@ Application::Application(const std::string parameterFileName) void Application::setPar(const Application::GlobalPar &par) { par_ = par; - LOG(Message) << par_.seed << std::endl; env_.setSeed(strToVec(par_.seed)); } @@ -143,14 +142,23 @@ void Application::schedule(void) return memPeak; }; - // constrained topological sort using a genetic algorithm - LOG(Message) << "Scheduling computation..." << std::endl; - unsigned int k = 0, gen, prevPeak, nCstPeak = 0; + // build module dependency graph + LOG(Message) << "Building module graph..." << std::endl; auto graph = env_.makeModuleGraph(); auto con = graph.getConnectedComponents(); - std::random_device rd; + + // constrained topological sort using a genetic algorithm + LOG(Message) << "Scheduling computation..." << std::endl; + LOG(Message) << " #module= " << graph.size() << std::endl; + LOG(Message) << " population size= " << par_.genetic.popSize << std::endl; + LOG(Message) << " max. generation= " << par_.genetic.maxGen << std::endl; + LOG(Message) << " max. cst. generation= " << par_.genetic.maxCstGen << std::endl; + LOG(Message) << " mutation rate= " << par_.genetic.mutationRate << std::endl; + + unsigned int k = 0, gen, prevPeak, nCstPeak = 0; + std::random_device rd; GeneticScheduler::Parameters par; - + par.popSize = par_.genetic.popSize; par.mutationRate = par_.genetic.mutationRate; par.seed = rd(); @@ -162,6 +170,7 @@ void Application::schedule(void) gen = 0; do { + LOG(Debug) << "Generation " << gen << ":" << std::endl; scheduler.nextGeneration(); if (gen != 0) { @@ -174,13 +183,14 @@ void Application::schedule(void) nCstPeak = 0; } } - LOG(Debug) << "generation " << gen << ":\n" << scheduler; + prevPeak = scheduler.getMinValue(); if (gen % 10 == 0) { LOG(Iterative) << "Generation " << gen << ": " << MEM_MSG(scheduler.getMinValue()) << std::endl; } + gen++; } while ((gen < par_.genetic.maxGen) and (nCstPeak < par_.genetic.maxCstGen)); From 51322da6f86c671b18141019e7cbd394bf3cc312 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 7 Dec 2016 09:00:45 +0900 Subject: [PATCH 086/106] Hadrons: genetic scheduler improvement --- extras/Hadrons/GeneticScheduler.hpp | 152 ++++++++++++++++++---------- lib/Threads.h | 2 + 2 files changed, 102 insertions(+), 52 deletions(-) diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index 3d75f2a4..0d0692cc 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -61,10 +61,12 @@ public: friend std::ostream & operator<<(std::ostream &out, const GeneticScheduler &s) { + out << "["; for (auto &p: s.population_) { - out << p.second << ": " << p.first << std::endl; + out << p.first << ", "; } + out << "\b\b]"; return out; } @@ -72,10 +74,10 @@ private: // randomly initialize population void initPopulation(void); // genetic operators - const std::vector & selection(void); - void crossover(const std::vector &c1, - const std::vector &c2); - void mutation(std::vector &c); + std::vector * select1(void); + std::pair *, std::vector *> select2(void); + void crossover(void); + void mutation(void); private: Graph &graph_; const ObjFunc &func_; @@ -115,38 +117,35 @@ int GeneticScheduler::getMinValue(void) template void GeneticScheduler::nextGeneration(void) { - std::uniform_real_distribution dis(0., 1.); - // random initialization of the population if necessary if (population_.size() != par_.popSize) { initPopulation(); } - - // mating - for (unsigned int i = 0; i < par_.popSize/2; ++i) - { - auto &p1 = selection(), &p2 = selection(); - crossover(p1, p2); - } + LOG(Debug) << "Starting population:\n" << *this << std::endl; // random mutations - auto buf = population_; - population_.clear(); - for (auto &c: buf) + PARALLEL_FOR_LOOP + for (unsigned int i = 0; i < par_.popSize; ++i) { - if (dis(gen_) < par_.mutationRate) - { - mutation(c.second); - } - population_.emplace(func_(c.second), c.second); + mutation(); } + LOG(Debug) << "After mutations:\n" << *this << std::endl; + + // mating + PARALLEL_FOR_LOOP + for (unsigned int i = 0; i < par_.popSize/2; ++i) + { + crossover(); + } + LOG(Debug) << "After mating:\n" << *this << std::endl; // grim reaper auto it = population_.begin(); std::advance(it, par_.popSize); population_.erase(it, population_.end()); + LOG(Debug) << "After grim reaper:\n" << *this << std::endl; } // randomly initialize population ////////////////////////////////////////////// @@ -164,37 +163,66 @@ void GeneticScheduler::initPopulation(void) // genetic operators /////////////////////////////////////////////////////////// template -const std::vector & GeneticScheduler::selection(void) +std::vector * GeneticScheduler::select1(void) +{ + std::uniform_int_distribution pdis(0, population_.size() - 1); + + auto it = population_.begin(); + std::advance(it, pdis(gen_)); + + return &(it->second); +} + +template +std::pair *, std::vector *> GeneticScheduler::select2(void) { std::vector prob; + unsigned int ind; + std::vector *p1, *p2; for (auto &c: population_) { prob.push_back(1./c.first); } - std::discrete_distribution dis(prob.begin(), prob.end()); - auto rIt = population_.begin(); - std::advance(rIt, dis(gen_)); + do + { + double probCpy; + + std::discrete_distribution dis1(prob.begin(), prob.end()); + auto rIt = population_.begin(); + ind = dis1(gen_); + std::advance(rIt, ind); + p1 = &(rIt->second); + probCpy = prob[ind]; + prob[ind] = 0.; + std::discrete_distribution dis2(prob.begin(), prob.end()); + rIt = population_.begin(); + std::advance(rIt, dis2(gen_)); + p2 = &(rIt->second); + prob[ind] = probCpy; + } while (p1 == p2); - return rIt->second; + return std::make_pair(p1, p2); } template -void GeneticScheduler::crossover(const std::vector &p1, - const std::vector &p2) +void GeneticScheduler::crossover(void) { - std::uniform_int_distribution dis(0, p1.size() - 1); - unsigned int cut = dis(gen_); + auto p = select2(); + auto &p1 = *(p.first), + &p2 = *(p.second); + std::uniform_int_distribution dis2(0, p1.size() - 1); + unsigned int cut = dis2(gen_); std::vector c1, c2, buf; auto cross = [&buf, cut](std::vector &c, const std::vector &p1, const std::vector &p2) { - buf = p2; + buf = p1; for (unsigned int i = 0; i < cut; ++i) { - c.push_back(p1[i]); - buf.erase(std::find(buf.begin(), buf.end(), p1[i])); + c.push_back(p2[i]); + buf.erase(std::find(buf.begin(), buf.end(), p2[i])); } for (unsigned int i = 0; i < buf.size(); ++i) { @@ -204,31 +232,51 @@ void GeneticScheduler::crossover(const std::vector &p1, cross(c1, p1, p2); cross(c2, p2, p1); - population_.emplace(func_(c1), c1); - population_.emplace(func_(c2), c2); + PARALLEL_CRITICAL + { + population_.emplace(func_(c1), c1); + population_.emplace(func_(c2), c2); + } } template -void GeneticScheduler::mutation(std::vector &c) +void GeneticScheduler::mutation(void) { - std::uniform_int_distribution dis(0, c.size() - 1); - unsigned int cut = dis(gen_); - Graph g = graph_; - std::vector buf; + std::uniform_real_distribution mdis(0., 1.); - for (unsigned int i = cut; i < c.size(); ++i) + if (mdis(gen_) < par_.mutationRate) { - g.removeVertex(c[i]); + auto &c = *select1(); + std::uniform_int_distribution cdis(0, c.size() - 1); + unsigned int cut = cdis(gen_); + std::vector buf1, buf2; + Graph g1 = graph_, g2 = graph_; + + for (unsigned int i = 0; i < cut; ++i) + { + g1.removeVertex(c[i]); + } + for (unsigned int i = cut; i < c.size(); ++i) + { + g2.removeVertex(c[i]); + } + if (g1.size() > 0) + { + buf1 = g1.topoSort(gen_); + } + if (g2.size() > 0) + { + buf2 = g2.topoSort(gen_); + } + for (unsigned int i = cut; i < c.size(); ++i) + { + buf2.push_back(buf1[i - cut]); + } + PARALLEL_CRITICAL + { + population_.emplace(func_(buf2), buf2); + } } - if (g.size() > 0) - { - buf = g.topoSort(gen_); - } - for (unsigned int i = cut; i < c.size(); ++i) - { - buf.push_back(c[i]); - } - c = buf; } END_HADRONS_NAMESPACE diff --git a/lib/Threads.h b/lib/Threads.h index 2f270b73..2f072633 100644 --- a/lib/Threads.h +++ b/lib/Threads.h @@ -46,11 +46,13 @@ Author: paboyle #endif #define PARALLEL_NESTED_LOOP2 _Pragma("omp parallel for collapse(2)") #define PARALLEL_REGION _Pragma("omp parallel") +#define PARALLEL_CRITICAL _Pragma("omp critical") #else #define PARALLEL_FOR_LOOP #define PARALLEL_FOR_LOOP_INTERN #define PARALLEL_NESTED_LOOP2 #define PARALLEL_REGION +#define PARALLEL_CRITICAL #endif namespace Grid { From 4a8748636595443642bb4a896006f439e9f5e04b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 10 Dec 2016 21:14:13 +0100 Subject: [PATCH 087/106] Hadrons: a bit of cleaning in the scheduler --- extras/Hadrons/GeneticScheduler.hpp | 176 ++++++++++++++-------------- 1 file changed, 91 insertions(+), 85 deletions(-) diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index 0d0692cc..46272a83 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -40,7 +40,9 @@ template class GeneticScheduler { public: - typedef std::function &)> ObjFunc; + typedef std::vector Gene; + typedef std::pair GenePair; + typedef std::function ObjFunc; struct Parameters { double mutationRate; @@ -53,8 +55,8 @@ public: // destructor virtual ~GeneticScheduler(void) = default; // access - const std::vector & getMinSchedule(void); - int getMinValue(void); + const Gene & getMinSchedule(void); + int getMinValue(void); // breed a new generation void nextGeneration(void); // print population @@ -71,19 +73,20 @@ public: return out; } private: - // randomly initialize population + // evolution steps void initPopulation(void); + void doCrossover(void); + void doMutation(void); // genetic operators - std::vector * select1(void); - std::pair *, std::vector *> select2(void); - void crossover(void); - void mutation(void); + GenePair selectPair(void); + void crossover(Gene &c, const Gene &p1, const Gene &p2); + void mutation(Gene &m, const Gene &c); private: - Graph &graph_; - const ObjFunc &func_; - const Parameters par_; - std::multimap> population_; - std::mt19937 gen_; + Graph &graph_; + const ObjFunc &func_; + const Parameters par_; + std::multimap population_; + std::mt19937 gen_; }; /****************************************************************************** @@ -102,7 +105,8 @@ GeneticScheduler::GeneticScheduler(Graph &graph, const ObjFunc &func, // access ////////////////////////////////////////////////////////////////////// template -const std::vector & GeneticScheduler::getMinSchedule(void) +const typename GeneticScheduler::Gene & +GeneticScheduler::getMinSchedule(void) { return population_.begin()->second; } @@ -128,7 +132,7 @@ void GeneticScheduler::nextGeneration(void) PARALLEL_FOR_LOOP for (unsigned int i = 0; i < par_.popSize; ++i) { - mutation(); + doMutation(); } LOG(Debug) << "After mutations:\n" << *this << std::endl; @@ -136,7 +140,7 @@ void GeneticScheduler::nextGeneration(void) PARALLEL_FOR_LOOP for (unsigned int i = 0; i < par_.popSize/2; ++i) { - crossover(); + doCrossover(); } LOG(Debug) << "After mating:\n" << *this << std::endl; @@ -148,7 +152,7 @@ void GeneticScheduler::nextGeneration(void) LOG(Debug) << "After grim reaper:\n" << *this << std::endl; } -// randomly initialize population ////////////////////////////////////////////// +// evolution steps ///////////////////////////////////////////////////////////// template void GeneticScheduler::initPopulation(void) { @@ -161,24 +165,50 @@ void GeneticScheduler::initPopulation(void) } } -// genetic operators /////////////////////////////////////////////////////////// template -std::vector * GeneticScheduler::select1(void) +void GeneticScheduler::doCrossover(void) { - std::uniform_int_distribution pdis(0, population_.size() - 1); + auto p = selectPair(); + auto &p1 = *(p.first), &p2 = *(p.second); + Gene c1, c2; - auto it = population_.begin(); - std::advance(it, pdis(gen_)); - - return &(it->second); + crossover(c1, p1, p2); + crossover(c2, p2, p1); + PARALLEL_CRITICAL + { + population_.emplace(func_(c1), c1); + population_.emplace(func_(c2), c2); + } } template -std::pair *, std::vector *> GeneticScheduler::select2(void) +void GeneticScheduler::doMutation(void) +{ + std::uniform_real_distribution mdis(0., 1.); + std::uniform_int_distribution pdis(0, population_.size() - 1); + + if (mdis(gen_) < par_.mutationRate) + { + Gene m; + auto it = population_.begin(); + + std::advance(it, pdis(gen_)); + mutation(m, it->second); + PARALLEL_CRITICAL + { + population_.erase(it); + population_.emplace(func_(m), m); + } + } +} + +// genetic operators /////////////////////////////////////////////////////////// +template +typename GeneticScheduler::GenePair GeneticScheduler::selectPair(void) { std::vector prob; unsigned int ind; - std::vector *p1, *p2; + Gene *p1, *p2; for (auto &c: population_) { @@ -206,76 +236,52 @@ std::pair *, std::vector *> GeneticScheduler::select2(void) } template -void GeneticScheduler::crossover(void) +void GeneticScheduler::crossover(Gene &c, const Gene &p1, const Gene &p2) { - auto p = select2(); - auto &p1 = *(p.first), - &p2 = *(p.second); - std::uniform_int_distribution dis2(0, p1.size() - 1); - unsigned int cut = dis2(gen_); - std::vector c1, c2, buf; + Gene buf; + std::uniform_int_distribution dis(0, p1.size() - 1); + unsigned int cut = dis(gen_); - auto cross = [&buf, cut](std::vector &c, const std::vector &p1, - const std::vector &p2) + c.clear(); + buf = p1; + for (unsigned int i = 0; i < cut; ++i) { - buf = p1; - for (unsigned int i = 0; i < cut; ++i) - { - c.push_back(p2[i]); - buf.erase(std::find(buf.begin(), buf.end(), p2[i])); - } - for (unsigned int i = 0; i < buf.size(); ++i) - { - c.push_back(buf[i]); - } - }; - - cross(c1, p1, p2); - cross(c2, p2, p1); - PARALLEL_CRITICAL + c.push_back(p2[i]); + buf.erase(std::find(buf.begin(), buf.end(), p2[i])); + } + for (unsigned int i = 0; i < buf.size(); ++i) { - population_.emplace(func_(c1), c1); - population_.emplace(func_(c2), c2); + c.push_back(buf[i]); } } template -void GeneticScheduler::mutation(void) +void GeneticScheduler::mutation(Gene &m, const Gene &c) { - std::uniform_real_distribution mdis(0., 1.); + Gene buf; + std::uniform_int_distribution dis(0, c.size() - 1); + unsigned int cut = dis(gen_); + Graph g1 = graph_, g2 = graph_; - if (mdis(gen_) < par_.mutationRate) + for (unsigned int i = 0; i < cut; ++i) { - auto &c = *select1(); - std::uniform_int_distribution cdis(0, c.size() - 1); - unsigned int cut = cdis(gen_); - std::vector buf1, buf2; - Graph g1 = graph_, g2 = graph_; - - for (unsigned int i = 0; i < cut; ++i) - { - g1.removeVertex(c[i]); - } - for (unsigned int i = cut; i < c.size(); ++i) - { - g2.removeVertex(c[i]); - } - if (g1.size() > 0) - { - buf1 = g1.topoSort(gen_); - } - if (g2.size() > 0) - { - buf2 = g2.topoSort(gen_); - } - for (unsigned int i = cut; i < c.size(); ++i) - { - buf2.push_back(buf1[i - cut]); - } - PARALLEL_CRITICAL - { - population_.emplace(func_(buf2), buf2); - } + g1.removeVertex(c[i]); + } + for (unsigned int i = cut; i < c.size(); ++i) + { + g2.removeVertex(c[i]); + } + if (g1.size() > 0) + { + buf = g1.topoSort(gen_); + } + if (g2.size() > 0) + { + m = g2.topoSort(gen_); + } + for (unsigned int i = cut; i < c.size(); ++i) + { + m.push_back(buf[i - cut]); } } From de8f80cf941f20d7a3040b42776d58b7f8cfb3d4 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 13 Dec 2016 19:02:05 +0000 Subject: [PATCH 088/106] Hadrons: genetic operators improvement --- extras/Hadrons/GeneticScheduler.hpp | 36 ++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index 46272a83..88ab41f8 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -79,8 +79,9 @@ private: void doMutation(void); // genetic operators GenePair selectPair(void); - void crossover(Gene &c, const Gene &p1, const Gene &p2); + void crossover(Gene &c1, Gene &c2, const Gene &p1, const Gene &p2); void mutation(Gene &m, const Gene &c); + private: Graph &graph_; const ObjFunc &func_; @@ -169,11 +170,10 @@ template void GeneticScheduler::doCrossover(void) { auto p = selectPair(); - auto &p1 = *(p.first), &p2 = *(p.second); + Gene &p1 = *(p.first), &p2 = *(p.second); Gene c1, c2; - crossover(c1, p1, p2); - crossover(c2, p2, p1); + crossover(c1, c2, p1, p2); PARALLEL_CRITICAL { population_.emplace(func_(c1), c1); @@ -196,7 +196,6 @@ void GeneticScheduler::doMutation(void) mutation(m, it->second); PARALLEL_CRITICAL { - population_.erase(it); population_.emplace(func_(m), m); } } @@ -236,22 +235,37 @@ typename GeneticScheduler::GenePair GeneticScheduler::selectPair(void) } template -void GeneticScheduler::crossover(Gene &c, const Gene &p1, const Gene &p2) +void GeneticScheduler::crossover(Gene &c1, Gene &c2, const Gene &p1, + const Gene &p2) { Gene buf; std::uniform_int_distribution dis(0, p1.size() - 1); unsigned int cut = dis(gen_); - c.clear(); - buf = p1; + c1.clear(); + buf = p2; for (unsigned int i = 0; i < cut; ++i) { - c.push_back(p2[i]); - buf.erase(std::find(buf.begin(), buf.end(), p2[i])); + c1.push_back(p1[i]); + buf.erase(std::find(buf.begin(), buf.end(), p1[i])); } for (unsigned int i = 0; i < buf.size(); ++i) { - c.push_back(buf[i]); + c1.push_back(buf[i]); + } + c2.clear(); + buf = p2; + for (unsigned int i = cut; i < p1.size(); ++i) + { + buf.erase(std::find(buf.begin(), buf.end(), p1[i])); + } + for (unsigned int i = 0; i < buf.size(); ++i) + { + c2.push_back(buf[i]); + } + for (unsigned int i = cut; i < p1.size(); ++i) + { + c2.push_back(p1[i]); } } From 16693bd69d359bcc192261fd93dddc4ecc937ea1 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 13 Dec 2016 19:02:32 +0000 Subject: [PATCH 089/106] Hadrons: scheduler heuristic benchmark --- extras/Hadrons/GeneticScheduler.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index 88ab41f8..857a4099 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -59,6 +59,8 @@ public: int getMinValue(void); // breed a new generation void nextGeneration(void); + // heuristic benchmarks + void benchmarkCrossover(const unsigned int nIt); // print population friend std::ostream & operator<<(std::ostream &out, const GeneticScheduler &s) @@ -299,6 +301,27 @@ void GeneticScheduler::mutation(Gene &m, const Gene &c) } } +template +void GeneticScheduler::benchmarkCrossover(const unsigned int nIt) +{ + Gene p1, p2, c1, c2; + double neg = 0., eq = 0., pos = 0., total; + int improvement; + + LOG(Message) << "Benchmarking crossover..." << std::endl; + for (unsigned int i = 0; i < nIt; ++i) + { + p1 = graph_.topoSort(gen_); + p2 = graph_.topoSort(gen_); + crossover(c1, c2, p1, p2); + improvement = (func_(c1) + func_(c2) - func_(p1) - func_(p2))/2; + if (improvement < 0) neg++; else if (improvement == 0) eq++; else pos++; + } + total = neg + eq + pos; + LOG(Message) << " -: " << neg/total << " =: " << eq/total + << " +: " << pos/total << std::endl; +} + END_HADRONS_NAMESPACE #endif // Hadrons_GeneticScheduler_hpp_ From 013e710c7d7d0f5c54f1042a6346d06acf39a0a8 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 13 Dec 2016 19:04:43 +0000 Subject: [PATCH 090/106] Hadrons: 3pt function test improvement --- tests/hadrons/Test_hadrons_meson_3pt.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/hadrons/Test_hadrons_meson_3pt.cc b/tests/hadrons/Test_hadrons_meson_3pt.cc index 159981d0..b3156918 100644 --- a/tests/hadrons/Test_hadrons_meson_3pt.cc +++ b/tests/hadrons/Test_hadrons_meson_3pt.cc @@ -50,14 +50,14 @@ int main(int argc, char *argv[]) // global parameters Application::GlobalPar globalPar; - globalPar.trajCounter.start = 1500; - globalPar.trajCounter.end = 1520; - globalPar.trajCounter.step = 20; - globalPar.seed = "1 2 3 4"; - globalPar.genetic.maxGen = 5000; - globalPar.genetic.maxCstGen = 100; - globalPar.genetic.popSize = 50; - globalPar.genetic.mutationRate = .25; + globalPar.trajCounter.start = 1500; + globalPar.trajCounter.end = 1520; + globalPar.trajCounter.step = 20; + globalPar.seed = "1 2 3 4"; + globalPar.genetic.maxGen = 1000; + globalPar.genetic.maxCstGen = 200; + globalPar.genetic.popSize = 20; + globalPar.genetic.mutationRate = .1; application.setPar(globalPar); // gauge field @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) application.createModule("CG_" + flavour[i], solverPar); } - for (unsigned int t = 0; t < nt; t += 8) + for (unsigned int t = 0; t < nt; t += 1) { std::string srcName; std::vector qName; @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) for (unsigned int mu = 0; mu < Nd; ++mu) { quarkPar.source = seqName[i][mu]; - seqName[i][mu] = qName[i] + "-" + seqName[i][mu]; + seqName[i][mu] = "Q_" + flavour[i] + "-" + seqName[i][mu]; application.createModule(seqName[i][mu], quarkPar); } } @@ -159,7 +159,6 @@ int main(int argc, char *argv[]) } } - Environment::getInstance().printContent(); // execution application.run(); From c22c3db9ad652eadbd334fde70235aace90faa75 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 13 Dec 2016 19:05:58 +0000 Subject: [PATCH 091/106] AVX: uninitialised variable fix --- lib/simd/Grid_avx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/simd/Grid_avx.h b/lib/simd/Grid_avx.h index 36360102..77927b10 100644 --- a/lib/simd/Grid_avx.h +++ b/lib/simd/Grid_avx.h @@ -514,7 +514,7 @@ namespace Optimization { template static inline __m256 tRotate(__m256 in){ __m256 tmp = Permute::Permute0(in); - __m256 ret; + __m256 ret = in; if ( n > 3 ) { _mm256_alignr_epi32_grid(ret,in,tmp,n); } else { @@ -526,7 +526,7 @@ namespace Optimization { template static inline __m256d tRotate(__m256d in){ __m256d tmp = Permute::Permute0(in); - __m256d ret; + __m256d ret = in; if ( n > 1 ) { _mm256_alignr_epi64_grid(ret,in,tmp,n); } else { From 3af663e17b6f3678a37321d3ddfbb9a8dac03813 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 17:59:45 +0000 Subject: [PATCH 092/106] Hadrons: modules remember their factory registration name --- extras/Hadrons/Module.cc | 7 +++++ extras/Hadrons/Module.hpp | 28 +++++++++++++++++-- extras/Hadrons/Modules/MAction/DWF.hpp | 12 ++++---- extras/Hadrons/Modules/MAction/Wilson.hpp | 8 ++---- .../Hadrons/Modules/MContraction/Baryon.hpp | 4 +-- extras/Hadrons/Modules/MContraction/Meson.hpp | 6 ++-- extras/Hadrons/Modules/MGauge/Load.cc | 12 ++++---- extras/Hadrons/Modules/MGauge/Load.hpp | 10 +++---- extras/Hadrons/Modules/MGauge/Random.cc | 12 ++++---- extras/Hadrons/Modules/MGauge/Random.hpp | 10 +++---- extras/Hadrons/Modules/MGauge/Unit.cc | 12 ++++---- extras/Hadrons/Modules/MGauge/Unit.hpp | 10 +++---- extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 6 ++-- extras/Hadrons/Modules/MSource/Point.hpp | 6 ++-- extras/Hadrons/Modules/MSource/SeqGamma.hpp | 6 ++-- extras/Hadrons/Modules/MSource/Z2.hpp | 6 ++-- extras/Hadrons/Modules/Quark.hpp | 6 ++-- 17 files changed, 87 insertions(+), 74 deletions(-) diff --git a/extras/Hadrons/Module.cc b/extras/Hadrons/Module.cc index e8a80f07..dccae582 100644 --- a/extras/Hadrons/Module.cc +++ b/extras/Hadrons/Module.cc @@ -51,6 +51,13 @@ Environment & ModuleBase::env(void) const return env_; } +// get factory registration name if available +std::string ModuleBase::getRegisteredName(void) +{ + HADRON_ERROR("module '" + getName() + "' has a type not registered" + + " in the factory"); +} + // execution /////////////////////////////////////////////////////////////////// void ModuleBase::operator()(void) { diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index d7065650..78ce8a6a 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -34,7 +34,17 @@ directory. BEGIN_HADRONS_NAMESPACE // module registration macros -#define MODULE_REGISTER(mod)\ +#define MODULE_REGISTER(mod, base)\ +class mod: public base\ +{\ +public:\ + typedef base Base;\ + using Base::Base;\ + virtual std::string getRegisteredName(void)\ + {\ + return std::string(#mod);\ + }\ +};\ class mod##ModuleRegistrar\ {\ public:\ @@ -49,7 +59,17 @@ public:\ };\ static mod##ModuleRegistrar mod##ModuleRegistrarInstance; -#define MODULE_REGISTER_NS(mod, ns)\ +#define MODULE_REGISTER_NS(mod, base, ns)\ +class mod: public base\ +{\ +public:\ + typedef base Base;\ + using Base::Base;\ + virtual std::string getRegisteredName(void)\ + {\ + return std::string(#ns "::" #mod);\ + }\ +};\ class ns##mod##ModuleRegistrar\ {\ public:\ @@ -64,6 +84,8 @@ public:\ };\ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; +#define ARG(...) __VA_ARGS__ + /****************************************************************************** * Module class * ******************************************************************************/ @@ -78,6 +100,8 @@ public: // access std::string getName(void) const; Environment &env(void) const; + // get factory registration name if available + virtual std::string getRegisteredName(void); // dependencies/products virtual std::vector getInput(void) = 0; virtual std::vector getOutput(void) = 0; diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index ceec975c..3f38c671 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -68,6 +68,8 @@ public: virtual void execute(void); }; +MODULE_REGISTER_NS(DWF, TDWF, MAction); + /****************************************************************************** * DWF template implementation * ******************************************************************************/ @@ -109,9 +111,9 @@ template void TDWF::execute(void) { LOG(Message) << "Setting up domain wall fermion matrix with m= " - << par().mass << ", M5= " << par().M5 << " and Ls= " - << par().Ls << " using gauge field '" << par().gauge << "'" - << std::endl; + << par().mass << ", M5= " << par().M5 << " and Ls= " + << par().Ls << " using gauge field '" << par().gauge << "'" + << std::endl; env().createGrid(par().Ls); auto &U = *env().template getObject(par().gauge); auto &g4 = *env().getGrid(); @@ -123,12 +125,8 @@ void TDWF::execute(void) env().setObject(getName(), fMatPt); } -typedef TDWF DWF; - END_MODULE_NAMESPACE -MODULE_REGISTER_NS(DWF, MAction); - END_HADRONS_NAMESPACE #endif // Hadrons_DWF_hpp_ diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index 6a4528ca..6a01d92e 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -66,6 +66,8 @@ public: virtual void execute(void); }; +MODULE_REGISTER_NS(Wilson, TWilson, MAction); + /****************************************************************************** * TWilson template implementation * ******************************************************************************/ @@ -98,7 +100,7 @@ void TWilson::setup(void) { unsigned int size; - size = 3*env().template lattice4dSize(); + size = 2*env().template lattice4dSize(); env().registerObject(getName(), size); } @@ -115,12 +117,8 @@ void TWilson::execute() env().setObject(getName(), fMatPt); } -typedef TWilson Wilson; - END_MODULE_NAMESPACE -MODULE_REGISTER_NS(Wilson, MAction); - END_HADRONS_NAMESPACE #endif // Hadrons_Wilson_hpp_ diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index e8191793..6ae9c1ab 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -47,7 +47,7 @@ public: virtual void execute(void); }; -typedef TBaryon Baryon; +MODULE_REGISTER_NS(Baryon, ARG(TBaryon), MContraction); /****************************************************************************** * TBaryon implementation * @@ -97,8 +97,6 @@ void TBaryon::execute(void) END_MODULE_NAMESPACE -MODULE_REGISTER_NS(Baryon, MContraction); - END_HADRONS_NAMESPACE #endif // Hadrons_Baryon_hpp_ diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index b2625b3e..438f3740 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -72,6 +72,8 @@ public: virtual void execute(void); }; +MODULE_REGISTER_NS(Meson, ARG(TMeson), MContraction); + /****************************************************************************** * TMeson implementation * ******************************************************************************/ @@ -137,12 +139,8 @@ void TMeson::execute(void) write(writer, "meson", result); } -typedef TMeson Meson; - END_MODULE_NAMESPACE -MODULE_REGISTER_NS(Meson, MContraction); - END_HADRONS_NAMESPACE #endif // Hadrons_Meson_hpp_ diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MGauge/Load.cc index 1a6cec0a..82920d97 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -32,22 +32,22 @@ using namespace Hadrons; using namespace MGauge; /****************************************************************************** -* Load implementation * +* TLoad implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -Load::Load(const std::string name) +TLoad::TLoad(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector Load::getInput(void) +std::vector TLoad::getInput(void) { std::vector in; return in; } -std::vector Load::getOutput(void) +std::vector TLoad::getOutput(void) { std::vector out = {getName()}; @@ -55,13 +55,13 @@ std::vector Load::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void Load::setup(void) +void TLoad::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void Load::execute(void) +void TLoad::execute(void) { NerscField header; std::string fileName = par().file + "." diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp index ff7cc128..21f9331c 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -46,13 +46,13 @@ public: std::string, file); }; -class Load: public Module +class TLoad: public Module { public: // constructor - Load(const std::string name); + TLoad(const std::string name); // destructor - virtual ~Load(void) = default; + virtual ~TLoad(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -62,9 +62,9 @@ public: virtual void execute(void); }; -END_MODULE_NAMESPACE +MODULE_REGISTER_NS(Load, TLoad, MGauge); -MODULE_REGISTER_NS(Load, MGauge); +END_MODULE_NAMESPACE END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index 6d5e0ec9..2c25f7c1 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -32,20 +32,20 @@ using namespace Hadrons; using namespace MGauge; /****************************************************************************** -* Random implementation * +* TRandom implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -Random::Random(const std::string name) +TRandom::TRandom(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector Random::getInput(void) +std::vector TRandom::getInput(void) { return std::vector(); } -std::vector Random::getOutput(void) +std::vector TRandom::getOutput(void) { std::vector out = {getName()}; @@ -53,13 +53,13 @@ std::vector Random::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void Random::setup(void) +void TRandom::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void Random::execute(void) +void TRandom::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index afa03de8..95db726c 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -39,13 +39,13 @@ BEGIN_HADRONS_NAMESPACE ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MGauge) -class Random: public Module +class TRandom: public Module { public: // constructor - Random(const std::string name); + TRandom(const std::string name); // destructor - virtual ~Random(void) = default; + virtual ~TRandom(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -55,9 +55,9 @@ public: virtual void execute(void); }; -END_MODULE_NAMESPACE +MODULE_REGISTER_NS(Random, TRandom, MGauge); -MODULE_REGISTER_NS(Random, MGauge); +END_MODULE_NAMESPACE END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index b9cfeac7..16dcff83 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -32,20 +32,20 @@ using namespace Hadrons; using namespace MGauge; /****************************************************************************** -* Unit implementation * +* TUnit implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -Unit::Unit(const std::string name) +TUnit::TUnit(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector Unit::getInput(void) +std::vector TUnit::getInput(void) { return std::vector(); } -std::vector Unit::getOutput(void) +std::vector TUnit::getOutput(void) { std::vector out = {getName()}; @@ -53,13 +53,13 @@ std::vector Unit::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void Unit::setup(void) +void TUnit::setup(void) { env().registerLattice(getName()); } // execution /////////////////////////////////////////////////////////////////// -void Unit::execute(void) +void TUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index da26dd37..d9566958 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -39,13 +39,13 @@ BEGIN_HADRONS_NAMESPACE ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MGauge) -class Unit: public Module +class TUnit: public Module { public: // constructor - Unit(const std::string name); + TUnit(const std::string name); // destructor - virtual ~Unit(void) = default; + virtual ~TUnit(void) = default; // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -55,9 +55,9 @@ public: virtual void execute(void); }; -END_MODULE_NAMESPACE +MODULE_REGISTER_NS(Unit, TUnit, MGauge); -MODULE_REGISTER_NS(Unit, MGauge); +END_MODULE_NAMESPACE END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index 57ebb816..82f2eafa 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -66,6 +66,8 @@ public: virtual void execute(void); }; +MODULE_REGISTER_NS(RBPrecCG, TRBPrecCG, MSolver); + /****************************************************************************** * TRBPrecCG template implementation * ******************************************************************************/ @@ -121,12 +123,8 @@ void TRBPrecCG::execute(void) env().setObject(getName(), new SolverFn(solver)); } -typedef TRBPrecCG RBPrecCG; - END_MODULE_NAMESPACE -MODULE_REGISTER_NS(RBPrecCG, MSolver); - END_HADRONS_NAMESPACE #endif // Hadrons_RBPrecCG_hpp_ diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 456de76c..84952512 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -76,6 +76,8 @@ public: virtual void execute(void); }; +MODULE_REGISTER_NS(Point, TPoint, MSource); + /****************************************************************************** * TPoint template implementation * ******************************************************************************/ @@ -124,12 +126,8 @@ void TPoint::execute(void) pokeSite(id, src, position); } -typedef TPoint Point; - END_MODULE_NAMESPACE -MODULE_REGISTER_NS(Point, MSource); - END_HADRONS_NAMESPACE #endif // Hadrons_Point_hpp_ diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp index e3dad26a..70b603fe 100644 --- a/extras/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -57,10 +57,10 @@ public: virtual void execute(void); }; -typedef TSeqGamma SeqGamma; +MODULE_REGISTER_NS(SeqGamma, TSeqGamma, MSource); /****************************************************************************** - * TSeqGamma implementation * + * TSeqGamma implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template @@ -130,8 +130,6 @@ void TSeqGamma::execute(void) END_MODULE_NAMESPACE -MODULE_REGISTER_NS(SeqGamma, MSource); - END_HADRONS_NAMESPACE #endif // Hadrons_SeqGamma_hpp_ diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index 76fefc8f..e50b2a73 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -80,6 +80,8 @@ public: virtual void execute(void); }; +MODULE_REGISTER_NS(Z2, TZ2, MSource); + /****************************************************************************** * TZ2 template implementation * ******************************************************************************/ @@ -140,12 +142,8 @@ void TZ2::execute(void) src = src*eta; } -typedef TZ2 Z2; - END_MODULE_NAMESPACE -MODULE_REGISTER_NS(Z2, MSource); - END_HADRONS_NAMESPACE #endif // Hadrons_Z2_hpp_ diff --git a/extras/Hadrons/Modules/Quark.hpp b/extras/Hadrons/Modules/Quark.hpp index 59274546..81b74755 100644 --- a/extras/Hadrons/Modules/Quark.hpp +++ b/extras/Hadrons/Modules/Quark.hpp @@ -67,6 +67,8 @@ private: SolverFn *solver_{nullptr}; }; +MODULE_REGISTER(Quark, TQuark); + /****************************************************************************** * TQuark implementation * ******************************************************************************/ @@ -176,10 +178,6 @@ void TQuark::execute(void) } } -typedef TQuark Quark; - -MODULE_REGISTER(Quark); - END_HADRONS_NAMESPACE #endif // Hadrons_Quark_hpp_ From 34df71e7557d558c298a836275407b2cbe770d7f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 18:01:56 +0000 Subject: [PATCH 093/106] Hadrons: function to save an application as an XML file --- extras/Hadrons/Application.cc | 35 ++++++++++++++++++++++++++++++---- extras/Hadrons/Application.hpp | 8 +++++--- extras/Hadrons/Environment.cc | 5 +++++ extras/Hadrons/Environment.hpp | 1 + extras/Hadrons/Module.hpp | 13 +++++++++++++ 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 62c69230..07971a16 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -79,12 +79,17 @@ void Application::setPar(const Application::GlobalPar &par) env_.setSeed(strToVec(par_.seed)); } +const Application::GlobalPar & Application::getPar(void) +{ + return par_; +} + // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { if (!parameterFileName_.empty()) { - parseParameterFile(); + parseParameterFile(parameterFileName_); } schedule(); configLoop(); @@ -99,13 +104,13 @@ public: std::string, type); }; -void Application::parseParameterFile(void) +void Application::parseParameterFile(const std::string parameterFileName) { - XmlReader reader(parameterFileName_); + XmlReader reader(parameterFileName); GlobalPar par; ObjectId id; - LOG(Message) << "Reading '" << parameterFileName_ << "'..." << std::endl; + LOG(Message) << "Reading '" << parameterFileName << "'..." << std::endl; read(reader, "parameters", par); setPar(par); push(reader, "modules"); @@ -119,6 +124,28 @@ void Application::parseParameterFile(void) pop(reader); } +void Application::saveParameterFile(const std::string parameterFileName) +{ + XmlWriter writer(parameterFileName); + ObjectId id; + const unsigned int nMod = env_.getNModule(); + + LOG(Message) << "Writing '" << parameterFileName << "'..." << std::endl; + write(writer, "parameters", getPar()); + push(writer, "modules"); + for (unsigned int i = 0; i < nMod; ++i) + { + push(writer, "module"); + id.name = env_.getModuleName(i); + id.type = env_.getModule(i)->getRegisteredName(); + write(writer, "id", id); + env_.getModule(i)->saveParameters(writer, "options"); + pop(writer); + } + pop(writer); + pop(writer); +} + // schedule computation //////////////////////////////////////////////////////// #define MEM_MSG(size)\ sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 846b4dfa..65e9ad34 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -77,7 +77,8 @@ public: // destructor virtual ~Application(void) = default; // access - void setPar(const GlobalPar &par); + void setPar(const GlobalPar &par); + const GlobalPar & getPar(void); // module creation template void createModule(const std::string name); @@ -85,8 +86,9 @@ public: void createModule(const std::string name, const typename M::Par &par); // execute void run(void); - // parse parameter file - void parseParameterFile(void); + // XML parameter file I/O + void parseParameterFile(const std::string parameterFileName); + void saveParameterFile(const std::string parameterFileName); // schedule computation void schedule(void); // loop on configurations diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 67880cd3..600ca855 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -190,6 +190,11 @@ void Environment::pushModule(Environment::ModPt &pt) } } +unsigned int Environment::getNModule(void) const +{ + return module_.size(); +} + void Environment::createModule(const std::string name, const std::string type, XmlReader &reader) { diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 88661c2e..065c889a 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -117,6 +117,7 @@ public: void createModule(const std::string name, const std::string type, XmlReader &reader); + unsigned int getNModule(void) const; ModuleBase * getModule(const unsigned int address) const; ModuleBase * getModule(const std::string name) const; template diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 78ce8a6a..358621f4 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -107,6 +107,7 @@ public: virtual std::vector getOutput(void) = 0; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name) = 0; + virtual void saveParameters(XmlWriter &writer, const std::string name) = 0; // setup virtual void setup(void) {}; // execution @@ -130,6 +131,7 @@ public: virtual ~Module(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); + virtual void saveParameters(XmlWriter &writer, const std::string name); // parameter access const P & par(void) const; void setPar(const P &par); @@ -150,6 +152,11 @@ public: virtual ~Module(void) = default; // parse parameters (do nothing) virtual void parseParameters(XmlReader &reader, const std::string name) {}; + virtual void saveParameters(XmlWriter &writer, const std::string name) + { + push(writer, "options"); + pop(writer); + }; }; /****************************************************************************** @@ -166,6 +173,12 @@ void Module

::parseParameters(XmlReader &reader, const std::string name) read(reader, name, par_); } +template +void Module

::saveParameters(XmlWriter &writer, const std::string name) +{ + write(writer, name, par_); +} + template const P & Module

::par(void) const { From ea40854e0b823f2cc5cf7ce3e00f2aa4c00a1173 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 18:02:18 +0000 Subject: [PATCH 094/106] Hadrons: type names are demangled --- extras/Hadrons/Environment.cc | 7 +++---- extras/Hadrons/Global.cc | 15 ++++++++++++++ extras/Hadrons/Global.hpp | 39 +++++++++++++++-------------------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 600ca855..60d8da00 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -250,7 +250,7 @@ std::string Environment::getModuleType(const unsigned int address) const { if (hasModule(address)) { - return module_[address].type->name(); + return typeName(module_[address].type); } else { @@ -473,7 +473,7 @@ std::string Environment::getObjectType(const unsigned int address) const { if (hasRegisteredObject(address)) { - return object_[address].type->name(); + return typeName(object_[address].type); } else if (hasObject(address)) { @@ -689,8 +689,7 @@ void Environment::printContent(void) for (unsigned int i = 0; i < module_.size(); ++i) { LOG(Message) << std::setw(4) << i << ": " - << getModuleName(i) << " (" - << getModuleType(i) << ")" << std::endl; + << getModuleName(i) << std::endl; } LOG(Message) << "Objects: " << std::endl; for (unsigned int i = 0; i < object_.size(); ++i) diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index 62997e1f..5c915172 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -63,3 +63,18 @@ std::string Hadrons::sizeString(long unsigned int bytes) return std::string(buf); } + +// type utilities ////////////////////////////////////////////////////////////// +constexpr unsigned int maxNameSize = 1024u; + +std::string Hadrons::typeName(const std::type_info *info) +{ + char *buf; + std::string name; + + buf = abi::__cxa_demangle(info->name(), nullptr, nullptr, nullptr); + name = buf; + free(buf); + + return name; +} diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 3107ef12..1ecbe7cf 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -31,6 +31,7 @@ directory. #include #include #include +#include #define BEGIN_HADRONS_NAMESPACE \ namespace Grid {\ @@ -56,11 +57,6 @@ using Grid::operator<<; BEGIN_HADRONS_NAMESPACE // type aliases -//typedef FermionOperator FMat; -//typedef FIMPL::FermionField FermionField; -//typedef FIMPL::PropagatorField PropagatorField; -//typedef std::function SolverFn; - #define TYPE_ALIASES(FImpl, suffix)\ typedef FermionOperator FMat##suffix; \ typedef typename FImpl::FermionField FermionField##suffix; \ @@ -120,34 +116,33 @@ private:\ // pretty size formating std::string sizeString(long unsigned int bytes); -template -std::string typeName(const T &x) -{ - std::string name(typeid(x).name()); - - return name; -} - -template -std::string typeName(void) -{ - std::string name(typeid(T).name()); - - return name; -} - +// type utilities template const std::type_info * typeIdPt(const T &x) { return &typeid(x); } +std::string typeName(const std::type_info *info); + template -const std::type_info * typeName(void) +const std::type_info * typeIdPt(void) { return &typeid(T); } +template +std::string typeName(const T &x) +{ + return typeName(typeIdPt(x)); +} + +template +std::string typeName(void) +{ + return typeName(typeIdPt()); +} + END_HADRONS_NAMESPACE #endif // Hadrons_Global_hpp_ From e1653a9f94e2188fb6c1d103a69da8f1cabd0eec Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 18:02:36 +0000 Subject: [PATCH 095/106] Hadrons: size fix in DWF module --- extras/Hadrons/Modules/MAction/DWF.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 3f38c671..4bed2596 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -102,7 +102,7 @@ void TDWF::setup(void) { unsigned int size; - size = 3*env().template lattice4dSize(); + size = 2*env().template lattice4dSize(); env().registerObject(getName(), size, par().Ls); } From 7e2482aad1c6b3c7f36bafa2e0754d7599b3e142 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 18:04:21 +0000 Subject: [PATCH 096/106] Hadrons: cpde cleaning --- tests/hadrons/Test_hadrons_meson_3pt.cc | 9 ++++----- tests/hadrons/Test_hadrons_spectrum.cc | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/hadrons/Test_hadrons_meson_3pt.cc b/tests/hadrons/Test_hadrons_meson_3pt.cc index b3156918..2645bfbe 100644 --- a/tests/hadrons/Test_hadrons_meson_3pt.cc +++ b/tests/hadrons/Test_hadrons_meson_3pt.cc @@ -42,11 +42,10 @@ int main(int argc, char *argv[]) LOG(Message) << "Grid initialized" << std::endl; // run setup /////////////////////////////////////////////////////////////// - Application application; - - std::vector flavour = {"l", "s", "c1", "c2", "c3"}; - std::vector mass = {.01, .04, .2 , .25 , .3 }; - unsigned int nt = GridDefaultLatt()[Tp]; + Application application; + std::vector flavour = {"l", "s", "c1", "c2", "c3"}; + std::vector mass = {.01, .04, .2 , .25 , .3 }; + unsigned int nt = GridDefaultLatt()[Tp]; // global parameters Application::GlobalPar globalPar; diff --git a/tests/hadrons/Test_hadrons_spectrum.cc b/tests/hadrons/Test_hadrons_spectrum.cc index 93d31fed..7e66ea9b 100644 --- a/tests/hadrons/Test_hadrons_spectrum.cc +++ b/tests/hadrons/Test_hadrons_spectrum.cc @@ -42,8 +42,7 @@ int main(int argc, char *argv[]) LOG(Message) << "Grid initialized" << std::endl; // run setup /////////////////////////////////////////////////////////////// - Application application; - + Application application; std::vector flavour = {"l", "s", "c1", "c2", "c3"}; std::vector mass = {.01, .04, .2 , .25 , .3 }; From decbb61ec1e64015e52fe5fbcaf8bbd8e768e533 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 18:19:24 +0000 Subject: [PATCH 097/106] Hadrons: XML driven program is again a binary installed with Grid --- .../Hadrons/{Hadrons.cc => HadronsXmlRun.cc} | 0 extras/Hadrons/Makefile.am | 4 ++ tests/hadrons/Test_hadrons_xmldriven.cc | 66 ------------------- 3 files changed, 4 insertions(+), 66 deletions(-) rename extras/Hadrons/{Hadrons.cc => HadronsXmlRun.cc} (100%) delete mode 100644 tests/hadrons/Test_hadrons_xmldriven.cc diff --git a/extras/Hadrons/Hadrons.cc b/extras/Hadrons/HadronsXmlRun.cc similarity index 100% rename from extras/Hadrons/Hadrons.cc rename to extras/Hadrons/HadronsXmlRun.cc diff --git a/extras/Hadrons/Makefile.am b/extras/Hadrons/Makefile.am index 6fd459dc..5d4a5c5e 100644 --- a/extras/Hadrons/Makefile.am +++ b/extras/Hadrons/Makefile.am @@ -1,4 +1,5 @@ lib_LIBRARIES = libHadrons.a +bin_PROGRAMS = HadronsXmlRun include modules.inc @@ -20,3 +21,6 @@ nobase_libHadrons_a_HEADERS = \ Module.hpp \ Modules.hpp \ ModuleFactory.hpp + +HadronsXmlRun_SOURCES = HadronsXmlRun.cc +HadronsXmlRun_LDADD = -lGrid libHadrons.a diff --git a/tests/hadrons/Test_hadrons_xmldriven.cc b/tests/hadrons/Test_hadrons_xmldriven.cc deleted file mode 100644 index feb547e9..00000000 --- a/tests/hadrons/Test_hadrons_xmldriven.cc +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* -Grid physics library, www.github.com/paboyle/Grid - -Source file: tests/hadrons/Test_hadrons_xmldriven.cc - -Copyright (C) 2015 - -Author: Antonin Portelli - -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. -*******************************************************************************/ - -#include - -using namespace Grid; -using namespace QCD; -using namespace Hadrons; - -int main(int argc, char *argv[]) -{ - // parse command line - std::string parameterFileName; - - if (argc < 2) - { - std::cerr << "usage: " << argv[0] << " [Grid options]"; - std::cerr << std::endl; - std::exit(EXIT_FAILURE); - } - parameterFileName = argv[1]; - - // initialization - Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; - - // execution - Application application(parameterFileName); - - application.run(); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} From f3e49e4b73f4b450920f2a1fbd4cd1d2a9335861 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 18:19:46 +0000 Subject: [PATCH 098/106] Hadrons: module templates update --- extras/Hadrons/Modules/templates/Module.cc.template | 12 ++++++------ extras/Hadrons/Modules/templates/Module.hpp.template | 8 ++++---- .../Modules/templates/Module_in_NS.cc.template | 12 ++++++------ .../Modules/templates/Module_in_NS.hpp.template | 10 +++++----- .../Modules/templates/Module_tmp.hpp.template | 4 +--- .../Modules/templates/Module_tmp_in_NS.hpp.template | 4 +--- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/extras/Hadrons/Modules/templates/Module.cc.template b/extras/Hadrons/Modules/templates/Module.cc.template index 5cd7664d..0c509d6d 100644 --- a/extras/Hadrons/Modules/templates/Module.cc.template +++ b/extras/Hadrons/Modules/templates/Module.cc.template @@ -4,22 +4,22 @@ using namespace Grid; using namespace Hadrons; /****************************************************************************** -* ___FILEBASENAME___ implementation * +* T___FILEBASENAME___ implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -___FILEBASENAME___::___FILEBASENAME___(const std::string name) +T___FILEBASENAME___::T___FILEBASENAME___(const std::string name) : Module<___FILEBASENAME___Par>(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector ___FILEBASENAME___::getInput(void) +std::vector T___FILEBASENAME___::getInput(void) { std::vector in; return in; } -std::vector ___FILEBASENAME___::getOutput(void) +std::vector T___FILEBASENAME___::getOutput(void) { std::vector out = {getName()}; @@ -27,13 +27,13 @@ std::vector ___FILEBASENAME___::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void ___FILEBASENAME___::setup(void) +void T___FILEBASENAME___::setup(void) { } // execution /////////////////////////////////////////////////////////////////// -void ___FILEBASENAME___::execute(void) +void T___FILEBASENAME___::execute(void) { } diff --git a/extras/Hadrons/Modules/templates/Module.hpp.template b/extras/Hadrons/Modules/templates/Module.hpp.template index bee4e618..fb43260f 100644 --- a/extras/Hadrons/Modules/templates/Module.hpp.template +++ b/extras/Hadrons/Modules/templates/Module.hpp.template @@ -17,13 +17,13 @@ public: unsigned int, i); }; -class ___FILEBASENAME___: public Module<___FILEBASENAME___Par> +class T___FILEBASENAME___: public Module<___FILEBASENAME___Par> { public: // constructor - ___FILEBASENAME___(const std::string name); + T___FILEBASENAME___(const std::string name); // destructor - virtual ~___FILEBASENAME___(void) = default; + virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -33,7 +33,7 @@ public: virtual void execute(void); }; -MODULE_REGISTER(___FILEBASENAME___); +MODULE_REGISTER(___FILEBASENAME___, T___FILEBASENAME___); END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.cc.template b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template index 64bc7aa9..8b2a0ec0 100644 --- a/extras/Hadrons/Modules/templates/Module_in_NS.cc.template +++ b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template @@ -5,22 +5,22 @@ using namespace Hadrons; using namespace ___NAMESPACE___; /****************************************************************************** -* ___FILEBASENAME___ implementation * +* T___FILEBASENAME___ implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -___FILEBASENAME___::___FILEBASENAME___(const std::string name) +T___FILEBASENAME___::T___FILEBASENAME___(const std::string name) : Module<___FILEBASENAME___Par>(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector ___FILEBASENAME___::getInput(void) +std::vector T___FILEBASENAME___::getInput(void) { std::vector in; return in; } -std::vector ___FILEBASENAME___::getOutput(void) +std::vector T___FILEBASENAME___::getOutput(void) { std::vector out = {getName()}; @@ -28,13 +28,13 @@ std::vector ___FILEBASENAME___::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void ___FILEBASENAME___::setup(void) +void T___FILEBASENAME___::setup(void) { } // execution /////////////////////////////////////////////////////////////////// -void ___FILEBASENAME___::execute(void) +void T___FILEBASENAME___::execute(void) { } diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template index 490e5a78..ece2bb58 100644 --- a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template @@ -19,13 +19,13 @@ public: unsigned int, i); }; -class ___FILEBASENAME___: public Module<___FILEBASENAME___Par> +class T___FILEBASENAME___: public Module<___FILEBASENAME___Par> { public: // constructor - ___FILEBASENAME___(const std::string name); + T___FILEBASENAME___(const std::string name); // destructor - virtual ~___FILEBASENAME___(void) = default; + virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); @@ -35,9 +35,9 @@ public: virtual void execute(void); }; -END_MODULE_NAMESPACE +MODULE_REGISTER_NS(___FILEBASENAME___, T___FILEBASENAME___, ___NAMESPACE___); -MODULE_REGISTER_NS(___FILEBASENAME___, ___NAMESPACE___); +END_MODULE_NAMESPACE END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Modules/templates/Module_tmp.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template index 53bee52b..2ee053a9 100644 --- a/extras/Hadrons/Modules/templates/Module_tmp.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template @@ -34,7 +34,7 @@ public: virtual void execute(void); }; -typedef T___FILEBASENAME___ ___FILEBASENAME___; +MODULE_REGISTER(___FILEBASENAME___, T___FILEBASENAME___); /****************************************************************************** * T___FILEBASENAME___ implementation * @@ -76,8 +76,6 @@ void T___FILEBASENAME___::execute(void) } -MODULE_REGISTER(___FILEBASENAME___); - END_HADRONS_NAMESPACE #endif // Hadrons____FILEBASENAME____hpp_ diff --git a/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template index e7ff8ace..a330652d 100644 --- a/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template @@ -36,7 +36,7 @@ public: virtual void execute(void); }; -typedef T___FILEBASENAME___ ___FILEBASENAME___; +MODULE_REGISTER_NS(___FILEBASENAME___, T___FILEBASENAME___, ___NAMESPACE___); /****************************************************************************** * T___FILEBASENAME___ implementation * @@ -80,8 +80,6 @@ void T___FILEBASENAME___::execute(void) END_MODULE_NAMESPACE -MODULE_REGISTER_NS(___FILEBASENAME___, ___NAMESPACE___); - END_HADRONS_NAMESPACE #endif // Hadrons____FILEBASENAME____hpp_ From 846272b0378626640b9fd674e74eff050690ba8a Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 19:40:36 +0000 Subject: [PATCH 099/106] Hadrons: option to save and load a schedule --- extras/Hadrons/Application.cc | 113 +++++++++++++++++++++++++-------- extras/Hadrons/Application.hpp | 15 +++-- 2 files changed, 96 insertions(+), 32 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 07971a16..3a7c93fa 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -87,11 +87,15 @@ const Application::GlobalPar & Application::getPar(void) // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { - if (!parameterFileName_.empty()) + if (!parameterFileName_.empty() and (env_.getNModule() == 0)) { parseParameterFile(parameterFileName_); } - schedule(); + if (!scheduled_) + { + schedule(); + } + printSchedule(); configLoop(); } @@ -110,7 +114,7 @@ void Application::parseParameterFile(const std::string parameterFileName) GlobalPar par; ObjectId id; - LOG(Message) << "Reading '" << parameterFileName << "'..." << std::endl; + LOG(Message) << "Building application from '" << parameterFileName << "'..." << std::endl; read(reader, "parameters", par); setPar(par); push(reader, "modules"); @@ -130,7 +134,7 @@ void Application::saveParameterFile(const std::string parameterFileName) ObjectId id; const unsigned int nMod = env_.getNModule(); - LOG(Message) << "Writing '" << parameterFileName << "'..." << std::endl; + LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl; write(writer, "parameters", getPar()); push(writer, "modules"); for (unsigned int i = 0; i < nMod; ++i) @@ -150,29 +154,31 @@ void Application::saveParameterFile(const std::string parameterFileName) #define MEM_MSG(size)\ sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" +#define DEFINE_MEMPEAK \ +auto memPeak = [this](const std::vector &program)\ +{\ + unsigned int memPeak;\ + bool msg;\ + \ + msg = HadronsLogMessage.isActive();\ + HadronsLogMessage.Active(false);\ + env_.dryRun(true);\ + memPeak = env_.executeProgram(program);\ + env_.dryRun(false);\ + env_.freeAll();\ + HadronsLogMessage.Active(true);\ + \ + return memPeak;\ +} + void Application::schedule(void) { - // memory peak function - auto memPeak = [this](const std::vector &program) - { - unsigned int memPeak; - bool msg; - - msg = HadronsLogMessage.isActive(); - HadronsLogMessage.Active(false); - env_.dryRun(true); - memPeak = env_.executeProgram(program); - env_.dryRun(false); - env_.freeAll(); - HadronsLogMessage.Active(true); - - return memPeak; - }; + DEFINE_MEMPEAK; // build module dependency graph LOG(Message) << "Building module graph..." << std::endl; - auto graph = env_.makeModuleGraph(); - auto con = graph.getConnectedComponents(); + auto graph = env_.makeModuleGraph(); + auto con = graph.getConnectedComponents(); // constrained topological sort using a genetic algorithm LOG(Message) << "Scheduling computation..." << std::endl; @@ -189,6 +195,7 @@ void Application::schedule(void) par.popSize = par_.genetic.popSize; par.mutationRate = par_.genetic.mutationRate; par.seed = rd(); + memPeak_ = 0; CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); for (unsigned int i = 0; i < con.size(); ++i) { @@ -222,16 +229,68 @@ void Application::schedule(void) } while ((gen < par_.genetic.maxGen) and (nCstPeak < par_.genetic.maxCstGen)); auto &t = scheduler.getMinSchedule(); - LOG(Message) << "Program " << i + 1 << " (memory peak: " - << MEM_MSG(scheduler.getMinValue()) << "):" << std::endl; + if (scheduler.getMinValue() > memPeak_) + { + memPeak_ = scheduler.getMinValue(); + } for (unsigned int j = 0; j < t.size(); ++j) { program_.push_back(t[j]); - LOG(Message) << std::setw(4) << k + 1 << ": " - << env_.getModuleName(program_[k]) << std::endl; - k++; } } + scheduled_ = true; +} + +void Application::saveSchedule(const std::string filename) +{ + TextWriter writer(filename); + std::vector program; + + if (!scheduled_) + { + HADRON_ERROR("Computation not scheduled"); + } + LOG(Message) << "Saving current schedule to '" << filename << "'..." + << std::endl; + for (auto address: program_) + { + program.push_back(env_.getModuleName(address)); + } + write(writer, "schedule", program); +} + +void Application::loadSchedule(const std::string filename) +{ + DEFINE_MEMPEAK; + + TextReader reader(filename); + std::vector program; + + LOG(Message) << "Loading schedule from '" << filename << "'..." + << std::endl; + read(reader, "schedule", program); + program_.clear(); + for (auto &name: program) + { + program_.push_back(env_.getModuleAddress(name)); + } + scheduled_ = true; + memPeak_ = memPeak(program_); +} + +void Application::printSchedule(void) +{ + if (!scheduled_) + { + HADRON_ERROR("Computation not scheduled"); + } + LOG(Message) << "Schedule (memory peak: " << MEM_MSG(memPeak_) << "):" + << std::endl; + for (unsigned int i = 0; i < program_.size(); ++i) + { + LOG(Message) << std::setw(4) << i + 1 << ": " + << env_.getModuleName(program_[i]) << std::endl; + } } // loop on configurations ////////////////////////////////////////////////////// diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 65e9ad34..f84b0caa 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -91,14 +91,19 @@ public: void saveParameterFile(const std::string parameterFileName); // schedule computation void schedule(void); + void saveSchedule(const std::string filename); + void loadSchedule(const std::string filename); + void printSchedule(void); // loop on configurations void configLoop(void); private: - long unsigned int locVol_; - std::string parameterFileName_{""}; - GlobalPar par_; - Environment &env_; - std::vector program_; + long unsigned int locVol_; + std::string parameterFileName_{""}; + GlobalPar par_; + Environment &env_; + std::vector program_; + Environment::Size memPeak_; + bool scheduled_{false}; }; /****************************************************************************** From ab92de89abb61be943e90e1f93aeadbf6b5670d9 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 19:41:04 +0000 Subject: [PATCH 100/106] Hadrons: utility to schedule a run --- extras/Hadrons/HadronsXmlSchedule.cc | 70 ++++++++++++++++++++++++++++ extras/Hadrons/Makefile.am | 5 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 extras/Hadrons/HadronsXmlSchedule.cc diff --git a/extras/Hadrons/HadronsXmlSchedule.cc b/extras/Hadrons/HadronsXmlSchedule.cc new file mode 100644 index 00000000..09c61c5f --- /dev/null +++ b/extras/Hadrons/HadronsXmlSchedule.cc @@ -0,0 +1,70 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: programs/Hadrons/HadronsXmlSchedule.cc + + Copyright (C) 2015 + + Author: Antonin Portelli + + 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. + *******************************************************************************/ + +#include + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // parse command line + std::string parameterFileName, scheduleFileName; + + if (argc < 3) + { + std::cerr << "usage: " << argv[0] << " [Grid options]"; + std::cerr << std::endl; + std::exit(EXIT_FAILURE); + } + parameterFileName = argv[1]; + scheduleFileName = argv[2]; + + // initialization + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + + // execution + Application application; + + application.parseParameterFile(parameterFileName); + application.schedule(); + application.printSchedule(); + application.saveSchedule(scheduleFileName); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} diff --git a/extras/Hadrons/Makefile.am b/extras/Hadrons/Makefile.am index 5d4a5c5e..bdc23efb 100644 --- a/extras/Hadrons/Makefile.am +++ b/extras/Hadrons/Makefile.am @@ -1,5 +1,5 @@ lib_LIBRARIES = libHadrons.a -bin_PROGRAMS = HadronsXmlRun +bin_PROGRAMS = HadronsXmlRun HadronsXmlSchedule include modules.inc @@ -24,3 +24,6 @@ nobase_libHadrons_a_HEADERS = \ HadronsXmlRun_SOURCES = HadronsXmlRun.cc HadronsXmlRun_LDADD = -lGrid libHadrons.a + +HadronsXmlSchedule_SOURCES = HadronsXmlSchedule.cc +HadronsXmlSchedule_LDADD = -lGrid libHadrons.a From f63fac0c69d41dee091e0ff0a7e5f150517f41f9 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 19:41:30 +0000 Subject: [PATCH 101/106] Hadrons: the XML runner can use a precomputed schedule --- extras/Hadrons/HadronsXmlRun.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index ad43b6cc..b7384424 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Hadrons.cc +Source file: programs/Hadrons/HadronsXmlRun.cc Copyright (C) 2015 @@ -34,15 +34,22 @@ using namespace Hadrons; int main(int argc, char *argv[]) { // parse command line - std::string parameterFileName; + std::string parameterFileName, scheduleFileName = ""; if (argc < 2) { - std::cerr << "usage: " << argv[0] << " [Grid options]"; + std::cerr << "usage: " << argv[0] << " [] [Grid options]"; std::cerr << std::endl; std::exit(EXIT_FAILURE); } parameterFileName = argv[1]; + if (argc > 2) + { + if (argv[2][0] != '-') + { + scheduleFileName = argv[2]; + } + } // initialization Grid_init(&argc, &argv); @@ -56,6 +63,11 @@ int main(int argc, char *argv[]) // execution Application application(parameterFileName); + application.parseParameterFile(parameterFileName); + if (!scheduleFileName.empty()) + { + application.loadSchedule(scheduleFileName); + } application.run(); // epilogue From cad158e42f305a0b097dd7c1ce0b47fdb88fa939 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 14 Dec 2016 19:41:51 +0000 Subject: [PATCH 102/106] Hadrons: tests improvement --- tests/hadrons/Test_hadrons_meson_3pt.cc | 3 ++- tests/hadrons/Test_hadrons_spectrum.cc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/hadrons/Test_hadrons_meson_3pt.cc b/tests/hadrons/Test_hadrons_meson_3pt.cc index 2645bfbe..56d0efa7 100644 --- a/tests/hadrons/Test_hadrons_meson_3pt.cc +++ b/tests/hadrons/Test_hadrons_meson_3pt.cc @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) { // sequential sources MSource::SeqGamma::Par seqPar; - qName.push_back("QZ2_" + flavour[i] + srcName); + qName.push_back("QZ2_" + flavour[i] + "_" + std::to_string(t)); seqPar.q = qName[i]; seqPar.tA = (t + nt/4) % nt; seqPar.tB = (t + nt/4) % nt; @@ -159,6 +159,7 @@ int main(int argc, char *argv[]) } // execution + application.saveParameterFile("meson3pt.xml"); application.run(); // epilogue diff --git a/tests/hadrons/Test_hadrons_spectrum.cc b/tests/hadrons/Test_hadrons_spectrum.cc index 7e66ea9b..ea6e4479 100644 --- a/tests/hadrons/Test_hadrons_spectrum.cc +++ b/tests/hadrons/Test_hadrons_spectrum.cc @@ -121,6 +121,7 @@ int main(int argc, char *argv[]) } // execution + application.saveParameterFile("spectrum.xml"); application.run(); // epilogue From 596dd570c76b8e22c7a426a4ff7871a7b630e3a4 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 15 Dec 2016 12:26:53 +0000 Subject: [PATCH 103/106] Linux linking fix --- extras/Hadrons/Makefile.am | 4 ++-- scripts/filelist | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/Hadrons/Makefile.am b/extras/Hadrons/Makefile.am index bdc23efb..9cb23600 100644 --- a/extras/Hadrons/Makefile.am +++ b/extras/Hadrons/Makefile.am @@ -23,7 +23,7 @@ nobase_libHadrons_a_HEADERS = \ ModuleFactory.hpp HadronsXmlRun_SOURCES = HadronsXmlRun.cc -HadronsXmlRun_LDADD = -lGrid libHadrons.a +HadronsXmlRun_LDADD = libHadrons.a -lGrid HadronsXmlSchedule_SOURCES = HadronsXmlSchedule.cc -HadronsXmlSchedule_LDADD = -lGrid libHadrons.a +HadronsXmlSchedule_LDADD = libHadrons.a -lGrid diff --git a/scripts/filelist b/scripts/filelist index ca7425c0..1ab95c7c 100755 --- a/scripts/filelist +++ b/scripts/filelist @@ -24,11 +24,11 @@ for subdir in $dirs; do echo "tests: ${TESTLIST} ${SUB}" > Make.inc echo ${PREF}_PROGRAMS = ${TESTLIST} >> Make.inc echo >> Make.inc - HADLINK=`[ $subdir = './hadrons' ] && echo '-lHadrons'` + HADLINK=`[ $subdir = './hadrons' ] && echo '-lHadrons '` for f in $TESTS; do BNAME=`basename $f .cc` echo ${BNAME}_SOURCES=$f >> Make.inc - echo ${BNAME}_LDADD=-lGrid ${HADLINK} >> Make.inc + echo ${BNAME}_LDADD=${HADLINK}-lGrid >> Make.inc echo >> Make.inc done if [ $subdir != '.' ]; then From b791c274b0ec610fdaef91e3d894cbb2bbab4f8f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 15 Dec 2016 18:15:35 +0000 Subject: [PATCH 104/106] Revert "AVX: uninitialised variable fix" This reverts commit c22c3db9ad652eadbd334fde70235aace90faa75. --- lib/simd/Grid_avx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/simd/Grid_avx.h b/lib/simd/Grid_avx.h index 77927b10..36360102 100644 --- a/lib/simd/Grid_avx.h +++ b/lib/simd/Grid_avx.h @@ -514,7 +514,7 @@ namespace Optimization { template static inline __m256 tRotate(__m256 in){ __m256 tmp = Permute::Permute0(in); - __m256 ret = in; + __m256 ret; if ( n > 3 ) { _mm256_alignr_epi32_grid(ret,in,tmp,n); } else { @@ -526,7 +526,7 @@ namespace Optimization { template static inline __m256d tRotate(__m256d in){ __m256d tmp = Permute::Permute0(in); - __m256d ret = in; + __m256d ret; if ( n > 1 ) { _mm256_alignr_epi64_grid(ret,in,tmp,n); } else { From 80cef1c78ff0efaf726a6b926ca46a49941fc950 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 15 Dec 2016 18:21:52 +0000 Subject: [PATCH 105/106] Hadrons: legal banner fix --- extras/Hadrons/Application.cc | 1 + extras/Hadrons/Application.hpp | 1 + extras/Hadrons/Environment.cc | 1 + extras/Hadrons/Environment.hpp | 1 + extras/Hadrons/Factory.hpp | 1 + extras/Hadrons/GeneticScheduler.hpp | 1 + extras/Hadrons/Global.cc | 1 + extras/Hadrons/Global.hpp | 1 + extras/Hadrons/Graph.hpp | 1 + extras/Hadrons/HadronsXmlRun.cc | 1 + extras/Hadrons/HadronsXmlSchedule.cc | 1 + extras/Hadrons/Module.cc | 1 + extras/Hadrons/Module.hpp | 1 + extras/Hadrons/ModuleFactory.hpp | 1 + extras/Hadrons/Modules/MAction/DWF.hpp | 1 + extras/Hadrons/Modules/MAction/Wilson.hpp | 3 ++- extras/Hadrons/Modules/MContraction/Meson.hpp | 2 +- extras/Hadrons/Modules/MGauge/Load.cc | 1 + extras/Hadrons/Modules/MGauge/Load.hpp | 1 + extras/Hadrons/Modules/MGauge/Random.cc | 1 + extras/Hadrons/Modules/MGauge/Random.hpp | 1 + extras/Hadrons/Modules/MGauge/Unit.cc | 1 + extras/Hadrons/Modules/MGauge/Unit.hpp | 1 + extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 3 ++- extras/Hadrons/Modules/MSource/Point.hpp | 3 ++- extras/Hadrons/Modules/MSource/Z2.hpp | 3 ++- extras/Hadrons/Modules/Quark.hpp | 3 ++- 27 files changed, 32 insertions(+), 6 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 3a7c93fa..85eda97a 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include #include diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index f84b0caa..05179e97 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Application_hpp_ #define Hadrons_Application_hpp_ diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 60d8da00..62e611c3 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include #include diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 065c889a..b3ff160b 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Environment_hpp_ #define Hadrons_Environment_hpp_ diff --git a/extras/Hadrons/Factory.hpp b/extras/Hadrons/Factory.hpp index ea358c21..65de9b96 100644 --- a/extras/Hadrons/Factory.hpp +++ b/extras/Hadrons/Factory.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Factory_hpp_ #define Hadrons_Factory_hpp_ diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index 857a4099..c93ac2e5 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_GeneticScheduler_hpp_ #define Hadrons_GeneticScheduler_hpp_ diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index 5c915172..296038e4 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 1ecbe7cf..e6d2adaa 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Global_hpp_ #define Hadrons_Global_hpp_ diff --git a/extras/Hadrons/Graph.hpp b/extras/Hadrons/Graph.hpp index 37ad077d..8f5beb30 100644 --- a/extras/Hadrons/Graph.hpp +++ b/extras/Hadrons/Graph.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Graph_hpp_ #define Hadrons_Graph_hpp_ diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index b7384424..a022c285 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include diff --git a/extras/Hadrons/HadronsXmlSchedule.cc b/extras/Hadrons/HadronsXmlSchedule.cc index 09c61c5f..5e213ab3 100644 --- a/extras/Hadrons/HadronsXmlSchedule.cc +++ b/extras/Hadrons/HadronsXmlSchedule.cc @@ -24,6 +24,7 @@ See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include diff --git a/extras/Hadrons/Module.cc b/extras/Hadrons/Module.cc index dccae582..fabc6557 100644 --- a/extras/Hadrons/Module.cc +++ b/extras/Hadrons/Module.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 358621f4..abb9cfd3 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Module_hpp_ #define Hadrons_Module_hpp_ diff --git a/extras/Hadrons/ModuleFactory.hpp b/extras/Hadrons/ModuleFactory.hpp index 01cc130c..b893cb8a 100644 --- a/extras/Hadrons/ModuleFactory.hpp +++ b/extras/Hadrons/ModuleFactory.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_ModuleFactory_hpp_ #define Hadrons_ModuleFactory_hpp_ diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 4bed2596..15654627 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_DWF_hpp_ #define Hadrons_DWF_hpp_ diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index 6a01d92e..cff6d482 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/TWilson.hpp +Source file: programs/Hadrons/Wilson.hpp Copyright (C) 2016 @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Wilson_hpp_ #define Hadrons_Wilson_hpp_ diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 438f3740..755cc7c8 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/TMeson.hpp +Source file: programs/Hadrons/Meson.hpp Copyright (C) 2015 diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MGauge/Load.cc index 82920d97..ba0d3a99 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp index 21f9331c..32274104 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Load_hpp_ #define Hadrons_Load_hpp_ diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index 2c25f7c1..bff989a4 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index 95db726c..dbc185a5 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Random_hpp_ #define Hadrons_Random_hpp_ diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index 16dcff83..d6d6da76 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #include diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index d9566958..86a4e128 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Unit_hpp_ #define Hadrons_Unit_hpp_ diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index 82f2eafa..874957c0 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/TRBPrecCG.hpp +Source file: programs/Hadrons/RBPrecCG.hpp Copyright (C) 2016 @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_RBPrecCG_hpp_ #define Hadrons_RBPrecCG_hpp_ diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 84952512..be3ad982 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/TPoint.hpp +Source file: programs/Hadrons/Point.hpp Copyright (C) 2016 @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Point_hpp_ #define Hadrons_Point_hpp_ diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index e50b2a73..1bcd276d 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/TZ2.hpp +Source file: programs/Hadrons/Z2.hpp Copyright (C) 2016 @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Z2_hpp_ #define Hadrons_Z2_hpp_ diff --git a/extras/Hadrons/Modules/Quark.hpp b/extras/Hadrons/Modules/Quark.hpp index 81b74755..e2c11aaa 100644 --- a/extras/Hadrons/Modules/Quark.hpp +++ b/extras/Hadrons/Modules/Quark.hpp @@ -1,7 +1,7 @@ /******************************************************************************* Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/TQuark.hpp +Source file: programs/Hadrons/Quark.hpp Copyright (C) 2015 @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory. *******************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Quark_hpp_ #define Hadrons_Quark_hpp_ From 67d72000e78863a825f5e1952c69ea0c3213bd77 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 15 Dec 2016 18:26:39 +0000 Subject: [PATCH 106/106] Hadrons: more legal banner fixes --- extras/Hadrons/Application.cc | 11 ++-- extras/Hadrons/Application.hpp | 11 ++-- extras/Hadrons/Environment.cc | 11 ++-- extras/Hadrons/Environment.hpp | 11 ++-- extras/Hadrons/Factory.hpp | 11 ++-- extras/Hadrons/GeneticScheduler.hpp | 11 ++-- extras/Hadrons/Global.cc | 11 ++-- extras/Hadrons/Global.hpp | 11 ++-- extras/Hadrons/Graph.hpp | 11 ++-- extras/Hadrons/HadronsXmlRun.cc | 11 ++-- extras/Hadrons/HadronsXmlSchedule.cc | 53 ++++++++++--------- extras/Hadrons/Module.cc | 11 ++-- extras/Hadrons/Module.hpp | 11 ++-- extras/Hadrons/ModuleFactory.hpp | 11 ++-- extras/Hadrons/Modules.hpp | 28 ++++++++++ extras/Hadrons/Modules/MAction/DWF.hpp | 11 ++-- extras/Hadrons/Modules/MAction/Wilson.hpp | 11 ++-- .../Hadrons/Modules/MContraction/Baryon.hpp | 29 ++++++++++ extras/Hadrons/Modules/MContraction/Meson.hpp | 12 +++-- extras/Hadrons/Modules/MGauge/Load.cc | 11 ++-- extras/Hadrons/Modules/MGauge/Load.hpp | 11 ++-- extras/Hadrons/Modules/MGauge/Random.cc | 11 ++-- extras/Hadrons/Modules/MGauge/Random.hpp | 11 ++-- extras/Hadrons/Modules/MGauge/Unit.cc | 11 ++-- extras/Hadrons/Modules/MGauge/Unit.hpp | 11 ++-- extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 11 ++-- extras/Hadrons/Modules/MSource/Point.hpp | 11 ++-- extras/Hadrons/Modules/MSource/SeqGamma.hpp | 29 ++++++++++ extras/Hadrons/Modules/MSource/Z2.hpp | 11 ++-- extras/Hadrons/Modules/Quark.hpp | 11 ++-- 30 files changed, 270 insertions(+), 156 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 85eda97a..cf7906eb 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Application.cc +Source file: extras/Hadrons/Application.cc Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 05179e97..4ea262df 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Application.hpp +Source file: extras/Hadrons/Application.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Application_hpp_ diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 62e611c3..4b230e20 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Environment.cc +Source file: extras/Hadrons/Environment.cc Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index b3ff160b..41a7a008 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Environment.hpp +Source file: extras/Hadrons/Environment.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Environment_hpp_ diff --git a/extras/Hadrons/Factory.hpp b/extras/Hadrons/Factory.hpp index 65de9b96..da86acae 100644 --- a/extras/Hadrons/Factory.hpp +++ b/extras/Hadrons/Factory.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Factory.hpp +Source file: extras/Hadrons/Factory.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Factory_hpp_ diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index c93ac2e5..7b5fc183 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/GeneticScheduler.hpp +Source file: extras/Hadrons/GeneticScheduler.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_GeneticScheduler_hpp_ diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index 296038e4..7b0b8fb6 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Global.cc +Source file: extras/Hadrons/Global.cc Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index e6d2adaa..81afab13 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Global.hpp +Source file: extras/Hadrons/Global.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Global_hpp_ diff --git a/extras/Hadrons/Graph.hpp b/extras/Hadrons/Graph.hpp index 8f5beb30..df255517 100644 --- a/extras/Hadrons/Graph.hpp +++ b/extras/Hadrons/Graph.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Graph.hpp +Source file: extras/Hadrons/Graph.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Graph_hpp_ diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index a022c285..0dff8f9a 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/HadronsXmlRun.cc +Source file: extras/Hadrons/HadronsXmlRun.cc Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/HadronsXmlSchedule.cc b/extras/Hadrons/HadronsXmlSchedule.cc index 5e213ab3..a8ca9a63 100644 --- a/extras/Hadrons/HadronsXmlSchedule.cc +++ b/extras/Hadrons/HadronsXmlSchedule.cc @@ -1,29 +1,30 @@ -/******************************************************************************* - Grid physics library, www.github.com/paboyle/Grid - - Source file: programs/Hadrons/HadronsXmlSchedule.cc - - Copyright (C) 2015 - - Author: Antonin Portelli - - 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. - *******************************************************************************/ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/HadronsXmlSchedule.cc + +Copyright (C) 2015 +Copyright (C) 2016 + +Author: Antonin Portelli + +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 */ #include diff --git a/extras/Hadrons/Module.cc b/extras/Hadrons/Module.cc index fabc6557..2549a931 100644 --- a/extras/Hadrons/Module.cc +++ b/extras/Hadrons/Module.cc @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Module.cc +Source file: extras/Hadrons/Module.cc Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index abb9cfd3..071e254a 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Module.hpp +Source file: extras/Hadrons/Module.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Module_hpp_ diff --git a/extras/Hadrons/ModuleFactory.hpp b/extras/Hadrons/ModuleFactory.hpp index b893cb8a..48ab305c 100644 --- a/extras/Hadrons/ModuleFactory.hpp +++ b/extras/Hadrons/ModuleFactory.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/ModuleFactory.hpp +Source file: extras/Hadrons/ModuleFactory.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_ModuleFactory_hpp_ diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 72807d8b..77ae08b7 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules.hpp + +Copyright (C) 2015 +Copyright (C) 2016 + +Author: Antonin Portelli + +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 */ #include #include #include diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 15654627..49861e3e 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/DWF.hpp +Source file: extras/Hadrons/Modules/MAction/DWF.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_DWF_hpp_ diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index cff6d482..6ffa997d 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Wilson.hpp +Source file: extras/Hadrons/Modules/MAction/Wilson.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Wilson_hpp_ diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index 6ae9c1ab..6bccda2e 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -1,3 +1,32 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MContraction/Baryon.hpp + +Copyright (C) 2015 +Copyright (C) 2016 + +Author: Antonin Portelli + +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 Hadrons_Baryon_hpp_ #define Hadrons_Baryon_hpp_ diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 755cc7c8..dc4f60ee 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Meson.hpp +Source file: extras/Hadrons/Modules/MContraction/Meson.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,9 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Meson_hpp_ #define Hadrons_Meson_hpp_ diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MGauge/Load.cc index ba0d3a99..e5ee8abb 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Load.cc +Source file: extras/Hadrons/Modules/MGauge/Load.cc +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp index 32274104..c41f9b8c 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Load.hpp +Source file: extras/Hadrons/Modules/MGauge/Load.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Load_hpp_ diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index bff989a4..c10fdfc3 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Random.cc +Source file: extras/Hadrons/Modules/MGauge/Random.cc +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index dbc185a5..e3fbcf1a 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Random.hpp +Source file: extras/Hadrons/Modules/MGauge/Random.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Random_hpp_ diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index d6d6da76..18d75c59 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Unit.cc +Source file: extras/Hadrons/Modules/MGauge/Unit.cc +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #include diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index 86a4e128..2ff10bfd 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Unit.hpp +Source file: extras/Hadrons/Modules/MGauge/Unit.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Unit_hpp_ diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index 874957c0..d7220271 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/RBPrecCG.hpp +Source file: extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_RBPrecCG_hpp_ diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index be3ad982..a0ecbc2a 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Point.hpp +Source file: extras/Hadrons/Modules/MSource/Point.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Point_hpp_ diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp index 70b603fe..181f9532 100644 --- a/extras/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -1,3 +1,32 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MSource/SeqGamma.hpp + +Copyright (C) 2015 +Copyright (C) 2016 + +Author: Antonin Portelli + +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 Hadrons_SeqGamma_hpp_ #define Hadrons_SeqGamma_hpp_ diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index 1bcd276d..cd5727be 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -1,8 +1,10 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Z2.hpp +Source file: extras/Hadrons/Modules/MSource/Z2.hpp +Copyright (C) 2015 Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Z2_hpp_ diff --git a/extras/Hadrons/Modules/Quark.hpp b/extras/Hadrons/Modules/Quark.hpp index e2c11aaa..e441a096 100644 --- a/extras/Hadrons/Modules/Quark.hpp +++ b/extras/Hadrons/Modules/Quark.hpp @@ -1,9 +1,11 @@ -/******************************************************************************* +/************************************************************************************* + Grid physics library, www.github.com/paboyle/Grid -Source file: programs/Hadrons/Quark.hpp +Source file: extras/Hadrons/Modules/Quark.hpp Copyright (C) 2015 +Copyright (C) 2016 Author: Antonin Portelli @@ -21,9 +23,8 @@ 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. -*******************************************************************************/ +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ /* END LEGAL */ #ifndef Hadrons_Quark_hpp_