ApplicationSupport.F90 Source File


This file depends on

sourcefile~~applicationsupport.f90~~EfferentGraph sourcefile~applicationsupport.f90 ApplicationSupport.F90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~applicationsupport.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_keywordenforcer.f90 MAPL_KeywordEnforcer.F90 sourcefile~applicationsupport.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~mapl_profiler.f90~2 MAPL_Profiler.F90 sourcefile~applicationsupport.f90->sourcefile~mapl_profiler.f90~2 sourcefile~pflogger_stub.f90 pflogger_stub.F90 sourcefile~applicationsupport.f90->sourcefile~pflogger_stub.f90 sourcefile~simulationtime.f90 SimulationTime.F90 sourcefile~applicationsupport.f90->sourcefile~simulationtime.f90

Files dependent on this one

sourcefile~~applicationsupport.f90~~AfferentGraph sourcefile~applicationsupport.f90 ApplicationSupport.F90 sourcefile~base.f90 Base.F90 sourcefile~base.f90->sourcefile~applicationsupport.f90 sourcefile~extdatadrivermod.f90 ExtDataDriverMod.F90 sourcefile~extdatadrivermod.f90->sourcefile~applicationsupport.f90 sourcefile~mapl.f90 MAPL.F90 sourcefile~extdatadrivermod.f90->sourcefile~mapl.f90 sourcefile~extdatadrivergridcomp.f90 ExtDataDriverGridComp.F90 sourcefile~extdatadrivermod.f90->sourcefile~extdatadrivergridcomp.f90 sourcefile~extdataroot_gridcomp.f90 ExtDataRoot_GridComp.F90 sourcefile~extdatadrivermod.f90->sourcefile~extdataroot_gridcomp.f90 sourcefile~mapl_bundleio_test.f90 mapl_bundleio_test.F90 sourcefile~mapl_bundleio_test.f90->sourcefile~applicationsupport.f90 sourcefile~mapl_cap.f90 MAPL_Cap.F90 sourcefile~mapl_cap.f90->sourcefile~applicationsupport.f90 sourcefile~regrid_util.f90 Regrid_Util.F90 sourcefile~regrid_util.f90->sourcefile~applicationsupport.f90 sourcefile~regrid_util.f90->sourcefile~mapl.f90 sourcefile~extdatadriver.f90 ExtDataDriver.F90 sourcefile~extdatadriver.f90->sourcefile~extdatadrivermod.f90 sourcefile~extdatadriver.f90->sourcefile~mapl.f90 sourcefile~extdatadriver.f90->sourcefile~extdatadrivergridcomp.f90 sourcefile~extdatadriver.f90->sourcefile~extdataroot_gridcomp.f90 sourcefile~mapl.f90->sourcefile~base.f90 sourcefile~mapl_gridcomps.f90 MAPL_GridComps.F90 sourcefile~mapl.f90->sourcefile~mapl_gridcomps.f90 sourcefile~mapl_gridcomps.f90->sourcefile~mapl_cap.f90 sourcefile~mapl_nuopcwrappermod.f90 MAPL_NUOPCWrapperMod.F90 sourcefile~mapl_nuopcwrappermod.f90->sourcefile~base.f90 sourcefile~mapl_nuopcwrappermod.f90->sourcefile~mapl_cap.f90 sourcefile~test_cfio_bundle.pf Test_CFIO_Bundle.pf sourcefile~test_cfio_bundle.pf->sourcefile~base.f90 sourcefile~tstqsat.f90 tstqsat.F90 sourcefile~tstqsat.f90->sourcefile~base.f90 sourcefile~ut_extdata.f90 ut_ExtData.F90 sourcefile~ut_extdata.f90->sourcefile~base.f90 sourcefile~utcfio_bundle.f90 utCFIO_Bundle.F90 sourcefile~utcfio_bundle.f90->sourcefile~base.f90 sourcefile~capdriver.f90 CapDriver.F90 sourcefile~capdriver.f90->sourcefile~mapl.f90 sourcefile~capdriver.f90->sourcefile~extdataroot_gridcomp.f90 sourcefile~comp_testing_driver.f90 Comp_Testing_Driver.F90 sourcefile~comp_testing_driver.f90->sourcefile~mapl.f90 sourcefile~extdatadrivergridcomp.f90->sourcefile~mapl.f90 sourcefile~extdataroot_gridcomp.f90->sourcefile~mapl.f90 sourcefile~varspecdescription.f90 VarspecDescription.F90 sourcefile~extdataroot_gridcomp.f90->sourcefile~varspecdescription.f90 sourcefile~mapl_demo_fargparse.f90 MAPL_demo_fargparse.F90 sourcefile~mapl_demo_fargparse.f90->sourcefile~mapl.f90 sourcefile~pfio_mapl_demo.f90 pfio_MAPL_demo.F90 sourcefile~pfio_mapl_demo.f90->sourcefile~mapl.f90 sourcefile~time_ave_util.f90 time_ave_util.F90 sourcefile~time_ave_util.f90->sourcefile~mapl.f90 sourcefile~varspecdescription.f90->sourcefile~mapl.f90

