Skip to content

Memory leak with RK4 in hurricane simulation #350

Closed

Description

@pwolfram

This memory leak error was identified on the branch at https://github.com/pwolfram/MPAS-Model/tree/coastal/Delaware_gaussian_hump with hash ba4bbdab91052b9ff3474a0540436a0e55fed6e5 for the Sandy Hurricane case and produces an insufficient virtual memory error.

@hrmoncada, I have given you the tgz file with the example case on LANL IC, although you can build it from COMPASS for the ocean/hurricane/USDEQU120at30cr10rr2WD/sandy/ case. Modules and run instructions for IC are detailed below.

Error messages occur after some time (depending upon total number of time steps) and are of the form

forrtl: severe (41): insufficient virtual memory                                
Image              PC                Routine            Line        Source
ocean_model        0000000000E6FE10  for_alloc_allocat     Unknown  Unknown
ocean_model        0000000000749E66  Unknown               Unknown  Unknown
ocean_model        00000000006C577E  Unknown               Unknown  Unknown
ocean_model        00000000007382D0  Unknown               Unknown  Unknown
ocean_model        000000000094972C  Unknown               Unknown  Unknown
ocean_model        00000000006ABD6B  Unknown               Unknown  Unknown
ocean_model        0000000000699590  Unknown               Unknown  Unknown
ocean_model        000000000063EE31  Unknown               Unknown  Unknown
ocean_model        000000000040F277  Unknown               Unknown  Unknown
ocean_model        000000000040F1FE  Unknown               Unknown  Unknown
ocean_model        000000000040F1AE  Unknown               Unknown  Unknown
libc-2.17.so       00002ADC24D273D5  __libc_start_main     Unknown  Unknown
ocean_model        000000000040F0A9  Unknown               Unknown  Unknown
...

This has occurred for a variety of runs (shown below):

dt last stable time stamp
10s 2012-10-05_22:18:50
5s 2012-10-03_11:09:05
25s 2012-10-13_07:43:45
25s 2012-10-13_08:22:55
25s restart (from above) 2012-10-25_08:30:25

This was experienced on 360 processors for 51536 cells, or ~143 cells / proc.

As you can see, this is a memory leak because the failure time depends on the time step and it is possible to advance the simulation via a restart.

I'm running with the following approach and modules:

#!/bin/bash
#SBATCH --account=XYZ
#SBATCH --job-name=XYZ
#SBATCH --qos=interactive
#SBATCH --time=4:00:00
#SBATCH --output=run.o%j
#SBATCH --nodes=10
#SBATCH --error=run.e%j
#SBATCH [email protected]
#SBATCH --mail-type=all

# Modules for grizzly
source ~/module_source_gr.sh

gpmetis graph.info 360
srun -n 360 ./ocean_model -n namelist.ocean -s streams.ocean

where module_source_gr.sh is

#!/bin/bash
module purge

module use /usr/projects/climate/SHARED_CLIMATE/modulefiles/all/

echo "loading modules anaconda, intel, openmpi, netcdf, pnetcdf, pio for grizzly"
module load intel/17.0.1 openmpi/1.10.5 netcdf/4.4.1 parallel-netcdf/1.5.0 pio/1.7.2
source /usr/projects/climate/SHARED_CLIMATE/anaconda_envs/base/etc/profile.d/conda.sh
conda activate compass_py3.7

alias metis=gpmetis

@hrmoncada, posting images of your output from valgrind will help us see where the memory leak is and that will help us trace it to the exact line of code where memory is allocated.

cc @mark-petersen and @sbrus89

Activity

  1. hrmoncada commented on Aug 28, 2019

    @hrmoncada

    Cool I will look that issue

  2. pwolfram commented on Aug 28, 2019

    @pwolfram
    ContributorAuthor

    Thanks @hrmoncada! I should also note that I would expect this issue to be independent of this branch, but the branch is needed to run the test case to demonstrate it.

  3. pwolfram commented on Aug 29, 2019

    @pwolfram
    ContributorAuthor

    This is related to #137, which I'm not sure entirely should be closed yet. We tested again in the hurricane case without wetting and drying and had better success with stability, indicating that a large part of the memory leak problem was fixed. However, it eventually did die (at days vs hr simulation scales), which indicates that if there were a few memory leaks found last time that weren't fixed my guess is that these would be great places to start as culprits.

  4. mark-petersen commented on Sep 5, 2019

    @mark-petersen
    Contributor

    @hrmoncada any progress on this? Please tell us if you are stuck on something. Totalview should tell us where the memory leak is.

  5. hrmoncada commented on Sep 5, 2019

    @hrmoncada
  6. pwolfram commented on Sep 5, 2019

    @pwolfram
    ContributorAuthor

    @mark-petersen, @hrmoncada is going to evaluate this case with 4 processors.

  7. mark-petersen commented on Sep 9, 2019

    @mark-petersen
    Contributor

    @hrmoncada sent this:
    image

    The trace implies that the problem is a memory leak in pio. @pwolfram please rerun your test case with all output streams off, and see if it runs past the previous time when it died with "out of memory" error. Of course, pio should not have a memory leak, but it is possible.

  8. pwolfram commented on Sep 9, 2019

    @pwolfram
    ContributorAuthor

    @mark-petersen, I can try this but am very skeptical. Why don't we see this issue in split_explicit, for example? I suppose there could be a difference in usage pattern but do find this confusing.

    Will run the case as you propose but would appreciate hearing your ideas as I think about this in the meantime. Any hints from your experience that would be aligned with this type of issue would be really helpful.

  9. hrmoncada commented on Sep 9, 2019

    @hrmoncada

    Screenshot from 2019-09-09 12-24-04
    @pwolfram, I run again the test case but this take a took a snapshot of the HEAP memory on run time, before end to complete the calculation.

  10. mark-petersen commented on Sep 9, 2019

    @mark-petersen
    Contributor

    box_rearrange.F90 is a PIO subroutine:
    http://mermaid.uconn.edu/cesm_climatology/CESM_code/cesm1_1_1/models/utils/pio/box_rearrange.F90.in
    @pwolfram maybe we need to play with the i/o flags to try to avoid this error. First turn off output altogether. We can also play with:

    config_pio_num_iotasks = 0
    config_pio_stride = 1
    

    and the output format.

  11. pwolfram commented on Sep 10, 2019

    @pwolfram
    ContributorAuthor

    @mark-petersen, I made the output frequency for the streams ten-times less frequent and reran, with the outcome of getting the same crash near about the same time happening.

    I'll try again with the streams output_interval='none' and report back...

  12. pwolfram commented on Sep 10, 2019

    @pwolfram
    ContributorAuthor

    Note, for the record this is with the default values of

         config_pio_num_iotasks = 0 
         config_pio_stride = 1
    
  13. mark-petersen commented on Sep 10, 2019

    @mark-petersen
    Contributor

    OK. Then that line of the memory report is most likely a red herring.

  14. 10 remaining items

  15. mark-petersen commented on Sep 12, 2019

    @mark-petersen
    Contributor

    @pwolfram, I can confirm your memory leak. Thanks for setting up your test problem.

    I'm running this on IC with intel, DEBUG=true OPENMP=true. OMP_NUM_THREADS=1.
    I'm running on one node, 36 cores, with your branch and tar file above, except I put a simple loop around your code in last comment, and it dies on iteration 26075.

    Looking into it now...

  16. pwolfram commented on Sep 12, 2019

    @pwolfram
    ContributorAuthor

    @jonbob, I tried your suggestion of

             call mpas_pool_create_pool(provisStatePool)
             call mpas_pool_clone_pool(statePool, provisStatePool, 1)
             call mpas_pool_empty_pool(provisStatePool)
             call mpas_pool_destroy_pool(provisStatePool)
    

    and interestingly, it appears to makes the memory leak even worse.

    Furthermore, it isn't completely clear to me the difference between empty_pool (18s wall clock to crash) and destroy_pool (10.5min) because what we really want in the loop is a full deallocation of the pool and its data structures. If I recall correctly empty_pool removes the pointers to memory locations whereas destroy_pool actually deallocates the memory locations themselves and then the pointers, albeit apparently incompletely in our code snipet above, unless we are missing another high-level API call in the RK4 loop. Note, a destroy_pool following an empty_pool still has a larger leak as a consequence (because of hanging memory locations).

  17. pwolfram commented on Sep 12, 2019

    @pwolfram
    ContributorAuthor

    @mark-petersen, thanks for taking a look!

  18. pwolfram commented on Sep 14, 2019

    @pwolfram
    ContributorAuthor

    @mark-petersen, it gets out to 16 days with this fix, which is only marginally better than 13 days, indicating that some of the leak was fixed but it doesn't appear to be the lion's share of the leak.

  19. pwolfram commented on Sep 15, 2019

    @pwolfram
    ContributorAuthor

    What is also more troubling is that it is now a hard crash vs an insufficient virtual memory error.

  20. pwolfram commented on Sep 15, 2019

    @pwolfram
    ContributorAuthor

    We also need to check performance-- I think this has made the code slower too although it now nearly runs for a full 4 hr cycle.

  21. mark-petersen commented on Sep 16, 2019

    @mark-petersen
    Contributor

    Wow, it's really disturbing that changing to a more complete 'deallocate' function makes the code run slower. That really makes me think that we should have permanent memory allocated for RK4 "provis" data, rather than the current clone pool and then destroy pool.

  22. pwolfram commented on Oct 31, 2019

    @pwolfram
    ContributorAuthor

    @mgduda's fix proposed in the thread at #367 is working so far based on our checks to resolve the issues; are verifying (with @sbrus89) with more robust cases to stress-test. Thanks @mgduda and @mark-petersen for your engagement on these fixes!

  23. added a commit that references this issue on Nov 14, 2019
    ca984d5
  24. pwolfram commented on Jan 15, 2020

    @pwolfram
    ContributorAuthor

    Thank you everyone! I believe this issue is now fully resolved and am closing.

  25. added a commit that references this issue on Jul 21, 2020
    2468116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions