Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix remaining memory leaks in HEMCO #255

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased 3.8.0] - TBD
### Changed
- Updated TOMAS_Jeagle sea salt extension

### Fixed
- Updated IsModelLevel check for CESM and WRF-GC

## [3.7.2] - 2023-12-01
### Added
- Script `.release/changeVersionNumbers.sh` to change version numbers before a new HEMCO release
Expand Down Expand Up @@ -111,14 +118,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [3.5.2] - 2022-11-29
### Added
- Added sanitizer option for detecting memory leaks in HEMCO
standalone during build
- Added sanitizer option for detecting memory leaks in HEMCO standalone during build

### Changed
- Remove unused, commented-out code in `src/Extensions/hcox_dustdead_mod.F`
- Replaced placeholder error messages in
`src/Core/hco_config_mod.F90` with more informational messages
(often including the line of the HEMCO_Config.rc in the printout)
- Replaced placeholder error messages in `src/Core/hco_config_mod.F90` with more informational messages (often including the line of the HEMCO_Config.rc in the printout)
- Added improved documentation for time cycle flag `EFYO` in ReadTheDocs

### Fixed
Expand All @@ -132,8 +136,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Support for MAPL 2.16 (needed by GCHP and GEOS)
- Bug fix for HEMCO standalone run directory creation
- Bug fix: If HEMCO masks are specified as `lon1/lat1/lon2/lat2`,
then don't try to read from disk
- Bug fix: If HEMCO masks are specified as `lon1/lat1/lon2/lat2`, then don't try to read from disk
- Documentation from the GEOS-Chem wiki (now on ReadTheDocs)
- Badges for the ReadTheDocs front page
- Bug fix for masking issues in MPI environment (for WRF, CESM)
Expand Down Expand Up @@ -276,6 +279,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bug fix for distributing emissions in the vertical dimension
- New error checks in the HEMCO standalone module
- Bug fix for `ifort` compiler in soil NOx extension

### Removed
- Null string character from netCDF unit string

Expand All @@ -291,8 +295,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2.1.004] - 2017-12-30
### Added
- Updates to remove possible issues and excessive print statements when
operating in GEOS environment
- Updates to remove possible issues and excessive print statements when operating in GEOS environment
- Fixed possible tracer ID mismatch in sea salt extension
- New option to normalize MEGAN LAI, HEMCO diagnostics
- Now write multiple time slices into one file
Expand Down Expand Up @@ -375,8 +378,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.1.009] - 2015-09-10
### Added
- Bug fixes to allow specifying flexible diagnostics output
frequencies.
- Bug fixes to allow specifying flexible diagnostics output frequencies.

