main Program

Uses

  • program~~main~14~~UsesGraph program~main~14 main module~mapl_errorhandlingmod MAPL_ErrorHandlingMod program~main~14->module~mapl_errorhandlingmod module~mapl_gathervkernel mapl_GathervKernel program~main~14->module~mapl_gathervkernel module~mapl_gathervspec mapl_GathervSpec program~main~14->module~mapl_gathervspec mpi mpi program~main~14->mpi module~mapl_errorhandlingmod->mpi module~mapl_throwmod MAPL_ThrowMod module~mapl_errorhandlingmod->module~mapl_throwmod module~mapl_gathervkernel->module~mapl_errorhandlingmod module~mapl_gathervkernel->mpi module~kernel_mod Kernel_mod module~mapl_gathervkernel->module~kernel_mod module~mapl_gathervspec->module~mapl_errorhandlingmod module~mapl_gathervspec->module~mapl_gathervkernel module~mapl_gathervspec->mpi fArgParse fArgParse module~mapl_gathervspec->fArgParse iso_fortran_env iso_fortran_env module~mapl_gathervspec->iso_fortran_env

Calls

program~~main~14~~CallsGraph program~main~14 main mpi_barrier mpi_barrier program~main~14->mpi_barrier mpi_finalize mpi_finalize program~main~14->mpi_finalize mpi_init mpi_init program~main~14->mpi_init proc~make_gathervspec make_GathervSpec program~main~14->proc~make_gathervspec proc~mapl_abort MAPL_abort program~main~14->proc~mapl_abort proc~mapl_verify MAPL_Verify program~main~14->proc~mapl_verify proc~run~14 run program~main~14->proc~run~14 proc~make_gathervspec->proc~mapl_verify add_argument add_argument proc~make_gathervspec->add_argument argparser argparser proc~make_gathervspec->argparser at at proc~make_gathervspec->at cast cast proc~make_gathervspec->cast interface~mapl_assert MAPL_Assert proc~make_gathervspec->interface~mapl_assert parse_args parse_args proc~make_gathervspec->parse_args proc~mapl_return MAPL_Return proc~make_gathervspec->proc~mapl_return mpi_abort mpi_abort proc~mapl_abort->mpi_abort proc~mapl_throw_exception MAPL_throw_exception proc~mapl_verify->proc~mapl_throw_exception proc~run~14->proc~mapl_verify mpi_comm_rank mpi_comm_rank proc~run~14->mpi_comm_rank mpi_comm_size mpi_comm_size proc~run~14->mpi_comm_size mpi_comm_split mpi_comm_split proc~run~14->mpi_comm_split proc~make_gathervkernel~2 make_GathervKernel proc~run~14->proc~make_gathervkernel~2 proc~run~14->proc~mapl_return proc~report~2 report proc~run~14->proc~report~2 proc~write_header~2 write_header proc~run~14->proc~write_header~2 proc~make_gathervkernel~2->proc~mapl_verify proc~make_gathervkernel~2->mpi_comm_size proc~make_gathervkernel~2->proc~mapl_return none~init~4 GathervKernel%init proc~make_gathervkernel~2->none~init~4 proc~mapl_return->at proc~mapl_return->proc~mapl_throw_exception insert insert proc~mapl_return->insert proc~report~2->proc~mapl_verify proc~report~2->mpi_comm_rank proc~report~2->mpi_comm_size proc~report~2->proc~mapl_return proc~write_header~2->proc~mapl_verify proc~write_header~2->mpi_comm_rank proc~write_header~2->proc~mapl_return none~init~4->proc~mapl_verify none~init~4->interface~mapl_assert none~init~4->mpi_comm_rank none~init~4->mpi_comm_size none~init~4->proc~mapl_return

Variables

Type Attributes Name Initial
integer :: status
type(GathervSpec) :: spec

Functions

function time(kernel, comm, rc)

Arguments

Type IntentOptional Attributes Name
type(GathervKernel), intent(in) :: kernel
integer, intent(in) :: comm
integer, intent(out), optional :: rc

Return Value real


Subroutines

subroutine report(spec, avg_time, rel_std_time, comm, rc)

Arguments

Type IntentOptional Attributes Name
type(GathervSpec), intent(in) :: spec
real, intent(in) :: avg_time
real, intent(in) :: rel_std_time
integer, intent(in) :: comm
integer, intent(out), optional :: rc

subroutine run(spec, rc)

Arguments

Type IntentOptional Attributes Name
type(GathervSpec), intent(in) :: spec
integer, intent(out), optional :: rc

