Programatically testing for openmp support from a python setup script -


i'm working on python project uses cython , c speed time sensitive operations. in few of our cython routines, use openmp further speed operation if idle cores available.

this leads bit of annoying situation on os x since default compiler recent os versions (llvm/clang on 10.7 , 10.8) doesn't support openmp. our stopgap solution tell people set gcc compiler when build. we'd programmatically since clang can build else no issues.

right now, compilation fail following error:

clang: error: linker command failed exit code 1 (use -v see invocation) error: command "cc -bundle -undefined dynamic_lookup -l/usr/local/lib -l/usr/local/opt/sqlite/lib build/temp.macosx-10.8-x86_64-2.7/yt/utilities/lib/geometry_utils.o -lm -o yt/utilities/lib/geometry_utils.so -fopenmp" failed exit status 1 

the relevant portion of our setup script looks this:

config.add_extension("geometry_utils",          ["yt/utilities/lib/geometry_utils.pyx"],          extra_compile_args=['-fopenmp'],          extra_link_args=['-fopenmp'],          libraries=["m"], depends=["yt/utilities/lib/fp_utils.pxd"]) 

the full setup.py file here.

is there way programmatically test openmp support inside setup script?

i able working checking see if test program compiles:

import os, tempfile, subprocess, shutil      # see http://openmp.org/wp/openmp-compilers/ omp_test = \ r""" #include <omp.h> #include <stdio.h> int main() { #pragma omp parallel printf("hello thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads()); } """  def check_for_openmp():     tmpdir = tempfile.mkdtemp()     curdir = os.getcwd()     os.chdir(tmpdir)      filename = r'test.c'     open(filename, 'w', 0) file:         file.write(omp_test)     open(os.devnull, 'w') fnull:         result = subprocess.call(['cc', '-fopenmp', filename],                                  stdout=fnull, stderr=fnull)      os.chdir(curdir)     #clean     shutil.rmtree(tmpdir)      return result 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -