Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Added mkl library to cmake files and also added ability to compile wi…
Browse files Browse the repository at this point in the history
…th coarrays enabled
  • Loading branch information
daminton committed Nov 28, 2022
1 parent 2bcff51 commit e3c03e6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)

# Set some options the user may choose
# Uncomment the below if you want the user to choose a parallelization library
OPTION(USE_MPI "Use the MPI library for parallelization" OFF)
OPTION(USE_MPI "Use the MPI library for parallelization" ON)
OPTION(USE_OPENMP "Use OpenMP for parallelization" ON)

# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, and TESTING. You should review this file and make sure the flags
# are to your liking.
INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake)

# Locate and set parallelization libraries. There are some CMake peculiarities
# taken care of here, such as the fact that the FindOpenMP routine doesn't know
# about Fortran.
INCLUDE(${CMAKE_MODULE_PATH}/SetParallelizationLibrary.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/SetUpNetCDF.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/SetMKL.cmake)

# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, PROFILING, and TESTING.
INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake)


# There is an error in CMAKE with this flag for pgf90. Unset it
GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME)
Expand Down
17 changes: 17 additions & 0 deletions cmake/Modules/FindMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# Swiftest 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.
# Swiftest 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 Swiftest.
# If not, see: https://www.gnu.org/licenses.

# - Finds the Intel MKL libraries
find_path(MKL_INCLUDE_DIR NAMES mkl.h HINTS ENV MKLROOT PATH_SUFFIXES include)
find_library(MKL_LIBRARY NAMES libmkl_core.a HINTS ENV MKLROOT PATH_SUFFIXES lib lib/intel64 )

set(MKL_FOUND TRUE)
set(MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR})
set(MKL_LIBRARIES ${MKL_LIBRARY})
mark_as_advanced(MKL_LIBRARY MKL_INCLUDE_DIR)
6 changes: 3 additions & 3 deletions cmake/Modules/FindOpenMP_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ INCLUDE (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)

SET (OpenMP_Fortran_FLAG_CANDIDATES
#Intel
"-qopenmp"
"-qopenmp -coarray"
#Intel windows
"/Qopenmp"
"/Qopenmp /Qcoarray"
#Gnu
"-fopenmp"
"-fopenmp -fcoarray=lib"
#Portland Group
"-mp"
#Empty, if compiler automatically accepts openmp
Expand Down
10 changes: 8 additions & 2 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_TESTING}"

# Unroll loops
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-funroll-loops" # GNU
"-unroll" # Intel
Fortran "-unroll" # Intel
"/unroll" # Intel Windows
"-funroll-loops" # GNU
"-Munroll" # Portland Group
)

Expand Down Expand Up @@ -288,6 +288,12 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-fma" # Intel
)

# Generate fused multiply-add instructions
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-qmkl=cluster" # Intel
Fortran "-qmkl" # Intel
Fortran "-mkl" # Old Intel
)

#####################
### MATH FLAGS ###
Expand Down
14 changes: 14 additions & 0 deletions cmake/Modules/SetMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# Swiftest 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.
# Swiftest 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 Swiftest.
# If not, see: https://www.gnu.org/licenses.

# Find MKL if not already found
IF(NOT MKL_FOUND)
ENABLE_LANGUAGE(C) # Some libraries need a C compiler to find
FIND_PACKAGE(MKL REQUIRED)
ENDIF(NOT MKL_FOUND)
22 changes: 8 additions & 14 deletions cmake/Modules/SetParallelizationLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# When one is turned on, the other is turned off
# If both are off, we explicitly disable them just in case

IF (USE_OPENMP AND USE_MPI)
MESSAGE (FATAL_ERROR "Cannot use both OpenMP and MPI")
ELSEIF (USE_OPENMP)
IF (USE_OPENMP)
# Find OpenMP
IF (NOT OpenMP_Fortran_FLAGS)
FIND_PACKAGE (OpenMP_Fortran)
Expand All @@ -23,20 +21,16 @@ ELSEIF (USE_OPENMP)
ENDIF (NOT OpenMP_Fortran_FLAGS)
ENDIF (NOT OpenMP_Fortran_FLAGS)
# Turn of MPI
UNSET (MPI_FOUND CACHE)
UNSET (MPI_COMPILER CACHE)
UNSET (MPI_LIBRARY CACHE)
ELSEIF (USE_MPI)
ENDIF (USE_OPENMP)

IF (USE_MPI)
# Find MPI
IF (NOT MPI_Fortran_FOUND)
FIND_PACKAGE (MPI REQUIRED)
ENDIF (NOT MPI_Fortran_FOUND)
# Turn off OpenMP
SET (OMP_NUM_PROCS 0 CACHE
STRING "Number of processors OpenMP may use" FORCE)
UNSET (OpenMP_C_FLAGS CACHE)
UNSET (GOMP_Fortran_LINK_FLAGS CACHE)
ELSE ()
ENDIF (USE_MPI)

IF (NOT USE_OPENMP AND NOT USE_MPI)
# Turn off both OpenMP and MPI
SET (OMP_NUM_PROCS 0 CACHE
STRING "Number of processors OpenMP may use" FORCE)
Expand All @@ -45,4 +39,4 @@ ELSE ()
UNSET (MPI_FOUND CACHE)
UNSET (MPI_COMPILER CACHE)
UNSET (MPI_LIBRARY CACHE)
ENDIF (USE_OPENMP AND USE_MPI)
ENDIF (NOT USE_OPENMP AND NOT USE_MPI)

0 comments on commit e3c03e6

Please sign in to comment.