Skip to content

Commit

Permalink
Fixed memory issues and array bounds check.
Browse files Browse the repository at this point in the history
  • Loading branch information
drnimbusrain committed Jul 12, 2022
1 parent b986ef8 commit aabc189
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 54 deletions.
188 changes: 188 additions & 0 deletions parallel/src/Makefile_gcc_hopper_debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#------------------------------------------------------------------------------#
# The Community Multiscale Air Quality (CMAQ) system software is in #
# continuous development by various groups and is based on information #
# from these groups: Federal Government employees, contractors working #
# within a United States Government contract, and non-Federal sources #
# including research institutions. These groups give the Government #
# permission to use, prepare derivative works of, and distribute copies #
# of their work in the CMAQ system to the public and to permit others #
# to do so. The United States Environmental Protection Agency #
# therefore grants similar permission to use the CMAQ system software, #
# but users are requested to provide copies of derivative works or #
# products designed to operate in the CMAQ system to the United States #
# Government without restrictions as to use by others. Software #
# that is used with the CMAQ system but distributed under the GNU #
# General Public License or the GNU Lesser General Public License is #
# subject to their copyright restrictions. #
#------------------------------------------------------------------------------#

.SUFFIXES:
.SUFFIXES: .o .f90 .F90

MODEL = mcip.exe

#...Portland Group Fortran
#FC = /usr/local/apps/pgi/linux86-64/17.10/bin/pgf90
#NETCDF = /usr/local/apps/netcdf-4.6.3/pgi-17.10
#IOAPI_ROOT = /usr/local/apps/ioapi-3.2_20181011/pgi-17.10
###FFLAGS = -g -O0 -Ktrap=unf -Ktrap=denorm -Ktrap=inv -Ktrap=ovf -Ktrap=divz \
### -Ktrap=fp -pc 32 -Mbounds -Mchkfpstk -Mchkptr -Kieee \
### -Minform,inform -Mfree -byteswapio -I$(NETCDF)/include \
### -I$(IOAPI_ROOT)/Linux2_x86_64pg
#FFLAGS = -O4 -fastsse -pc 32 -Mfree -byteswapio -I$(NETCDF)/include \
# -I$(IOAPI_ROOT)/Linux2_x86_64pg
#LIBS = -L$(IOAPI_ROOT)/Linux2_x86_64pg -lioapi \
# -L$(NETCDF)/lib -lnetcdff -lnetcdf

#...gfortran
#FC = gfortran
#NETCDF = /usr/local/apps/netcdf-4.6.3/gcc-6.1.0
#IOAPI_ROOT = /usr/local/apps/ioapi-3.2_20181011/gcc-6.1.0
#FFLAGS = -O3 -I$(NETCDF)/include -I$(IOAPI_ROOT)/Linux2_x86_64
###FFLAGS = -g -O0 \
### -ffpe-trap='invalid','zero','overflow','underflow' \
### -I$(NETCDF)/include -I$(IOAPI_ROOT)/Linux2_x86_64
#LIBS = -L$(IOAPI_ROOT)/Linux2_x86_64 -lioapi \
# -L$(NETCDF)/lib -lnetcdff -lnetcdf

FC = mpifort

#NetCDF Settings
NETCDF = /opt/sw/spack/apps/linux-centos8-cascadelake/gcc-9.3.0-openmpi-4.0.4/netcdf-c-4.7.4-vh

#IOAPI Settings
IOAPI_ROOT = /opt/sw/other/apps/linux-centos8-cascadelake/gnu-9.3.0-openmpi-4.0.4/ioapi/3.2-spack

#MPI Settings for parallel
MPI_ROOT = /opt/ohpc/pub/mpi/openmpi4-gnu9/4.0.4

FFLAGS = -g -O0 -fbacktrace -fbounds-check -I$(NETCDF)/include -I$(IOAPI_ROOT) -I$(MPI_ROOT)/include

