Quantcast
Channel: Intel® Software - Intel® Many Integrated Core Architecture (Intel MIC Architecture)
Viewing all articles
Browse latest Browse all 1789

Calling C Code (Uses OpenMP) from Python

$
0
0

Hello all,

I'm a high school student working on running some Python code. It's a huge computational task so we actually have to run it on the Stampede super computer to make sure it completes in time. We will be taking advantage of the MIC Architecture there. My major problem is the following: because it takes so long to do there, we were thinking to port some of the Python over to C in order to take advantage of OpenMP parallelization. Somebody has successfully done this using Fortran already but I am doing this in C because we think there is better support for C for some of the stuff we are doing at Stampede. I am having a lot of trouble linking together the C code and the Python stuff. I have been working on just basics so far in order to get an idea of it. I am uploading all my files (it won't accept a .py file so I'm just attaching source in .txt instead.) and will include my command line building options later on in this post.

I am using ctypes to import the shared object file and then get the functions out of there. The error message I'm getting when trying to execute sayhello() from Python is:

Traceback (most recent call last):
File "calltestpython.py", line 3, in <module>
lib = cdll.LoadLibrary('./libtest.so')
File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./libtest.so: undefined symbol: __kmpc_end_serialized_parallel

I'm guessing that this is being introduced simply by using the OpenMP stuff since commenting out sayhello and then running everything else works no problem. Can somebody give me some guidance as to how to avoid this error?

The commands I use to compile are the following:

icc -fPIC -openmp --vec-report=3 -O3 -c test.c -o test.o

icc -shared -lc -o libtest.so test.o

If somebody could also give me guidance as to what these flags are actually doing, that would also be wonderful.

Thank you in advance for all the support!!

AttachmentSize
Downloadtest.c438 bytes
Downloadpythonsource.txt439 bytes

Viewing all articles
Browse latest Browse all 1789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>