From 538b16610b773613a5b0689b55ff976310264dc8 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 27 Oct 2015 17:33:18 +0000 Subject: [PATCH 001/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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/157] 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 b1cfb4d661efee3d78f1a98821e86400675adf11 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 5 Aug 2016 15:29:18 +0100 Subject: [PATCH 058/157] first try at a nicer Doxygen implementation --- Makefile.am | 2 + configure.ac | 17 +- docs/doxy.cfg.in | 2305 ----------------- docs/doxy.cfg => doxygen.cfg | 512 ++-- doxygen.cfg.bak | 1130 ++++++++ .../iterative/ImplicitlyRestartedLanczos.h | 8 +- lib/simd/Grid_avx512.h | 9 - lib/simd/Grid_imci.h | 8 - m4/ac_prog_doxygen.m4 | 54 - ...-ax_prog_doxygen.m4 => ax_prog_doxygen.m4} | 0 10 files changed, 1457 insertions(+), 2588 deletions(-) delete mode 100644 docs/doxy.cfg.in rename docs/doxy.cfg => doxygen.cfg (84%) create mode 100644 doxygen.cfg.bak delete mode 100644 m4/ac_prog_doxygen.m4 rename m4/{m4-ax_prog_doxygen.m4 => ax_prog_doxygen.m4} (100%) diff --git a/Makefile.am b/Makefile.am index 90c5cd71..470de83b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,7 @@ # additional include paths necessary to compile the C++ library SUBDIRS = lib benchmarks tests +include $(top_srcdir)/doxygen.inc + AM_CXXFLAGS += -I$(top_builddir)/include ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 89bb3568..3fa98288 100644 --- a/configure.ac +++ b/configure.ac @@ -250,12 +250,17 @@ esac AM_CONDITIONAL(BUILD_CHROMA_REGRESSION,[ test "X${ac_CHROMA}X" == "XyesX" ]) ############### Doxygen -AC_PROG_DOXYGEN - -if test -n "$DOXYGEN" -then -AC_CONFIG_FILES([docs/doxy.cfg]) -fi +DX_DOXYGEN_FEATURE([OFF]) +DX_DOT_FEATURE([OFF]) +DX_HTML_FEATURE([ON]) +DX_CHM_FEATURE([OFF]) +DX_CHI_FEATURE([OFF]) +DX_MAN_FEATURE([OFF]) +DX_RTF_FEATURE([OFF]) +DX_XML_FEATURE([OFF]) +DX_PDF_FEATURE([OFF]) +DX_PS_FEATURE([OFF]) +DX_INIT_DOXYGEN([$PACKAGE_NAME], [doxygen.cfg]) ############### Ouput cwd=`pwd -P`; cd ${srcdir}; abs_srcdir=`pwd -P`; cd ${cwd} diff --git a/docs/doxy.cfg.in b/docs/doxy.cfg.in deleted file mode 100644 index c4b82094..00000000 --- a/docs/doxy.cfg.in +++ /dev/null @@ -1,2305 +0,0 @@ -# Doxyfile 1.8.6 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = "Grid" - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = 1.0 - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = - -# With the PROJECT_LOGO tag one can specify an logo or icon that is included in -# the documentation. The maximum height of the logo should not exceed 55 pixels -# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo -# to the output directory. - -PROJECT_LOGO = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = ./doxy-en/ - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. -# The default value is: NO. - -CREATE_SUBDIRS = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, -# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), -# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, -# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, -# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, -# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, -# Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a -# new page for each member. If set to NO, the documentation of a member will be -# part of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 4 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:\n" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -ALIASES = - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. -# -# Note For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by by putting a % sign in front of the word -# or globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = YES - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = NO - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = NO - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = YES - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = YES - -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = YES - -# If the EXTRACT_STATIC tag is set to YES all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = YES - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = YES - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO these classes will be included in the various overviews. This option has -# no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO these declarations will be -# included in the documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. - -CASE_SENSE_NAMES = YES - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each -# grouped member an include statement to the documentation, telling the reader -# which file to include in order to use the member. -# The default value is: NO. - -SHOW_GROUPED_MEMB_INC = NO - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. Note that -# this will also influence the order of the classes in the class list. -# The default value is: NO. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = YES - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the -# todo list. This list is created by putting \todo commands in the -# documentation. -# The default value is: YES. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the -# test list. This list is created by putting \test commands in the -# documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if ... \endif and \cond -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES the list -# will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. Do not use file names with spaces, bibtex cannot handle them. See -# also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO doxygen will only warn about wrong or incomplete parameter -# documentation, but not about the absence of documentation. -# The default value is: NO. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. -# Note: If this tag is empty the current directory is searched. - -INPUT = ../lib \ - ../tests \ - ../benchmarks - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank the -# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, -# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, -# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, -# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, -# *.qsf, *.as and *.js. - -FILE_PATTERNS = - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories use the pattern */test/* - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# -# -# where is the value of the INPUT_FILTER tag, and is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER ) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = YES - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = NO - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = NO - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES, then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = YES - -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output -# The default value is: YES. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- -# defined cascading style sheet that is included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. -# Doxygen will copy the style sheet file to the output directory. For an example -# see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the stylesheet and background images according to -# this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = NO - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler ( hhc.exe). If non-empty -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated ( -# YES) or that it should be included in the master .chm file ( NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated ( -# YES) or a normal table of contents ( NO) in the .chm file. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = YES - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_TRANSPARENT = YES - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using prerendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = YES - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use + S -# (what the is depends on the OS and browser, but it is typically -# , /