13#include "../settings/settings.hpp"
20template <
typename Tfun>
24 auto task_par = [&](
int i_begin,
int i_end_,
int Nth) {
25 while (i_begin < i_end_) {
32 if (numMaxParallelWorkers == 1)
33 task_par(0, i_end, 1);
35 if (numMaxParallelWorkers < 1)
36 numMaxParallelWorkers = std::thread::hardware_concurrency();
38 const unsigned int N_th_max = std::min(numMaxParallelWorkers, std::thread::hardware_concurrency());
40 std::vector<std::thread> threads;
41 threads.reserve(N_th_max);
43 for (
unsigned int i_begin = 0; i_begin < N_th_max; i_begin++)
47 threads.emplace_back(task_par, i_begin, i_end, N_th_max);
50 for (
auto &th : threads) {
56 task_par(0, i_end, 1);
constexpr unsigned int numMaxParallelWorkers
Maximum number of threads to use if isParallel true.
Definition: settings.hpp:29
constexpr bool isParallel
Parallelises the code if possible.
Definition: settings.hpp:28
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
void run(Tfun task_indv, int i_end, unsigned int numMaxParallelWorkers=settings::numMaxParallelWorkers)
Definition: parallelisation.hpp:21