#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void test_openmp()
{
FILE* log = fopen("log_openmp.txt","w");
fprintf(log, "I am working (openmp with %d threads)\n",
omp_get_max_threads());
fclose(log);
}
int main()
{
test_openmp();
return 1;
}
import os
from cffi import FFI
# 1. test that it works (i)
os.system('gcc -fopenmp test_openmp.c -o test_openmp.exe')
os.system('test_openmp.exe')
# 2. cffi
cmd = 'gcc -shared -fopenmp test_openmp.c -o test_openmp.so'
os.system(cmd)
ffi = FFI()
ffi.cdef(r''' void test_openmp(); ''')
cfuncs = ffi.dlopen("test_openmp.so")
cfuncs.test_openmp()
OSError Traceback (most recent call last)
<ipython-input-4-0b2f5b870168> in <module>()
8 ffi.cdef(r''' void test_openmp(); ''')
9
---> 10 cfuncs = ffi.dlopen("test_openmp.so")
11 cfuncs.test_openmp()
C:\Users\gmf123\AppData\Local\Continuum\Anaconda3\lib\site-packages\cffi\api.py in dlopen(self, name, flags)
137 assert isinstance(name, basestring) or name is None
138 with self._lock:
--> 139 lib, function_cache = _make_ffi_library(self, name, flags)
140 self._function_caches.append(function_cache)
141 self._libraries.append(lib)
C:\Users\gmf123\AppData\Local\Continuum\Anaconda3\lib\site-packages\cffi\api.py in _make_ffi_library(ffi, libname, flags)
767 import os
768 backend = ffi._backend
--> 769 backendlib = _load_backend_lib(backend, libname, flags)
770 #
771 def accessor_function(name):
C:\Users\gmf123\AppData\Local\Continuum\Anaconda3\lib\site-packages\cffi\api.py in _load_backend_lib(backend, name, flags)
756 if '.' not in name and '/' not in name:
757 raise OSError("library not found: %r" % (name,))
--> 758 return backend.load_library(name, flags)
759 except OSError:
760 import ctypes.util
OSError: cannot load library test_openmp.so: error 0x45a