Hi,


I am trying to call C code from Julia.It works for 'regular' C code but now 
I have code that (potentially) uses OpenMP which causes trouble. I am 
trying to interpolate a function using a spline approximation. In short, if 
I type:

gcc -shared -O3 nspline_omp.c -o libcspline.dll -ffast-math


and then call one of the functions in the library from Julia using ccall, 
it works. But judging from the speed and comparison with other languages, 
only 1 thread is used. The code certainly supports multi-threading, for a 
my friend of mine on his Mac, it worked. If I type:

gcc -shared -O3 nspline_omp.c -o libcspline2.dll -ffast-math -fopenmp 

iand try to call it from Julia, it doesn't work anymore, in particular:

LoadError: error compiling spline: could not load library "libcspline2.dll" 
The specified module could not be found.


Libdl.dlopen("libcspline2.dll")

gives the same error. As an example, consider:

#include<omp.h>

int banana(int hello) {
 int nt;
#pragma omp parallel
{
 nt = omp_get_num_threads();
}
 return nt;
}


#include <stdio.h>
int main() { printf("%d\n", banana(12)); }


which perfectly works when compiled as .exe (gcc helloworld.c -fopenmp). When I 
try to compile 

#include <stdlib.h>
#include <omp.h>

int banana(int hello) {
 int nt;
#pragma omp parallel
 {
 nt = omp_get_num_threads();
 }
 return nt;
}

as a shared library using

gcc -shared -O3 helloworld2.c -o libcpsline3.dll -ffast-math -fopenmp

and then in Julia:

Libdl.dlopen("libcspline3.dll")
LoadError: could not load library "libcspline3.dll" 
The specified module could not be found.


Finally, I am new to Julia and C and basically I have not much of an idea what 
I am doing, so it could be an obvious mistake. Thanks for your help. 



Reply via email to