Loading include/dca/parallel/stdthread/thread_pool/affinity.hpp 0 → 100644 +32 −0 Original line number Diff line number Diff line // Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 UT-Battelle, LLC // All rights reserved. // // See LICENSE for terms of usage. // See CITATION.md for citation guidelines, if DCA++ is used for scientific publications. // // Author: Giovanni Balduzzi(gbalduzz@itp.phys.ethz.ch) // // These methods allow to retrieve and set the list of cores the current thread has affinity to. #ifndef DCA_PARALLEL_STDTHREAD_THREAD_POOL_AFFINITY_HPP #define DCA_PARALLEL_STDTHREAD_THREAD_POOL_AFFINITY_HPP #include <vector> namespace dca { namespace parallel { // dca::parallel:: // Returns a list of cores id for which the calling thread has affinity. std::vector<int> get_affinity(); void set_affinity(const std::vector<int>& cores); // Number of cores used by this process. int get_core_count(); } // namespace parallel } // namespace dca #endif // DCA_PARALLEL_STDTHREAD_THREAD_POOL_AFFINITY_HPP include/dca/parallel/stdthread/thread_pool/thread_pool.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,9 @@ private: std::vector<std::unique_ptr<std::condition_variable>> condition_; std::atomic<bool> stop_; std::atomic<unsigned int> active_id_; int core_count_; std::vector<int> master_affinity_; }; template <class F, class... Args> Loading include/dca/phys/dca_step/cluster_mapping/coarsegraining/coarsegraining_sp.hpp +3 −3 Original line number Diff line number Diff line #// Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 UT-Battelle, LLC // All rights reserved. // Loading @@ -6,9 +6,9 @@ // See CITATION.md for citation guidelines, if DCA++ is used for scientific publications. // // Author: Peter Staar (taa@zurich.ibm.com) // Giovani Balduzzi(gbalduzz@itp.phys.ethz.ch) // Giovanni Balduzzi(gbalduzz@itp.phys.ethz.ch) // // This class performs the coarsegraining of single-particle functions. // This class performs the coarse-graining of single-particle functions. #ifndef DCA_PHYS_DCA_STEP_CLUSTER_MAPPING_COARSEGRAINING_COARSEGRAINING_SP_HPP #define DCA_PHYS_DCA_STEP_CLUSTER_MAPPING_COARSEGRAINING_COARSEGRAINING_SP_HPP Loading src/parallel/stdthread/CMakeLists.txt +2 −1 Original line number Diff line number Diff line # parallel stdthread add_library(parallel_stdthread STATIC stdthread.cpp thread_pool/thread_pool.cpp) add_library(parallel_stdthread STATIC stdthread.cpp thread_pool/thread_pool.cpp thread_pool/affinity.cpp) src/parallel/stdthread/thread_pool/affinity.cpp 0 → 100644 +74 −0 Original line number Diff line number Diff line // Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 UT-Battelle, LLC // All rights reserved. // // See LICENSE for terms of usage. // See CITATION.md for citation guidelines, if DCA++ is used for scientific publications. // // Author: Giovanni Balduzzi(gbalduzz@itp.phys.ethz.ch) // // This file implements the methods in affinity.hpp. #include "dca/parallel/stdthread/thread_pool/affinity.hpp" #include <iostream> #include <cstdlib> // GNU extensions are required for linux-specific features for querying affinity #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include <sched.h> #include <stdexcept> namespace dca { namespace parallel { // dca::parallel:: std::vector<int> get_affinity() { cpu_set_t cpu_set_mask; auto status = sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set_mask); if (status == -1) { throw(std::runtime_error("Unable to get thread affinity.")); } auto cpu_count = CPU_COUNT(&cpu_set_mask); std::vector<int> cores; cores.reserve(cpu_count); for (auto i = 0; i < CPU_SETSIZE && cores.size() < cpu_count; ++i) { if (CPU_ISSET(i, &cpu_set_mask)) { cores.push_back(i); } } if (cores.size() != cpu_count) { throw(std::logic_error("Core count mismatch.")); } return cores; } void set_affinity(const std::vector<int>& cores) { cpu_set_t cpu_set_mask; CPU_ZERO(&cpu_set_mask); for (int core : cores) { CPU_SET(core, &cpu_set_mask); } sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set_mask); } int get_core_count() { cpu_set_t cpu_set_mask; sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set_mask); return CPU_COUNT(&cpu_set_mask); } } // namespace parallel } // namespace dca Loading
include/dca/parallel/stdthread/thread_pool/affinity.hpp 0 → 100644 +32 −0 Original line number Diff line number Diff line // Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 UT-Battelle, LLC // All rights reserved. // // See LICENSE for terms of usage. // See CITATION.md for citation guidelines, if DCA++ is used for scientific publications. // // Author: Giovanni Balduzzi(gbalduzz@itp.phys.ethz.ch) // // These methods allow to retrieve and set the list of cores the current thread has affinity to. #ifndef DCA_PARALLEL_STDTHREAD_THREAD_POOL_AFFINITY_HPP #define DCA_PARALLEL_STDTHREAD_THREAD_POOL_AFFINITY_HPP #include <vector> namespace dca { namespace parallel { // dca::parallel:: // Returns a list of cores id for which the calling thread has affinity. std::vector<int> get_affinity(); void set_affinity(const std::vector<int>& cores); // Number of cores used by this process. int get_core_count(); } // namespace parallel } // namespace dca #endif // DCA_PARALLEL_STDTHREAD_THREAD_POOL_AFFINITY_HPP
include/dca/parallel/stdthread/thread_pool/thread_pool.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,9 @@ private: std::vector<std::unique_ptr<std::condition_variable>> condition_; std::atomic<bool> stop_; std::atomic<unsigned int> active_id_; int core_count_; std::vector<int> master_affinity_; }; template <class F, class... Args> Loading
include/dca/phys/dca_step/cluster_mapping/coarsegraining/coarsegraining_sp.hpp +3 −3 Original line number Diff line number Diff line #// Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 UT-Battelle, LLC // All rights reserved. // Loading @@ -6,9 +6,9 @@ // See CITATION.md for citation guidelines, if DCA++ is used for scientific publications. // // Author: Peter Staar (taa@zurich.ibm.com) // Giovani Balduzzi(gbalduzz@itp.phys.ethz.ch) // Giovanni Balduzzi(gbalduzz@itp.phys.ethz.ch) // // This class performs the coarsegraining of single-particle functions. // This class performs the coarse-graining of single-particle functions. #ifndef DCA_PHYS_DCA_STEP_CLUSTER_MAPPING_COARSEGRAINING_COARSEGRAINING_SP_HPP #define DCA_PHYS_DCA_STEP_CLUSTER_MAPPING_COARSEGRAINING_COARSEGRAINING_SP_HPP Loading
src/parallel/stdthread/CMakeLists.txt +2 −1 Original line number Diff line number Diff line # parallel stdthread add_library(parallel_stdthread STATIC stdthread.cpp thread_pool/thread_pool.cpp) add_library(parallel_stdthread STATIC stdthread.cpp thread_pool/thread_pool.cpp thread_pool/affinity.cpp)
src/parallel/stdthread/thread_pool/affinity.cpp 0 → 100644 +74 −0 Original line number Diff line number Diff line // Copyright (C) 2018 ETH Zurich // Copyright (C) 2018 UT-Battelle, LLC // All rights reserved. // // See LICENSE for terms of usage. // See CITATION.md for citation guidelines, if DCA++ is used for scientific publications. // // Author: Giovanni Balduzzi(gbalduzz@itp.phys.ethz.ch) // // This file implements the methods in affinity.hpp. #include "dca/parallel/stdthread/thread_pool/affinity.hpp" #include <iostream> #include <cstdlib> // GNU extensions are required for linux-specific features for querying affinity #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include <sched.h> #include <stdexcept> namespace dca { namespace parallel { // dca::parallel:: std::vector<int> get_affinity() { cpu_set_t cpu_set_mask; auto status = sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set_mask); if (status == -1) { throw(std::runtime_error("Unable to get thread affinity.")); } auto cpu_count = CPU_COUNT(&cpu_set_mask); std::vector<int> cores; cores.reserve(cpu_count); for (auto i = 0; i < CPU_SETSIZE && cores.size() < cpu_count; ++i) { if (CPU_ISSET(i, &cpu_set_mask)) { cores.push_back(i); } } if (cores.size() != cpu_count) { throw(std::logic_error("Core count mismatch.")); } return cores; } void set_affinity(const std::vector<int>& cores) { cpu_set_t cpu_set_mask; CPU_ZERO(&cpu_set_mask); for (int core : cores) { CPU_SET(core, &cpu_set_mask); } sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set_mask); } int get_core_count() { cpu_set_t cpu_set_mask; sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set_mask); return CPU_COUNT(&cpu_set_mask); } } // namespace parallel } // namespace dca