add support for intel compilers

This commit is contained in:
Michele Guerini Rocco 2024-10-09 18:09:15 +02:00 committed by rnhmjoj
parent ee4183faa7
commit 5c78af975a
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
6 changed files with 65 additions and 32 deletions

View File

@ -50,7 +50,7 @@ LIBGRAY = $(LIBDIR)/libgray.so
BINARIES = $(GRAY) $(GRAY)-convert BINARIES = $(GRAY) $(GRAY)-convert
LIBRARIES = $(LIBGRAY) LIBRARIES = $(LIBGRAY)
MANPAGES = $(addprefix $(SHAREDIR)/,gray.1 gray-convert.1 gray.ini.5 \ MANPAGES = $(addprefix $(SHAREDIR)/,gray.1 gray-convert.1 gray.ini.5 \
profiles.txt.5 beamdata.txt.5 magneticdata.txt.5) profiles.txt.5 beamdata.txt.5 magneticdata.txt.5)
## ##
## Git information (used in the version string) ## Git information (used in the version string)
@ -73,14 +73,23 @@ DATE=$(shell LC_TIME=C date -d @$(SOURCE_DATE_EPOCH) '+%B %Y')
## Fortran compiler and flags ## Fortran compiler and flags
## ##
# Note: can't use ?= for FC because GNU Make defaults to f77 LD = $(FC)
FC = gfortran FFLAGS += -I$(INCDIR) -fpic
LD = gfortran
FFLAGS += -J$(OBJDIR) -I$(INCDIR) -ffree-line-length-none -fPIC -frecursive
FFLAGS += -Wfatal-errors
LDFLAGS += -L$(LIBDIR) LDFLAGS += -L$(LIBDIR)
CPPFLAGS += -DREVISION=\"$(GIT_REV)$(GIT_DIRTY)\" -DPREFIX=\"$(PREFIX)\" CPPFLAGS += -DREVISION=\"$(GIT_REV)$(GIT_DIRTY)\" -DPREFIX=\"$(PREFIX)\"
# Compiler-specific flags
ifdef GNU
FFLAGS += -J$(OBJDIR) -frecursive
FFLAGS += -fmax-errors=1 -ffree-line-length-none
CPPFLAGS += -DGNU
endif
ifdef INTEL
FFLAGS += -module $(OBJDIR) -assume recursion -heap-arrays
FFLAGS += -diag-error-limit=1
CPPFLAGS += -DINTEL
endif
ifdef PARALLEL ifdef PARALLEL
FFLAGS += -ftree-parallelize-loops=$(PARALLEL) -fopt-info-loop FFLAGS += -ftree-parallelize-loops=$(PARALLEL) -fopt-info-loop
LDFLAGS += -fopenmp LDFLAGS += -fopenmp
@ -104,7 +113,7 @@ ifndef SEMISTATIC
LDFLAGS += -static LDFLAGS += -static
endif endif
else else
LDFLAGS += -Wl,-rpath '$$ORIGIN/../lib/' LDFLAGS += -Wl,-rpath='$$ORIGIN/../lib/'
endif endif
# Debug build options # Debug build options
@ -227,7 +236,7 @@ vpath %.f90 $(SRCDIR):$(SRCDIR)/vendor
# dependencies (ie. the dependency graph is a DAG); # dependencies (ie. the dependency graph is a DAG);
$(OBJDIR)/%.d: %.f90 | $(OBJDIR) $(OBJDIR)/%.d: %.f90 | $(OBJDIR)
@printf '$(@:d=o): $< \\\n' > '$@' @printf '$(@:d=o): $< \\\n' > '$@'
@grep -vE '^[[:blank:]]*use.*(intrinsic|iso_)' '$<' | \ @grep -vE '^[[:blank:]]*use.*(intrinsic|iso_|ifport)' '$<' | \
sed -nE 's@^[[:blank:]]*use[[:blank:]]+'\ sed -nE 's@^[[:blank:]]*use[[:blank:]]+'\
'([^,[:blank:]&]+).*@$(OBJDIR)/\1.o \\@p' | \ '([^,[:blank:]&]+).*@$(OBJDIR)/\1.o \\@p' | \
sort -u >> '$@' sort -u >> '$@'

9
configure vendored
View File

