9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-21 11:03:29 +01:00

Accelerate Cholesky

This commit is contained in:
Anthony Scemama 2023-07-03 21:04:50 +02:00
parent 3c7a10934f
commit 837ec89f1b

View File

@ -81,6 +81,9 @@ subroutine direct_cholesky(L, ndim, rank, tau)
double precision :: Dmax, Dmin, Qmax, f double precision :: Dmax, Dmin, Qmax, f
double precision, external :: get_ao_two_e_integral double precision, external :: get_ao_two_e_integral
logical, external :: ao_two_e_integral_zero
print *, 'Entering Cholesky'
allocate( D(ndim), Lset(ndim), Dset(ndim) ) allocate( D(ndim), Lset(ndim), Dset(ndim) )
allocate( addr(2,ndim) ) allocate( addr(2,ndim) )
@ -139,6 +142,9 @@ subroutine direct_cholesky(L, ndim, rank, tau)
! d., e. ! d., e.
allocate(Delta(np,nq), Ltmp_p(max(np,1),max(N,1)), Ltmp_q(max(nq,1),max(N,1))) allocate(Delta(np,nq), Ltmp_p(max(np,1),max(N,1)), Ltmp_q(max(nq,1),max(N,1)))
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(m,k,p,q)
!$OMP DO
do k=1,N do k=1,N
do p=1,np do p=1,np
Ltmp_p(p,k) = L(Lset(p),k) Ltmp_p(p,k) = L(Lset(p),k)
@ -147,10 +153,24 @@ subroutine direct_cholesky(L, ndim, rank, tau)
Ltmp_q(q,k) = L(Dset(q),k) Ltmp_q(q,k) = L(Dset(q),k)
enddo enddo
enddo enddo
!$OMP END DO NOWAIT
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(m,k) !$OMP DO
do m=1,nq do m=1,nq
do k=1,np do k=1,np
Delta(k,m) = 0.d0
enddo
enddo
!$OMP END DO
!$OMP DO
do m=1,nq
do k=1,np
if (ao_two_e_integral_zero( &
addr(1,Lset(k)), &
addr(1,Dset(m)), &
addr(2,Lset(k)), &
addr(2,Dset(m)) ) ) cycle
Delta(k,m) = get_ao_two_e_integral( & Delta(k,m) = get_ao_two_e_integral( &
addr(1,Lset(k)), & addr(1,Lset(k)), &
addr(1,Dset(m)), & addr(1,Dset(m)), &
@ -159,7 +179,9 @@ subroutine direct_cholesky(L, ndim, rank, tau)
ao_integrals_map) ao_integrals_map)
enddo enddo
enddo enddo
!$OMP END PARALLEL DO !$OMP END DO
!$OMP END PARALLEL
call dgemm('N','T',np,nq,N,-1.d0, & call dgemm('N','T',np,nq,N,-1.d0, &
Ltmp_p, np, Ltmp_q, nq, 1.d0, Delta, np) Ltmp_p, np, Ltmp_q, nq, 1.d0, Delta, np)
@ -188,28 +210,36 @@ subroutine direct_cholesky(L, ndim, rank, tau)
! iii. ! iii.
f = 1.d0/dsqrt(Qmax) f = 1.d0/dsqrt(Qmax)
!$OMP PARALLEL PRIVATE(m,k)
!$OMP DO
do p=1,np do p=1,np
Ltmp_p(p,1) = Delta(p,dj) * f Ltmp_p(p,1) = Delta(p,dj) * f
L(Lset(p), rank) = Ltmp_p(p,1) L(Lset(p), rank) = Ltmp_p(p,1)
enddo enddo
!$OMP END DO
!$OMP DO
do q=1,nq do q=1,nq
Ltmp_q(q,1) = L(Dset(q), rank) Ltmp_q(q,1) = L(Dset(q), rank)
enddo enddo
!$OMP END DO
! iv. ! iv.
! call dger(np, nq, -1.d0, Ltmp_p, 1, Ltmp_q, 1, Delta, np) !$OMP DO
!$OMP PARALLEL DO PRIVATE(f,m,k)
do m=1, nq do m=1, nq
do k=1, np do k=1, np
Delta(k,m) = Delta(k,m) - Ltmp_p(k,1) * Ltmp_q(m,1) Delta(k,m) = Delta(k,m) - Ltmp_p(k,1) * Ltmp_q(m,1)
enddo enddo
enddo enddo
!$OMP END PARALLEL DO !$OMP END DO NOWAIT
! call dger(np, nq, -1.d0, Ltmp_p, 1, Ltmp_q, 1, Delta, np)
!$OMP DO
do k=1, np do k=1, np
D(Lset(k)) = D(Lset(k)) - Ltmp_p(k,1) * Ltmp_p(k,1) D(Lset(k)) = D(Lset(k)) - Ltmp_p(k,1) * Ltmp_p(k,1)
enddo enddo
!$OMP END DO
!$OMP END PARALLEL
Qmax = D(Dset(1)) Qmax = D(Dset(1))
do q=1,np do q=1,np