main Program

Uses

  • program~~main~12~~UsesGraph program~main~12 main module~kernel_mod Kernel_mod program~main~12->module~kernel_mod module~mapl_bw_benchmark mapl_BW_Benchmark program~main~12->module~mapl_bw_benchmark module~mapl_combospec mapl_ComboSpec program~main~12->module~mapl_combospec module~mapl_errorhandlingmod MAPL_ErrorHandlingMod program~main~12->module~mapl_errorhandlingmod module~mapl_gathervkernel~2 mapl_GathervKernel program~main~12->module~mapl_gathervkernel~2 mpi mpi program~main~12->mpi module~mapl_bw_benchmark->module~kernel_mod module~mapl_bw_benchmark->module~mapl_errorhandlingmod iso_fortran_env iso_fortran_env module~mapl_bw_benchmark->iso_fortran_env module~mapl_combospec->module~mapl_bw_benchmark module~mapl_combospec->module~mapl_errorhandlingmod module~mapl_combospec->module~mapl_gathervkernel~2 module~mapl_combospec->mpi fArgParse fArgParse module~mapl_combospec->fArgParse module~mapl_combospec->iso_fortran_env module~mapl_errorhandlingmod->mpi module~mapl_throwmod MAPL_ThrowMod module~mapl_errorhandlingmod->module~mapl_throwmod module~mapl_gathervkernel~2->module~mapl_errorhandlingmod module~mapl_gathervkernel~2->mpi

Calls

program~~main~12~~CallsGraph program~main~12 main mpi_barrier mpi_barrier program~main~12->mpi_barrier mpi_finalize mpi_finalize program~main~12->mpi_finalize mpi_init mpi_init program~main~12->mpi_init proc~make_combospec make_ComboSpec program~main~12->proc~make_combospec proc~mapl_abort MAPL_abort program~main~12->proc~mapl_abort proc~mapl_verify MAPL_Verify program~main~12->proc~mapl_verify proc~run~12 run program~main~12->proc~run~12 proc~make_combospec->proc~mapl_verify add_argument add_argument proc~make_combospec->add_argument argparser argparser proc~make_combospec->argparser at at proc~make_combospec->at cast cast proc~make_combospec->cast interface~mapl_assert MAPL_Assert proc~make_combospec->interface~mapl_assert parse_args parse_args proc~make_combospec->parse_args proc~mapl_return MAPL_Return proc~make_combospec->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~12->proc~mapl_verify mpi_comm_rank mpi_comm_rank proc~run~12->mpi_comm_rank mpi_comm_size mpi_comm_size proc~run~12->mpi_comm_size mpi_comm_split mpi_comm_split proc~run~12->mpi_comm_split proc~make_bw_benchmark~2 make_BW_Benchmark proc~run~12->proc~make_bw_benchmark~2 proc~make_gathervkernel~2 make_GathervKernel proc~run~12->proc~make_gathervkernel~2 proc~run~12->proc~mapl_return proc~report~3 report proc~run~12->proc~report~3 proc~write_header~3 write_header proc~run~12->proc~write_header~3 proc~make_bw_benchmark~2->proc~mapl_verify proc~make_bw_benchmark~2->mpi_comm_rank proc~make_bw_benchmark~2->proc~mapl_return proc~make_gathervkernel~2->proc~mapl_verify proc~make_gathervkernel~2->mpi_comm_size proc~make_gathervkernel~2->proc~mapl_return none~init~5 GathervKernel%init proc~make_gathervkernel~2->none~init~5 proc~mapl_return->at proc~mapl_return->proc~mapl_throw_exception insert insert proc~mapl_return->insert proc~report~3->proc~mapl_verify proc~report~3->mpi_comm_rank proc~report~3->mpi_comm_size proc~report~3->proc~mapl_return proc~write_header~3->proc~mapl_verify proc~write_header~3->mpi_comm_rank proc~write_header~3->proc~mapl_return none~init~5->proc~mapl_verify none~init~5->interface~mapl_assert none~init~5->mpi_comm_rank none~init~5->mpi_comm_size none~init~5->proc~mapl_return

