File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,15 @@ else()
5252 endif ()
5353endif ()
5454
55+ # Use OpenMP if it can be found.
56+ find_package (OpenMP COMPONENTS CXX NO_POLICY_SCOPE )
57+ add_library (qsim_openmp_config INTERFACE )
58+ if (OpenMP_CXX_FOUND)
59+ target_link_libraries (qsim_openmp_config INTERFACE OpenMP::OpenMP_CXX )
60+ else ()
61+ message (STATUS "${MSG_PREFIX} cannot use thread parallelization" )
62+ endif ()
63+
5564# Add optimization flags to any configuration that is NOT Debug. Note: CMake
5665# will automatically use the appropriate debug flags (e.g., /Od and /Zi for
5766# MSVC, or -O0 -g for GCC/Clang), so there's no need to do that part.
6170 add_compile_options ($<$<NOT :$<CONFIG :Debug >>:-O3 >)
6271endif ()
6372
64- find_package (OpenMP REQUIRED )
65-
6673# Always build the basic part.
6774add_subdirectory (pybind_interface/basic )
6875add_subdirectory (pybind_interface/decide )
@@ -90,5 +97,4 @@ set(CMAKE_CXX_STANDARD 17)
9097set (CMAKE_POSITION_INDEPENDENT_CODE ON )
9198
9299# Print additional useful info.
93- message (STATUS "${MSG_PREFIX} OpenMP found = ${OPENMP_FOUND} " )
94100message (STATUS "${MSG_PREFIX} shell $PATH = $ENV{PATH} " )
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ CXX ?= g++
3838NVCC ?= nvcc
3939HIPCC ?= hipcc
4040
41- BASE_CXXFLAGS := -std=c++17 -fopenmp
41+ BASE_CXXFLAGS := -std=c++17
4242BASE_NVCCFLAGS := -std c++17 -Wno-deprecated-gpu-targets
4343BASE_HIPCCFLAGS :=
4444
@@ -49,7 +49,15 @@ HIPCCFLAGS := $(BASE_HIPCCFLAGS) $(HIPCCFLAGS)
4949LTO_FLAGS := -flto=auto
5050USING_CLANG := $(shell $(CXX ) --version | grep -isq clang && echo "true")
5151ifeq ($(USING_CLANG ) ,"true")
52- LTO_FLAGS := -flto
52+ LTO_FLAGS := -flto
53+ endif
54+
55+ # Test if OpenMP header files are available and we can link with the library.
56+ OMP_CHECK_CMD := echo "int main() { return 0; }" | \
57+ $(CXX ) -fopenmp -x c++ - -o /dev/null 2>/dev/null
58+ HAVE_OPENMP := $(shell $(OMP_CHECK_CMD ) && echo "true")
59+ ifeq ($(HAVE_OPENMP ) ,true)
60+ OPENMP_FLAGS := -fopenmp
5361endif
5462
5563ifdef DEBUG
@@ -58,7 +66,7 @@ ifdef DEBUG
5866 NVCCFLAGS += $(DEBUG_FLAGS )
5967 HIPCCFLAGS += $(DEBUG_FLAGS )
6068else
61- CXXFLAGS += -O3 $(LTO_FLAGS )
69+ CXXFLAGS += -O3 $(OPENMP_FLAGS ) $( LTO_FLAGS )
6270 NVCCFLAGS += -O3
6371 HIPCCFLAGS += -O3
6472endif
Original file line number Diff line number Diff line change @@ -46,4 +46,4 @@ endif()
4646include (../GetPybind11.cmake )
4747pybind11_add_module (qsim_avx2 pybind_main_avx2.cpp )
4848
49- target_link_libraries (qsim_avx2 PUBLIC OpenMP::OpenMP_CXX )
49+ target_link_libraries (qsim_avx2 PRIVATE qsim_openmp_config )
Original file line number Diff line number Diff line change @@ -39,4 +39,4 @@ endif()
3939include (../GetPybind11.cmake )
4040pybind11_add_module (qsim_avx512 pybind_main_avx512.cpp )
4141
42- target_link_libraries (qsim_avx512 PUBLIC OpenMP::OpenMP_CXX )
42+ target_link_libraries (qsim_avx512 PRIVATE qsim_openmp_config )
Original file line number Diff line number Diff line change @@ -39,4 +39,4 @@ endif()
3939include (../GetPybind11.cmake )
4040pybind11_add_module (qsim_basic pybind_main_basic.cpp )
4141
42- target_link_libraries (qsim_basic PUBLIC OpenMP::OpenMP_CXX )
42+ target_link_libraries (qsim_basic PRIVATE qsim_openmp_config )
Original file line number Diff line number Diff line change @@ -57,4 +57,4 @@ set_target_properties(qsim_cuda PROPERTIES
5757)
5858set_source_files_properties (pybind_main_cuda.cpp PROPERTIES LANGUAGE CUDA )
5959
60- target_link_libraries (qsim_cuda OpenMP::OpenMP_CXX )
60+ target_link_libraries (qsim_cuda PRIVATE qsim_openmp_config )
Original file line number Diff line number Diff line change @@ -53,4 +53,4 @@ set_target_properties(qsim_custatevec PROPERTIES
5353)
5454set_source_files_properties (pybind_main_custatevec.cpp PROPERTIES LANGUAGE CUDA )
5555
56- target_link_libraries (qsim_custatevec OpenMP::OpenMP_CXX )
56+ target_link_libraries (qsim_custatevec PRIVATE qsim_openmp_config )
Original file line number Diff line number Diff line change @@ -53,4 +53,4 @@ set_target_properties(qsim_custatevecex PROPERTIES
5353)
5454set_source_files_properties (pybind_main_custatevecex.cpp PROPERTIES LANGUAGE CUDA )
5555
56- target_link_libraries (qsim_custatevecex OpenMP::OpenMP_CXX )
56+ target_link_libraries (qsim_custatevecex PRIVATE qsim_openmp_config )
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ if(CMAKE_CUDA_COMPILER)
6161 SUFFIX "${PYTHON_MODULE_EXTENSION} "
6262 )
6363 set_source_files_properties (decide.cpp PROPERTIES LANGUAGE CUDA )
64- target_link_libraries ( qsim_decide OpenMP::OpenMP_CXX )
64+
6565elseif (has_hipcc)
6666 list (APPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake/hip" )
6767 find_package (HIP REQUIRED )
@@ -73,8 +73,9 @@ elseif(has_hipcc)
7373 PREFIX "${PYTHON_MODULE_PREFIX} "
7474 SUFFIX "${PYTHON_MODULE_EXTENSION} "
7575 )
76- target_link_libraries ( qsim_decide PUBLIC OpenMP::OpenMP_CXX )
76+
7777else ()
7878 pybind11_add_module (qsim_decide decide.cpp )
79- target_link_libraries (qsim_decide PUBLIC OpenMP::OpenMP_CXX )
8079endif ()
80+
81+ target_link_libraries (qsim_decide PRIVATE qsim_openmp_config )
Original file line number Diff line number Diff line change @@ -37,4 +37,4 @@ set_target_properties(qsim_hip PROPERTIES
3737)
3838set_source_files_properties (pybind_main_hip.cpp PROPERTIES LANGUAGE HIP )
3939
40- target_link_libraries (qsim_hip PUBLIC OpenMP::OpenMP_CXX )
40+ target_link_libraries (qsim_hip PRIVATE qsim_openmp_config )
You can’t perform that action at this time.
0 commit comments