#Parallel
LIBS = -L$(IOAPI_ROOT) -lioapi \
-L$(NETCDF)/lib -lnetcdf -lnetcdff -fopenmp \
-L$(MPI_ROOT)/lib -lmpi

/EFS =


MODULES =\
const_mod.o \
const_pbl_mod.o \
coord_mod.o \
ctmvars_mod.o \
date_time_mod.o \
date_pack_mod.o \
files_mod.o \
lucats_mod.o \
mcipparm_mod.o \
metinfo_mod.o \
metvars_mod.o \
netcdf_io_mod.o \
vgrd_mod.o \
xvars_mod.o

OBJS =\
mcip.o \
alloc_ctm.o \
alloc_met.o \
alloc_x.o \
bcldprc_ak.o \
blddesc.o \
chkwpshdr.o \
chkwrfhdr.o \
chkfv3hdr.o \
close_files.o \
collapx.o \
comheader.o \
comheader_lufrac.o \
comheader_mos.o \
comheader_soi.o \
ctmout.o \
ctmproc.o \
dealloc_ctm.o \
dealloc_met.o \
dealloc_x.o \
detangle_soil_px.o \
e_aerk.o \
dynflds.o \
fv3mopts.o \
fv3lammopts.o \
getluse.o \
getmet.o \
getpblht.o \
getpsih.o \
getsdt.o \
getxyindex.o \
graceful_stop.o \
gridout.o \
gridproc.o \
init_ctm.o \
init_io.o \
init_met.o \
init_x.o \
julian.o \
layht.o \
ll2xy_lam.o \
ll2xy_lam_sec.o \
ll2xy_lam_tan.o \
ll2xy_merc.o \
ll2xy_ps.o \
locate.o \
mapfac_lam.o \
mapfac_merc.o \
mapfac_ps.o \
metgrid2ctm.o \
metvars2ctm.o \
myinterp.o \
outclog.o \
outcm3io.o \
outglog.o \
outgm3io.o \
outncf.o \
outncfbdy.o \
outncfglobal.o \
pblsup.o \
ptemp.o \
pvs.o \
qsat.o \
rdwrfem.o \
rdfv3.o \
rdfv3_lam.o \
readnml.o \
resistcalc.o \
setgriddefs.o \
setup.o \
setup_wrfem.o \
setup_fv3.o \
setup_fv3_lam.o \
sfclayer.o \
statflds.o \
vertarys.o \
vertnhy_wrf.o \
vstamp.o \
vtemp.o \
wind.o \
windrotation.o \
wrfemopts.o \
wrgdesc.o \
xy2ll_lam.o \
xy2ll_merc.o \

all:
@$(MAKE) $(MODULES)
@$(MAKE) $(MODEL)

$(MODEL): $(OBJS)
$(FC) -o $(MODEL) $(FFLAGS) $(OBJS) $(MODULES) $(LIBS)

$(OBJS): $(MODULES)

.f90.o:
$(FC) $(FFLAGS) $(INCLUDES) -c $<

.F90.o:
$(FC) $(FFLAGS) $(INCLUDES) -c $< $(DEFS)

clean:
rm -f *.o *.mod *.il $(MODEL)
52 changes: 26 additions & 26 deletions parallel/src/ctmproc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -581,65 +581,65 @@ END SUBROUTINE collapx
! CALL collapx (xwvapor, xx3midl, x3midl)
! CALL collapx (x3htm, xx3midl, x3midl)

CALL collapx (xrhojm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xdensam(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xpresm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xtempm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xwvapor(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (x3htm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xrhojm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xdensam(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xpresm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xtempm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xwvapor(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (x3htm(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)


IF ( nqspecies >= 2 ) THEN
! CALL collapx (xcldwtr, xx3midl, x3midl)
! CALL collapx (xranwtr, xx3midl, x3midl)
CALL collapx (xcldwtr(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xranwtr(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xcldwtr(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xranwtr(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)

IF ( nqspecies >= 4 ) THEN
! CALL collapx (xqice, xx3midl, x3midl)
! CALL collapx (xqsnow, xx3midl, x3midl)
CALL collapx (xqice(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xqsnow(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xqice(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xqsnow(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
IF ( nqspecies == 5 ) THEN
! CALL collapx (xqgraup, xx3midl, x3midl)
CALL collapx (xqgraup(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xqgraup(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
ENDIF
ENDIF
ENDIF

IF ( ( iftke ) .AND. ( .NOT. iftkef ) ) THEN ! TKE on half-layers
! CALL collapx (xtke, xx3midl, x3midl)
CALL collapx (xtke(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xtke(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
ENDIF

IF ( lpv > 0 ) THEN ! Output potential vorticity
! CALL collapx (xpvc, xx3midl, x3midl)
CALL collapx (xpvc(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xpvc(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
ENDIF

IF ( ifcld3d ) THEN
! CALL collapx (xcfrac3d, xx3midl, x3midl)
CALL collapx (xcfrac3d(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xcfrac3d(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
ENDIF

! CALL collapx (xrhojf, xx3face, x3face)
! CALL collapx (xwhat, xx3face, x3face)
! CALL collapx (x3htf, xx3face, x3face)
! CALL collapx (xdensaf, xx3face, x3face)

CALL collapx (xrhojf(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face(0:metlay_sub))
CALL collapx (xwhat(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face(0:metlay_sub))
CALL collapx (x3htf(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face(0:metlay_sub))
CALL collapx (xdensaf(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face(0:metlay_sub))
CALL collapx (xrhojf(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face)
CALL collapx (xwhat(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face)
CALL collapx (x3htf(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face)
CALL collapx (xdensaf(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face)

IF ( lwout > 0 ) THEN
! CALL collapx (xwwind, xx3face, x3face)
CALL collapx (xwwind(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face(0:metlay_sub))
CALL collapx (xwwind(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face)
ENDIF

IF ( ( iftke ) .AND. ( iftkef ) ) THEN ! TKE on full-levels
! CALL collapx (xtke, xx3face, x3face)
CALL collapx (xtke(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face(0:metlay_sub))
CALL collapx (xtke(:,:,0:metlay_sub), xx3face(0:metlay_sub), x3face)
ENDIF

ENDIF
Expand Down Expand Up @@ -1224,10 +1224,10 @@ END SUBROUTINE collapx
! CALL collapx (xuu_d, xx3midl, x3midl)
! CALL collapx (xvv_d, xx3midl, x3midl)

CALL collapx (xuhat_s(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xvhat_t(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xuu_d(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xvv_d(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xuhat_s(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xvhat_t(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xuu_d(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xvv_d(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)



Expand All @@ -1242,8 +1242,8 @@ END SUBROUTINE collapx
ENDDO
! CALL collapx (xuu_s, xx3midl, x3midl)
! CALL collapx (xvv_t, xx3midl, x3midl)
CALL collapx (xuu_s(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xvv_t(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl(1:metlay_sub))
CALL collapx (xuu_s(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
CALL collapx (xvv_t(:,:,1:metlay_sub), xx3midl(1:metlay_sub), x3midl)
ENDIF

ENDIF
Expand Down
2 changes: 1 addition & 1 deletion parallel/src/metvars2ctm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ END SUBROUTINE layht
xpresf(:,:,0) = xprsfc(:,:)

DO k = 1, metlay
xgeof (:,:,k) = xgeof (:,:,k-1) - ((1.0/giwrf) * delz(:,:,k))
xgeof (:,:,k) = xgeof (:,:,k-1) - ((1.0/giwrf) * delz(sc:ec,sr:er,k))
xpresf(:,:,k) = xpresf(:,:,k-1) * &
EXP( (xgeof(:,:,k-1) - xgeof(:,:,k)) / &
(rdwrf * xtempm(:,:,k)) )
Expand Down
Loading

0 comments on commit aabc189

Please sign in to comment.