Skip to content

Commit fe7e593

Browse files
committed
disable openblas multithreading
1 parent b0cf6d2 commit fe7e593

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

SEMain/src/program/SourceXtractor.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,26 @@ static void setupEnvironment(void) {
128128
}
129129

130130
/**
131-
* MKL blas implementation use multithreading by default, which
131+
* MKL Blas and OpenBlas implementation use multithreading by default, which
132132
* tends to play badly with sourcextractor++ own multithreading.
133-
* We disable multithreading here *unless* explicitly enabled by the user via
134-
* environment variables
133+
* We disable multithreading here *always* as enabling multithreading causes bugs
135134
*/
136135
static void disableBlasMultithreading() {
137-
bool omp_env_present = getenv("OMP_NUM_THREADS") || getenv("OMP_DYNAMIC");
138-
bool mkl_env_present = getenv("MKL_NUM_THREADS") || getenv("MKL_DYNAMIC");
139-
if (!omp_env_present && !mkl_env_present) {
140-
// Despite the documentation, the methods following C ABI are capitalized
141-
void (*set_num_threads)(int) = reinterpret_cast<void (*)(int)>(dlsym(RTLD_DEFAULT, "MKL_Set_Num_Threads"));
142-
void (*set_dynamic)(int) = reinterpret_cast<void (*)(int)>(dlsym(RTLD_DEFAULT, "MKL_Set_Dynamic"));
143-
if (set_num_threads) {
144-
logger.debug() << "Disabling multithreading";
145-
set_num_threads(1);
146-
}
147-
if (set_dynamic) {
148-
logger.debug() << "Disabling dynamic multithreading";
149-
set_dynamic(0);
150-
}
136+
// Despite the documentation, the methods following C ABI are capitalized
137+
void (*set_num_threads)(int) = reinterpret_cast<void (*)(int)>(dlsym(RTLD_DEFAULT, "MKL_Set_Num_Threads"));
138+
void (*set_dynamic)(int) = reinterpret_cast<void (*)(int)>(dlsym(RTLD_DEFAULT, "MKL_Set_Dynamic"));
139+
void (*openblas_set_num_threads)(int) = reinterpret_cast<void (*)(int)>(dlsym(RTLD_DEFAULT, "openblas_set_num_threads"));
140+
if (set_num_threads) {
141+
logger.debug() << "Disabling multithreading";
142+
set_num_threads(1);
143+
}
144+
if (openblas_set_num_threads) {
145+
logger.debug() << "Disabling OpenBLAS multithreading";
146+
openblas_set_num_threads(1);
147+
}
148+
if (set_dynamic) {
149+
logger.debug() << "Disabling dynamic multithreading";
150+
set_dynamic(0);
151151
}
152152
}
153153

0 commit comments

Comments
 (0)