subroutine write_header(comm, rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: comm
integer, intent(out), optional :: rc

Source Code

program main
   use mapl_GathervSpec
   use mapl_GathervKernel
   use mapl_ErrorHandlingMod
   use mpi
   implicit none

   type(GathervSpec) :: spec
   integer :: status
      
   call mpi_init(status)
   _VERIFY(status)
   spec = make_GathervSpec() ! CLI

   call run(spec, _RC)

   call MPI_Barrier(MPI_COMM_WORLD, status)
   _VERIFY(status)
   call mpi_finalize(status)

   stop

contains


#undef I_AM_MAIN
#include "MAPL_ErrLog.h"
   subroutine run(spec, rc)
      type(GathervSpec), intent(in) :: spec
      integer, optional, intent(out) :: rc

      integer :: status

      real :: tot_time
      real :: tot_time_sq
      real :: avg_time
      real :: rel_std_time
      type(GathervKernel) :: kernel
      integer :: writer_comm
      integer :: gather_comm
      integer :: i
      real :: t

      integer :: color, rank, npes
      call MPI_Comm_rank(MPI_COMM_WORLD, rank, status)
      _VERIFY(status)
      call MPI_Comm_size(MPI_COMM_WORLD, npes, status)
      _VERIFY(status)

      color = (rank*spec%n_writers) / npes
      call MPI_Comm_split(MPI_COMM_WORLD, color, 0, gather_comm, status)
      _VERIFY(status)
      
      call MPI_Comm_rank(gather_comm, rank, status)
      _VERIFY(status)
      call MPI_Comm_split(MPI_COMM_WORLD, rank, 0, writer_comm, status)
      _VERIFY(status)

      kernel = make_GathervKernel(spec, gather_comm, _RC)

      call write_header(MPI_COMM_WORLD, _RC)

      tot_time = 0
      tot_time_sq = 0
      associate (n => spec%n_tries)
        do i = 1, n
           t = time(kernel, writer_comm, _RC)
           tot_time = tot_time + t
           tot_time_sq = tot_time_sq + t**2
        end do
        avg_time = tot_time / n

        rel_std_time = -1 ! unless
        if (n > 1) then
           rel_std_time = sqrt((tot_time_sq - spec%n_tries*avg_time**2)/(n-1))/avg_time
        end if
      end associate

      call report(spec, avg_time, rel_std_time, MPI_COMM_WORLD, _RC)

      _RETURN(_SUCCESS)
   end subroutine run


   real function time(kernel, comm, rc)
      type(GathervKernel), intent(in) :: kernel
      integer, intent(in) :: comm
      integer, optional, intent(out) :: rc

      integer :: status
      real :: t0, t1

      call MPI_Barrier(comm, status)
      _VERIFY(status)
      t0 = MPI_Wtime()
      call kernel%run(_RC)
      call MPI_Barrier(comm, status)
      _VERIFY(status)
      t1 = MPI_Wtime()

      time = t1 - t0

      _RETURN(_SUCCESS)
   end function time

   subroutine write_header(comm, rc)
      integer, intent(in) :: comm
      integer, optional, intent(out) :: rc

      integer :: status
      integer :: rank

      call MPI_Comm_rank(comm, rank, status)
      _VERIFY(status)
      _RETURN_UNLESS(rank == 0)
      
      write(*,'(4(a6,","),3(a15,:,","))',iostat=status) 'NX', '# levs', '# writers', 'group size', 'Time (s)', 'Rel. Std. dev.', 'BW (GB/sec)'

      _RETURN(status)
   end subroutine write_header


   subroutine report(spec, avg_time, rel_std_time, comm, rc)
      type(GathervSpec), intent(in) :: spec
      real, intent(in) :: avg_time
      real, intent(in) :: rel_std_time
      integer, intent(in) :: comm
      integer, optional, intent(out) :: rc

      integer :: status
      integer :: rank
      integer :: npes
      integer :: group
      real :: bw_gb
      integer, parameter :: WORD=4

      call MPI_Comm_rank(comm, rank, status)
      _VERIFY(status)
      _RETURN_UNLESS(rank == 0)

      call MPI_Comm_size(MPI_COMM_WORLD, npes, status)
      _VERIFY(status)
      group = npes /spec%n_writers

      bw_gb = 1.e-9 * WORD * (spec%nx**2)*6*spec%n_levs / avg_time
      write(*,'(4(i6.0,","),3(f15.4,:,","))') spec%nx, spec%n_levs, spec%n_writers, group, avg_time, rel_std_time, bw_gb
 
      _RETURN(_SUCCESS)
   end subroutine report


end program main