Source Code

#include "MAPL_ErrLog.h"
module MAPL_ApplicationSupport
 use MPI
 use MAPL_ExceptionHandling
 use MAPL_KeywordEnforcerMod
 use pflogger, only: logging
 use pflogger, only: Logger
 use MAPL_Profiler, initialize_profiler =>initialize, finalize_profiler =>finalize

 implicit none
 private

 public MAPL_Initialize
 public MAPL_Finalize

 contains

   subroutine MAPL_Initialize(unusable,comm,logging_config,rc)
      class (KeywordEnforcer), optional, intent(in) :: unusable
      integer, optional, intent(in) :: comm
      character(len=*), optional,intent(in) :: logging_config
      integer, optional, intent(out) :: rc

      character(:), allocatable :: logging_configuration_file
      integer :: comm_world,status

      _UNUSED_DUMMY(unusable)

      if (present(logging_config)) then
         logging_configuration_file=logging_config
      else
         logging_configuration_file=''
      end if
      if (present(comm)) then
         comm_world = comm
      else
         comm_world=MPI_COMM_WORLD
      end if
#ifdef BUILD_WITH_PFLOGGER
      call initialize_pflogger(comm=comm_world,logging_config=logging_configuration_file,rc=status)
      _VERIFY(status)
#endif
      call initialize_profiler(comm=comm_world)
      call start_global_time_profiler(rc=status)
      _VERIFY(status)
      _RETURN(_SUCCESS)

   end subroutine MAPL_Initialize

   subroutine MAPL_Finalize(unusable,comm,rc)
      class (KeywordEnforcer), optional, intent(in) :: unusable
      integer, optional, intent(in) :: comm
      integer, optional, intent(out) :: rc

      integer :: comm_world,status

      _UNUSED_DUMMY(unusable)

      if (present(comm)) then
         comm_world = comm
      else
         comm_world=MPI_COMM_WORLD
      end if
      call stop_global_time_profiler(rc=status)
      _VERIFY(status)
      call report_global_profiler(comm=comm_world)
      call finalize_profiler()
      call finalize_pflogger()
      _RETURN(_SUCCESS)

   end subroutine MAPL_Finalize

   subroutine finalize_pflogger()
      call logging%free()
   end subroutine finalize_pflogger

