geoschem / HEMCO

The Harmonized Emissions Component (HEMCO), developed by the GEOS-Chem Support Team.
https://hemco.readthedocs.io
Other
17 stars 33 forks source link

Remove memory leaks in HEMCO core and standalone routines (closes #190) #194

Closed yantosca closed 1 year ago

yantosca commented 1 year ago

This is the companion PR to #190. We have rewritten code in several HEMCO modules to remove memory leaks (which were diagnosed with -DSANITIZE=y).

NOTE: The memory leak in hco_config_mod.F90 (due to the FileData object) has not been solved, despite what the comments say.

Closes #190

yantosca commented 1 year ago

Integration tests revealed an error:

-------------------------------------------------------------------------------
Using HEMCO 3.6.0       

HEMCO precision (hp) is set to is 8-byte real (aka REAL*8)
-------------------------------------------------------------------------------

Reading fields of HEMCO configuration file: HEMCO_Config.rc

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x2b4b02f633ff in ???
#1  0x11eaf02 in addzeroscal
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/HEMCO/src/Core/hco_config_mod.F90:1758
#2  0x11ec15d in addshadowfields
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/HEMCO/src/Core/hco_config_mod.F90:1677
#3  0x11f1d7e in config_readcont
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/HEMCO/src/Core/hco_config_mod.F90:1275
#4  0x11f3bb1 in __hco_config_mod_MOD_config_readfile
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/HEMCO/src/Core/hco_config_mod.F90:367
#5  0x5dfed2 in __hco_interface_gc_mod_MOD_hcoi_gc_init
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/GEOS-Chem/GeosCore/hco_interface_gc_mod.F90:469
#6  0x4e0c48 in __emissions_mod_MOD_emissions_init
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/GEOS-Chem/GeosCore/emissions_mod.F90:117
#7  0x406280 in geos_chem
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/GEOS-Chem/Interfaces/GCClassic/main.F90:691
#8  0x40bb72 in main
    at /n/holyscratch01/jacob_lab/ryantosca/tests/memleak/GCC_memleak/CodeDir/src/GEOS-Chem/Interfaces/GCClassic/main.F90:32
srun: error: holy2c01209: task 0: Segmentation fault (core dumped)

I am investigating further.

yantosca commented 1 year ago

After reverting the hco_config_mod.F90 in commit 78d230d, GEOS-Chem Classic integration tests now pass.

==============================================================================
GEOS-Chem Classic: Execution Test Results

GCClassic #76f9571 GEOS-Chem submod update: Merge PRs #1663, #1669 into version 14.1.1
GEOS-Chem #22c5c0278 Merge PR #1669 (RRTMG diagnostic indexing fix) into 14.1.1
HEMCO     #78d230d Revert hco_config_mod.F90 to prior state (52beff6) but keep new comments

Using 24 OpenMP threads
Number of execution tests: 26

Submitted as SLURM job: 44164630
==============================================================================

Execution tests:
------------------------------------------------------------------------------
gc_05x0625_NA_47L_merra2_CH4........................Execute Simulation....PASS
gc_05x0625_NA_47L_merra2_fullchem...................Execute Simulation....PASS
gc_4x5_47L_merra2_fullchem..........................Execute Simulation....PASS
gc_4x5_47L_merra2_fullchem_TOMAS15..................Execute Simulation....PASS
gc_4x5_47L_merra2_fullchem_TOMAS40..................Execute Simulation....PASS
gc_4x5_merra2_aerosol...............................Execute Simulation....PASS
gc_4x5_merra2_carbon................................Execute Simulation....PASS
gc_4x5_merra2_CH4...................................Execute Simulation....PASS
gc_4x5_merra2_CO2...................................Execute Simulation....PASS
gc_4x5_merra2_fullchem..............................Execute Simulation....PASS
gc_4x5_merra2_fullchem_aciduptake...................Execute Simulation....PASS
gc_4x5_merra2_fullchem_APM..........................Execute Simulation....PASS
gc_4x5_merra2_fullchem_benchmark....................Execute Simulation....PASS
gc_4x5_merra2_fullchem_complexSOA...................Execute Simulation....PASS
gc_4x5_merra2_fullchem_complexSOA_SVPOA.............Execute Simulation....PASS
gc_4x5_merra2_fullchem_LuoWd........................Execute Simulation....PASS
gc_4x5_merra2_fullchem_marinePOA....................Execute Simulation....PASS
gc_4x5_merra2_fullchem_RRTMG........................Execute Simulation....PASS
gc_4x5_merra2_Hg....................................Execute Simulation....PASS
gc_4x5_merra2_metals................................Execute Simulation....PASS
gc_4x5_merra2_POPs_BaP..............................Execute Simulation....PASS
gc_4x5_merra2_tagCH4................................Execute Simulation....PASS
gc_4x5_merra2_tagCO.................................Execute Simulation....PASS
gc_4x5_merra2_tagO3.................................Execute Simulation....PASS
gc_4x5_merra2_TransportTracers......................Execute Simulation....PASS
gc_4x5_merra2_TransportTracers_LuoWd................Execute Simulation....PASS

Summary of test results:
------------------------------------------------------------------------------
Execution tests passed: 26
Execution tests failed: 0
Execution tests not yet completed: 0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  All execution tests passed!  %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

and GCHP integration tests also pass except tagO3, which is a known issue and which will be fixed later.

==============================================================================
GCHP: Execution Test Results

GCClassic #8d3db1a GEOS-Chem submod update: Merge PRs #1663, #1669 into version 14.1.1
GEOS-Chem #22c5c0278 Merge PR #1669 (RRTMG diagnostic indexing fix) into 14.1.1
HEMCO     #78d230d Revert hco_config_mod.F90 to prior state (52beff6) but keep new comments

Number of execution tests: 5

Submitted as SLURM job: 44165605
==============================================================================

Execution tests:
------------------------------------------------------------------------------
gchp_merra2_fullchem................................Execute Simulation....PASS
gchp_merra2_fullchem_benchmark......................Execute Simulation....PASS
gchp_merra2_fullchem_RRTMG..........................Execute Simulation....PASS
gchp_merra2_tagO3...................................Execute Simulation....FAIL
gchp_merra2_TransportTracers........................Execute Simulation....PASS

Summary of test results:
------------------------------------------------------------------------------
Execution tests passed: 4
Execution tests failed: 1
Execution tests not yet completed: 0