Skip to content

Commit ce3b4cd

Browse files
committed
Fix python unit tests
1 parent 4f648fd commit ce3b4cd

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ if (BUILD_PYTHON)
365365
COMMENT "Copying raffle python files"
366366
)
367367

368+
# If parallel build, need to add the parallel flag
369+
if (CMAKE_BUILD_TYPE MATCHES "Release*" OR CMAKE_BUILD_TYPE MATCHES "Parallel*" OR CMAKE_BUILD_TYPE MATCHES "Debug")
370+
set(GOMPFLAGS "-lgomp")
371+
else()
372+
set(GOMPFLAGS "")
373+
endif()
374+
368375
# Create a Python module using f2py
369376
add_custom_command(
370377
OUTPUT ${F2PY_OUTPUT_FILE}
@@ -373,6 +380,7 @@ if (BUILD_PYTHON)
373380
-m _${PROJECT_NAME}
374381
-I${MODULE_DIR}
375382
--f90flags="${PPFLAGS}"
383+
${GOMPFLAGS}
376384
--backend meson
377385
${F90WRAP_FILE}
378386
-L${CMAKE_BUILD_DIR}

test/test_raffle.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,36 @@
3030
print(line)
3131
test_name = line.split()[0]
3232
test_names.append(test_name)
33+
print("Test names: ", test_names)
34+
35+
def uses_openmp(lib_path):
36+
try:
37+
out = subprocess.check_output(["nm", "-g", lib_path], text=True)
38+
return "_GOMP_parallel" in out
39+
except Exception:
40+
return False
3341

3442
def build_fortran_test(test_name):
3543
os.makedirs(temp_test_dir, exist_ok=True)
3644
# make using a fortran compiler
3745
# point to raffle's pip install include and lib to include during compilation
3846

39-
build_result = subprocess.run(
40-
[
47+
if uses_openmp(os.path.join(lib_dir, "libraffle.dylib")):
48+
compile_args = ["-fopenmp", "-lgomp"]
49+
else:
50+
compile_args = []
51+
52+
compile_list = [
4153
fc, "-o", test_name+".o",
4254
"../../test/test_io_utils.f90",
55+
" ".join(compile_args),
4356
"-I", include_dir,
4457
"-I", etc_dir,
4558
"-L", lib_dir,
4659
"-lraffle"
47-
],
60+
]
61+
build_result = subprocess.run(
62+
compile_list,
4863
cwd=temp_test_dir
4964
)
5065
return build_result
@@ -271,4 +286,4 @@ def test_fortran(self, test_name):
271286
self.assertEqual(run_result.returncode, 0)
272287

273288
if __name__ == '__main__':
274-
unittest.main()
289+
unittest.main()

0 commit comments

Comments
 (0)