Commit 5a445d53 authored by Martin Reinecke's avatar Martin Reinecke

revert to old (non-resizable) thread pool

parent 1614cb9e
Pipeline #80368 passed with stages
in 14 minutes and 48 seconds
......@@ -203,8 +203,6 @@ py::array py_transpose(const py::array &in, py::array &out)
MR_fail("unsupported datatype");
}
void py_set_thread_pool_size(size_t new_pool_size)
{ set_pool_size(new_pool_size); }
const char *misc_DS = R"""(
Various unsorted utilities
......@@ -227,8 +225,6 @@ void add_misc(py::module &msup)
m.def("ascontiguousarray",&py_ascontiguousarray, "in"_a);
m.def("transpose",&py_transpose, "in"_a, "out"_a);
m.def("set_thread_pool_size",&py_set_thread_pool_size, "new_pool_size"_a);
}
}
......
......@@ -29,7 +29,6 @@
#include <queue>
#include <atomic>
#include <vector>
#include <memory>
#if __has_include(<pthread.h>)
#include <pthread.h>
#endif
......@@ -41,7 +40,9 @@ namespace detail_threading {
#ifndef DUCC0_NO_THREADING
std::atomic<size_t> default_nthreads_(std::max<size_t>(1, std::thread::hardware_concurrency()));
static const size_t max_threads_ = std::max<size_t>(1, std::thread::hardware_concurrency());
std::atomic<size_t> default_nthreads_(max_threads_);
size_t get_default_nthreads()
{ return default_nthreads_; }
......@@ -49,6 +50,8 @@ size_t get_default_nthreads()
void set_default_nthreads(size_t new_default_nthreads)
{ default_nthreads_ = std::max<size_t>(1, new_default_nthreads); }
size_t max_threads() { return max_threads_; }
class latch
{
std::atomic<size_t> num_left_;
......@@ -152,9 +155,9 @@ class thread_pool
threads_(nthreads)
{ create_threads(); }
~thread_pool() { shutdown(); }
thread_pool(): thread_pool(max_threads_) {}
size_t size() const { return threads_.size(); }
~thread_pool() { shutdown(); }
void submit(std::function<void()> work)
{
......@@ -176,12 +179,9 @@ class thread_pool
}
};
thread_pool &get_pool(size_t nthreads=0)
inline thread_pool &get_pool()
{
static std::unique_ptr<thread_pool> pool;
if ((!pool) && (nthreads==0)) nthreads=default_nthreads_;
if ((!pool) || ((nthreads!=0) && (nthreads!=pool->size()))) // resize
pool = std::make_unique<thread_pool>(nthreads);
static thread_pool pool;
#if __has_include(<pthread.h>)
static std::once_flag f;
call_once(f,
......@@ -194,12 +194,9 @@ thread_pool &get_pool(size_t nthreads=0)
});
#endif
return *pool;
return pool;
}
void set_pool_size(size_t new_pool_size)
{ get_pool(new_pool_size); }
class Distribution
{
private:
......@@ -320,7 +317,7 @@ void Distribution::thread_map(std::function<void(Scheduler &)> f)
return;
}
auto &pool = get_pool();
auto & pool = get_pool();
latch counter(nthreads_);
std::exception_ptr ex;
std::mutex ex_mut;
......
......@@ -47,11 +47,10 @@ class Scheduler
virtual Range getNext() = 0;
};
size_t max_threads();
void set_default_nthreads(size_t new_default_nthreads);
size_t get_default_nthreads();
void set_pool_size(size_t new_pool_size);
void execSingle(size_t nwork,
std::function<void(Scheduler &)> func);
void execStatic(size_t nwork, size_t nthreads, size_t chunksize,
......@@ -64,7 +63,7 @@ void execParallel(size_t nthreads, std::function<void(Scheduler &)> func);
} // end of namespace detail_threading
using detail_threading::set_pool_size;
using detail_threading::max_threads;
using detail_threading::get_default_nthreads;
using detail_threading::set_default_nthreads;
using detail_threading::Scheduler;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment