PDS/homework_1/src/v1.cpp

55 lines
1.2 KiB
C++

/**
* \file v1.hpp
* \brief
*
* \author
* Christos Choutouridis AEM:8997
* <cchoutou@ece.auth.gr>
*/
#include "v1.hpp"
/*!
* \fn void init_workers()
*
* Initialize worker settings
*/
void init_workers() {
#if defined CILK
size_t cilk_w = __cilkrts_get_nworkers();
if (!session.max_threads)
session.max_threads = (session.slices) ? (session.slices) : cilk_w;
// else if (session.max_threads < cilk_w)
// __cilkrts_set_param("nworkers", "4");
// else ignored by cilk
#elif defined OMP
// omp_set_dynamic(1);
size_t omp_w = (size_t)omp_get_max_threads();
if (!session.max_threads) {
session.max_threads = (session.slices) ? (session.slices) : omp_w;
// omp_set_dynamic(1);
}
else if (session.max_threads < omp_w) {
// omp_set_dynamic(0);
omp_set_num_threads(session.max_threads);
}
// else ignored by omp
#elif defined PTHREADS
size_t pth_w = std::thread::hardware_concurrency();
if (!session.max_threads)
session.max_threads = (session.slices) ? (session.slices) : pth_w;
#else
#endif
if (!session.slices)
session.slices = session.max_threads;
openblas_set_num_threads(1); // Limit OpenBLAS to 1 thread
}