File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11#include < gtest/gtest.h>
2+ #include < tbb/global_control.h>
23
34#include < boost/mpi/communicator.hpp>
45#include < boost/mpi/environment.hpp>
@@ -56,6 +57,21 @@ int main(int argc, char** argv) {
5657 boost::mpi::environment env (argc, argv);
5758 boost::mpi::communicator world;
5859
60+ #ifdef _WIN32
61+ size_t len;
62+ char omp_env[100 ];
63+ errno_t err = getenv_s (&len, omp_env, sizeof (omp_env), " OMP_NUM_THREADS" );
64+ if (err != 0 || len == 0 ) {
65+ omp_env[0 ] = ' \0 ' ;
66+ }
67+ #else
68+ const char * omp_env = std::getenv (" OMP_NUM_THREADS" );
69+ #endif
70+ int num_threads = (omp_env != nullptr ) ? std::atoi (omp_env) : 1 ;
71+
72+ // Limit the number of threads in TBB
73+ tbb::global_control control (tbb::global_control::max_allowed_parallelism, num_threads);
74+
5975 ::testing::InitGoogleTest (&argc, argv);
6076
6177 auto & listeners = ::testing::UnitTest::GetInstance ()->listeners ();
Original file line number Diff line number Diff line change 11#include < gtest/gtest.h>
2+ #include < tbb/global_control.h>
3+
4+ int main (int argc, char ** argv) {
5+ #ifdef _WIN32
6+ size_t len;
7+ char omp_env[100 ];
8+ errno_t err = getenv_s (&len, omp_env, sizeof (omp_env), " OMP_NUM_THREADS" );
9+ if (err != 0 || len == 0 ) {
10+ omp_env[0 ] = ' \0 ' ;
11+ }
12+ #else
13+ const char * omp_env = std::getenv (" OMP_NUM_THREADS" );
14+ #endif
15+ int num_threads = (omp_env != nullptr ) ? std::atoi (omp_env) : 1 ;
16+
17+ // Limit the number of threads in TBB
18+ tbb::global_control control (tbb::global_control::max_allowed_parallelism, num_threads);
219
3- int main (int argc, char **argv) {
420 ::testing::InitGoogleTest (&argc, argv);
521 return RUN_ALL_TESTS ();
622}
You can’t perform that action at this time.
0 commit comments