Skip to content

Commit

Permalink
Merge pull request #29 from Goddard-Fortran-Ecosystem/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tclune authored May 1, 2020
2 parents 3165f91 + f55680e commit 612a1e1
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# ------------------------------------------------------------------------ #
cmake_minimum_required (VERSION 3.8.0)
project (PFLOGGER
VERSION 1.4.0
VERSION 1.4.1
LANGUAGES Fortran)

set (CMAKE_MODULE_PATH
Expand Down
9 changes: 9 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.1] - 2020-05-01

### Added
- Added free() methods to various classes to ensure that MPI resources
are deleted at the end of the run. Without this, some MPI flavors
will report an error on MPI_Finalize(). To use:

call logging%free

## [1.4.0] - 2020-04-17

### Added
Expand Down
6 changes: 6 additions & 0 deletions src/AbstractHandler.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module PFL_AbstractHandler
procedure :: handle
procedure(close), deferred :: close
procedure(flush), deferred :: flush
procedure(free), deferred :: free
procedure :: set_formatter
procedure :: format
procedure :: set_level
Expand Down Expand Up @@ -80,6 +81,11 @@ subroutine flush(this)
class(AbstractHandler), intent(in) :: this
end subroutine flush

subroutine free(this)
import AbstractHandler
class(AbstractHandler), intent(inout) :: this
end subroutine free

logical function equal(a, b)
import AbstractHandler
class (AbstractHandler), intent(in) :: a
Expand Down
9 changes: 9 additions & 0 deletions src/AbstractLogger.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ module PFL_AbstractLogger
public :: AbstractLogger

type, abstract, extends(Filterer) :: AbstractLogger
contains
procedure :: free
end type AbstractLogger

contains

! no op
subroutine free(this)
class(AbstractLogger), intent(inout) :: this
end subroutine free

end module PFL_AbstractLogger
11 changes: 11 additions & 0 deletions src/FileHandler.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module PFL_FileHandler
procedure :: equal
procedure :: set_lock
procedure :: is_lockable
procedure :: free
end type FileHandler

interface FileHandler
Expand Down Expand Up @@ -275,4 +276,14 @@ subroutine set_lock(this, lock)

end subroutine set_lock

subroutine free(this)
class (FileHandler), intent(inout) :: this

if (this%is_lockable()) then
call this%lock%destroy()
deallocate(this%lock)
end if

end subroutine free

end module PFL_FileHandler
19 changes: 19 additions & 0 deletions src/Logger.F90
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module PFL_Logger
procedure :: get_parent
procedure :: set_propagate
procedure :: get_propagate
procedure :: free
end type Logger

interface Logger
Expand Down Expand Up @@ -171,6 +172,21 @@ subroutine add_handler(this, handler)

end subroutine add_handler

subroutine free(this)
class (Logger), intent(inout) :: this
class (AbstractHandler), pointer :: handler

type (HandlerVectorIterator) :: iter

iter = this%handlers%begin()
do while (iter /= this%handlers%end())
handler => iter%get()
call handler%free()
call iter%next()
end do

end subroutine free


!---------------------------------------------------------------------------
!*ROUTINE: remove_handler
Expand All @@ -181,10 +197,13 @@ subroutine remove_handler(this, handler)
class (Logger), intent(inout) :: this
class (AbstractHandler), intent(in) :: handler

class (AbstractHandler), pointer :: hdlerPtr
integer :: i

i = this%handlers%get_index(handler)
if (i > 0) then
hdlerPtr=>this%handlers%at(i)
call hdlerPtr%free()
call this%handlers%erase(this%handlers%begin() + i - 1)
else
! Only can get here if handler not found
Expand Down
19 changes: 19 additions & 0 deletions src/LoggerManager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module PFL_LoggerManager
procedure :: build_root_logger
procedure :: basic_config

procedure :: free
end type LoggerManager


Expand Down Expand Up @@ -487,4 +488,22 @@ subroutine basic_config(this, unusable, filename, level, stream, force, handlers

end subroutine basic_config

subroutine free(this)
class(LoggerManager), intent(inout) :: this
character(len=:), allocatable :: name
type(LoggerIterator) :: iter
class(AbstractLogger), pointer :: loggerPtr

iter = this%loggers%begin()
do while (iter /= this%loggers%end())
name = iter%key()
loggerPtr=> this%loggers%at(name)
call loggerPtr%free()
call iter%next()
enddo

call this%root_node%free()

end subroutine free

end module PFL_LoggerManager
3 changes: 2 additions & 1 deletion src/MpiLock.F90
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ subroutine destroy(this)
call MPI_Free_mem(scratchpad, ierror)
end if

call MPI_Comm_free(this%comm, ierror)
!W.J comment out. Does this comm belong to this lock? Maybe not
!call MPI_Comm_free(this%comm, ierror)

end subroutine destroy

Expand Down
6 changes: 6 additions & 0 deletions src/StreamHandler.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module PFL_StreamHandler
procedure :: set_unit
procedure :: emit_message
procedure :: close ! noop
procedure :: free ! noop
procedure :: flush => flush_unit
procedure :: equal
end type StreamHandler
Expand Down Expand Up @@ -143,6 +144,11 @@ subroutine close(this)
class (StreamHandler), intent(inout) :: this
end subroutine close

! A no-op routine.
!---------------------------------------------------------------------------
subroutine free(this)
class (StreamHandler), intent(inout) :: this
end subroutine free

!---------------------------------------------------------------------------
! FUNCTION:
Expand Down
4 changes: 4 additions & 0 deletions tests/MockHandler.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module MockHandler_mod
contains
procedure :: emit_message
procedure :: close ! noop
procedure :: free ! noop
procedure :: flush => flushUnit
procedure :: equal
end type MockHandler
Expand Down Expand Up @@ -72,6 +73,9 @@ subroutine close(this)
class (MockHandler), intent(inout) :: this
end subroutine close

subroutine free(this)
class(MockHandler), intent(inout) :: this
end subroutine free

logical function equal(a, b)
class (MockHandler), intent(in) :: a
Expand Down

0 comments on commit 612a1e1

Please sign in to comment.