MCPcopy Create free account
hub / github.com/PythonOT/POT / check_openmp_support

Function check_openmp_support

ot/helpers/openmp_helpers.py:40–85  ·  view source on GitHub ↗

Check whether OpenMP test code can be compiled and run

()

Source from the content-addressed store, hash-verified

38
39
40def check_openmp_support():
41 """Check whether OpenMP test code can be compiled and run"""
42
43 code = textwrap.dedent(
44 """\
45 #include <omp.h>
46 #include <stdio.h>
47 int main(void) {
48 #pragma omp parallel
49 printf("nthreads=%d\\n", omp_get_num_threads());
50 return 0;
51 }
52 """
53 )
54
55 extra_preargs = os.getenv("LDFLAGS", None)
56 if extra_preargs is not None:
57 extra_preargs = extra_preargs.strip().split(" ")
58 extra_preargs = [
59 flag
60 for flag in extra_preargs
61 if flag.startswith(("-L", "-Wl,-rpath", "-l"))
62 ]
63
64 extra_postargs = get_openmp_flag
65
66 try:
67 output, compile_flags = compile_test_program(
68 code, extra_preargs=extra_preargs, extra_postargs=extra_postargs
69 )
70
71 if output and "nthreads=" in output[0]:
72 nthreads = int(output[0].strip().split("=")[1])
73 openmp_supported = len(output) == nthreads
74 elif "PYTHON_CROSSENV" in os.environ:
75 # Since we can't run the test program when cross-compiling
76 # assume that openmp is supported if the program can be
77 # compiled.
78 openmp_supported = True
79 else:
80 openmp_supported = False
81
82 except (CompileError, LinkError, subprocess.CalledProcessError):
83 openmp_supported = False
84 compile_flags = []
85 return openmp_supported, compile_flags

Callers 2

setup.pyFile · 0.90
test_helpersFunction · 0.90

Calls 1

compile_test_programFunction · 0.90

Tested by 1

test_helpersFunction · 0.72