CMAKE, MAKE: Add support for OpenMP.

Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
Grzegorz Kowal 2021-12-07 10:37:56 -03:00
parent e1fa68b54f
commit 2c336a4d74
4 changed files with 38 additions and 1 deletions

View File

@ -64,6 +64,16 @@ if(ENABLE_MPI)
endif() endif()
endif() endif()
option(ENABLE_OMP "Enable OpenMP support" ON)
if(ENABLE_OMP)
find_package(OpenMP COMPONENTS Fortran)
if(OpenMP_Fortran_FOUND)
include_directories(${OpenMP_Fortran_INCLUDE_DIRS})
target_compile_options(amun.x PRIVATE "${OpenMP_Fortran_FLAGS}")
target_link_libraries(amun.x ${OpenMP_Fortran_LIBRARIES})
endif()
endif()
option(ENABLE_SIGNALS "Enables signal handler support" ON) option(ENABLE_SIGNALS "Enables signal handler support" ON)
if(ENABLE_SIGNALS) if(ENABLE_SIGNALS)
target_compile_definitions(amun.x PRIVATE SIGNALS) target_compile_definitions(amun.x PRIVATE SIGNALS)

View File

@ -27,6 +27,9 @@ FFLAGS = -Og -g -DDEBUG -fcheck=all
else else
FFLAGS = -O2 -march=native -pipe FFLAGS = -O2 -march=native -pipe
endif endif
ifeq ($(OPENMP),Y)
FFLAGS += -fopenmp
endif
LDFLAGS = $(FFLAGS) LDFLAGS = $(FFLAGS)
ifeq ($(STATIC),Y) ifeq ($(STATIC),Y)
LDFLAGS += -static LDFLAGS += -static
@ -56,6 +59,9 @@ FFLAGS = -O0 -g -Mbounds -Mchkptr -Mcache_align -Mnovintr -Mchkstk -DDEBUG
else else
FFLAGS = -fast -O3 FFLAGS = -fast -O3
endif endif
ifeq ($(OPENMP),Y)
FFLAGS += -mp
endif
LDFLAGS = $(FFLAGS) LDFLAGS = $(FFLAGS)
ifeq ($(STATIC),Y) ifeq ($(STATIC),Y)
LDFLAGS += -Bstatic LDFLAGS += -Bstatic
@ -85,6 +91,9 @@ FFLAGS = -O -g -DDEBUG
else else
FFLAGS = -fast FFLAGS = -fast
endif endif
ifeq ($(OPENMP),Y)
FFLAGS += -mp
endif
LDFLAGS = $(FFLAGS) LDFLAGS = $(FFLAGS)
ifeq ($(STATIC),Y) ifeq ($(STATIC),Y)
LDFLAGS += -Bstatic LDFLAGS += -Bstatic
@ -114,6 +123,9 @@ FFLAGS = -O -g -DDEBUG
else else
FFLAGS = -O2 -xHost FFLAGS = -O2 -xHost
endif endif
ifeq ($(OPENMP),Y)
FFLAGS += -openmp
endif
LDFLAGS = $(FFLAGS) LDFLAGS = $(FFLAGS)
ifeq ($(STATIC),Y) ifeq ($(STATIC),Y)
LDFLAGS += -static LDFLAGS += -static

View File

@ -15,8 +15,10 @@ SIGNALS = N
# parallelization flags: # parallelization flags:
# #
# MPI - enable or disable MPI parallelization # MPI - enable or disable MPI parallelization
# OPENMP - enable or disable OpenMP parallelization
# #
MPI = N MPI = N
OPENMP = N
# output data format: # output data format:
# #

View File

@ -65,6 +65,11 @@ program amun
integer :: iin, iev, itm integer :: iin, iev, itm
integer :: ed, eh, em, es integer :: ed, eh, em, es
! OpenMP
!
integer :: nthreads = 1
!$ integer :: omp_get_num_threads
! the format string ! the format string
! !
character(len=80) :: sfmt character(len=80) :: sfmt
@ -131,8 +136,16 @@ program amun
call print_welcome(verbose) call print_welcome(verbose)
#ifdef MPI #ifdef MPI
call print_section(verbose, "Parallelization") call print_section(verbose, "Parallelization")
call print_parameter(verbose, "MPI processes", nprocs) call print_parameter(verbose, "MPI processes" , nprocs)
#else /* MPI */
!$ call print_section(verbose, "Parallelization")
#endif /* MPI */ #endif /* MPI */
!$omp parallel
!$omp master
!$ nthreads = omp_get_num_threads()
!$ call print_parameter(verbose, "OpenMP threads", nthreads)
!$omp end master
!$omp end parallel
! read parameters ! read parameters
! !