read kpoints from kpoint.dat and distribute
subroutine pw90common_wanint_get_kpoint_file
!===========================================================!
! !
!! read kpoints from kpoint.dat and distribute
! !
!===========================================================!
use w90_constants, only: dp
use w90_io, only: io_error, io_file_unit, &
io_date, io_time, io_stopwatch
integer :: k_unit
integer :: loop_nodes, loop_kpt, i, ierr
real(kind=dp) :: sum
k_unit = io_file_unit()
if (on_root) then
open (unit=k_unit, file='kpoint.dat', status='old', form='formatted', err=106)
read (k_unit, *) num_int_kpts
end if
call comms_bcast(num_int_kpts, 1)
allocate (num_int_kpts_on_node(0:num_nodes - 1))
num_int_kpts_on_node(:) = num_int_kpts/num_nodes
max_int_kpts_on_node = num_int_kpts - (num_nodes - 1)*(num_int_kpts/num_nodes)
num_int_kpts_on_node(0) = max_int_kpts_on_node
! if(my_node_id < num_int_kpts- num_int_kpts_on_node*num_nodes) num_int_kpts_on_node= num_int_kpts_on_node+1
allocate (int_kpts(3, max_int_kpts_on_node), stat=ierr)
if (ierr /= 0) call io_error('Error allocating max_int_kpts_on_node in param_read_um')
int_kpts = 0.0_dp
allocate (weight(max_int_kpts_on_node), stat=ierr)
if (ierr /= 0) call io_error('Error allocating weight in param_read_um')
weight = 0.0_dp
sum = 0.0_dp
if (on_root) then
do loop_nodes = 1, num_nodes - 1
do loop_kpt = 1, num_int_kpts_on_node(loop_nodes)
read (k_unit, *) (int_kpts(i, loop_kpt), i=1, 3), weight(loop_kpt)
sum = sum + weight(loop_kpt)
end do
call comms_send(int_kpts(1, 1), 3*num_int_kpts_on_node(loop_nodes), loop_nodes)
call comms_send(weight(1), num_int_kpts_on_node(loop_nodes), loop_nodes)
end do
do loop_kpt = 1, num_int_kpts_on_node(0)
read (k_unit, *) (int_kpts(i, loop_kpt), i=1, 3), weight(loop_kpt)
sum = sum + weight(loop_kpt)
end do
! print*,'rsum',sum
end if
if (.not. on_root) then
call comms_recv(int_kpts(1, 1), 3*num_int_kpts_on_node(my_node_id), root_id)
call comms_recv(weight(1), num_int_kpts_on_node(my_node_id), root_id)
end if
return
106 call io_error('Error: Problem opening file kpoint.dat in pw90common_wanint_get_kpoint_file')
end subroutine pw90common_wanint_get_kpoint_file