Skip to content

Commit

Permalink
Compile with -std=f2008 (#228)
Browse files Browse the repository at this point in the history
* updated make rule for F77 and F90 with std=f2008

* fixed tabs

* swapping around variable declaration orders

* use myisnan instead of non-standard isnan function from GCC

* fixed some string and format issues

* fixed some warnings

* fix real/complex types

* Fixing type issues for t0

* Fixing previously fixed string continuation

* Update obsolete string definitions

* Update myisnan to handle different types and to use more modern modules. Removing older c function

* More fixes

* Remove old Makefile

* Update intel fortran flags

* More fixes for the intel compiler

* Updating linker flags

* Make new module compile without optimization

* Add new file

* Removing debug flags from config and unused flags

* Remove line continuation

* Updating build system build certain files without optimization

* get myisnan from the new module

* Updating build files for complex

* ran tapenade

* remove whitespace

Co-authored-by: Eirikur Jonsson <[email protected]>
Co-authored-by: Sabet Seraj <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2022
1 parent af5c32b commit 83a611d
Show file tree
Hide file tree
Showing 42 changed files with 419 additions and 499 deletions.
6 changes: 4 additions & 2 deletions config/defaults/config.LINUX_GFORTRAN.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF90_FLAGS = -DHAS_ISNAN -fPIC -fdefault-real-8 -fdefault-double-8 -g -O3 -march=native -ffast-math
C_FLAGS = -DHAS_ISNAN -O -fPIC -g
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native
FF90_FLAGS = $(FF77_FLAGS) -std=f2008
FFXX_OPT_FLAGS = -O3 -ffast-math
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
AR = ar
Expand Down
8 changes: 5 additions & 3 deletions config/defaults/config.LINUX_INTEL.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF90_FLAGS = -DHAS_ISNAN -fPIC -r8 -O2 -g
C_FLAGS = -DHAS_ISNAN -O -fPIC
FF77_FLAGS = -fPIC -r8
FF90_FLAGS = $(FF77_FLAGS) -std08
FFXX_OPT_FLAGS = -O2
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
AR = ar
AR_FLAGS = -rvs

# ------- Define Linker Flags ------------------------------------------
LINKER = $(FF90)
LINKER_FLAGS = -nofor_main
LINKER_FLAGS = -nofor-main

# ------- Define Petsc Info ---
include ${PETSC_DIR}/lib/petsc/conf/variables
Expand Down
8 changes: 5 additions & 3 deletions config/defaults/config.LINUX_INTEL_SAFE.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF90_FLAGS = -DHAS_ISNAN -fPIC -r8 -O1 -g
C_FLAGS = -DHAS_ISNAN -O -fPIC
FF77_FLAGS = -fPIC -r8
FF90_FLAGS = $(FF77_FLAGS) -std08
FFXX_OPT_FLAGS = -O1
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
AR = ar
AR_FLAGS = -rvs

# ------- Define Linker Flags ------------------------------------------
LINKER = $(FF90)
LINKER_FLAGS = -nofor_main
LINKER_FLAGS = -nofor-main

# ------- Define Petsc Info ---
include ${PETSC_DIR}/lib/petsc/conf/variables
Expand Down
6 changes: 4 additions & 2 deletions config/defaults/config.OSX_GFORTRAN.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ CGNS_INCLUDE_FLAGS=-I$(CGNS_HOME)/include
CGNS_LINKER_FLAGS=-L$(CGNS_HOME)/lib -lcgns

# ------- Define Compiler Flags ----------------------------------------
FF90_FLAGS = -DHAS_ISNAN -fPIC -fdefault-real-8 -fdefault-double-8 -g -O3 -march=native -ffast-math
C_FLAGS = -DHAS_ISNAN -O -fPIC -g
FF77_FLAGS = -fPIC -fdefault-real-8 -fdefault-double-8 -march=native
FF90_FLAGS = $(FF77_FLAGS) -std=f2008
FFXX_OPT_FLAGS = -O3 -ffast-math
C_FLAGS = -fPIC -O

# ------- Define Archiver and Flags -----------------------------------
AR = ar
Expand Down
67 changes: 36 additions & 31 deletions src/NKSolver/NKSolvers.F90
Original file line number Diff line number Diff line change
Expand Up @@ -680,18 +680,19 @@ end subroutine NKStep
subroutine LSCubic(x, f, g, y, w, fnorm, ynorm, gnorm, nfevals, flag, lambda)

use constants
use utils, only : EChk, myisnan
use utils, only : EChk
use genericISNAN, only : myisnan
use communication, only : myid
use initializeFlow, only : setUniformFlow
use iteration, only : totalR0
implicit none

! Input/Output
Vec x, f, g, y, w
!x - current iterate
!f - residual evaluated at x
!y - search direction
!w - work vector -> On output, new iterate
!x - current iterate
!f - residual evaluated at x
!y - search direction
!w - work vector -> On output, new iterate
!g - residual evaluated at new iterate y

real(kind=alwaysrealType) :: fnorm, gnorm, ynorm
Expand Down Expand Up @@ -768,10 +769,10 @@ subroutine LSCubic(x, f, g, y, w, fnorm, ynorm, gnorm, nfevals, flag, lambda)
! order of magnitude or more.

hadANan = .False.
if (isnan(gnorm) .or. turbRes2 > 2.0*turbRes1) then
if (myisnan(gnorm) .or. turbRes2 > 2.0*turbRes1) then
! Special testing for nans

if (isnan(gnorm)) then
if (myisnan(gnorm)) then
hadANan = .True.
call setUniformFlow()
lambda = 0.5
Expand All @@ -798,7 +799,7 @@ subroutine LSCubic(x, f, g, y, w, fnorm, ynorm, gnorm, nfevals, flag, lambda)

nfevals = nfevals + 1

if (isnan(gnorm)) then
if (myisnan(gnorm)) then
! Just reset the flow, adjust the step back and keep
! going
call setUniformFlow()
Expand Down Expand Up @@ -914,7 +915,7 @@ subroutine LSCubic(x, f, g, y, w, fnorm, ynorm, gnorm, nfevals, flag, lambda)
lambda = lambdatemp
end if

if (isnan(lambda)) then
if (myisnan(lambda)) then
flag = .False.
exit cubic_loop
end if
Expand Down Expand Up @@ -954,10 +955,10 @@ subroutine LSNone(x, f, g, y, w, nfevals, flag, step)

! Input/Output
Vec x, f, g, y, w
!x - current iterate
!f - residual evaluated at x
!y - search direction
!w - work vector -> On output, new iterate
!x - current iterate
!f - residual evaluated at x
!y - search direction
!w - work vector -> On output, new iterate
!g - residual evaluated at new iterate y

integer(kind=intType) :: nfevals
Expand Down Expand Up @@ -990,10 +991,10 @@ subroutine LSNM(x, f, g, y, w, fnorm, ynorm, gnorm, nfevals, flag, step)

! Input/Output
Vec x, f, g, y, w
!x - current iterate
!f - residual evaluated at x
!y - search direction
!w - work vector -> On output, new iterate
!x - current iterate
!f - residual evaluated at x
!y - search direction
!w - work vector -> On output, new iterate
!g - residual evaluated at new iterate y

real(kind=alwaysRealType) :: fnorm, gnorm, ynorm
Expand Down Expand Up @@ -1520,8 +1521,8 @@ subroutine setInfo(info, iSize)
use utils, only : setPointers
implicit none

real(kind=realType), intent(in), dimension(iSize) :: info
integer(kind=intType), intent(in) :: iSize
real(kind=realType), intent(in), dimension(iSize) :: info
integer(kind=intType) :: nn, counter, i, j, k, l, sps
! Determine the size of a flat array needed to store w, P, ( and
! rlv, rev if necessary) with full double halos.
Expand Down Expand Up @@ -1566,8 +1567,8 @@ subroutine getInfo(info, iSize)

implicit none

real(kind=realType), intent(out), dimension(iSize) :: info
integer(kind=intType), intent(in) :: iSize
real(kind=realType), intent(out), dimension(iSize) :: info
integer(kind=intType) :: nn, counter, i, j, k, l, sps
! Determine the size of a flat array needed to store w, P, ( and
! rlv, rev if necessary) with full double halos.
Expand Down Expand Up @@ -3063,7 +3064,8 @@ subroutine physicalityCheckANK(lambdaP)
use blockPointers, only : ndom, il, jl, kl
use flowVarRefState, only : nw, nwf, nt1, nt2
use inputtimespectral, only : nTimeIntervalsSpectral
use utils, only : setPointers, EChk, myisnan
use utils, only : setPointers, EChk
use genericISNAN, only : myisnan
use communication, only : ADflow_comm_world
implicit none

Expand Down Expand Up @@ -3234,7 +3236,7 @@ subroutine physicalityCheckANK(lambdaP)
call EChk(ierr,__FILE__,__LINE__)

! Make sure that we did not get any NaN's in the process
if (isnan(lambdaL)) then
if (myisnan(lambdaL)) then
lambdaL = zero
end if

Expand All @@ -3260,7 +3262,8 @@ subroutine physicalityCheckANKTurb(lambdaP)
use blockPointers, only : ndom, il, jl, kl
use flowVarRefState, only : nw, nwf, nt1,nt2
use inputtimespectral, only : nTimeIntervalsSpectral
use utils, only : setPointers, EChk, myisnan
use utils, only : setPointers, EChk
use genericISNAN, only : myisnan
use communication, only : ADflow_comm_world
implicit none

Expand Down Expand Up @@ -3358,7 +3361,7 @@ subroutine physicalityCheckANKTurb(lambdaP)
call EChk(ierr,__FILE__,__LINE__)

! Make sure that we did not get any NaN's in the process
if (isnan(lambdaL)) then
if (myisnan(lambdaL)) then
lambdaL = zero
end if

Expand Down Expand Up @@ -3389,7 +3392,8 @@ subroutine ANKTurbSolveKSP
use inputTimeSpectral, only : nTimeIntervalsSpectral
use inputDiscretization, only : approxSA, orderturb
use iteration, only : approxTotalIts, totalR0, totalR, currentLevel
use utils, only : EChk, setPointers, myisnan
use utils, only : EChk, setPointers
use genericISNAN, only : myisnan
use solverUtils, only : computeUTau
use NKSolver, only : getEwTol
use BCRoutines, only : applyAllBC, applyAllBC_block
Expand Down Expand Up @@ -3555,7 +3559,7 @@ subroutine ANKTurbSolveKSP
! initialize this outside the ls
LSFailed = .False.

if ((unsteadyNorm > totalRTurb*ANK_unstdyLSTol .or. isnan(unsteadyNorm))) then
if ((unsteadyNorm > totalRTurb*ANK_unstdyLSTol .or. myisnan(unsteadyNorm))) then
! The unsteady residual is too high or we have a NAN. Do a
! backtracking line search until we get a residual that is lower.

Expand Down Expand Up @@ -3585,7 +3589,7 @@ subroutine ANKTurbSolveKSP
call VecNorm(rVecTurb, NORM_2, unsteadyNorm, ierr)
call EChk(ierr, __FILE__, __LINE__)

if (unsteadyNorm > totalRTurb*ANK_unstdyLSTol .or. isnan(unsteadyNorm)) then
if (unsteadyNorm > totalRTurb*ANK_unstdyLSTol .or. myisnan(unsteadyNorm)) then

! Restore back to the original wVec
call VecAXPY(wVecTurb, lambdaTurb, deltaWTurb, ierr)
Expand All @@ -3600,7 +3604,7 @@ subroutine ANKTurbSolveKSP
end if
end do backtrack

if (LSFailed .or. isnan(unsteadyNorm)) then
if (LSFailed .or. myisnan(unsteadyNorm)) then
! the line search wasn't much help.

if (ANK_CFL > ANK_CFLMin) then
Expand Down Expand Up @@ -3670,7 +3674,8 @@ subroutine ANKStep(firstCall)
use inputTimeSpectral, only : nTimeIntervalsSpectral
use inputDiscretization, only : lumpedDiss, approxSA, orderturb
use iteration, only : approxTotalIts, totalR0, totalR, stepMonitor, linResMonitor, currentLevel, iterType
use utils, only : EChk, setPointers, myisnan
use utils, only : EChk, setPointers
use genericISNAN, only : myisnan
use turbAPI, only : turbSolveDDADI
use solverUtils, only : computeUTau
use adjointUtils, only : referenceShockSensor
Expand Down Expand Up @@ -3976,7 +3981,7 @@ subroutine ANKStep(firstCall)
! initialize this outside the ls
LSFailed = .False.

if ((unsteadyNorm > unsteadyNorm_old*ANK_unstdyLSTol .or. isnan(unsteadyNorm))) then
if ((unsteadyNorm > unsteadyNorm_old*ANK_unstdyLSTol .or. myisnan(unsteadyNorm))) then
! The unsteady residual is too high or we have a NAN. Do a
! backtracking line search until we get a residual that is lower.

Expand Down Expand Up @@ -4006,7 +4011,7 @@ subroutine ANKStep(firstCall)
call VecNorm(rVec, NORM_2, unsteadyNorm, ierr)
call EChk(ierr, __FILE__, __LINE__)

if (unsteadyNorm > unsteadyNorm_old*ANK_unstdyLSTol .or. isnan(unsteadyNorm)) then
if (unsteadyNorm > unsteadyNorm_old*ANK_unstdyLSTol .or. myisnan(unsteadyNorm)) then

! Restore back to the original wVec
call VecAXPY(wVec, lambda, deltaW, ierr)
Expand All @@ -4021,7 +4026,7 @@ subroutine ANKStep(firstCall)
end if
end do backtrack

if (LSFailed .or. isnan(unsteadyNorm)) then
if (LSFailed .or. myisnan(unsteadyNorm)) then
! the line search wasn't much help.

if (ANK_CFL > ANK_CFLMin) then
Expand Down
82 changes: 0 additions & 82 deletions src/adjoint/ADFirstAidKit/Makefile

This file was deleted.

Loading

0 comments on commit 83a611d

Please sign in to comment.