Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openmp #42

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 16 additions & 15 deletions cmake/compilers/GNU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down
7 changes: 6 additions & 1 deletion cmake/compilers/intel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
8 changes: 8 additions & 0 deletions cmake/compilers/oneapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/a_module_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
37 changes: 37 additions & 0 deletions src/a_module_tests/openmp_parallel.f90
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ if(EXT_MODTEST)

endif()

add_subdirectory(test_openmp_parallel)
add_subdirectory(test_openmp_reduction)

add_subdirectory(test_zdotc_128)
Expand Down
5 changes: 5 additions & 0 deletions test/test_openmp_parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_test(
NAME "Test OpenMP"
COMMAND $<TARGET_FILE:test_openmp_parallel>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)