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 1
1
#include < gtest/gtest.h>
2
+ #include < tbb/global_control.h>
2
3
3
4
#include < boost/mpi/communicator.hpp>
4
5
#include < boost/mpi/environment.hpp>
@@ -56,6 +57,21 @@ int main(int argc, char** argv) {
56
57
boost::mpi::environment env (argc, argv);
57
58
boost::mpi::communicator world;
58
59
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
+
59
75
::testing::InitGoogleTest (&argc, argv);
60
76
61
77
auto & listeners = ::testing::UnitTest::GetInstance ()->listeners ();
Original file line number Diff line number Diff line change 1
1
#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);
2
19
3
- int main (int argc, char **argv) {
4
20
::testing::InitGoogleTest (&argc, argv);
5
21
return RUN_ALL_TESTS ();
6
22
}
You can’t perform that action at this time.
0 commit comments