Skip to content

Commit

Permalink
fix deallocation issue when dbug_flag>5
Browse files Browse the repository at this point in the history
* delay the deallocation of gindex arrays until after the diagnose_mesh
routine is called. This only impacts cases where dbug_flag>5, compiled
with gnu+debug
  • Loading branch information
DeniseWorthen committed Oct 22, 2024
1 parent 6f28c27 commit 06c2099
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions model/src/wav_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,6 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! create distGrid from global index array of sea points with no ghost points
DistGrid = ESMF_DistGridCreate(arbSeqIndexList=gindex_sea, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
deallocate(gindex_sea)
else
! create a global index array for non-sea (i.e. land points)
allocate(mask_global(nx*ny), mask_local(nx*ny))
Expand Down Expand Up @@ -884,8 +883,6 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
gindex(ncnt) = gindex_lnd(ncnt-nseal_cpl)
end if
end do
deallocate(gindex_sea)
deallocate(gindex_lnd)

! create distGrid from global index array
DistGrid = ESMF_DistGridCreate(arbSeqIndexList=gindex, rc=rc)
Expand All @@ -895,14 +892,23 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! get the mesh file name
call NUOPC_CompAttributeGet(gcomp, name='mesh_wav', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! read in the mesh with the above DistGrid
! read in the mesh with the the DistGrid
EMesh = ESMF_MeshCreate(filename=trim(cvalue), fileformat=ESMF_FILEFORMAT_ESMFMESH, &
elementDistgrid=Distgrid,rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (dbug_flag > 5) then
call diagnose_mesh(EMesh, size(gindex), 'EMesh', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (unstr_mesh) then
call diagnose_mesh(EMesh, size(gindex_sea), 'EMesh', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
deallocate(gindex_sea)
else
call diagnose_mesh(EMesh, size(gindex), 'EMesh', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
deallocate(gindex)
deallocate(gindex_sea)
deallocate(gindex_lnd)
end if
end if

if (.not. unstr_mesh) then
Expand Down Expand Up @@ -934,7 +940,6 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
deallocate(meshmask)
deallocate(gindex)
end if

if (dbug_flag > 5) then
Expand Down

0 comments on commit 06c2099

Please sign in to comment.