w90_distribute_kpts Subroutine

public subroutine w90_distribute_kpts(common_data, num_kpts, mpi_size, dist_k, istdout, istderr, ierr)

Uses

  • proc~~w90_distribute_kpts~~UsesGraph proc~w90_distribute_kpts w90_distribute_kpts module~w90_comms w90_comms proc~w90_distribute_kpts->module~w90_comms module~w90_error w90_error proc~w90_distribute_kpts->module~w90_error module~w90_error_base w90_error_base proc~w90_distribute_kpts->module~w90_error_base module~w90_comms->module~w90_error_base module~w90_constants w90_constants module~w90_comms->module~w90_constants module~w90_error->module~w90_comms module~w90_error->module~w90_error_base

provide a distribution of num_kpts k-points across mpi_size MPI ranks

Arguments

Type IntentOptional Attributes Name
type(lib_common_type), intent(in) :: common_data

library object: only the communicator type is referenced

integer, intent(in) :: num_kpts

number of k-points

integer, intent(in) :: mpi_size

number of ranks in MPI communicator

integer, intent(inout), allocatable :: dist_k(:)

already allocated array assigned here such that dist_k(i) = rank handling kpt i size and allocation status are tested

integer, intent(in) :: istdout

destination for error messages

integer, intent(in) :: istderr

destination for error messages

integer, intent(out) :: ierr

return code, nonzero in case of error


Calls

proc~~w90_distribute_kpts~~CallsGraph proc~w90_distribute_kpts w90_distribute_kpts proc~prterr prterr proc~w90_distribute_kpts->proc~prterr proc~set_error_fatal set_error_fatal proc~w90_distribute_kpts->proc~set_error_fatal interface~comms_no_sync_bcast comms_no_sync_bcast proc~prterr->interface~comms_no_sync_bcast interface~comms_no_sync_recv comms_no_sync_recv proc~prterr->interface~comms_no_sync_recv interface~comms_no_sync_send comms_no_sync_send proc~prterr->interface~comms_no_sync_send proc~mpirank mpirank proc~prterr->proc~mpirank proc~mpisize mpisize proc~prterr->proc~mpisize proc~comms_sync_error comms_sync_error proc~set_error_fatal->proc~comms_sync_error proc~set_base_error set_base_error proc~set_error_fatal->proc~set_base_error proc~comms_no_sync_bcast_char comms_no_sync_bcast_char interface~comms_no_sync_bcast->proc~comms_no_sync_bcast_char proc~comms_no_sync_bcast_cmplx comms_no_sync_bcast_cmplx interface~comms_no_sync_bcast->proc~comms_no_sync_bcast_cmplx proc~comms_no_sync_bcast_int comms_no_sync_bcast_int interface~comms_no_sync_bcast->proc~comms_no_sync_bcast_int proc~comms_no_sync_bcast_logical comms_no_sync_bcast_logical interface~comms_no_sync_bcast->proc~comms_no_sync_bcast_logical proc~comms_no_sync_bcast_real comms_no_sync_bcast_real interface~comms_no_sync_bcast->proc~comms_no_sync_bcast_real proc~comms_no_sync_recv_char comms_no_sync_recv_char interface~comms_no_sync_recv->proc~comms_no_sync_recv_char proc~comms_no_sync_recv_cmplx comms_no_sync_recv_cmplx interface~comms_no_sync_recv->proc~comms_no_sync_recv_cmplx proc~comms_no_sync_recv_int comms_no_sync_recv_int interface~comms_no_sync_recv->proc~comms_no_sync_recv_int proc~comms_no_sync_recv_logical comms_no_sync_recv_logical interface~comms_no_sync_recv->proc~comms_no_sync_recv_logical proc~comms_no_sync_recv_real comms_no_sync_recv_real interface~comms_no_sync_recv->proc~comms_no_sync_recv_real proc~comms_no_sync_send_char comms_no_sync_send_char interface~comms_no_sync_send->proc~comms_no_sync_send_char proc~comms_no_sync_send_cmplx comms_no_sync_send_cmplx interface~comms_no_sync_send->proc~comms_no_sync_send_cmplx proc~comms_no_sync_send_int comms_no_sync_send_int interface~comms_no_sync_send->proc~comms_no_sync_send_int proc~comms_no_sync_send_logical comms_no_sync_send_logical interface~comms_no_sync_send->proc~comms_no_sync_send_logical proc~comms_no_sync_send_real comms_no_sync_send_real interface~comms_no_sync_send->proc~comms_no_sync_send_real

Called by

proc~~w90_distribute_kpts~~CalledByGraph proc~w90_distribute_kpts w90_distribute_kpts program~wannier wannier program~wannier->proc~w90_distribute_kpts

Source Code

  subroutine w90_distribute_kpts(common_data, num_kpts, mpi_size, dist_k, istdout, istderr, ierr)
    !! provide a distribution of num_kpts k-points across mpi_size MPI ranks
    ! should be called from all ranks in a parallel environment for error propagation
    use w90_comms, only: comms_sync_error
    use w90_error_base, only: w90_error_type
    use w90_error, only: set_error_fatal

    implicit none

    ! arguments
    integer, intent(in) :: num_kpts
    !! number of k-points
    integer, intent(in) :: mpi_size
    !! number of ranks in MPI communicator
    integer, intent(in) :: istdout, istderr
    !! destination for error messages
    integer, intent(inout), allocatable :: dist_k(:)
    !! already allocated array
    !! assigned here such that dist_k(i) = rank handling kpt i
    !! size and allocation status are tested
    integer, intent(out) :: ierr
    !! return code, nonzero in case of error
    type(lib_common_type), intent(in) :: common_data
    !! library object: only the communicator type is referenced

    ! local variables
    type(w90_error_type), allocatable :: error
    integer :: ctr, i, nkl

    ierr = 0

    if (mpi_size < 1) then
      call set_error_fatal(error, 'Error: mpi_size < 1 in w90_distribute_kpts call.', common_data%comm)
    elseif (num_kpts < 1) then
      call set_error_fatal(error, 'Error: num_kpts < 1 in w90_distribute_kpts call.', common_data%comm)
    elseif (.not. allocated(dist_k)) then
      call set_error_fatal(error, 'Error: dist_k not allocated in w90_distribute_kpts call.', common_data%comm)
    elseif (size(dist_k) < num_kpts) then
      call set_error_fatal(error, 'Error: size(dist_k) < num_kpts in w90_distribute_kpts call.', common_data%comm)
    end if
    if (allocated(error)) then
      call prterr(error, ierr, istdout, istderr, common_data%comm)
      return
    end if

    ctr = 0
    do i = 0, mpi_size - 1
      nkl = num_kpts/mpi_size ! number of kpoints per rank
      if (mod(num_kpts, mpi_size) > i) nkl = nkl + 1
      if (nkl > 0) then
        dist_k(ctr + 1:ctr + nkl) = i
        ctr = ctr + nkl
      end if
    end do
  end subroutine w90_distribute_kpts