@ -13,6 +13,7 @@ VAR=VALUE. Defaults for the options are specified in brackets.
Options: Options:
-h, --help display this help and exit -h, --help display this help and exit
--prefix=PREFIX install files in PREFIX [/usr/local] --prefix=PREFIX install files in PREFIX [/usr/local]
--with-compiler=PROG use PROG as Fortran compiler [automatically detect]
--enable-static statically link programs and libraries [no] --enable-static statically link programs and libraries [no]
--disable-static dynamically link programs and libraries [yes] --disable-static dynamically link programs and libraries [yes]
--enable-deterministic try to make a bit-for-bit deterministic build [no] --enable-deterministic try to make a bit-for-bit deterministic build [no]
@ -39,6 +40,7 @@ for arg in "$@"; do
PREFIX="${arg#*=}" PREFIX="${arg#*=}"
printf 'install prefix set to %s\n' "$PREFIX" printf 'install prefix set to %s\n' "$PREFIX"
;; ;;
--with-compiler=*) FC="${arg#*=}" ;;
--enable-static) printf 'STATIC=1\n' >> configure.mk ;; --enable-static) printf 'STATIC=1\n' >> configure.mk ;;
--disable-static) ;; --disable-static) ;;
--enable-deterministic) printf 'DETERMINISTIC=1\n' >> configure.mk ;; --enable-deterministic) printf 'DETERMINISTIC=1\n' >> configure.mk ;;
@ -74,7 +76,7 @@ printf 'Processor architecture %s\n' "$arch"
printf '%s=%s\n' PREFIX "${PREFIX:-/usr/local}" >> configure.mk printf '%s=%s\n' PREFIX "${PREFIX:-/usr/local}" >> configure.mk
# Detect the Fortran compiler # Detect the Fortran compiler
for FC in "$FC" ifort gfortran f77; do for FC in "$FC" ifx ifort gfortran f77; do
check "$FC" && break check "$FC" && break
done done
# shellcheck disable=SC2181 # shellcheck disable=SC2181
@ -85,6 +87,11 @@ fi
printf 'using %s as Fortran compiler\n' "$FC" printf 'using %s as Fortran compiler\n' "$FC"
printf '%s=%s\n' FC "$FC" >> configure.mk printf '%s=%s\n' FC "$FC" >> configure.mk
case $FC in
ifx|ifort) echo 'INTEL=1' >> configure.mk ;;
gfortran|f77) echo 'GNU=1' >> configure.mk ;;
esac
# Check whether ar is deterministic by default # Check whether ar is deterministic by default
if ar h | grep -q '\[D\].*(default)' 2>/dev/null; then if ar h | grep -q '\[D\].*(default)' 2>/dev/null; then
printf 'AR_DEFAULT_DETERMINISTIC=1\n' >> configure.mk printf 'AR_DEFAULT_DETERMINISTIC=1\n' >> configure.mk

View File

