23 integer,
parameter ::
dp = kind(1.0d0)
40 & Ef, nparts, verbose)
42 integer,
parameter ::
dp = kind(1.0d0)
43 type(bml_matrix_t),
intent(in) :: ham_bml, g_bml
44 type(bml_matrix_t),
intent(out) :: rho_bml
45 real(
dp) :: bndfil, threshold
46 integer ::
myrank, norbs, nnodes, tnnz, i, vsize(2), inorbs
47 integer,
intent(inout) :: nparts
48 real(
dp),
intent(inout) :: ef
49 character(20) :: bml_type
50 integer,
allocatable :: xadj(:), adjncy(:), vector(:)
51 integer,
allocatable :: part(:), core_count(:), halo_count(:,:), ch_count(:)
53 real(
dp) :: maxch, pnorm=6, smooth_maxch, sumcubes, mlsi, mlsii
55 integer,
optional,
intent(in) :: verbose
57 real(
dp) :: error, dnocc_part, dnocc, nocc
63 bml_type = bml_get_type(ham_bml)
66 norbs = bml_get_n(ham_bml)
67 if(.not. bml_allocated(rho_bml))
then
68 call bml_zero_matrix(bml_type,bml_element_real,
dp,norbs,norbs,rho_bml)
72 allocate(xadj(norbs+1))
76 tnnz = tnnz + bml_get_row_bandwidth(g_bml,i)
79 allocate(adjncy(tnnz+1))
81 call bml_adjacency(g_bml, xadj, adjncy, 1)
85 allocate(part(nnodes))
86 allocate(core_count(nparts))
87 allocate(ch_count(nparts))
88 allocate(halo_count(nparts, nnodes))
91 ch_count, halo_count, sumcubes, maxch, smooth_maxch, pnorm)
93 if(
present(verbose))
then
94 if(verbose > 1 .and.
myrank == 1)
then
95 write(*,*)
"gpat = ",gpat%pname
96 write(*,*)
"totalParts = ",gpat%totalParts
97 write(*,*)
"totalNodes = ",gpat%totalNodes
98 write(*,*)
"partMin = ",gpat%localPartMin(1)
99 write(*,*)
"partMax = ",gpat%localPartMax(1)
103 allocate(syprt(gpat%TotalParts))
107 if(
present(verbose) .and. (verbose > 1 .and.
myrank == 1)) mlsi =
mls()
111 do i=1,gpat%TotalParts
112 call bml_matrix2submatrix_index(g_bml,&
113 gpat%sgraph(i)%nodeInPart,gpat%nnodesInPart(i),&
114 gpat%sgraph(i)%core_halo_index, &
116 gpat%sgraph(i)%lsize = vsize(1)
117 gpat%sgraph(i)%llsize = vsize(2)
118 if(
present(verbose))
then
119 if(verbose > 1 .and.
myrank == 1)
then
120 write(*,*)
'nodeInpart size',
size(gpat%sgraph(i)%nodeInPart)
121 write(*,*)
'nodeInpart(i)', gpat%nnodesInPart(i)
122 write(*,*)
"Core and CH sizes:",vsize(2),vsize(1)
128 do i = gpat%localPartMin(
myrank), gpat%localPartMax(
myrank)
130 call bml_matrix2submatrix_index(g_bml,&
131 gpat%sgraph(i)%nodeInPart,gpat%nnodesInPart(i),&
132 gpat%sgraph(i)%core_halo_index, &
134 gpat%sgraph(i)%lsize = vsize(1)
135 gpat%sgraph(i)%llsize = vsize(2)
137 call bml_zero_matrix(
"dense",bml_element_real,
dp,inorbs,inorbs,syprt(i)%estr%ham)
138 if(
allocated(vector))
deallocate(vector)
139 allocate(vector(gpat%sgraph(i)%lsize))
140 vector(:) = gpat%sgraph(i)%core_halo_index(1:gpat%sgraph(i)%lsize)
141 call bml_matrix2submatrix(ham_bml, syprt(i)%estr%ham, vector, &
146 call bml_zero_matrix(
"dense",bml_element_real,
dp,inorbs,inorbs,syprt(i)%estr%rho)
148 dnocc = dnocc + dnocc_part
151 if(
present(verbose))
then
152 if(verbose > 1 .and.
myrank == 1)
write(*,*)
"Time for prg_build_density_T0",
mls()-mlsii
154 call bml_submatrix2matrix(syprt(i)%estr%rho,rho_bml,vector,gpat%sgraph(i)%lsize,gpat%sgraph(i)%llsize,threshold)
162 nocc = bml_trace(rho_bml)
163 error = abs(nocc-2*bndfil*norbs)
164 if (nocc < 2*bndfil*norbs) dnocc = - dnocc
166 if(
present(verbose))
then
167 if(verbose > 1 .and.
myrank == 1)
write(6,
'(A,10es15.6)')
'Ef, Nocc, delta_nocc, gradient', &
168 ef, nocc, error, dnocc
171 if (error > 1.e-6_dp .and. abs(dnocc) > 1.e-6_dp)
then
172 if ( error > 1.0_dp )
then
175 ef = ef - error / dnocc
179 if(
present(verbose))
then
180 if(verbose > 1 .and.
myrank == 1)
write(*,*)
"Total time for graph solver =",
mls()-mlsi
183 do i = gpat%localPartMin(
myrank), gpat%localPartMax(
myrank)
184 call bml_deallocate(syprt(i)%estr%ham)
185 call bml_deallocate(syprt(i)%estr%rho)
205 integer,
parameter ::
dp = kind(1.0d0)
206 type(bml_matrix_t),
intent(in) :: over_bml, g_bml
207 type(bml_matrix_t),
intent(out) :: zmat_bml
208 real(
dp) :: threshold
209 integer ::
myrank, norbs, nnodes, tnnz, i, vsize(2), inorbs
210 integer,
intent(inout) :: nparts
211 character(20) :: bml_type
212 integer,
allocatable :: xadj(:), adjncy(:), vector(:)
213 integer,
allocatable :: part(:), core_count(:), halo_count(:,:), ch_count(:)
215 real(
dp) :: maxch, pnorm=6, smooth_maxch, sumcubes, mlsi, mlsii
217 integer,
optional,
intent(in) :: verbose
224 bml_type = bml_get_type(over_bml)
227 norbs = bml_get_n(over_bml)
228 if(.not. bml_allocated(zmat_bml))
then
229 call bml_zero_matrix(bml_type,bml_element_real,
dp,norbs,norbs,zmat_bml)
233 allocate(xadj(norbs+1))
237 tnnz = tnnz + bml_get_row_bandwidth(g_bml,i)
240 allocate(adjncy(tnnz+1))
242 call bml_adjacency(g_bml, xadj, adjncy, 1)
246 allocate(part(nnodes))
247 allocate(core_count(nparts))
248 allocate(ch_count(nparts))
249 allocate(halo_count(nparts, nnodes))
251 call prg_metispartition(gpat, nnodes, nnodes, xadj, adjncy, nparts, part, core_count,&
252 ch_count, halo_count, sumcubes, maxch, smooth_maxch, pnorm)
254 if(
present(verbose))
then
255 if(verbose > 1 .and.
myrank == 1)
then
256 write(*,*)
"gpat = ",gpat%pname
257 write(*,*)
"totalParts = ",gpat%totalParts
258 write(*,*)
"totalNodes = ",gpat%totalNodes
259 write(*,*)
"partMin = ",gpat%localPartMin(1)
260 write(*,*)
"partMax = ",gpat%localPartMax(1)
263 allocate(syprt(gpat%TotalParts))
270 do i=1,gpat%TotalParts
271 call bml_matrix2submatrix_index(g_bml,&
272 gpat%sgraph(i)%nodeInPart,gpat%nnodesInPart(i),&
273 gpat%sgraph(i)%core_halo_index, &
275 gpat%sgraph(i)%lsize = vsize(1)
276 gpat%sgraph(i)%llsize = vsize(2)
277 if(
present(verbose))
then
278 if(verbose > 1 .and.
myrank == 1)
then
279 write(*,*)
'nodeInpart size',
size(gpat%sgraph(i)%nodeInPart)
280 write(*,*)
'nodeInpart(i)', gpat%nnodesInPart(i)
281 write(*,*)
"Core and CH sizes:",vsize(2),vsize(1)
287 do i = gpat%localPartMin(
myrank), gpat%localPartMax(
myrank)
289 call bml_matrix2submatrix_index(g_bml,&
290 gpat%sgraph(i)%nodeInPart,gpat%nnodesInPart(i),&
291 gpat%sgraph(i)%core_halo_index, &
293 gpat%sgraph(i)%lsize = vsize(1)
294 gpat%sgraph(i)%llsize = vsize(2)
296 call bml_zero_matrix(
"dense",bml_element_real,
dp,inorbs,inorbs,syprt(i)%estr%over)
297 if(
allocated(vector))
deallocate(vector)
298 allocate(vector(gpat%sgraph(i)%lsize))
299 vector(:) = gpat%sgraph(i)%core_halo_index(1:gpat%sgraph(i)%lsize)
300 call bml_matrix2submatrix(over_bml, syprt(i)%estr%over, vector, &
305 call bml_zero_matrix(
"dense",bml_element_real,
dp,inorbs,inorbs,syprt(i)%estr%zmat)
306 call prg_buildzdiag(syprt(i)%estr%over,syprt(i)%estr%zmat,threshold,inorbs,
"dense")
308 if(
present(verbose))
then
309 if(verbose > 1 .and.
myrank == 1)
write(*,*)
"Time for prg_build_density_T0",
mls()-mlsii
311 call bml_submatrix2matrix(syprt(i)%estr%zmat,zmat_bml,vector,gpat%sgraph(i)%lsize,gpat%sgraph(i)%llsize,threshold)
319 if(
present(verbose))
then
320 if(verbose > 1 .and.
myrank == 1)
write(*,*)
"Total time for graph solver =",
mls()-mlsi
323 do i = gpat%localPartMin(
myrank), gpat%localPartMax(
myrank)
324 call bml_deallocate(syprt(i)%estr%over)
325 call bml_deallocate(syprt(i)%estr%zmat)
Module to obtain the density matrix by diagonalizing an orthogonalized Hamiltonian.
subroutine, public prg_build_density_t_fermi(ham_bml, rho_bml, threshold, kbt, ef, verbose, drho)
Builds the density matrix from for electronic temperature T. Where, is the matrix eigenvector and ...
To produce a matrix which is needed to orthogonalize .
subroutine, public prg_buildzdiag(smat_bml, zmat_bml, threshold, mdimin, bml_type, verbose)
Usual subroutine involving diagonalization. , where = eigenvectors and = eigenvalues....
Module for graph-based solvers.
subroutine, public prg_build_densitygp_t0(ham_bml, g_bml, rho_bml, threshold, bndfil, Ef, nparts, verbose)
Builds the density matrix from using a graph-based approach.
subroutine, public prg_build_zmatgp(over_bml, g_bml, zmat_bml, threshold, nparts, verbose)
Builds the inverse overlap factor matrix from using a graph-based approach.
integer function, public getnranks()
integer function, public getmyrank()
subroutine, public prg_wait()
subroutine, public prg_metispartition(gp, ngroups, nnodes, xadj, adjncy, nparts, part, core_count, CH_count, Halo_count, sumCubes, maxCH, smooth_maxCH, pnorm)
Create graph partitions minizing number of cut edges.
subroutine, public prg_progress_init()
Initialize progress.
subroutine, public prg_progress_shutdown()
Shutdown progress.
subroutine, public prg_partordering(gp)
Set row ordering bases on parts.
subroutine, public prg_collectmatrixfromparts(gp, rho_bml)
Collect distributed parts into same matrix.
A module to read and handle chemical systems.