Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tasks/all/runner.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
#include <tbb/global_control.h>

#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
Expand Down Expand Up @@ -56,6 +57,21 @@ int main(int argc, char** argv) {
boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;

#ifdef _WIN32
size_t len;
char omp_env[100];
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "OMP_NUM_THREADS");
if (err != 0 || len == 0) {
omp_env[0] = '\0';
}
#else
const char* omp_env = std::getenv("OMP_NUM_THREADS");
#endif
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;

// Limit the number of threads in TBB
tbb::global_control control(tbb::global_control::max_allowed_parallelism, num_threads);

::testing::InitGoogleTest(&argc, argv);

auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
Expand Down
18 changes: 17 additions & 1 deletion tasks/tbb/runner.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#include <gtest/gtest.h>
#include <tbb/global_control.h>

int main(int argc, char** argv) {
#ifdef _WIN32
size_t len;
char omp_env[100];
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "OMP_NUM_THREADS");
if (err != 0 || len == 0) {
omp_env[0] = '\0';
}
#else
const char* omp_env = std::getenv("OMP_NUM_THREADS");
#endif
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;

// Limit the number of threads in TBB
tbb::global_control control(tbb::global_control::max_allowed_parallelism, num_threads);

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading