Skip to content

Commit 508efa3

Browse files
committed
Try ugly solution for missing blas_shutdown
1 parent d6c90e1 commit 508efa3

6 files changed

Lines changed: 16 additions & 20 deletions

File tree

extern/HighsExtrasApi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ HIGHS_EXTRAS_API bool HighsExtras_getApi(HighsExtrasApi* api) {
7676
&cblas_daxpy, &cblas_dcopy, &cblas_dscal, &cblas_dswap,
7777
&cblas_dgemv, &cblas_dtpsv, &cblas_dtrsv, &cblas_dger,
7878
&cblas_dgemm, &cblas_dsyrk, &cblas_dtrsm,
79-
&highs_openblas_set_num_threads, &highs_openblas_shutdown));
79+
&highs_openblas_set_num_threads));
8080

8181
bind_api<metis_methods>(api, std::make_tuple(&Highs_METIS_SetDefaultOptions,
8282
&Highs_METIS_NodeND));

extern/HighsExtrasExternalDeps.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ using blas_methods = std::tuple<
6767
decltype(&cblas_dswap), decltype(&cblas_dgemv), decltype(&cblas_dtpsv),
6868
decltype(&cblas_dtrsv), decltype(&cblas_dger), decltype(&cblas_dgemm),
6969
decltype(&cblas_dsyrk), decltype(&cblas_dtrsm),
70-
decltype(&highs_openblas_set_num_threads),
71-
decltype(&highs_openblas_shutdown)>;
70+
decltype(&highs_openblas_set_num_threads)>;
7271

7372
using metis_methods = std::tuple<decltype(&Highs_METIS_SetDefaultOptions),
7473
decltype(&Highs_METIS_NodeND)>;
@@ -188,8 +187,6 @@ struct blas : extras_feature<1> {
188187
static void openblas_set_num_threads(int num_threads) {
189188
impl::template fn<11>()(num_threads);
190189
}
191-
192-
static void openblas_shutdown(void) { impl::template fn<12>()(); }
193190
};
194191

195192
struct metis : extras_feature<2> {

extern/blas/myblas.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,3 @@ void highs_openblas_set_num_threads(int num_threads) {
55
openblas_set_num_threads(num_threads);
66
#endif
77
}
8-
9-
void highs_openblas_shutdown() {
10-
#if defined(HIPO_USES_OPENBLAS)
11-
blas_shutdown();
12-
#endif
13-
}

extern/blas/mycblas.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,9 @@ void cblas_dtrsm(const enum CBLAS_ORDER order, const enum CBLAS_SIDE side,
7979

8080
#if defined(HIPO_USES_OPENBLAS)
8181
void openblas_set_num_threads(int num_threads);
82-
void blas_shutdown(void);
8382
#endif
8483

8584
void highs_openblas_set_num_threads(int num_threads);
86-
void highs_openblas_shutdown(void);
87-
8885
#ifdef __cplusplus
8986
}
9087
#endif

highs/HighsExternalApi.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
#include <mutex>
1515
using namespace HighsExtras;
1616

17-
HighsExternalApi::~HighsExternalApi() {
18-
#ifdef HIGHS_SHARED_EXTRAS_LIBRARY
19-
if (isAvailable<HighsExtras::blas>()) HighsExtras::blas::openblas_shutdown();
20-
#endif
21-
unload();
22-
}
17+
HighsExternalApi::~HighsExternalApi() { unload(); }
2318

2419
HighsExternalApi& HighsExternalApi::instance() {
2520
static HighsExternalApi _instance;

highs/util/HighsDynamicLibrary.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ void HighsDynamicLibrary::unload() {
6868
#if defined(_WIN32) || defined(_WIN64)
6969
FreeLibrary(static_cast<HMODULE>(handle_));
7070
#else
71+
// check if blas_shutdown exists and potentially use it before dlclose-ing
72+
73+
using shutdown_t = void (*)();
74+
75+
shutdown_t shutdown_fn = nullptr;
76+
77+
if (auto p = dlsym(handle_, "blas_shutdown"))
78+
shutdown_fn = reinterpret_cast<shutdown_t>(p);
79+
else if (auto p = dlsym(handle_, "openblas_shutdown"))
80+
shutdown_fn = reinterpret_cast<shutdown_t>(p);
81+
82+
if (shutdown_fn) shutdown_fn();
83+
7184
dlclose(handle_);
7285
#endif
7386

0 commit comments

Comments
 (0)