tem_restart_getTotalChunks Subroutine

public subroutine tem_restart_getTotalChunks(restart, nElems, comm, chunkSize)

calculate the maximum number of elements which fit into the output buffer = chunk

for a given set of variable systems with their nScalar values to dump Also, calculate the number of local chunks required to dump all the data = nChunks Finally find the globally largest number of nChunks

Arguments

Type IntentOptional Attributes Name
type(tem_restart_type), intent(inout) :: restart

the restart type

integer, intent(in) :: nElems

mesh, provided in treelm format optional subTree

integer, intent(in) :: comm

mesh, provided in treelm format optional subTree

integer, intent(in), optional :: chunkSize

optional predefined chunksize


Calls

proc~~tem_restart_gettotalchunks~~CallsGraph proc~tem_restart_gettotalchunks tem_restart_getTotalChunks proc~tem_abort tem_abort proc~tem_restart_gettotalchunks->proc~tem_abort mpi_allreduce mpi_allreduce proc~tem_restart_gettotalchunks->mpi_allreduce mpi_comm_rank mpi_comm_rank proc~tem_restart_gettotalchunks->mpi_comm_rank mpi_abort mpi_abort proc~tem_abort->mpi_abort

Called by

proc~~tem_restart_gettotalchunks~~CalledByGraph proc~tem_restart_gettotalchunks tem_restart_getTotalChunks proc~tem_init_restart tem_init_restart proc~tem_init_restart->proc~tem_restart_gettotalchunks proc~hvs_output_init hvs_output_init proc~hvs_output_init->proc~tem_init_restart proc~tem_init_tracker tem_init_tracker proc~tem_init_tracker->proc~hvs_output_init

Contents


Source Code

  subroutine tem_restart_getTotalChunks( restart, nElems, comm, chunkSize )
    ! -------------------------------------------------------------------- !
    !> the restart type
    type( tem_restart_type ), intent(inout) :: restart
    !> mesh, provided in treelm format
    !type(treelmesh_type), intent(in) :: tree
    !> optional subTree
    ! type(tem_subTree_type), optional, intent(in) :: subTree
    integer, intent(in) :: nElems, comm
    !> optional predefined chunksize
    integer, optional, intent(in) :: chunkSize
    ! -------------------------------------------------------------------- !
    integer :: nTotalScalars
    integer :: iError ! MPI error
    integer :: rank
    ! -------------------------------------------------------------------- !
    ! Get the number of total scalars.
    nTotalScalars = restart%varMap%nScalars
    if ( nTotalScalars ==  0 ) then
      write(logUnit(0),*) '!! Error !! No variable found in restart varSys !!'
      write(logUnit(0),*) 'May be variable label in requested system is not ' &
        &                 // 'found in global varsys'
      call tem_abort()
    endif

    if( present( chunkSize ))then
      restart%read_file%chunkSize = chunkSize
      restart%write_file%chunkSize = chunkSize
    else
      ! Get the number of elements that fit into the IO buffer.
      restart%read_file%chunkSize                            &
        &  = min( io_buffer_size                             &
        &         / (nTotalScalars*restart%read_file%nDofs), &
        &         nElems                                   )
      restart%write_file%chunkSize                            &
        &  = min( io_buffer_size                              &
        &         / (nTotalScalars*restart%write_file%nDofs), &
        &         nElems                                    )
    end if

    ! check if at least one complete element fits into the buffer
    ! if not abort since no valid output can be garanteed
    if (restart%write_file%chunkSize <= 0) then
      write(logUnit(0),*) 'The chosen io_buffer_size of ', io_buffer_size
      write(logUnit(0),*) 'is too small for outputting ', nTotalScalars
      write(logUnit(0),*) 'scalar values with ', restart%write_file%nDofs
      write(logUnit(0),*) 'degrees of freedom!'
      write(logUnit(0),*) 'Please increase the io_buffer_size to' &
        &                 // ' at least (MB) ', &
        &                 real(nTotalScalars*restart%write_file%nDofs) &
        &                 / real(131072)
      call tem_abort()
    end if

    if (restart%read_file%chunkSize <= 0) then
      write(logUnit(0),*) 'The chosen io_buffer_size of ', io_buffer_size
      write(logUnit(0),*) 'is too small for reading ', nTotalScalars
      write(logUnit(0),*) 'scalar values with ', restart%read_file%nDofs
      write(logUnit(0),*) 'degrees of freedom!'
      write(logUnit(0),*) 'Please increase the io_buffer_size to'     &
        &                 // ' at least (MB) ',                       &
        &                 real(nTotalScalars*restart%read_file%nDofs) &
        &                 / real(131072)
      call tem_abort()
    end if

    ! Get the number of chunks which are needed to dump all values to disk.
    ! This needs to be rounded up, to cover also a possible last incomplete
    ! chunk.
    restart%write_file%nChunks                           &
      &  = ceiling( real(nElems, kind=rk)              &
      &             / real(restart%write_file%chunkSize, kind=rk) )

    restart%read_file%nChunks                           &
      &  = ceiling( real(nElems, kind=rk)             &
      &             / real(restart%read_file%chunkSize, kind=rk) )

    ! identify the maximum number of chunks throughout all processes
    ! and store that into restart%maxnChunks
    call MPI_Allreduce( restart%write_file%nChunks,        &
      &                 restart%write_file%maxnChunks, 1,  &
      &                 MPI_INTEGER, MPI_MAX, comm, iError )
    call MPI_Allreduce( restart%read_file%nChunks,         &
      &                 restart%read_file%maxnChunks, 1,   &
      &                 MPI_INTEGER, MPI_MAX, comm, iError )

    call MPI_Comm_Rank( comm, rank, iError )

  end subroutine tem_restart_getTotalChunks