diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4ab2af..09f13b6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -301,6 +301,9 @@ endforeach()
#
# Setting native OMP to off
#
+# For some compilers this can be set off, but then compile time issues
+# emerge. Maybe is better to keep this OFF
+#
set( NATIVE_OMP_B OFF )
@@ -561,6 +564,7 @@ if(EXT_MODTEST)
add_target_exe_serial_wrapper(test_zgetrf test_tools)
add_target_exe_serial_wrapper(test_dgetrfi test_tools)
add_target_exe_serial_wrapper(test_zgetrfi test_tools)
+ add_target_exe_serial_wrapper(test_openmp_parallel test_tools)
add_target_exe_serial_wrapper(test_openmp_reduction_real test_tools)
add_target_exe_serial_wrapper(test_openmp_reduction_complex test_tools)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index e1ef950..77725f3 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -57,6 +57,15 @@ endmacro()
#
######################################################################
+macro(ADD_TARGET_LINK_FLAG)
+ foreach( TARGET IN LISTS EXECUTABLES_S_L
+ EXECUTABLES_P_L
+ LIBRARIES_S_L
+ LIBRARIES_P_L)
+ target_link_options( ${TARGET} PRIVATE ${ARGV0} )
+ endforeach()
+endmacro()
+
macro(SET_MODULE_PATH_DIRECTORY)
if( ${ARGV1} MATCHES "serial")
set_target_properties(${ARGV0} PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/serial_modules)
diff --git a/cmake/compilers/GNU/CMakeLists.txt b/cmake/compilers/GNU/CMakeLists.txt
index 66eb13b..a89ac0c 100644
--- a/cmake/compilers/GNU/CMakeLists.txt
+++ b/cmake/compilers/GNU/CMakeLists.txt
@@ -39,21 +39,22 @@ macro(SET_GNU_FORTRAN_COMPILER)
add_c_flag_if_avail( "-foffload-options=-lgfortran" )
add_c_flag_if_avail( "-foffload-options=-lm" )
add_c_flag_if_avail( "-foffload-options=-latomic" )
- foreach( TARGET IN LISTS EXECUTABLES_S_L
- EXECUTABLES_P_L
- LIBRARIES_S_L
- LIBRARIES_P_L)
- target_link_options( ${TARGET} PRIVATE "-fopenmp" )
- target_link_options( ${TARGET} PRIVATE "-foffload=nvptx-none" )
- target_link_options( ${TARGET} PRIVATE "-foffload-options=-lgfortran" )
- target_link_options( ${TARGET} PRIVATE "-foffload-options=-lm" )
- target_link_options( ${TARGET} PRIVATE "-foffload-options=-latomic" )
- if(CUDAToolkit_FOUND)
- target_link_libraries( ${TARGET} PUBLIC CUDA::cudart)
- target_link_libraries( ${TARGET} PUBLIC CUDA::cublas)
- target_link_libraries( ${TARGET} PUBLIC CUDA::cusolver)
- endif()
- endforeach()
+ add_target_link_flag( "-fopenmp" )
+ add_target_link_flag( "-foffload=nvptx-none" )
+ add_target_link_flag( "-foffload-options=-lgfortran" )
+ add_target_link_flag( "-foffload-options=-lm" )
+ add_target_link_flag( "-foffload-options=-latomic" )
+ if(CUDAToolkit_FOUND)
+ add_target_link_flag( CUDA::cudart )
+ add_target_link_flag( CUDA::cublas )
+ add_target_link_flag( CUDA::cusolver )
+ endif()
+ else()
+ if(OpenMP_FOUND)
+ add_fortran_flag_if_avail( "-fopenmp" )
+ add_c_flag_if_avail( "-fopenmp" )
+ add_target_link_flag( "-fopenmp" )
+ endif()
endif()
add_fortran_flag_if_avail( "-march=native" )
diff --git a/cmake/compilers/intel/CMakeLists.txt b/cmake/compilers/intel/CMakeLists.txt
index faca5ed..7569258 100644
--- a/cmake/compilers/intel/CMakeLists.txt
+++ b/cmake/compilers/intel/CMakeLists.txt
@@ -12,7 +12,12 @@ macro(SET_INTEL_FORTRAN_COMPILER)
set(PASIVE_F "-O1")
add_fortran_flag_if_avail( "-fpp" "Intel (Legacy) Fortran compiler does not supports c preprocessor" )
- add_fortran_flag_if_avail( "-qopenmp" )
+ if(OpenMP_FOUND)
+ add_fortran_flag_if_avail( "-qopenmp" )
+ add_c_flag_if_avail( "-qopenmp" )
+ add_target_link_flag( "-qopenmp" )
+ endif()
+
add_fortran_flag_if_avail( "-g" )
#message(${CMAKE_APPLE_SILICON_PROCESSOR})
diff --git a/cmake/compilers/oneapi/CMakeLists.txt b/cmake/compilers/oneapi/CMakeLists.txt
index b93e9a9..00e229a 100644
--- a/cmake/compilers/oneapi/CMakeLists.txt
+++ b/cmake/compilers/oneapi/CMakeLists.txt
@@ -16,6 +16,14 @@ macro(SET_ONEAPI_FORTRAN_COMPILER)
set(PASIVE_F "-O0")
endif()
+ add_fortran_flag_if_avail( "-g" )
+
+ if(OpenMP_FOUND)
+ add_fortran_flag_if_avail( "-qopenmp" )
+ add_c_flag_if_avail( "-qopenmp" )
+ add_target_link_flag( "-qopenmp" )
+ endif()
+
# Set optimization flags:
foreach( LIBRARY IN LISTS LIBRARIES_S_L
LIBRARIES_P_L
diff --git a/src/a_module_tests/CMakeLists.txt b/src/a_module_tests/CMakeLists.txt
index 79ce57f..af188d1 100644
--- a/src/a_module_tests/CMakeLists.txt
+++ b/src/a_module_tests/CMakeLists.txt
@@ -239,6 +239,15 @@ foreach( EXECUTABLE IN LISTS EXECUTABLES_S_L
)
endif()
+ if(${EXECUTABLE} STREQUAL test_openmp_parallel)
+ set_target_properties( ${EXECUTABLE} PROPERTIES SUFFIX ".x")
+
+ target_sources( ${EXECUTABLE}
+ PRIVATE
+ openmp_parallel.f90
+ )
+ endif()
+
if(${EXECUTABLE} STREQUAL test_openmp_reduction_real)
set_target_properties( ${EXECUTABLE} PROPERTIES SUFFIX ".x")
diff --git a/src/a_module_tests/openmp_parallel.f90 b/src/a_module_tests/openmp_parallel.f90
new file mode 100644
index 0000000..b8b6e70
--- /dev/null
+++ b/src/a_module_tests/openmp_parallel.f90
@@ -0,0 +1,37 @@
+! Copyright (C) 2022 TurboRVB group
+!
+! This program is free software: you can redistribute it and/or modify
+! it under the terms of the GNU General Public License as published by
+! the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! This program is distributed in the hope that it will be useful,
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+! GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License
+! along with this program. If not, see .
+
+program openmp_test
+
+ use omp_lib
+
+ integer :: num_threads
+
+ call omp_set_num_threads(2)
+ !$omp parallel
+ !$omp master
+ num_threads = omp_get_num_threads()
+ !$omp end master
+ !$omp end parallel
+
+ write (*,*) "Number of OMP threads:", num_threads
+
+ if (num_threads.ne.2) then
+ stop 1
+ end if
+
+ stop 0
+
+end program openmp_test
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index eee8aa6..42fd5c3 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -84,6 +84,7 @@ if(EXT_MODTEST)
endif()
+ add_subdirectory(test_openmp_parallel)
add_subdirectory(test_openmp_reduction)
add_subdirectory(test_zdotc_128)
diff --git a/test/test_openmp_parallel/CMakeLists.txt b/test/test_openmp_parallel/CMakeLists.txt
new file mode 100644
index 0000000..220a1d7
--- /dev/null
+++ b/test/test_openmp_parallel/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_test(
+ NAME "Test OpenMP"
+ COMMAND $
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )