HeLo Posted September 16, 2020 Report Share Posted September 16, 2020 As the faddeeva function is not available in LabVIEW, I have compiled the code of Steven G. Johnson into a DLL using the GCC compiler in Code::Blocks - and it works (the same code is used also in SciPy, Matlab and others). In order to improve in speed, I would like to run the function in a for-loop "enabling loop parallelism" or have it called by multiple clones of a reentrant "Faddeeva.vi". However calling the function that way produces erroneous results - it looks like there is some interference between the different calls. As native LabVIEW functions like "Integral x(t).vi" can do exactly this and as these functions also call a dll, I must have some statements in my dll that are not thread save. Can anybody point me to the mistake, that prevents a correct multi threaded call? Herbert P.S.: Please find below a part of the c-file attached #include <math.h> #include <windows.h> /* The Faddeeva.cc file contains macros to let it compile as C code (assuming C99 complex-number support), so just #include it. */ #include "Faddeeva.cc" BOOL WINAPI DllMain (HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ , LPVOID reserved /* Not used. */ ) { switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } /* Returns TRUE on success, FALSE on failure */ return TRUE; } /* LabVIEW created typedefs */ #pragma pack (1) typedef struct { long dimSize; double elt[1]; } TD1; typedef TD1 **dArr; double *Re_zArr, *Im_zArr, *RelErr_Arr, *Re_wArr, *Im_wArr; double complex z, w; int Npts; int i; _declspec(dllexport) void FaddeevaW(dArr x, dArr y, dArr RelErr, dArr Re_w, dArr Im_w); _declspec(dllexport) void FaddeevaW(dArr x, dArr y, dArr RelErr, dArr Re_w, dArr Im_w) { Npts = (*x)->dimSize; Re_zArr = & (*x)->elt[0]; Im_zArr = & (*y)->elt[0]; RelErr_Arr = & (*RelErr)->elt[0]; Re_wArr = & (*Re_w)->elt[0]; Im_wArr = & (*Im_w)->elt[0]; for (i=0; i<Npts; i++) { w = Faddeeva_w((*Re_zArr + *Im_zArr*I), *RelErr_Arr); *Re_wArr = creal(w); *Im_wArr = cimag(w); Re_zArr++; Im_zArr++; RelErr_Arr++; Re_wArr++; Im_wArr++; } } Faddeeva.c Faddeeva.cc Faddeeva.h Quote Link to comment
mhenz Posted September 17, 2020 Report Share Posted September 17, 2020 You created a couple of global variables. This is not thread save. double *Re_zArr, *Im_zArr, *RelErr_Arr, *Re_wArr, *Im_wArr; double complex z, w; int Npts; int i; 1 Quote Link to comment
HeLo Posted September 17, 2020 Author Report Share Posted September 17, 2020 Hi mhenz, thank you very much!!!! I corrected this and - it works 😃. For all, who maybe have a need for it, I attach the corrected code (only the file "Faddeeva.c" was changed). Herbert Faddeeva.zip Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.