56 # if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__ 57 # define thread_local _Thread_local 58 # elif defined _WIN32 && ( \ 62 defined __BORLANDC__ ) 63 # define thread_local __declspec(thread) 65 # elif defined __GNUC__ || \ 66 defined __SUNPRO_C || \ 68 # define thread_local __thread 70 # error "Cannot define thread_local" 76 thread_local
int modena_error_code = 0;
78 PyObject *modena_DoesNotExist = NULL;
79 PyObject *modena_OutOfBounds = NULL;
80 PyObject *modena_ParametersNotValid = NULL;
88 { MODENA_SUCCESS,
"No error" },
89 { MODENA_MODEL_NOT_FOUND,
"Surrogate model not found in database" },
90 { MODENA_FUNCTION_NOT_FOUND,
"Surrogate function not found in database" },
91 { MODENA_INDEX_SET_NOT_FOUND,
"Index set not found in database" }
94 const char* modena_error_message(
int error_code)
99 static PyMethodDef module_methods[] = {
103 #ifndef PyMODINIT_FUNC 104 #define PyMODINIT_FUNC void 108 PyMODINIT_FUNC initlibmodena(
void) __attribute__((constructor));
110 PyMODINIT_FUNC initlibmodena(
void)
113 if(!Py_IsInitialized())
118 if(PyType_Ready(&modena_index_set_tType) < 0)
123 if(PyType_Ready(&modena_function_tType) < 0)
128 if(PyType_Ready(&modena_model_tType) < 0)
133 PyObject* module = Py_InitModule3
137 "Module that creates extension types for modena framework." 145 if(!modena_DoesNotExist)
147 Py_INCREF(&modena_index_set_tType);
151 "modena_index_set_t",
152 (PyObject *) &modena_index_set_tType
155 Py_INCREF(&modena_function_tType);
160 (PyObject *) &modena_function_tType
163 Py_INCREF(&modena_model_tType);
168 (PyObject *) &modena_model_tType
171 PyObject *pName = PyString_FromString(
"modena.SurrogateModel");
172 if(!pName){ Modena_PyErr_Print(); }
174 PyObject *pModule = PyImport_Import(pName);
176 if(!pModule){ Modena_PyErr_Print(); }
178 PyObject *pDict = PyModule_GetDict(pModule);
179 if(!pDict){ Modena_PyErr_Print(); }
182 pName = PyString_FromString(
"IndexSet");
183 if(!pName){ Modena_PyErr_Print(); }
185 modena_IndexSet = PyObject_GetItem(pDict, pName);
187 if(!modena_IndexSet){ Modena_PyErr_Print(); }
189 pName = PyString_FromString(
"SurrogateFunction");
190 if(!pName){ Modena_PyErr_Print(); }
192 modena_SurrogateFunction = PyObject_GetItem(pDict, pName);
194 if(!modena_SurrogateFunction){ Modena_PyErr_Print(); }
196 pName = PyString_FromString(
"SurrogateModel");
197 if(!pName){ Modena_PyErr_Print(); }
199 modena_SurrogateModel = PyObject_GetItem(pDict, pName);
201 if(!modena_SurrogateModel){ Modena_PyErr_Print(); }
204 pName = PyString_FromString(
"DoesNotExist");
205 if(!pName){ Modena_PyErr_Print(); }
207 modena_DoesNotExist = PyObject_GetItem(pDict, pName);
209 if(!modena_DoesNotExist){ Modena_PyErr_Print(); }
211 pName = PyString_FromString(
"ParametersNotValid");
212 if(!pName){ Modena_PyErr_Print(); }
214 modena_ParametersNotValid = PyObject_GetItem(pDict, pName);
216 if(!modena_ParametersNotValid){ Modena_PyErr_Print(); }
218 pName = PyString_FromString(
"OutOfBounds");
219 if(!pName){ Modena_PyErr_Print(); }
221 modena_OutOfBounds = PyObject_GetItem(pDict, pName);
223 if(!modena_OutOfBounds){ Modena_PyErr_Print(); }
231 void modena_print_backtrace()
233 void* tracePtrs[100];
234 int count = backtrace( tracePtrs, 100 );
236 char** funcNames = backtrace_symbols( tracePtrs, count );
239 for( ii = 0; ii < count; ii++ )
240 printf(
"%s\n", funcNames[ii] );