From 2f31053dc544c383e532af945ffb7aab2c1620d8 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Wed, 2 Jun 2021 17:21:29 +1200 Subject: [PATCH 1/5] Allow overriding default compiler flag in CMake --- CMakeLists.txt | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82a5de312..bbc4710cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,15 +99,31 @@ set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) # Additional Fortran compiler flags. # -# -fno-automatic: this was set in the original make_environment_gfortran_UBC file. +# -fno-automatic: this was set in the original make_environment_gfortran_UBC file. # -# Note: optimization should be enabled on the Release target automatically. +# Note: there is no need to pass optimization flags explicitly (e.g. -O2) -- CMake enables +# -O2 automatically on the Release target. Similarly, -g is automatically set for the Debug +# target. # -# If need be, you can also set up linker flags. E.g.: +# To set additional compiler flags, you can set CMAKE_Fortran_FLAGS when invoking CMake. +# For example # -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgfortran") +# cmake -DCMAKE_Fortran_FLAGS="-fno-automatic -fconvert=big-endian" .. # -set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-automatic") +# Note: this will override the defaults, so you need to pass -fno-automatic yourself. This +# behavior is useful when using e.g. the Intel compiler, which has a different name for this +# option, and so you don't want to pass a For GFortran-specific flag. +# +# Similarly, additional linker options can be passed via CMAKE_EXE_LINKER_FLAGS, e.g. +# +# cmake -DCMAKE_EXE_LINKER_FLAGS="-static-libgfortran" .. +# +if(NOT DEFINED CMAKE_Fortran_FLAGS) + set(CMAKE_Fortran_FLAGS "-fno-automatic") +else() + message("CMAKE_Fortran_FLAGS set by user to: ${CMAKE_Fortran_FLAGS}") + message("Note: GRASP requires -fno-automatic (or equivalent)") +endif() message("Compiler flags etc. for this GRASP build:") message("* CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") From 67c9f258babf167f817d6d4ebb460a36e98c2be5 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Sun, 6 Jun 2021 14:31:44 +1200 Subject: [PATCH 2/5] Use new variable to control defaults: GRASP_DEFAULT_FLAGS --- CMakeLists.txt | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbc4710cd..c62f28a81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,34 +99,43 @@ set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) # Additional Fortran compiler flags. # -# -fno-automatic: this was set in the original make_environment_gfortran_UBC file. -# -# Note: there is no need to pass optimization flags explicitly (e.g. -O2) -- CMake enables -# -O2 automatically on the Release target. Similarly, -g is automatically set for the Debug -# target. -# # To set additional compiler flags, you can set CMAKE_Fortran_FLAGS when invoking CMake. # For example # # cmake -DCMAKE_Fortran_FLAGS="-fno-automatic -fconvert=big-endian" .. # -# Note: this will override the defaults, so you need to pass -fno-automatic yourself. This -# behavior is useful when using e.g. the Intel compiler, which has a different name for this -# option, and so you don't want to pass a For GFortran-specific flag. +# Note: there is no need to pass optimization flags explicitly (e.g. -O2) -- CMake enables +# -O2 automatically on the Release target. Similarly, -g is automatically set for the Debug +# target. # # Similarly, additional linker options can be passed via CMAKE_EXE_LINKER_FLAGS, e.g. # # cmake -DCMAKE_EXE_LINKER_FLAGS="-static-libgfortran" .. # -if(NOT DEFINED CMAKE_Fortran_FLAGS) - set(CMAKE_Fortran_FLAGS "-fno-automatic") -else() - message("CMAKE_Fortran_FLAGS set by user to: ${CMAKE_Fortran_FLAGS}") - message("Note: GRASP requires -fno-automatic (or equivalent)") +# Default flags (in addition to CMake defaults): +# +# -fno-automatic / -save: these were set in the original Makefiles +# +# To disable GRASP-specific default flags, you can set GRASP_DEFAULT_FLAGS=FALSE when +# calling CMake with +# +# cmake -DGRASP_DEFAULT_FLAGS=FALSE .. +# +set(GRASP_DEFAULT_FLAGS TRUE CACHE BOOL "If TRUE (default), -fno-automatic (gfortran) or -save (ifort) is automatically set in CMAKE_Fortran_FLAGS.") +if(GRASP_DEFAULT_FLAGS) + if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-automatic") + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -save") + else() + message("GRASP requires -fno-automatic or -save or equivalent, but is unable to determine the correct argument for this compiler (${CMAKE_Fortran_COMPILER_ID})") + endif() endif() message("Compiler flags etc. for this GRASP build:") +message("* GRASP_DEFAULT_FLAGS: ${GRASP_DEFAULT_FLAGS}") message("* CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message("* CMAKE_Fortran_COMPILER_ID: ${CMAKE_Fortran_COMPILER_ID}") message("* CMAKE_Fortran_COMPILER: ${CMAKE_Fortran_COMPILER}") message("* CMAKE_Fortran_COMPILER_VERSION: ${CMAKE_Fortran_COMPILER_VERSION}") message("* CMAKE_Fortran_FLAGS: ${CMAKE_Fortran_FLAGS}") From 6fcd439db054a491e721ff41377dfc3aead0ebb7 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Sun, 6 Jun 2021 14:35:17 +1200 Subject: [PATCH 3/5] Edits --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c62f28a81..fc9da2a13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,7 @@ set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) # To set additional compiler flags, you can set CMAKE_Fortran_FLAGS when invoking CMake. # For example # -# cmake -DCMAKE_Fortran_FLAGS="-fno-automatic -fconvert=big-endian" .. +# cmake -DCMAKE_Fortran_FLAGS="-fconvert=big-endian" .. # # Note: there is no need to pass optimization flags explicitly (e.g. -O2) -- CMake enables # -O2 automatically on the Release target. Similarly, -g is automatically set for the Debug @@ -128,7 +128,7 @@ if(GRASP_DEFAULT_FLAGS) elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -save") else() - message("GRASP requires -fno-automatic or -save or equivalent, but is unable to determine the correct argument for this compiler (${CMAKE_Fortran_COMPILER_ID})") + message(WARNING "GRASP requires -fno-automatic or -save or equivalent, but is unable to determine the correct argument for this compiler (${CMAKE_Fortran_COMPILER_ID})") endif() endif() From b061815c4f4fbe31e47768f88d90061cd95d2fed Mon Sep 17 00:00:00 2001 From: Jon Grumer Date: Tue, 8 Jun 2021 14:25:40 +0200 Subject: [PATCH 4/5] revert to modern sys mkdir call --- src/lib/mpi90/sys_mkdir.f90 | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/lib/mpi90/sys_mkdir.f90 b/src/lib/mpi90/sys_mkdir.f90 index 69459d757..8b9fb5388 100644 --- a/src/lib/mpi90/sys_mkdir.f90 +++ b/src/lib/mpi90/sys_mkdir.f90 @@ -13,9 +13,6 @@ subroutine sys_mkdir (dir, lendir, ierr) !...Modified by Charlotte Froese Fischer ! Gediminas Gaigalas 10/05/17 ! -! function 'system' and execute_command_line commented out -!cjb Jacek Bieron 2018 June 18 -! !----------------------------------------------- ! M o d u l e s !----------------------------------------------- @@ -28,25 +25,15 @@ subroutine sys_mkdir (dir, lendir, ierr) integer, intent(in):: lendir integer, intent(out):: ierr character(len=255) mkdir_error_message -! character(len=*), parameter::iam = 'SUN' ! soly for machine -! character(len=len_trim (iam)), optional, intent(out):: machine - -! integer system mkdir_error_message = " no message passed from the shell " ierr = -999 -!cjb -! print*, dir(1:lendir) -! print*, dir(1:lendir) -! - ierr = system ('mkdir -p -m 775 ' // dir(1:lendir)) -!cjb use EXECUTE_COMMAND_LINE if function 'system' is not supported -! call execute_command_line ('mkdir -p -m 775 ' // dir(1:lendir), & -! exitstat=ierr, cmdmsg=mkdir_error_message) +! ierr = system ('mkdir -p -m 775 ' // dir(1:lendir)) + call execute_command_line ('mkdir -p -m 775 ' // dir(1:lendir), & + exitstat=ierr, cmdmsg=mkdir_error_message) if (ierr.ne.0) then print*, ' sys_mkdir error message = ', trim(mkdir_error_message) -! ' myid = ', myid endif return end subroutine sys_mkdir From 868616e3314df390ed12f6d9871a53467d08ae87 Mon Sep 17 00:00:00 2001 From: Jon Grumer Date: Tue, 8 Jun 2021 14:26:46 +0200 Subject: [PATCH 5/5] add -mkl to default ifort CMake flags --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc9da2a13..1814ac145 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,7 @@ if(GRASP_DEFAULT_FLAGS) if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-automatic") elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -save") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -save -mkl") else() message(WARNING "GRASP requires -fno-automatic or -save or equivalent, but is unable to determine the correct argument for this compiler (${CMAKE_Fortran_COMPILER_ID})") endif()