@ -23,57 +23,64 @@ module gray_errors
end type end type
! macros used for defining errors ! macros used for defining errors
# define after(x) x%offset + x%subcases #define after(x) x%offset + x%subcases
#define str character(64)
! All GRAY errors ! All GRAY errors
type(error_spec), parameter :: unstable_beam = & type(error_spec), parameter :: unstable_beam = &
error_spec(offset=0, subcases=2, & error_spec(offset=0, subcases=2, &
mod='gray_core', proc='gray_main', & mod='gray_core', proc='gray_main', &
msg=reshape(['beamtracing may be unstable'], [10], [''])) msg=reshape([str :: &
'beamtracing may be unstable'], &
[10], [str :: '']))
type(error_spec), parameter :: dielectric_tensor = & type(error_spec), parameter :: dielectric_tensor = &
error_spec(offset=after(unstable_beam), subcases=2, & error_spec(offset=after(unstable_beam), subcases=2, &
mod='gray_core', proc='gray_main', & mod='gray_core', proc='gray_main', &
msg=reshape([character(64) :: & msg=reshape([str :: &
'ε tensor, overflow in `fsup`', & 'ε tensor, overflow in `fsup`', &
'ε tensor, integration error in `hermitian_2`' & 'ε tensor, integration error in `hermitian_2`'], &
], [10], [''])) [10], [str :: '']))
type(error_spec), parameter :: warmdisp_convergence = & type(error_spec), parameter :: warmdisp_convergence = &
error_spec(offset=after(dielectric_tensor), subcases=2, & error_spec(offset=after(dielectric_tensor), subcases=2, &
mod='dispersion', proc='warmdisp', & mod='dispersion', proc='warmdisp', &
msg=reshape([character(64) :: & msg=reshape([str :: &
'failed to converge, returned fallback value', & 'failed to converge, returned fallback value', &
'failed to converge, returned last value' & 'failed to converge, returned last value'], &
], [10], [''])) [10], [str :: '']))
type(error_spec), parameter :: warmdisp_result = & type(error_spec), parameter :: warmdisp_result = &
error_spec(offset=after(warmdisp_convergence), subcases=2, & error_spec(offset=after(warmdisp_convergence), subcases=2, &
mod='dispersion', proc='warmdisp', & mod='dispersion', proc='warmdisp', &
msg=reshape([character(64) :: & msg=reshape([str :: &
'final N⊥² is NaN or ±Infinity', & 'final N⊥² is NaN or ±Infinity', &
'final N⊥² in 3rd quadrant' & 'final N⊥² in 3rd quadrant'], &
], [10], [''])) [10], [str :: '']))
type(error_spec), parameter :: negative_absorption = & type(error_spec), parameter :: negative_absorption = &
error_spec(offset=after(warmdisp_result), subcases=1, & error_spec(offset=after(warmdisp_result), subcases=1, &
mod='gray_core', proc='alpha_effj', & mod='gray_core', proc='alpha_effj', &
msg=reshape(['negative absorption coeff.'], [10], [''])) msg=reshape([str :: &
'negative absorption coeff.'], &
[10], [str :: '']))
type(error_spec), parameter :: fpp_integration = & type(error_spec), parameter :: fpp_integration = &
error_spec(offset=after(negative_absorption), subcases=1, & error_spec(offset=after(negative_absorption), subcases=1, &
mod='eccd', proc='eccdeff', & mod='eccd', proc='eccdeff', &
msg=reshape(['fpp integration error'], [10], [''])) msg=reshape([str :: &
'fpp integration error'], &
[10], [str :: '']))
type(error_spec), parameter :: fcur_integration = & type(error_spec), parameter :: fcur_integration = &
error_spec(offset=after(fpp_integration), subcases=3, & error_spec(offset=after(fpp_integration), subcases=3, &
mod='eccd', proc='eccdeff', & mod='eccd', proc='eccdeff', &
msg=reshape([character(64) :: & msg=reshape([str :: &
'fcur integration error (no trapping)', & 'fcur integration error (no trapping)', &
'fcur integration error (1st trapping region)', & 'fcur integration error (1st trapping region)', &
'fcur integration error (2st trapping region)' & 'fcur integration error (2st trapping region)'], &
], [10], [''])) [10], [str :: '']))
! Errors occuring during raytracing ! Errors occuring during raytracing
type(error_spec), parameter :: raytracing_errors(*) = [unstable_beam] type(error_spec), parameter :: raytracing_errors(*) = [unstable_beam]

View File

@ -11,6 +11,9 @@
module logger module logger
use, intrinsic :: iso_fortran_env, only : error_unit use, intrinsic :: iso_fortran_env, only : error_unit
#ifdef INTEL
use ifport, only : isatty
#endif
implicit none implicit none

View File

@ -1,4 +1,8 @@
program main program main
#ifdef INTEL
use ifport, only : chdir, getcwd
#endif
use const_and_precisions, only : wp_ use const_and_precisions, only : wp_
use logger, only : INFO, ERROR, WARNING, set_logger, log_message use logger, only : INFO, ERROR, WARNING, set_logger, log_message
use utils, only : dirname use utils, only : dirname
@ -32,7 +36,7 @@ program main
! Store the original working directory ! Store the original working directory
integer :: err integer :: err
character(len=256) :: cwd character(len=256) :: cwd
call getcwd(cwd) err = getcwd(cwd)
! Parse the command-line options ! Parse the command-line options
call parse_cli_options(opts) call parse_cli_options(opts)

View File

@ -1,5 +1,8 @@
module utils module utils
#ifdef INTEL
use ifport, only : getcwd
#endif
use const_and_precisions, only : wp_ use const_and_precisions, only : wp_
implicit none implicit none
@ -151,14 +154,14 @@ contains
! local variables ! local variables
character(255) :: cwd character(255) :: cwd
integer :: last_sep integer :: last_sep, err
last_sep = scan(filepath, '/', back=.true.) last_sep = scan(filepath, '/', back=.true.)
directory = filepath(1:last_sep) directory = filepath(1:last_sep)
! append the cwd to relative paths ! append the cwd to relative paths
if (isrelative(filepath)) then if (isrelative(filepath)) then
call getcwd(cwd) err = getcwd(cwd)
directory = trim(cwd) // '/' // directory directory = trim(cwd) // '/' // directory
end if end if
end function dirname end function dirname