Skip to content

Commit

Permalink
Merge pull request #1 from Goddard-Fortran-Ecosystem/develop
Browse files Browse the repository at this point in the history
sync with Tom's develop
  • Loading branch information
weiyuan-jiang authored Aug 6, 2020
2 parents 9b67b95 + 3ea71ac commit 977e577
Show file tree
Hide file tree
Showing 15 changed files with 104 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.2
LANGUAGES Fortran)

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

## [Unreleased]

## [1.4.2] - 2020-05-20

### Changed

- Modified name of Pair type in gFTL maps. These are not used within
pFlogger outside of their host modules, but it is more consistent with
the latest gFTL-shared and may help anyone that tries to port with XLF.


## [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
6 changes: 5 additions & 1 deletion src/MpiLock.F90
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
! Based upon
! http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113.30&rep=rep1&type=pdf

module PFL_MpiLock
use mpi
use PFL_AbstractLock
Expand Down Expand Up @@ -182,7 +185,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
2 changes: 2 additions & 0 deletions src/StringAbstractLoggerPolyMap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ module PFL_StringAbstractLoggerPolyMap

#define _map LoggerMap
#define _iterator LoggerIterator
#define _pair StringLoggerPair
#include "types/key_deferredLengthString.inc"

#define _value class(AbstractLogger)
#define _value_allocatable
#define _value_equal_defined


#define _alt
#define _pair_allocatable
#include "templates/map.inc"
Expand Down
1 change: 1 addition & 0 deletions src/StringFilterMap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
module PFL_StringFilterMap
use PFL_AbstractFilter
#define _map FilterMap
#define _pair FilterPair
#define _iterator FilterIterator

#include "types/key_deferredLengthString.inc"
Expand Down
1 change: 1 addition & 0 deletions src/StringFormatterMap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
module PFL_StringFormatterMap
use PFL_Formatter
#define _map FormatterMap
#define _pair FormatterPair
#define _iterator FormatterIterator

#include "types/key_deferredLengthString.inc"
Expand Down
1 change: 1 addition & 0 deletions src/StringHandlerMap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
module PFL_StringHandlerMap
use PFL_AbstractHandler
#define _map HandlerMap
#define _pair HandlerPair
#define _iterator HandlerIterator

#include "types/key_deferredLengthString.inc"
Expand Down
1 change: 1 addition & 0 deletions src/StringLockMap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
module PFL_StringLockMap
use PFL_AbstractLock
#define _map LockMap
#define _pair LockPair
#define _iterator LockIterator

#include "types/key_deferredLengthString.inc"
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 977e577

Please sign in to comment.