Skip to content

Commit

Permalink
Ensure that trajectory memory is deallocated
Browse files Browse the repository at this point in the history
- We now deallocate the links in the trajectory chain when packing
  into the i/o buffer. This is in preparation for repeatedly
  calling write_trajectory(), see issue #1.
- No answer changes.
  • Loading branch information
adcroft committed Jul 16, 2015
1 parent 19107e7 commit 150ae95
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions icebergs_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ subroutine write_trajectory(trajectory)
call append_posn(traj4io, this)
this=>this%next
enddo
trajectory => null()
endif
endif

Expand All @@ -869,16 +870,14 @@ subroutine write_trajectory(trajectory)
endif
enddo
else
!Pack and Send trajs to the root pe for this I/O tile
if (associated(trajectory)) then
this=>trajectory
do while (associated(this))
ntrajs_sent_io = ntrajs_sent_io +1
call pack_traj_into_buffer2(this, obuffer_io, ntrajs_sent_io)

this=>this%next
enddo
endif
! Pack and send trajectories to the root PE for this I/O tile
do while (associated(trajectory))
ntrajs_sent_io = ntrajs_sent_io +1
call pack_traj_into_buffer2(trajectory, obuffer_io, ntrajs_sent_io)
this => trajectory ! Need to keep pointer in order to free up the links memory
trajectory => trajectory%next ! This will eventually result in trajectory => null()
deallocate(this) ! Delete the link from memory
enddo

call mpp_send(ntrajs_sent_io, plen=1, to_pe=io_tile_root_pe, tag=COMM_TAG_11)
if (ntrajs_sent_io .gt. 0) then
Expand Down Expand Up @@ -1064,8 +1063,7 @@ subroutine write_trajectory(trajectory)
deallocate(this)
this=>next
enddo
trajectory=>null()


! Finish up
iret = nf_close(ncid)
if (iret .ne. NF_NOERR) write(stderrunit,*) 'diamonds, write_trajectory: nf_close failed',mpp_pe(),filename
Expand Down

0 comments on commit 150ae95

Please sign in to comment.