## [1.1.008] - 2015-07-06
### Added
Expand Down
28 changes: 28 additions & 0 deletions src/Core/hco_arr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,9 @@ SUBROUTINE HCO_ArrCleanup_2D_Hp( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_2D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1685,6 +1688,9 @@ SUBROUTINE HCO_ArrCleanup_2D_Sp( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_2D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1732,6 +1738,9 @@ SUBROUTINE HCO_ArrCleanup_2D_I( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_2D_I
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1778,6 +1787,10 @@ SUBROUTINE HCO_ArrCleanup_3D_Hp( Arr, DeepClean )
CALL HCO_ValCleanup( Arr%Val, Arr%Alloc, DeepClean=DC )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_3D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1825,6 +1838,9 @@ SUBROUTINE HCO_ArrCleanup_3D_Sp( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_3D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1876,6 +1892,9 @@ SUBROUTINE HCO_ArrVecCleanup_2D_Hp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_2D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1927,6 +1946,9 @@ SUBROUTINE HCO_ArrVecCleanup_2D_Sp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_2D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1978,6 +2000,9 @@ SUBROUTINE HCO_ArrVecCleanup_3D_Hp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_3D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -2029,6 +2054,9 @@ SUBROUTINE HCO_ArrVecCleanup_3D_Sp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_3D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion src/Core/hco_tidx_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ SUBROUTINE tIDx_Cleanup( AlltIDx )
! tIDx_Cleanup begins here!
!======================================================================

! Deallocate fields
IF ( ASSOCIATED( AlltIDx ) ) THEN

IF ( ASSOCIATED(AlltIDx%CONSTANT) ) THEN
Expand All @@ -307,9 +308,18 @@ SUBROUTINE tIDx_Cleanup( AlltIDx )
DEALLOCATE(AlltIDx%MONTHLY)
ENDIF

! Also deallocate AlltIDx pointer
! Nullify fields
AlltIDx%CONSTANT => NULL()
AlltIDx%HOURLY => NULL()
AlltIDx%HOURLY_GRID => NULL()
AlltIDx%WEEKDAY => NULL()
AlltIDx%MONTHLY => NULL()

! Deallocate container
DEALLOCATE( AlltIDx )
ENDIF

! Make sure we return a null pointer
AlltIDx => NULL()

END SUBROUTINE tIDx_Cleanup
Expand Down
27 changes: 27 additions & 0 deletions src/Core/hcoio_read_std_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,39 @@ SUBROUTINE HCOIO_Read( HcoState, Lct, RC )
! going to 72 levels. Otherwise, use MESSy (nbalasus, 8/24/2023).
IF ( Lct%Dct%Dta%Levels == 0 ) THEN

#if defined( MODEL_CESM ) || defined( MODEL_WRF )

! In WRF/CESM, IsModelLevel has a different meaning of "GEOS-Chem levels"
! because the models in WRF and CESM are user-defined and thus fixed input
! files would never be on the model level. In this case, a check is added
! in order to match the file with known GEOS-Chem levels, and if so, the
! data will be handled later in this file accordingly to be vertically
! regridded to the runtime model levels using MESSy.
! This fixes a regression from the vertical regridding fixes in 3.7.1.
!
! The meaning of "is model levels" in WRF and CESM are different.
! Model levels can be changed and thus data is never on the model level.
! In this case, IsModelLevel means that the data is on standard
! GEOS-Chem levels, and if so, the data will be handled accordingly
! using a hard-coded set of GEOS-Chem levels to be interpolated using MESSy.
! (hplin, 10/15/23)
IF ( TRIM(LevUnit) == "level" .or. TRIM(LevUnit) == "GEOS-Chem level" ) THEN
! the below check will be obsolete and is unmaintainable, but would be consistent with ModelLev_Check.
! it is more robust to check for the explicit intention of LevUnit
! nlev == 47 .or. nlev == 48 .or. nlev == 36 .or. nlev == 72 .or. nlev == 73 ) THEN
IsModelLevel = .true.
ENDIF

#else

CALL ModelLev_Check( HcoState, nlev, IsModelLevel, RC )
IF ( RC /= HCO_SUCCESS ) THEN
CALL HCO_ERROR( 'ERROR 3', RC, THISLOC=LOC )
RETURN
ENDIF

#endif

! Set level indeces to be read
lev1 = 1
lev2 = nlev
Expand Down
18 changes: 9 additions & 9 deletions src/Extensions/hcox_tomas_dustdead_mod.F
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,15 @@ SUBROUTINE HCOX_TOMAS_DustDead_Run( ExtState, HcoState, RC )

! Get the proper species name
!%%% This is a kludge, do better later %%%
IF ( N==1 ) SpcName = 'NK1'
IF ( N==2 ) SpcName = 'NK2'
IF ( N==3 ) SpcName = 'NK3'
IF ( N==4 ) SpcName = 'NK4'
IF ( N==5 ) SpcName = 'NK5'
IF ( N==6 ) SpcName = 'NK6'
IF ( N==7 ) SpcName = 'NK7'
IF ( N==8 ) SpcName = 'NK8'
IF ( N==9 ) SpcName = 'NK9'
IF ( N==1 ) SpcName = 'NK01'
IF ( N==2 ) SpcName = 'NK02'
IF ( N==3 ) SpcName = 'NK03'
IF ( N==4 ) SpcName = 'NK04'
IF ( N==5 ) SpcName = 'NK05'
IF ( N==6 ) SpcName = 'NK06'
IF ( N==7 ) SpcName = 'NK07'
IF ( N==8 ) SpcName = 'NK08'
IF ( N==9 ) SpcName = 'NK09'
IF ( N==10 ) SpcName = 'NK10'
IF ( N==11 ) SpcName = 'NK11'
IF ( N==12 ) SpcName = 'NK12'
Expand Down
Loading