From 444a377edab1c79a0e284a3bba7428163d879a1c Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Wed, 7 Feb 2024 15:31:10 +0000 Subject: [PATCH 01/17] First attempt --- src/exx_kernel_default.f90 | 40 +++++++++++++++++++++++--------------- src/exx_memory.f90 | 11 ++++++++++- src/exx_types.f90 | 4 ++-- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 3ef219716..ba24fcbca 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -992,6 +992,10 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & real(double), dimension(3) :: xyz_zero = zero real(double) :: dr,dv,K_val real(double) :: exx_mat_elem + + ! real(double), dimension(:), allocatable :: phi_i_1d_buffer + ! real(double), :: Ome_kj_reduced_1d_buffer((2*extent+1)*(2*extent+1)*(2*extent+1)) + real(double), pointer :: phi_i(:,:,:), Ome_kj_reduced(:,:,:) ! type(prim_atomic_data) :: ia !i_alpha type(neigh_atomic_data) :: jb !j_beta @@ -1115,6 +1119,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & !print*, 'i',i, 'global_num',ia%ip,'spe',ia%spec ! if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i','alloc') + phi_i(1:2*extent+1, 1:2*extent+1, 1:2*extent+1, 1:ia%nsup) => phi_i_1d_buffer ! call exx_phi_on_grid(inode,ia%ip,ia%spec,extent, & ia%xyz,ia%nsup,phi_i,r_int,xyz_zero) @@ -1156,7 +1161,8 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & call exx_phi_on_grid(inode,jb%global_num,jb%spec,extent, & jb%xyz,jb%nsup,phi_j,r_int,xyz_zero) ! - if ( exx_alloc ) call exx_mem_alloc(extent,0,0,'Ome_kj','alloc') + if ( exx_alloc ) call exx_mem_alloc(extent,0,0,'Ome_kj_1d_buffer','alloc') + Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer ! call start_timer(tmr_std_exx_accumul) !$omp parallel do schedule(runtime) collapse(2) default(none) reduction(+: c) & @@ -1192,21 +1198,23 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! do nsf3 = 1, ia%nsup ! - exx_mat_elem = zero - ! - do r = 1, 2*extent+1 - do s = 1, 2*extent+1 - do t = 1, 2*extent+1 - - exx_mat_elem = exx_mat_elem & - + phi_i(t,s,r,nsf3) & - * Ome_kj(t,s,r) - - end do - end do - end do - ! - c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + exx_mat_elem * dv + ! exx_mat_elem = zero + ! ! + ! do r = 1, 2*extent+1 + ! do s = 1, 2*extent+1 + ! do t = 1, 2*extent+1 + + ! exx_mat_elem = exx_mat_elem & + ! + phi_i(t,s,r,nsf3) & + ! * Ome_kj_reduced(t,s,r) * dv + + ! end do + ! end do + ! end do + ! ! + ! c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + exx_mat_elem + + c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + dot((2*extent+1)**3, phi_i(:,:,:,nsf3), 1, Ome_kj, 1) * dv ! end do ! nsf3 = 1, ia%nsup ! diff --git a/src/exx_memory.f90 b/src/exx_memory.f90 index 0fc3c8877..48aa252e9 100644 --- a/src/exx_memory.f90 +++ b/src/exx_memory.f90 @@ -98,7 +98,7 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) !!$ ! case('phi_i') ! allocate phi_i for primary atom - allocate(phi_i(2*extent+1,2*extent+1,2*extent+1,nsf1), STAT=stat) + allocate(phi_i_1d_buffer(nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1)), STAT=stat) if(stat/=0) call cq_abort('Error allocating memory to phi_i/exx !',stat) call reg_alloc_mem(area_exx,nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1),& type_dbl,matrix,lun) @@ -148,6 +148,15 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) !write(unit,*) '\Ome_{k\gamma}_{j\beta} allocated' ! ! + case('Ome_kj_1d_buffer') ! allocate Ome_kj_1d_buffer + allocate(Ome_kj_1d_buffer((2*extent+1)*(2*extent+1)*(2*extent+1)), STAT=stat) + if(stat/=0) call cq_abort('Error allocating memory to Ome_kj_1d_buffer/exx !',stat) + call reg_alloc_mem(area_exx,(2*extent+1)*(2*extent+1)*(2*extent+1),& + type_dbl,matrix,lun) + Ome_kj_1d_buffer = zero + !write(unit,*) '\Ome_{k\gamma}_{j\beta}_1d_buffer allocated' + ! + ! case('Phy_k')! allocate Phy_k allocate(Phy_k(2*extent+1,2*extent+1,2*extent+1,nsf1), STAT=stat) if(stat/=0) call cq_abort('Error allocating memory to Phy_k/exx !',stat) diff --git a/src/exx_types.f90 b/src/exx_types.f90 index 3a34979e2..2343bfbb4 100644 --- a/src/exx_types.f90 +++ b/src/exx_types.f90 @@ -55,13 +55,13 @@ module exx_types ! end type fftw1d ! PAOs on grid - real(double), dimension(:,:,:,:), allocatable :: phi_i + real(double), dimension(:), allocatable :: phi_i_1d_buffer real(double), dimension(:,:,:,:), allocatable :: phi_j real(double), dimension(:,:,:,:), allocatable :: phi_k real(double), dimension(:,:,:,:), allocatable :: phi_l ! Auxiliary densities and potentials - real(double), dimension(:,:,:), allocatable :: Ome_kj + real(double), dimension(:,:,:), allocatable :: Ome_kj_1d_buffer real(double), dimension(:,:,:,:), allocatable :: Phy_k From a324ddf709c32d96fd6d995f9383d3fd33e706ea Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Wed, 7 Feb 2024 15:39:27 +0000 Subject: [PATCH 02/17] Fixing references to phi_i and Ome_kj --- src/exx_memory.f90 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/exx_memory.f90 b/src/exx_memory.f90 index 48aa252e9..f586f7677 100644 --- a/src/exx_memory.f90 +++ b/src/exx_memory.f90 @@ -21,7 +21,7 @@ module exx_memory use datatypes use exx_types, ONLY: phi_i, phi_j, phi_k, phi_l - use exx_types, ONLY: Phy_k, Ome_kj + use exx_types, ONLY: Phy_k, Ome_kj_1d_buffer use exx_types, ONLY: work_in_3d,work_out_3d @@ -102,7 +102,7 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) if(stat/=0) call cq_abort('Error allocating memory to phi_i/exx !',stat) call reg_alloc_mem(area_exx,nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1),& type_dbl,matrix,lun) - phi_i = zero + phi_i_1d_buffer = zero !write(*,*) '\phi_{i\alpha} allocated', shape(phi_i) ! ! @@ -148,7 +148,7 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) !write(unit,*) '\Ome_{k\gamma}_{j\beta} allocated' ! ! - case('Ome_kj_1d_buffer') ! allocate Ome_kj_1d_buffer + case('Ome_kj_1d_buffer') ! allocate Ome_kj_1d_buffer allocate(Ome_kj_1d_buffer((2*extent+1)*(2*extent+1)*(2*extent+1)), STAT=stat) if(stat/=0) call cq_abort('Error allocating memory to Ome_kj_1d_buffer/exx !',stat) call reg_alloc_mem(area_exx,(2*extent+1)*(2*extent+1)*(2*extent+1),& @@ -289,8 +289,8 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) call start_timer(tmr_std_exx_dealloc) select case (matrix) case('phi_i') - deallocate(phi_i,STAT=stat) - if(stat/=0) call cq_abort('Error deallocating memory to phi_i/exx !',stat) + deallocate(phi_i_1d_buffer,STAT=stat) + if(stat/=0) call cq_abort('Error deallocating memory to phi_i_1d_buffer/exx !',stat) call reg_dealloc_mem(area_exx,nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1),& type_dbl,matrix,lun) !write(*,*) '\phi_{i\alpha} deallocated' @@ -320,9 +320,9 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) !write(*,*) '\phi_{l\delta} deallocated' ! ! - case('Ome_kj') - deallocate(Ome_kj,STAT=stat) - if(stat/=0) call cq_abort('Error deallocating memory to Ome_kj/exx !',stat) + case('Ome_kj_1d_buffer') + deallocate(Ome_kj_1d_buffer,STAT=stat) + if(stat/=0) call cq_abort('Error deallocating memory to Ome_kj_1d_buffer/exx !',stat) call reg_dealloc_mem(area_exx,(2*extent+1)*(2*extent+1)*(2*extent+1),& type_dbl,matrix,lun) !write(unit,*) '\Ome_{k\gamma}_{j\beta} deallocated' From 74df9999a8aa66966829a04ceba48e0eb52e085e Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Wed, 7 Feb 2024 15:48:14 +0000 Subject: [PATCH 03/17] Redefine phi_i and Ome_kj --- src/exx_types.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/exx_types.f90 b/src/exx_types.f90 index 2343bfbb4..05e41290d 100644 --- a/src/exx_types.f90 +++ b/src/exx_types.f90 @@ -56,12 +56,13 @@ module exx_types ! PAOs on grid real(double), dimension(:), allocatable :: phi_i_1d_buffer + real(double), dimension(:,:,:,:), allocatable :: phi_i real(double), dimension(:,:,:,:), allocatable :: phi_j real(double), dimension(:,:,:,:), allocatable :: phi_k real(double), dimension(:,:,:,:), allocatable :: phi_l ! Auxiliary densities and potentials - real(double), dimension(:,:,:), allocatable :: Ome_kj_1d_buffer + real(double), dimension(:), allocatable :: Ome_kj_1d_buffer real(double), dimension(:,:,:,:), allocatable :: Phy_k From 69e3efd4cc140da56fb5c1e5c97947e48148df22 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Wed, 7 Feb 2024 15:54:07 +0000 Subject: [PATCH 04/17] Fixing array declarations --- src/exx_kernel_default.f90 | 3 ++- src/exx_types.f90 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index ba24fcbca..613f76f84 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -917,6 +917,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & use numbers, only: zero, one use matrix_module, only: matrix_halo, matrix_trans use global_module, only: area_exx + use GenBlas, only: dot ! use basic_types, only: primary_set use primary_module, only: bundle @@ -995,7 +996,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! real(double), dimension(:), allocatable :: phi_i_1d_buffer ! real(double), :: Ome_kj_reduced_1d_buffer((2*extent+1)*(2*extent+1)*(2*extent+1)) - real(double), pointer :: phi_i(:,:,:), Ome_kj_reduced(:,:,:) + real(double), pointer :: phi_i(:,:,:,:), Ome_kj_reduced(:,:,:) ! type(prim_atomic_data) :: ia !i_alpha type(neigh_atomic_data) :: jb !j_beta diff --git a/src/exx_types.f90 b/src/exx_types.f90 index 05e41290d..0fe33b18d 100644 --- a/src/exx_types.f90 +++ b/src/exx_types.f90 @@ -55,7 +55,7 @@ module exx_types ! end type fftw1d ! PAOs on grid - real(double), dimension(:), allocatable :: phi_i_1d_buffer + real(double), dimension(:), allocatable, target :: phi_i_1d_buffer real(double), dimension(:,:,:,:), allocatable :: phi_i real(double), dimension(:,:,:,:), allocatable :: phi_j real(double), dimension(:,:,:,:), allocatable :: phi_k From ece73a0fb442afb560ecebe49fd11c9c398934c6 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Wed, 7 Feb 2024 16:58:11 +0000 Subject: [PATCH 05/17] Cleaning up code --- src/exx_kernel_default.f90 | 16 ---------------- src/exx_memory.f90 | 20 ++++++++++++++++++-- src/exx_types.f90 | 10 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 613f76f84..7065e8f95 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1199,22 +1199,6 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! do nsf3 = 1, ia%nsup ! - ! exx_mat_elem = zero - ! ! - ! do r = 1, 2*extent+1 - ! do s = 1, 2*extent+1 - ! do t = 1, 2*extent+1 - - ! exx_mat_elem = exx_mat_elem & - ! + phi_i(t,s,r,nsf3) & - ! * Ome_kj_reduced(t,s,r) * dv - - ! end do - ! end do - ! end do - ! ! - ! c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + exx_mat_elem - c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + dot((2*extent+1)**3, phi_i(:,:,:,nsf3), 1, Ome_kj, 1) * dv ! end do ! nsf3 = 1, ia%nsup diff --git a/src/exx_memory.f90 b/src/exx_memory.f90 index f586f7677..57bec0460 100644 --- a/src/exx_memory.f90 +++ b/src/exx_memory.f90 @@ -98,14 +98,22 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) !!$ ! case('phi_i') ! allocate phi_i for primary atom - allocate(phi_i_1d_buffer(nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1)), STAT=stat) + allocate(phi_i(2*extent+1,2*extent+1,2*extent+1,nsf1), STAT=stat) if(stat/=0) call cq_abort('Error allocating memory to phi_i/exx !',stat) call reg_alloc_mem(area_exx,nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1),& type_dbl,matrix,lun) - phi_i_1d_buffer = zero + phi_i = zero !write(*,*) '\phi_{i\alpha} allocated', shape(phi_i) ! ! + case('phi_i_1d_buffer') ! allocate phi_i for primary atom + allocate(phi_i_1d_buffer(nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1)), STAT=stat) + if(stat/=0) call cq_abort('Error allocating memory to phi_i_1d_buffer/exx !',stat) + call reg_alloc_mem(area_exx,nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1),& + type_dbl,matrix,lun) + phi_i_1d_buffer = zero + ! + ! case('phi_j') ! allocate phi_j for neighbour atom [Srange] allocate(phi_j(2*extent+1,2*extent+1,2*extent+1,nsf1), STAT=stat) if(stat/=0) call cq_abort('Error allocating memory to phi_j/exx !',stat) @@ -289,6 +297,14 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) call start_timer(tmr_std_exx_dealloc) select case (matrix) case('phi_i') + deallocate(phi_i,STAT=stat) + if(stat/=0) call cq_abort('Error deallocating memory to phi_i/exx !',stat) + call reg_dealloc_mem(area_exx,nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1),& + type_dbl,matrix,lun) + !write(*,*) '\phi_{i\alpha} deallocated' + ! + ! + case('phi_i_1d_buffer') deallocate(phi_i_1d_buffer,STAT=stat) if(stat/=0) call cq_abort('Error deallocating memory to phi_i_1d_buffer/exx !',stat) call reg_dealloc_mem(area_exx,nsf1*(2*extent+1)*(2*extent+1)*(2*extent+1),& diff --git a/src/exx_types.f90 b/src/exx_types.f90 index 0fe33b18d..7593199a3 100644 --- a/src/exx_types.f90 +++ b/src/exx_types.f90 @@ -55,11 +55,11 @@ module exx_types ! end type fftw1d ! PAOs on grid - real(double), dimension(:), allocatable, target :: phi_i_1d_buffer - real(double), dimension(:,:,:,:), allocatable :: phi_i - real(double), dimension(:,:,:,:), allocatable :: phi_j - real(double), dimension(:,:,:,:), allocatable :: phi_k - real(double), dimension(:,:,:,:), allocatable :: phi_l + real(double), dimension(:,:,:,:), allocatable :: phi_i + real(double), dimension(:), allocatable, target :: phi_i_1d_buffer + real(double), dimension(:,:,:,:), allocatable :: phi_j + real(double), dimension(:,:,:,:), allocatable :: phi_k + real(double), dimension(:,:,:,:), allocatable :: phi_l ! Auxiliary densities and potentials real(double), dimension(:), allocatable :: Ome_kj_1d_buffer From 1f80cfdcf6a4c03c640666e038fdf1415037cbde Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Thu, 8 Feb 2024 12:23:19 +0000 Subject: [PATCH 06/17] allocate 1d buffers --- src/exx_kernel_default.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 7065e8f95..62f473718 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1119,7 +1119,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! !print*, 'i',i, 'global_num',ia%ip,'spe',ia%spec ! - if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i','alloc') + if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i_1d_buffer','alloc') phi_i(1:2*extent+1, 1:2*extent+1, 1:2*extent+1, 1:ia%nsup) => phi_i_1d_buffer ! call exx_phi_on_grid(inode,ia%ip,ia%spec,extent, & From 90d0f79eebe95ec49ec4c41f89c6b1f3645e68e2 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Thu, 8 Feb 2024 12:36:35 +0000 Subject: [PATCH 07/17] calling correct deallocate and adding print statements --- src/exx_kernel_default.f90 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 62f473718..fe7bf09ee 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1120,10 +1120,13 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & !print*, 'i',i, 'global_num',ia%ip,'spe',ia%spec ! if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i_1d_buffer','alloc') + print *, "Allocated phi_i_1d_buffer" phi_i(1:2*extent+1, 1:2*extent+1, 1:2*extent+1, 1:ia%nsup) => phi_i_1d_buffer + print *, "pointed phi_i at phi_i_1d_buffer"^ ! call exx_phi_on_grid(inode,ia%ip,ia%spec,extent, & - ia%xyz,ia%nsup,phi_i,r_int,xyz_zero) + ia%xyz,ia%nsup,phi_i,r_int,xyz_zero) + print *, "populated phi_i" ! !print*, size(chalo%i_h2d), shape(chalo%i_h2d) ! @@ -1202,6 +1205,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + dot((2*extent+1)**3, phi_i(:,:,:,nsf3), 1, Ome_kj, 1) * dv ! end do ! nsf3 = 1, ia%nsup + print *, nsf1, nsf2, "calculated c" ! end do ! nsf2 = 1, jb%nsup end do ! nsf1 = 1, kg%nsup @@ -1209,7 +1213,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! call stop_timer(tmr_std_exx_accumul,.true.) ! - if ( exx_alloc ) call exx_mem_alloc(extent,0,0,'Ome_kj','dealloc') + if ( exx_alloc ) call exx_mem_alloc(extent,0,0,'Ome_kj_1d_buffer','dealloc') if ( exx_alloc ) call exx_mem_alloc(extent,jb%nsup,0,'phi_j','dealloc') ! end if ! ( ncbeg /=0 ) @@ -1226,7 +1230,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & !!$ ****[ i end loop ]**** !!$ ! - if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i','dealloc') + if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i_1d_buffer','dealloc') ! end do ! End of i = 1, at%n_hnab(k_in_halo) ! From a4e986c51997ad0e20894d219ea828610f1ead8d Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Thu, 8 Feb 2024 12:37:26 +0000 Subject: [PATCH 08/17] Remving typo --- src/exx_kernel_default.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index fe7bf09ee..4b3380f02 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1122,7 +1122,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i_1d_buffer','alloc') print *, "Allocated phi_i_1d_buffer" phi_i(1:2*extent+1, 1:2*extent+1, 1:2*extent+1, 1:ia%nsup) => phi_i_1d_buffer - print *, "pointed phi_i at phi_i_1d_buffer"^ + print *, "pointed phi_i at phi_i_1d_buffer" ! call exx_phi_on_grid(inode,ia%ip,ia%spec,extent, & ia%xyz,ia%nsup,phi_i,r_int,xyz_zero) From 9792a66fb8e628d810f98ce5ad1d1cd7c0560a7d Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Thu, 8 Feb 2024 14:05:51 +0000 Subject: [PATCH 09/17] Make Ome_kj_reduced firstprivate --- src/exx_kernel_default.f90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 4b3380f02..0b6b41d45 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1169,12 +1169,12 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer ! call start_timer(tmr_std_exx_accumul) - !$omp parallel do schedule(runtime) collapse(2) default(none) reduction(+: c) & - !$omp shared(kg,jb,tmr_std_exx_poisson,tmr_std_exx_accumul,Phy_k,phi_j,phi_k,ncbeg,ia, & - !$omp tmr_std_exx_matmult,ewald_pot,phi_i,exx_psolver,exx_pscheme,extent,dv, & - !$omp ewald_rho,inode,pulay_radius,p_omega,p_gauss,w_gauss,reckernel_3d,r_int) & - !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge,Ome_kj,ncaddr,nsf3, & - !$omp exx_mat_elem,r,s,t) + !$omp parallel do schedule(runtime) collapse(2) default(none) reduction(+: c) & + !$omp shared(kg,jb,tmr_std_exx_poisson,tmr_std_exx_accumul,Phy_k,phi_j,phi_k,ncbeg,ia,tmr_std_exx_matmult,ewald_pot,phi_i, & + !$omp exx_psolver,exx_pscheme,extent,dv,ewald_rho,inode,pulay_radius,p_omega,p_gauss,w_gauss,reckernel_3d,r_int) & + !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge, & + !$omp ncaddr,nsf3,exx_mat_elem,r,s,t) & + !$omp firstprivate(Ome_kj) do nsf1 = 1, kg%nsup do nsf2 = 1, jb%nsup From f3aab62e35b9de8474abc3197b2725cbc12fdee7 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Thu, 8 Feb 2024 14:08:30 +0000 Subject: [PATCH 10/17] Removing print statements --- src/exx_kernel_default.f90 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 0b6b41d45..eb2ed0028 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1120,13 +1120,10 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & !print*, 'i',i, 'global_num',ia%ip,'spe',ia%spec ! if ( exx_alloc ) call exx_mem_alloc(extent,ia%nsup,0,'phi_i_1d_buffer','alloc') - print *, "Allocated phi_i_1d_buffer" phi_i(1:2*extent+1, 1:2*extent+1, 1:2*extent+1, 1:ia%nsup) => phi_i_1d_buffer - print *, "pointed phi_i at phi_i_1d_buffer" ! call exx_phi_on_grid(inode,ia%ip,ia%spec,extent, & ia%xyz,ia%nsup,phi_i,r_int,xyz_zero) - print *, "populated phi_i" ! !print*, size(chalo%i_h2d), shape(chalo%i_h2d) ! @@ -1205,7 +1202,6 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + dot((2*extent+1)**3, phi_i(:,:,:,nsf3), 1, Ome_kj, 1) * dv ! end do ! nsf3 = 1, ia%nsup - print *, nsf1, nsf2, "calculated c" ! end do ! nsf2 = 1, jb%nsup end do ! nsf1 = 1, kg%nsup From 8376f5c421ebc1c188ecc6cfa10c8c174848a5e8 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Thu, 8 Feb 2024 15:08:20 +0000 Subject: [PATCH 11/17] point inside parallel region --- src/exx_kernel_default.f90 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index eb2ed0028..5e910aa12 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1166,12 +1166,14 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer ! call start_timer(tmr_std_exx_accumul) - !$omp parallel do schedule(runtime) collapse(2) default(none) reduction(+: c) & + !$omp parallel default(none) reduction(+: c) & !$omp shared(kg,jb,tmr_std_exx_poisson,tmr_std_exx_accumul,Phy_k,phi_j,phi_k,ncbeg,ia,tmr_std_exx_matmult,ewald_pot,phi_i, & !$omp exx_psolver,exx_pscheme,extent,dv,ewald_rho,inode,pulay_radius,p_omega,p_gauss,w_gauss,reckernel_3d,r_int) & - !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge, & + !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge,Ome_kj_reduced_1d_buffer, & !$omp ncaddr,nsf3,exx_mat_elem,r,s,t) & !$omp firstprivate(Ome_kj) + Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer + !$omp do schedule(runtime) collapse(2) do nsf1 = 1, kg%nsup do nsf2 = 1, jb%nsup @@ -1205,7 +1207,9 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! end do ! nsf2 = 1, jb%nsup end do ! nsf1 = 1, kg%nsup - !$omp end parallel do + !$omp end do + !$omp end parallel + call stop_timer(tmr_std_exx_accumul,.true.) ! call stop_timer(tmr_std_exx_accumul,.true.) ! From dabf0aff5071e6067c680f7e6096ebffa43661e4 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Fri, 9 Feb 2024 13:07:49 +0000 Subject: [PATCH 12/17] Fixing broken stuff after rebase --- src/exx_kernel_default.f90 | 15 ++++++--------- src/exx_memory.f90 | 11 +---------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 5e910aa12..8c740974d 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -344,7 +344,7 @@ subroutine get_X_matrix( exxspin, scheme, backup_eris, niter, siter, level ) ! if ( scheme == 1 ) then call exx_mem_alloc(extent,maxsuppfuncs,0,'Phy_k','alloc') - call exx_mem_alloc(extent,maxsuppfuncs,maxsuppfuncs,'Ome_kj','alloc') + call exx_mem_alloc(extent,maxsuppfuncs,maxsuppfuncs,'Ome_kj_1d_buffer','alloc') ! end if ! @@ -799,7 +799,7 @@ subroutine get_X_matrix( exxspin, scheme, backup_eris, niter, siter, level ) ! if ( scheme == 1 ) then call exx_mem_alloc(extent,maxsuppfuncs,0,'Phy_k','dealloc') - call exx_mem_alloc(extent,maxsuppfuncs,maxsuppfuncs,'Ome_kj','dealloc') + call exx_mem_alloc(extent,maxsuppfuncs,maxsuppfuncs,'Ome_kj_1d_buffer','dealloc') ! end if ! @@ -937,7 +937,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & unit_exx_debug ! use exx_types, only: phi_i, phi_j, phi_k, phi_l, & - Phy_k, Ome_kj, & + Phy_k, Ome_kj_1d_buffer, & work_in_3d, work_out_3d use exx_types, only: exx_alloc ! @@ -993,10 +993,8 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & real(double), dimension(3) :: xyz_zero = zero real(double) :: dr,dv,K_val real(double) :: exx_mat_elem - - ! real(double), dimension(:), allocatable :: phi_i_1d_buffer - ! real(double), :: Ome_kj_reduced_1d_buffer((2*extent+1)*(2*extent+1)*(2*extent+1)) - real(double), pointer :: phi_i(:,:,:,:), Ome_kj_reduced(:,:,:) + ! + real(double), pointer :: phi_i(:,:,:,:), Ome_kj(:,:,:) ! type(prim_atomic_data) :: ia !i_alpha type(neigh_atomic_data) :: jb !j_beta @@ -1163,13 +1161,12 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & jb%xyz,jb%nsup,phi_j,r_int,xyz_zero) ! if ( exx_alloc ) call exx_mem_alloc(extent,0,0,'Ome_kj_1d_buffer','alloc') - Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer ! call start_timer(tmr_std_exx_accumul) !$omp parallel default(none) reduction(+: c) & !$omp shared(kg,jb,tmr_std_exx_poisson,tmr_std_exx_accumul,Phy_k,phi_j,phi_k,ncbeg,ia,tmr_std_exx_matmult,ewald_pot,phi_i, & !$omp exx_psolver,exx_pscheme,extent,dv,ewald_rho,inode,pulay_radius,p_omega,p_gauss,w_gauss,reckernel_3d,r_int) & - !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge,Ome_kj_reduced_1d_buffer, & + !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge,Ome_kj_1d_buffer, & !$omp ncaddr,nsf3,exx_mat_elem,r,s,t) & !$omp firstprivate(Ome_kj) Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer diff --git a/src/exx_memory.f90 b/src/exx_memory.f90 index 57bec0460..f07d93083 100644 --- a/src/exx_memory.f90 +++ b/src/exx_memory.f90 @@ -147,15 +147,6 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) !!$ !!$ ! - case('Ome_kj') ! allocate Ome_kj - allocate(Ome_kj(2*extent+1,2*extent+1,2*extent+1), STAT=stat) - if(stat/=0) call cq_abort('Error allocating memory to Ome_kj/exx !',stat) - call reg_alloc_mem(area_exx,(2*extent+1)*(2*extent+1)*(2*extent+1),& - type_dbl,matrix,lun) - Ome_kj = zero - !write(unit,*) '\Ome_{k\gamma}_{j\beta} allocated' - ! - ! case('Ome_kj_1d_buffer') ! allocate Ome_kj_1d_buffer allocate(Ome_kj_1d_buffer((2*extent+1)*(2*extent+1)*(2*extent+1)), STAT=stat) if(stat/=0) call cq_abort('Error allocating memory to Ome_kj_1d_buffer/exx !',stat) @@ -341,7 +332,7 @@ subroutine exx_mem_alloc(extent,nsf1,nsf2,matrix,flag,unit,n_neigh,neigh) if(stat/=0) call cq_abort('Error deallocating memory to Ome_kj_1d_buffer/exx !',stat) call reg_dealloc_mem(area_exx,(2*extent+1)*(2*extent+1)*(2*extent+1),& type_dbl,matrix,lun) - !write(unit,*) '\Ome_{k\gamma}_{j\beta} deallocated' + !write(unit,*) '\Ome_{k\gamma}_{j\beta}_1d_buffer deallocated' case('Phy_k') deallocate(Phy_k, STAT=stat) From cfa1b96b0b4486243206b7d7bbba1710247de9c5 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Fri, 9 Feb 2024 13:13:56 +0000 Subject: [PATCH 13/17] Fix broken phi_i allocation --- src/exx_kernel_default.f90 | 2 +- src/exx_memory.f90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 8c740974d..3a6e31625 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -936,7 +936,7 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & exx_psolver, exx_pscheme, & unit_exx_debug ! - use exx_types, only: phi_i, phi_j, phi_k, phi_l, & + use exx_types, only: phi_i_1d_buffer, phi_j, phi_k, phi_l, & Phy_k, Ome_kj_1d_buffer, & work_in_3d, work_out_3d use exx_types, only: exx_alloc diff --git a/src/exx_memory.f90 b/src/exx_memory.f90 index f07d93083..51df63ddf 100644 --- a/src/exx_memory.f90 +++ b/src/exx_memory.f90 @@ -20,7 +20,7 @@ module exx_memory use datatypes - use exx_types, ONLY: phi_i, phi_j, phi_k, phi_l + use exx_types, ONLY: phi_i, phi_i_1d_buffer, phi_j, phi_k, phi_l use exx_types, ONLY: Phy_k, Ome_kj_1d_buffer From 6791e7e5301ee254d79d9eecdb689097be775364 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Fri, 9 Feb 2024 13:52:38 +0000 Subject: [PATCH 14/17] make Ome_kj_1d_buffer a target --- src/exx_types.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exx_types.f90 b/src/exx_types.f90 index 7593199a3..2f77bbbc4 100644 --- a/src/exx_types.f90 +++ b/src/exx_types.f90 @@ -62,8 +62,8 @@ module exx_types real(double), dimension(:,:,:,:), allocatable :: phi_l ! Auxiliary densities and potentials - real(double), dimension(:), allocatable :: Ome_kj_1d_buffer - real(double), dimension(:,:,:,:), allocatable :: Phy_k + real(double), dimension(:), allocatable, target :: Ome_kj_1d_buffer + real(double), dimension(:,:,:,:), allocatable :: Phy_k From a241c36c9956f4404741236651e3e6605b806e48 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Mon, 12 Feb 2024 11:02:27 +0000 Subject: [PATCH 15/17] Remove extra stop_timer for tmr_std_exx_accumul --- src/exx_kernel_default.f90 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 3a6e31625..184380b1c 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1206,7 +1206,6 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & end do ! nsf1 = 1, kg%nsup !$omp end do !$omp end parallel - call stop_timer(tmr_std_exx_accumul,.true.) ! call stop_timer(tmr_std_exx_accumul,.true.) ! From 7eb8dd852192696b502c8fabfdaa6f5f43436779 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Mon, 12 Feb 2024 15:26:11 +0000 Subject: [PATCH 16/17] Making Ome_kj private --- src/exx_kernel_default.f90 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index 184380b1c..fb46e230c 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1164,11 +1164,11 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! call start_timer(tmr_std_exx_accumul) !$omp parallel default(none) reduction(+: c) & - !$omp shared(kg,jb,tmr_std_exx_poisson,tmr_std_exx_accumul,Phy_k,phi_j,phi_k,ncbeg,ia,tmr_std_exx_matmult,ewald_pot,phi_i, & - !$omp exx_psolver,exx_pscheme,extent,dv,ewald_rho,inode,pulay_radius,p_omega,p_gauss,w_gauss,reckernel_3d,r_int) & - !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge,Ome_kj_1d_buffer, & + !$omp shared(kg,jb,tmr_std_exx_poisson,tmr_std_exx_accumul,Phy_k,phi_j,phi_k,ncbeg,ia, & + !$omp tmr_std_exx_matmult,ewald_pot,phi_i,exx_psolver,exx_pscheme,extent,dv, & + !$omp ewald_rho,inode,pulay_radius,p_omega,p_gauss,w_gauss,reckernel_3d,r_int) & + !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge,Ome_kj_1d_buffer,Ome_kj, & !$omp ncaddr,nsf3,exx_mat_elem,r,s,t) & - !$omp firstprivate(Ome_kj) Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer !$omp do schedule(runtime) collapse(2) do nsf1 = 1, kg%nsup @@ -1198,7 +1198,8 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & ! do nsf3 = 1, ia%nsup ! - c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) + dot((2*extent+1)**3, phi_i(:,:,:,nsf3), 1, Ome_kj, 1) * dv + c(ncaddr + nsf3 - 1) = c(ncaddr + nsf3 - 1) & + + dot((2*extent+1)**3, phi_i(:,:,:,nsf3), 1, Ome_kj, 1) * dv ! end do ! nsf3 = 1, ia%nsup ! From cee9e0fd95067d75638f6d2a39745cc0f04c80a2 Mon Sep 17 00:00:00 2001 From: Connor Aird Date: Tue, 13 Feb 2024 13:16:00 +0000 Subject: [PATCH 17/17] remove trailing & --- src/exx_kernel_default.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exx_kernel_default.f90 b/src/exx_kernel_default.f90 index fb46e230c..9ea194278 100644 --- a/src/exx_kernel_default.f90 +++ b/src/exx_kernel_default.f90 @@ -1163,12 +1163,12 @@ subroutine m_kern_exx_cri(k_off, kpart, ib_nd_acc, ibaddr, nbnab, & if ( exx_alloc ) call exx_mem_alloc(extent,0,0,'Ome_kj_1d_buffer','alloc') ! call start_timer(tmr_std_exx_accumul) - !$omp parallel default(none) reduction(+: c) & + !$omp parallel default(none) reduction(+: c) & !$omp shared(kg,jb,tmr_std_exx_poisson,tmr_std_exx_accumul,Phy_k,phi_j,phi_k,ncbeg,ia, & !$omp tmr_std_exx_matmult,ewald_pot,phi_i,exx_psolver,exx_pscheme,extent,dv, & !$omp ewald_rho,inode,pulay_radius,p_omega,p_gauss,w_gauss,reckernel_3d,r_int) & !$omp private(nsf1,nsf2,work_out_3d,work_in_3d,ewald_charge,Ome_kj_1d_buffer,Ome_kj, & - !$omp ncaddr,nsf3,exx_mat_elem,r,s,t) & + !$omp ncaddr,nsf3,exx_mat_elem,r,s,t) Ome_kj(1:2*extent+1, 1:2*extent+1, 1:2*extent+1) => Ome_kj_1d_buffer !$omp do schedule(runtime) collapse(2) do nsf1 = 1, kg%nsup