5 #include <PB3D_macros.h>
6 use strumpackdensepackage
21 integer,
parameter :: bs = 16
53 integer :: desc_h(blacsctxtsize)
54 integer :: desc_g(blacsctxtsize)
59 integer,
allocatable :: sec_x(:)
60 integer,
allocatable :: lims_c(:,:)
61 integer,
allocatable :: lims_r(:,:)
63 real(
dp),
allocatable :: ang(:,:)
64 real(
dp),
allocatable :: norm(:,:)
65 real(
dp),
allocatable :: dnorm(:,:)
66 real(
dp),
allocatable :: h_fac(:,:)
67 real(
dp),
allocatable :: x_vec(:,:)
68 real(
dp),
allocatable :: h(:,:)
69 real(
dp),
allocatable :: g(:,:)
70 complex(dp),
allocatable :: res(:,:)
72 real(
dp) :: estim_mem_usage
120 integer function init_vac(vac,style,n_bnd,prim_X,n_ang,jq)
result(ierr)
128 character(*),
parameter :: rout_name =
'init_vac'
131 class(
vac_type),
intent(inout) :: vac
132 integer,
intent(in) :: style
133 integer,
intent(in) :: n_bnd
134 integer,
intent(in) :: prim_x
135 integer,
intent(in) :: n_ang(2)
136 real(dp),
intent(in) :: jq
139 character(len=max_str_ln) :: err_msg
142 integer,
allocatable :: proc_map(:,:)
153 if (product(n_ang).ne.n_bnd)
then
155 err_msg =
'The total number of angles along B, '//&
156 &trim(
i2str(product(n_ang)))//
', is not equal to n_bnd = '//&
163 if (n_procs.eq.1) vac%bs = n_bnd
170 vac%n_p(1)=floor(sqrt(n_procs*1._dp))
171 vac%n_p(2)=n_procs/vac%n_p(1)
172 allocate(proc_map(vac%n_p(1),vac%n_p(2)))
173 proc_map = transpose(reshape(&
174 &[(jd+n_procs-1-product(vac%n_p),jd=1,product(vac%n_p))],vac%n_p))
175 call blacs_get(0,0,vac%ctxt_HG)
176 call blacs_gridmap(vac%ctxt_HG,proc_map,vac%n_p(1),vac%n_p(1),&
178 call blacs_gridinfo(vac%ctxt_HG,vac%n_p(1),vac%n_p(2),vac%ind_p(1),&
180 if(minval(vac%ind_p).ge.0)
then
182 vac%n_loc(jd) = numroc(vac%n_bnd,vac%bs,vac%ind_p(jd),0,&
185 call descinit(vac%desc_H,n_bnd,n_bnd,vac%bs,vac%bs,0,0,vac%ctxt_HG,&
186 &max(1,vac%n_loc(1)),ierr)
187 chckerr(
'descinit failed')
188 call descinit(vac%desc_G,n_bnd,n_bnd,vac%bs,vac%bs,0,0,vac%ctxt_HG,&
189 &max(1,vac%n_loc(1)),ierr)
190 chckerr(
'descinit failed')
191 call mpi_comm_split(mpi_comm_world,1,rank,vac%MPI_Comm,ierr)
195 call mpi_comm_split(mpi_comm_world,mpi_undefined,rank,&
201 call set_loc_lims(vac%n_loc(1),vac%bs,vac%ind_p(1),vac%n_p(1),&
203 call set_loc_lims(vac%n_loc(2),vac%bs,vac%ind_p(2),vac%n_p(2),&
208 select case (vac%style)
215 err_msg =
'No vacuum style '//trim(
i2str(vac%style))//&
221 allocate(vac%norm(vac%n_bnd,n_dims))
222 allocate(vac%x_vec(vac%n_bnd,n_dims))
225 select case (vac%style)
227 allocate(vac%h_fac(vac%n_bnd,4))
229 allocate(vac%ang(n_ang(1),n_ang(2)))
230 allocate(vac%dnorm(vac%n_bnd,n_dims))
237 allocate(vac%G(vac%n_loc(1),vac%n_loc(2)))
238 allocate(vac%H(vac%n_loc(1),vac%n_loc(2)))
245 &vac%estim_mem_usage +
size(vac%G) +
n_mod_x**2
252 &
' - Expected memory usage of vac: '//&
253 &trim(
r2strt(vac%estim_mem_usage*weight_dp*2))//
' kB]',alert=.true.)
262 integer,
intent(in) :: n_loc
263 integer,
intent(in) :: bs
264 integer,
intent(in) :: ind_p
265 integer,
intent(in) :: n_p
266 integer,
intent(inout),
allocatable :: lims(:,:)
273 allocate(lims(2,ceiling(n_loc*1._dp/bs)))
274 do jd = 1,
size(lims,2)
275 lims(1,jd) = indxl2g((jd-1)*bs+1,bs,ind_p,0,n_p)
276 lims(2,jd) = indxl2g(min(jd*bs,n_loc),bs,ind_p,0,n_p)
292 class(
vac_type),
intent(inout) :: vac
297 real(dp) :: estim_mem_usage
302 estim_mem_usage = vac%estim_mem_usage
307 if (
in_context(vac%ctxt_HG))
call blacs_gridexit(vac%ctxt_HG)
310 call dealloc_vac_final(vac)
320 &trim(
i2str(mem_diff))//
'kB deallocating vac ('//&
321 &trim(
i2str(nint(100*mem_diff/&
322 &(estim_mem_usage*weight_dp*2))))//&
323 &
'% of estimated)]',alert=.true.)
329 subroutine dealloc_vac_final(vac)
332 end subroutine dealloc_vac_final
338 integer function copy_vac(vac,vac_copy)
result(ierr)
343 class(
vac_type),
intent(inout) :: vac_copy
345 character(*),
parameter :: rout_name =
'copy_vac'
351 ierr = vac_copy%init(vac%style,vac%n_bnd,vac%prim_X,vac%n_ang,&
356 vac_copy%norm = vac%norm
357 vac_copy%x_vec = vac%x_vec
360 select case (vac%style)
362 vac_copy%h_fac = vac%h_fac
364 vac_copy%dnorm = vac%dnorm
365 vac_copy%ang = vac%ang
379 integer,
intent(in) :: ctxt
385 call blacs_gridinfo(ctxt,n_p(1),n_p(2),ind_p(1),ind_p(2))