Variables

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

Functions

function time(kernel, comm, rc)

Arguments

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

Return Value real


Subroutines

subroutine report(spec, avg_time, avg_time_gather, avg_time_write, comm, rc)

Arguments

Type IntentOptional Attributes Name
type(ComboSpec), intent(in) :: spec
real, intent(in) :: avg_time
real, intent(in) :: avg_time_gather
real, intent(in) :: avg_time_write
integer, intent(in) :: comm
integer, intent(out), optional :: rc

subroutine run(spec, rc)

Arguments

Type IntentOptional Attributes Name
type(ComboSpec), 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_ComboSpec
   use mapl_GathervKernel
   use mapl_BW_Benchmark
   use mapl_ErrorHandlingMod
   use Kernel_mod
   use mpi
   implicit none

   type(ComboSpec) :: spec
   integer :: status
      
   call mpi_init(_IERROR)
   spec = make_ComboSpec() ! CLI

   call run(spec, _RC)

   call MPI_Barrier(MPI_COMM_WORLD, _IERROR)
   call mpi_finalize(_IERROR)

   stop

contains


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

      integer :: status

      real :: tot_time
      real :: tot_time_write
      real :: tot_time_gather
      real :: avg_time
      real :: avg_time_write
      real :: avg_time_gather
      type(GathervKernel) :: kernel
      type(BW_Benchmark) :: benchmark
      integer :: writer_comm
      integer :: gather_comm
      integer :: i
      real :: ta, tb

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

      color = (rank*spec%n_writers) / npes
      call MPI_Comm_split(MPI_COMM_WORLD, color, 0, gather_comm, _IERROR)
      
      call MPI_Comm_rank(gather_comm, rank, _IERROR)
      call MPI_Comm_split(MPI_COMM_WORLD, rank, 0, writer_comm, _IERROR)
      if (rank /= 0) then
         writer_comm = MPI_COMM_NULL
      end if

      kernel = make_GathervKernel(spec, gather_comm, _RC)
      if (rank == 0) then
         benchmark = make_BW_Benchmark(spec, writer_comm, _RC)
      end if

      call write_header(MPI_COMM_WORLD, _RC)

      tot_time = 0
      tot_time_gather = 0
      tot_time_write = 0
      associate (n => spec%n_tries)
        do i = 1, n
           ta = time(kernel, gather_comm, _RC)
           if (writer_comm /= MPI_COMM_NULL) then
              tb = time(benchmark, writer_comm, _RC)
           end if
           tot_time_gather = tot_time_gather + ta
           tot_time_write = tot_time_write + tb
           tot_time = tot_time + ta + tb
        end do
        avg_time = tot_time / n
        avg_time_gather = tot_time_gather / n
        avg_time_write = tot_time_write / n

      end associate

      call report(spec, avg_time, avg_time_gather, avg_time_write, MPI_COMM_WORLD, _RC)

      _RETURN(_SUCCESS)
   end subroutine run


   real function time(kernel, comm, rc)
      class(Kernel_T), intent(in) :: kernel
      integer, intent(in) :: comm
      integer, optional, intent(out) :: rc

      integer :: status
      real :: t0, t1

      call MPI_Barrier(comm, _IERROR)
      t0 = MPI_Wtime()
      call kernel%run(_RC)
      call MPI_Barrier(comm, _IERROR)
      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, _IERROR)
      _RETURN_UNLESS(rank == 0)
      
      write(*,'(4(a6,","),4(a15,:,","))',iostat=status) 'NX', '# levs', '# writers', 'group size', 'Time (s)', 'G Time (s)', 'W Time (s)', 'BW (GB/sec)'

      _RETURN(status)
   end subroutine write_header


   subroutine report(spec, avg_time, avg_time_gather, avg_time_write, comm, rc)
      type(ComboSpec), intent(in) :: spec
      real, intent(in) :: avg_time
      real, intent(in) :: avg_time_gather
      real, intent(in) :: avg_time_write

      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, _IERROR)
      _RETURN_UNLESS(rank == 0)

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

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


end program main