From 9b3a50042db84e9fdc8f60ed377a64e0a5cb7d7d Mon Sep 17 00:00:00 2001 From: Florian Goth Date: Mon, 28 Jun 2021 17:39:59 +0200 Subject: [PATCH 1/6] first round of extensions --- src/libmarqov/core.h | 17 ++++++++--------- src/libmarqov/emcs.h | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/libmarqov/core.h b/src/libmarqov/core.h index c288ebb..2569af9 100644 --- a/src/libmarqov/core.h +++ b/src/libmarqov/core.h @@ -49,7 +49,7 @@ namespace MARQOV { /** Marqov Config. * - * We have a global marqov object that collects parameters that are special + * We have a global marqov object that collects runtime parameters that are special * for MARQOV. Hamiltonian and lattice parameters are elsewhere. */ struct Config @@ -361,7 +361,7 @@ namespace MARQOV //forward declaration of Core. //FIXME think about proper placement of docs and where... - template class RefType> + template class RefType> class Core; /** A class to encapsulate the state space of a hamiltonian. @@ -377,7 +377,7 @@ namespace MARQOV StateVectorT *const myspace; ///< the storage of the state space. const std::size_t size_; ///< how many state vectors are in our state space - template class RefType> + template class RefType> friend class Core; public: @@ -431,6 +431,8 @@ namespace MARQOV * The RNGCache will be initialized. * @tparam Grid the Lattice that we should use. * @tparam Hamiltonian The Hamiltonian that we should use. + * @tparam MutexType The type of the mutex that we use for locking. + * @tparam RNGType The type of the Random Number Generator that we use. * @tparam RefType used internally to distinguish, whether MARQOV::Core should * create the lattice or whether it is user provided. */ @@ -442,7 +444,7 @@ struct TrivialMutex static TrivialMutex tm; -template class RefType = detail::Ref > +template class RefType = detail::Ref > class Core : public RefType { public: @@ -1190,9 +1192,6 @@ class Core : public RefType typedef decltype(std::declval().observables) ObsTs; ///< This type is mostly a tuple of other observables. typename ObsTupleToObsCacheTuple::RetType obscache; ///< The HDF5 caches for each observable. ObsTs& obs; /// rngcache;///< The caching RNG }; @@ -1215,7 +1214,7 @@ class Core : public RefType template inline constexpr auto makeCore_with_latt(const Config& mc, std::mutex& mtx, std::tuple&& largs, const std::tuple hargs, std::index_sequence ) { - return Core(std::forward>(largs), mc, mtx, std::get(hargs)...); + return Core(std::forward>(largs), mc, mtx, std::get(hargs)...); } /** Instantiate Core and use a reference to a precreated lattice. @@ -1236,7 +1235,7 @@ inline constexpr auto makeCore_with_latt(const Config& mc, std::mutex& mtx, std: template inline constexpr auto makeCore_using_latt(Grid&& latt, const Config& mc, MutexType& mtx, std::tuple hargs, std::index_sequence) { - return Core(std::forward(latt), mc, mtx, std::get(hargs)...); + return Core(std::forward(latt), mc, mtx, std::get(hargs)...); } /** Instantiate Core with a reference to a precreated lattice. diff --git a/src/libmarqov/emcs.h b/src/libmarqov/emcs.h index 7c4c981..208fc31 100644 --- a/src/libmarqov/emcs.h +++ b/src/libmarqov/emcs.h @@ -82,8 +82,8 @@ namespace MARQOV return avgclustersize/ncluster; } -template class RefType> -double Core::elementaryMCstep() +template class RefType> +double Core::elementaryMCstep() { return EMCS::move(this->ham, this->grid, -- GitLab From d42cd85a0b28fa1f70303d9b024cbab18e460b44 Mon Sep 17 00:00:00 2001 From: Florian Goth Date: Mon, 28 Jun 2021 18:20:54 +0200 Subject: [PATCH 2/6] makeCore can now be used to select the RNGType --- src/libmarqov/core.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/libmarqov/core.h b/src/libmarqov/core.h index 2569af9..82c0e0e 100644 --- a/src/libmarqov/core.h +++ b/src/libmarqov/core.h @@ -1202,6 +1202,7 @@ class Core : public RefType * * @tparam H the type of Hamiltonian * @tparam Grid the type of the lattice + * @tparam MutexType The Type of the mutex that is employed. * @tparam LArgs The arguments of the lattice. * @tparam HArgs the arguments of the hamiltonian. * @tparam S a parameter pack of integers for unpacking the hamiltonian parameters. @@ -1211,10 +1212,10 @@ class Core : public RefType * @param largs The lattice arguments * @param hargs The hamiltonian arguments. */ -template -inline constexpr auto makeCore_with_latt(const Config& mc, std::mutex& mtx, std::tuple&& largs, const std::tuple hargs, std::index_sequence ) +template +inline constexpr auto makeCore_with_latt(const Config& mc, MutexType& mtx, std::tuple&& largs, const std::tuple hargs, std::index_sequence ) { - return Core(std::forward>(largs), mc, mtx, std::get(hargs)...); + return Core(std::forward>(largs), mc, mtx, std::get(hargs)...); } /** Instantiate Core and use a reference to a precreated lattice. @@ -1232,10 +1233,10 @@ inline constexpr auto makeCore_with_latt(const Config& mc, std::mutex& mtx, std: * @param latt A reference to a lattice. * @param hargs The hamiltonian arguments. */ -template +template inline constexpr auto makeCore_using_latt(Grid&& latt, const Config& mc, MutexType& mtx, std::tuple hargs, std::index_sequence) { - return Core(std::forward(latt), mc, mtx, std::get(hargs)...); + return Core(std::forward(latt), mc, mtx, std::get(hargs)...); } /** Instantiate Core with a reference to a precreated lattice. @@ -1248,12 +1249,12 @@ inline constexpr auto makeCore_using_latt(Grid&& latt, const Config& mc, MutexTy * @param t a tuple of a reference to a lattice, a config object and the hamiltonian parameters. * @param mtx The mutex that synchronizes access to the HDF5 files. */ -template +template inline auto makeCore(const std::tuple > t, MutexType& mtx=tm) { //The first argument is a Lattice-like type -> from this we infer that //we get a reference to sth. already allocated - return makeCore_using_latt(std::forward(std::get<0>(t)), std::get<1>(t), mtx, std::get<2>(t), + return makeCore_using_latt(std::forward(std::get<0>(t)), std::get<1>(t), mtx, std::get<2>(t), std::make_index_sequence>::type>::value>() ); } @@ -1268,10 +1269,10 @@ inline auto makeCore(const std::tuple > t, M * @param t a tuple of the lattice parameters, a config object and the hamiltonian parameters. * @param mtx The mutex that synchronizes access to the HDF5 files. */ -template +template inline auto makeCore(std::tuple, Config, std::tuple > t, std::mutex& mtx) { - return makeCore_with_latt(std::get<1>(t), mtx, std::forward >(std::get<0>(t)), std::get<2>(t), + return makeCore_with_latt(std::get<1>(t), mtx, std::forward >(std::get<0>(t)), std::get<2>(t), std::make_index_sequence>::type>::value>() ); } @@ -1286,10 +1287,10 @@ inline auto makeCore(std::tuple, Config, std::tuple +template inline constexpr auto makeCore(std::tuple&, Config, std::tuple > t, std::mutex& mtx) { - return makeCore_with_latt(std::get<1>(t), mtx, std::forward >(std::get<0>(t)), std::get<2>(t), + return makeCore_with_latt(std::get<1>(t), mtx, std::forward >(std::get<0>(t)), std::get<2>(t), std::make_index_sequence>::type>::value>() ); } @@ -1306,10 +1307,10 @@ inline constexpr auto makeCore(std::tuple&, Config, std::tu * @param t a tuple of the lattice parameters, a config object and the hamiltonian parameters. * @param mtx The mutex that synchronizes access to the HDF5 files. */ -template +template inline auto makeCore(std::tuple, Config, std::tuple& > t, std::mutex& mtx) { - return makeCore_with_latt(std::get<1>(t), mtx, std::forward >(std::get<0>(t)), std::get<2>(t), + return makeCore_with_latt(std::get<1>(t), mtx, std::forward >(std::get<0>(t)), std::get<2>(t), std::make_index_sequence>::type>::value>() ); } -- GitLab From 753e6d8164a769020669279436d40a37c58ab584 Mon Sep 17 00:00:00 2001 From: Florian Goth Date: Mon, 28 Jun 2021 18:46:14 +0200 Subject: [PATCH 3/6] make the RNGType configurable in the Scheduler --- src/libmarqov/marqovscheduler.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libmarqov/marqovscheduler.h b/src/libmarqov/marqovscheduler.h index 790f8da..8cef53f 100644 --- a/src/libmarqov/marqovscheduler.h +++ b/src/libmarqov/marqovscheduler.h @@ -352,12 +352,13 @@ namespace MARQOV * @tparam Lattice The type of the lattice. * @tparam Parameters The type of the parameters. We instantiate Hamiltonian * and probably lattice in Marqov, hence the params. + * @tparam RNGType The type of the Random Number Generator. Must conform to C++11 Interface. */ - template + template struct GetSchedulerType { typedef std::mutex& mtxref; - typedef decltype(makeCore(std::declval(), std::declval())) MarqovType; + typedef decltype(makeCore(std::declval(), std::declval())) MarqovType; typedef Scheduler MarqovScheduler; ///< Holds the type of a scheduler for these simulations. }; }; -- GitLab From ddc023f4fef4665076a407c2499beb7db4174773 Mon Sep 17 00:00:00 2001 From: Florian Goth Date: Mon, 28 Jun 2021 19:31:13 +0200 Subject: [PATCH 4/6] some docs on how to have proper names in the HDF5 output --- src/libmarqov/marqovscheduler.h | 2 ++ src/libmarqov/rngcache.h | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libmarqov/marqovscheduler.h b/src/libmarqov/marqovscheduler.h index 8cef53f..aa9e59d 100644 --- a/src/libmarqov/marqovscheduler.h +++ b/src/libmarqov/marqovscheduler.h @@ -353,6 +353,8 @@ namespace MARQOV * @tparam Parameters The type of the parameters. We instantiate Hamiltonian * and probably lattice in Marqov, hence the params. * @tparam RNGType The type of the Random Number Generator. Must conform to C++11 Interface. + * If you intend to use it for a non-STL RNG, have a look at @see rngcache.h + * to have a proper name dumped for it in the HDF5 files. */ template struct GetSchedulerType diff --git a/src/libmarqov/rngcache.h b/src/libmarqov/rngcache.h index f1cd9a5..6ea5dc9 100644 --- a/src/libmarqov/rngcache.h +++ b/src/libmarqov/rngcache.h @@ -34,7 +34,10 @@ SOFTWARE. * @tparam T the used RNG. */ template -struct RNGName; +struct RNGName +{ + std::string name = "RNG NAME NOT SPECIFIED!!!!!!!!!!!"; ///< name of the RNG available as a plain string. +}; /** Specialization for ranlux48. */ @@ -88,7 +91,7 @@ struct RNGName * * This implements a cache for random values. * If the cache is empty we refill it with new random values from a user - * defined RNG. + * defined RNG. Also RNGName how to get a proper name for I/O. * @tparam RNG The RNG that the user wishes to use. */ -- GitLab From 7c8abeab21e815324bce4cd9444e1e08605bce6b Mon Sep 17 00:00:00 2001 From: Florian Goth Date: Tue, 29 Jun 2021 13:54:21 +0200 Subject: [PATCH 5/6] more RNG names --- src/libmarqov/rngcache.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libmarqov/rngcache.h b/src/libmarqov/rngcache.h index 6ea5dc9..4dfa159 100644 --- a/src/libmarqov/rngcache.h +++ b/src/libmarqov/rngcache.h @@ -42,6 +42,22 @@ struct RNGName /** Specialization for ranlux48. */ template <> +struct RNGName +{ + std::string name = "ranlux48"; ///< name of the RNG available as a plain string. +}; + +/** Specialization for knuth_b. + */ +template <> +struct RNGName +{ + std::string name = "knuth_b"; ///< name of the RNG available as a plain string. +}; + +/** Specialization for ranlux48_base. + */ +template <> struct RNGName { std::string name = "ranlux48_base"; ///< name of the RNG available as a plain string. -- GitLab From 8aba2f71ac0ec8448811d8d7727bfeda06faf0b3 Mon Sep 17 00:00:00 2001 From: Florian Goth Date: Tue, 29 Jun 2021 13:54:33 +0200 Subject: [PATCH 6/6] two examples --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5bc8422..d1c37df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -267,7 +267,7 @@ void selectsim() //typedef RegularRandomBond Lattice; typedef std::tuple, MARQOV::Config, typename decltype(hp)::value_type > ParameterType; - typedef typename GetSchedulerType::MarqovScheduler SchedulerType; + typedef typename GetSchedulerType::MarqovScheduler SchedulerType; SchedulerType sched(1, nthreads); @@ -334,7 +334,7 @@ void selectsim() typedef ConstantCoordinationLattice Lattice; typedef std::tuple, MARQOV::Config, typename decltype(hp)::value_type > ParameterType; - typedef typename GetSchedulerType::MarqovScheduler SchedulerType; + typedef typename GetSchedulerType::MarqovScheduler SchedulerType; // Lattice size loop -- GitLab