summaryrefslogtreecommitdiffstats
path: root/matlab
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2016-01-27 10:05:57 +0100
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2016-01-27 10:08:48 +0100
commit4a75ab09962015d90acaa3e2be8357a1c917d5eb (patch)
tree139bd09d0319bc031578733a9948fcdf154c7d7e /matlab
parentcf0eff7075d21ccfa985676eb3a5e30f8694fc4c (diff)
downloadastra-4a75ab09962015d90acaa3e2be8357a1c917d5eb.tar.gz
astra-4a75ab09962015d90acaa3e2be8357a1c917d5eb.tar.bz2
astra-4a75ab09962015d90acaa3e2be8357a1c917d5eb.tar.xz
astra-4a75ab09962015d90acaa3e2be8357a1c917d5eb.zip
Move fixLapackLoading to astra_mex_plugin
Diffstat (limited to 'matlab')
-rw-r--r--matlab/mex/astra_mex_plugin_c.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/matlab/mex/astra_mex_plugin_c.cpp b/matlab/mex/astra_mex_plugin_c.cpp
index a279df8..4ed534e 100644
--- a/matlab/mex/astra_mex_plugin_c.cpp
+++ b/matlab/mex/astra_mex_plugin_c.cpp
@@ -42,6 +42,35 @@ $Id$
using namespace std;
using namespace astra;
+static void fixLapackLoading()
+{
+ // When running in Matlab, we need to force numpy
+ // to use its internal lapack library instead of
+ // Matlab's MKL library to avoid errors. To do this,
+ // we set Python's dlopen flags to RTLD_NOW|RTLD_DEEPBIND
+ // and import 'numpy.linalg.lapack_lite' here. We reset
+ // Python's dlopen flags afterwards.
+ PyObject *sys = PyImport_ImportModule("sys");
+ if (sys != NULL) {
+ PyObject *curFlags = PyObject_CallMethod(sys, "getdlopenflags", NULL);
+ if (curFlags != NULL) {
+ PyObject *retVal = PyObject_CallMethod(sys, "setdlopenflags", "i", 10); // RTLD_NOW|RTLD_DEEPBIND
+ if (retVal != NULL) {
+ PyObject *lapack = PyImport_ImportModule("numpy.linalg.lapack_lite");
+ if (lapack != NULL) {
+ Py_DECREF(lapack);
+ }
+ PyObject *retVal2 = PyObject_CallMethod(sys, "setdlopenflags", "O",curFlags);
+ if (retVal2 != NULL) {
+ Py_DECREF(retVal2);
+ }
+ Py_DECREF(retVal);
+ }
+ Py_DECREF(curFlags);
+ }
+ Py_DECREF(sys);
+ }
+}
//-----------------------------------------------------------------------------------------
/** astra_mex_plugin('init');
@@ -55,6 +84,10 @@ void astra_mex_plugin_init()
PyEval_InitThreads();
}
+#ifndef _MSC_VER
+ fixLapackLoading();
+#endif
+
// Importing astra may be overkill, since we only need to initialize
// PythonPluginAlgorithmFactory from astra.plugin_c.
PyObject *mod = PyImport_ImportModule("astra");