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

Commit

Permalink
Reorganized testing and made the compiler-option finding much more ro…
Browse files Browse the repository at this point in the history
…bust and efficient by getting the compiler id first instead of trying every possible flag.
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 1, 2023
1 parent 05a00cb commit bd1fb58
Show file tree
Hide file tree
Showing 10 changed files with 647 additions and 325 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dump*
!examples/**
*ipynb_checkpoints
**/.DS_Store
!test/test_suite.py
!python/swiftest/tests/test_suite.py

#Documentation
!docs/*
Expand Down
30 changes: 19 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ PROJECT(Swiftest Fortran)
# Set the Swiftest version
SET(VERSION 1.0.0)

INCLUDE(CTest)

# Add our local modlues to the module path
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

Expand All @@ -27,29 +29,32 @@ IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)


IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
ELSEIF (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
SET(COMPILER_OPTIONS "GNU" CACHE STRING "Compiler identified as gfortran")
ELSE ()
MESSAGE(FATAL_ERROR "Compiler not recognized!")
ENDIF ()

# Set some options the user may choose
OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF)
OPTION(USE_OPENMP "Use OpenMP for parallelization" ON)
OPTION(USE_SIMD "Use SIMD vectorization" ON)
OPTION(CONTAINERIZE "Compiling for use in a Docker/Singularity container" OFF)
OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON)

INCLUDE(${CMAKE_MODULE_PATH}/SetParallelizationLibrary.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/SetUpNetCDF.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/SetMKL.cmake)
IF (COMPILER_OPTIONS STREQUAL "Intel")
INCLUDE(${CMAKE_MODULE_PATH}/SetMKL.cmake)
ENDIF ()

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

INCLUDE_DIRECTORIES($ENV{NETCDF_FORTRAN_HOME}/include;$ENV{NETCDF_HOME}/include)

# There is an error in CMAKE with this flag for pgf90. Unset it
GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME)
IF(FCNAME STREQUAL "pgf90")
UNSET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
ENDIF(FCNAME STREQUAL "pgf90")

############################################################
# Define the actual files and folders that make up the build
############################################################
Expand All @@ -62,16 +67,19 @@ SET(SRC ${CMAKE_SOURCE_DIR}/src)
SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(BIN ${CMAKE_SOURCE_DIR}/bin)
SET(MOD ${CMAKE_SOURCE_DIR}/include)
SET(TEST ${CMAKE_SOURCE_DIR}/test)

# Have the .mod files placed in the lib folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})

# The source for the SWIFTEST binary and have it placed in the bin folder
ADD_SUBDIRECTORY(${SRC} ${BIN})

# Set up test directory
ENABLE_TESTING()
ADD_SUBDIRECTORY(${TEST})

# Add a distclean target to the Makefile
ADD_CUSTOM_TARGET(distclean
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/distclean.cmake
)


51 changes: 32 additions & 19 deletions cmake/Modules/FindCoarray_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,40 @@ INCLUDE (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)

STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
IF(BT STREQUAL "DEBUG")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Intel
"-coarray=single"
#Intel windows
"/Qcoarray:single"
#Gnu
"-fcoarray=single"
#Empty, if compiler automatically accepts coarray
" "
IF (COMPILER_OPTIONS STREQUAL "Intel")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Intel
"-coarray=single"
#Intel windows
"/Qcoarray:single"
#Empty, if compiler automatically accepts coarray
" "
)
ELSEIF (COMPILER_OPTIONS STREQUAL "GNU")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Gnu
"-fcoarray=single"
#Empty, if compiler automatically accepts coarray
" "
)
ENDIF()
ELSE()
SET (Coarray_Fortran_FLAG_CANDIDATES
#Intel
"-coarray=distributed"
#Intel windows
"/Qcoarray:distributed"
#Gnu
"-fcoarray=lib -lcaf_mpi"
#Empty, if compiler automatically accepts coarray
" "
)
IF (COMPILER_OPTIONS STREQUAL "Intel")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Intel
"-coarray=distributed"
#Intel windows
"/Qcoarray:distributed"
#Empty, if compiler automatically accepts coarray
" "
)
ELSEIF (COMPILER_OPTIONS STREQUAL "GNU")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Gnu
"-fcoarray=lib -lcaf_mpi"
#Empty, if compiler automatically accepts coarray
" "
)
ENDIF()


Expand Down
37 changes: 24 additions & 13 deletions cmake/Modules/FindOpenMP_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,30 @@

INCLUDE (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)

IF (USE_SIMD)
SET (OpenMP_Fortran_FLAG_CANDIDATES
"-qopenmp" # Intel
"/Qopenmp" # Intel Windows
"-fopenmp" # GNU
)
ELSE ()
SET (OpenMP_Fortran_FLAG_CANDIDATES
"-qopenmp -qno-openmp-simd" # Intel
"/Qopenmp-simd-" # Intel Windows
"-fopenmp" # GNU
)
ENDIF (USE_SIMD)
IF (COMPILER_OPTIONS STREQUAL "Intel")
IF (USE_SIMD)
SET (OpenMP_Fortran_FLAG_CANDIDATES
"-qopenmp" # Intel
"/Qopenmp" # Intel Windows
)
ELSE ()
SET (OpenMP_Fortran_FLAG_CANDIDATES
"-qopenmp -qno-openmp-simd" # Intel
"/Qopenmp-simd-" # Intel Windows
)
ENDIF (USE_SIMD)
ELSEIF (COMPILER_OPTIONS STREQUAL "GNU")
IF (USE_SIMD)
SET (OpenMP_Fortran_FLAG_CANDIDATES
"-fopenmp" # GNU
)
ELSE ()
SET (OpenMP_Fortran_FLAG_CANDIDATES
"-fopenmp -fno-openmp-simd" # GNU
)
ENDIF (USE_SIMD)

ENDIF ()

IF (DEFINED OpenMP_Fortran_FLAGS)
SET (OpenMP_Fortran_FLAG_CANDIDATES)
Expand Down
Loading

0 comments on commit bd1fb58

Please sign in to comment.