Skip to content

Commit 74b5f37

Browse files
committed
Try blas_shutdown
1 parent 548eec0 commit 74b5f37

6 files changed

Lines changed: 25 additions & 7 deletions

File tree

extern/HighsExtrasApi.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ HIGHS_EXTRAS_API bool HighsExtras_getApi(HighsExtrasApi* api) {
7272
std::make_tuple(&Highs_amd_defaults, &Highs_amd_order));
7373

7474
bind_api<blas_methods>(
75-
api,
76-
std::make_tuple(&cblas_daxpy, &cblas_dcopy, &cblas_dscal, &cblas_dswap,
77-
&cblas_dgemv, &cblas_dtpsv, &cblas_dtrsv, &cblas_dger,
78-
&cblas_dgemm, &cblas_dsyrk, &cblas_dtrsm,
79-
&highs_openblas_set_num_threads));
75+
api, std::make_tuple(
76+
&cblas_daxpy, &cblas_dcopy, &cblas_dscal, &cblas_dswap,
77+
&cblas_dgemv, &cblas_dtpsv, &cblas_dtrsv, &cblas_dger,
78+
&cblas_dgemm, &cblas_dsyrk, &cblas_dtrsm,
79+
&highs_openblas_set_num_threads, &highs_openblas_shutdown));
8080

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

extern/HighsExtrasExternalDeps.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ 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)>;
70+
decltype(&highs_openblas_set_num_threads),
71+
decltype(&highs_openblas_shutdown)>;
7172

7273
using metis_methods = std::tuple<decltype(&Highs_METIS_SetDefaultOptions),
7374
decltype(&Highs_METIS_NodeND)>;
@@ -187,6 +188,8 @@ struct blas : extras_feature<1> {
187188
static void openblas_set_num_threads(int num_threads) {
188189
impl::template fn<11>()(num_threads);
189190
}
191+
192+
static void openblas_shutdown(void) { impl::template fn<12>()(); }
190193
};
191194

192195
struct metis : extras_feature<2> {

extern/blas/myblas.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ 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);
8283
#endif
8384

8485
void highs_openblas_set_num_threads(int num_threads);
86+
void highs_openblas_shutdown(void);
8587

8688
#ifdef __cplusplus
8789
}

highs/HighsExternalApi.cpp

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

17+
HighsExternalApi::~HighsExternalApi() {
18+
#ifdef HIGHS_SHARED_EXTRAS_LIBRARY
19+
HighsExtras::blas::openblas_shutdown();
20+
#endif
21+
unload();
22+
}
23+
1724
HighsExternalApi& HighsExternalApi::instance() {
1825
static HighsExternalApi _instance;
1926
return _instance;

highs/HighsExternalApi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct trait_pack_ops<Trait, Rest...> {
119119
struct HighsExternalApi {
120120
public:
121121
HighsExternalApi() = default;
122-
~HighsExternalApi() { unload(); }
122+
~HighsExternalApi();
123123

124124
// Prevent copying
125125
HighsExternalApi(const HighsExternalApi&) = delete;

0 commit comments

Comments
 (0)