#ifdef BUILD_WITH_PFLOGGER
   subroutine initialize_pflogger(unusable,comm,logging_config,rc)
      use pflogger, only: pfl_initialize => initialize
      use pflogger, only: StreamHandler, FileHandler, HandlerVector
      use pflogger, only: MpiLock, MpiFormatter
      use pflogger, only: INFO, WARNING
      use PFL_Formatter, only: get_sim_time
      use mapl_SimulationTime, only: fill_time_dict

      use, intrinsic :: iso_fortran_env, only: OUTPUT_UNIT

      class (KeywordEnforcer), optional, intent(in) :: unusable
      integer, optional, intent(in) :: comm
      character(len=*), optional,intent(in) :: logging_config
      integer, optional, intent(out) :: rc

      type (HandlerVector) :: handlers
      type (StreamHandler) :: console
      type (FileHandler) :: file_handler
      integer :: level,rank,status
      character(:), allocatable :: logging_configuration_file
      integer :: comm_world
      type(Logger), pointer :: lgr

      _UNUSED_DUMMY(unusable)
      if (present(logging_config)) then
         logging_configuration_file=logging_config
      else
         logging_configuration_file=''
      end if
      if (present(comm)) then
         comm_world = comm
      else
         comm_world=MPI_COMM_WORLD
      end if

      call pfl_initialize()
      get_sim_time => fill_time_dict

      if (logging_configuration_file /= '') then
         call logging%load_file(logging_configuration_file)
      else

         call MPI_COMM_Rank(comm_world,rank,status)
         _VERIFY(status)
         console = StreamHandler(OUTPUT_UNIT)
         call console%set_level(INFO)
         call console%set_formatter(MpiFormatter(comm_world, fmt='%(short_name)a10~: %(message)a'))
         call handlers%push_back(console)

         file_handler = FileHandler('warnings_and_errors.log')
         call file_handler%set_level(WARNING)
         call file_handler%set_formatter(MpiFormatter(comm_world, fmt='pe=%(mpi_rank)i5.5~: %(short_name)a~: %(message)a'))
         call file_handler%set_lock(MpiLock(comm_world))
         call handlers%push_back(file_handler)

         if (rank == 0) then
            level = INFO
         else
            level = WARNING
         end if

         call logging%basic_config(level=level, handlers=handlers, rc=status)
         _VERIFY(status)

         if (rank == 0) then
            lgr => logging%get_logger('MAPL')
            call lgr%warning('No configure file specified for logging layer.  Using defaults.')
         end if

      end if
      _RETURN(_SUCCESS)

   end subroutine initialize_pflogger
#endif

   subroutine report_global_profiler(unusable,comm,rc)
      class (KeywordEnforcer), optional, intent(in) :: unusable
      integer, optional, intent(in) :: comm
      integer, optional, intent(out) :: rc
      type (ProfileReporter) :: reporter
      integer :: i, world_comm
      character(:), allocatable :: report_lines(:)
      type (MultiColumn) :: inclusive
      type (MultiColumn) :: exclusive
      integer :: npes, my_rank, ierror
      character(1) :: empty(0)
      class (BaseProfiler), pointer :: t_p
      type(Logger), pointer :: lgr

      _UNUSED_DUMMY(unusable)
      if (present(comm)) then
         world_comm = comm
      else
         world_comm=MPI_COMM_WORLD
      end if
      t_p => get_global_time_profiler()

      reporter = ProfileReporter(empty)
      call reporter%add_column(NameColumn(50, separator= " "))
      call reporter%add_column(FormattedTextColumn('#-cycles','(i8.0)', 8, NumCyclesColumn(),separator='-'))

      inclusive = MultiColumn(['Inclusive'], separator='=')
      call inclusive%add_column(FormattedTextColumn(' T (sec) ','(f9.3)', 9, InclusiveColumn(), separator='-'))
      call inclusive%add_column(FormattedTextColumn('   %  ','(f6.2)', 6, PercentageColumn(InclusiveColumn(),'MAX'),separator='-'))
      call reporter%add_column(inclusive)

      exclusive = MultiColumn(['Exclusive'], separator='=')
      call exclusive%add_column(FormattedTextColumn(' T (sec) ','(f9.3)', 9, ExclusiveColumn(), separator='-'))
      call exclusive%add_column(FormattedTextColumn('   %  ','(f6.2)', 6, PercentageColumn(ExclusiveColumn()), separator='-'))
      call reporter%add_column(exclusive)

      call MPI_Comm_size(world_comm, npes, ierror)
      _VERIFY(ierror)
      call MPI_Comm_Rank(world_comm, my_rank, ierror)
      _VERIFY(ierror)

      if (my_rank == 0) then
         report_lines = reporter%generate_report(t_p)
         lgr => logging%get_logger('MAPL.profiler')
         call lgr%info('Report on process: %i0', my_rank)
         do i = 1, size(report_lines)
            call lgr%info('%a', report_lines(i))
         end do
      end if
      call MPI_Barrier(world_comm, ierror)
      _VERIFY(ierror)

      _RETURN(_SUCCESS)
   end subroutine report_global_profiler

end module MAPL_ApplicationSupport