Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OpenMP parallelization in WSC to avoid data-races #1191

Merged
merged 12 commits into from
Feb 13, 2025
29 changes: 15 additions & 14 deletions src/generate_wsc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ subroutine generate_wsc(mol,wsc)
! Variables
! ------------------------------------------------------------------------
integer :: rep(3)
integer :: ii,jj,ich
integer :: ii,jj
integer :: aa,bb,cc
integer :: c,wc
integer :: minpos
Expand All @@ -54,22 +54,22 @@ subroutine generate_wsc(mol,wsc)
call wsc%allocate(mol%n,rep)

! ------------------------------------------------------------------------
! initialize
! ------------------------------------------------------------------------
allocate( lattr(3,wsc%cells), source = 0 )
allocate( dist(wsc%cells), source = 0.0_wp )
allocate( trans(wsc%cells), source = .true. )
! ------------------------------------------------------------------------
! Create the Wigner-Seitz Cell (WSC)
! ------------------------------------------------------------------------
wsc%at = 0
wsc%itbl= 0
!$omp parallel default(none) &
!$omp private(ii,jj,wc,c,dist,trans,t,lattr,rw) &
!$omp shared(mol,wsc,rep) &
!$omp shared(mindist,minpos,nmindist,nminpos)
!$omp do schedule(dynamic)

!$omp parallel default(none) &
!$omp private(ii,jj,aa,bb,cc,wc,c,dist,trans,t,lattr,rw) &
!$omp shared(mol,wsc,rep) &
!$omp private(mindist,minpos,nmindist,nminpos)

allocate( lattr(3,wsc%cells), source = 0 )
allocate( dist(wsc%cells), source = 0.0_wp )
allocate( trans(wsc%cells), source = .true. )

! Each WSC of one atom consists of n atoms
!$omp do collapse(2) schedule(dynamic,32)
do ii=1,mol%n
do jj=1,mol%n
!if (ii.eq.jj) cycle
Expand Down Expand Up @@ -123,7 +123,8 @@ subroutine generate_wsc(mol,wsc)
endif
end do
end do
!$omp enddo
!$omp endparallel
!$omp end do
deallocate(lattr, dist, trans)
!$omp end parallel

end subroutine generate_wsc