Skip to content

Commit

Permalink
#857: conditionally rely on PARALLEL WORKSHARE
Browse files Browse the repository at this point in the history
- Avoid IF-condition as part of the directive.
  • Loading branch information
hfp committed Oct 16, 2024
1 parent 66eb88e commit 9105048
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 36 deletions.
24 changes: 16 additions & 8 deletions src/data/dbcsr_ptr_util.F
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ MODULE dbcsr_ptr_util
mp_deallocate
#include "base/dbcsr_base_uses.f90"

!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_get_num_threads
!$ USE OMP_LIB, ONLY: omp_in_parallel

IMPLICIT NONE

Expand Down Expand Up @@ -294,14 +294,18 @@ SUBROUTINE mem_copy_${nametype1}$ (dst, src, n)
!! length of copy
${type1}$, DIMENSION(1:n), INTENT(OUT) :: dst
!! destination memory
${type1}$, DIMENSION(1:n), INTENT(IN) :: src
${type1}$, DIMENSION(1:n), INTENT(IN) :: src
!! source memory
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(dst,src)
!$ IF (.NOT. omp_in_parallel()) THEN
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(dst,src)
dst(:) = src(:)
!$OMP END PARALLEL WORKSHARE
!$ ELSE
#endif
dst(:) = src(:)
dst(:) = src(:)
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP END PARALLEL WORKSHARE
!$ END IF
#endif
END SUBROUTINE mem_copy_${nametype1}$

Expand All @@ -313,11 +317,15 @@ SUBROUTINE mem_zero_${nametype1}$ (dst, n)
${type1}$, DIMENSION(1:n), INTENT(OUT) :: dst
!! destination memory
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(dst)
!$ IF (.NOT. omp_in_parallel()) THEN
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(dst)
dst(:) = ${zero1}$
!$OMP END PARALLEL WORKSHARE
!$ ELSE
#endif
dst(:) = ${zero1}$
dst(:) = ${zero1}$
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP END PARALLEL WORKSHARE
!$ END IF
#endif
END SUBROUTINE mem_zero_${nametype1}$

Expand Down
12 changes: 9 additions & 3 deletions src/mpi/dbcsr_mpiwrap.F
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ MODULE dbcsr_mpiwrap
#define MPI_STATUS_EXTRACT(X) (X)
#endif

!$ USE OMP_LIB, ONLY: omp_in_parallel

IMPLICIT NONE
PRIVATE

Expand Down Expand Up @@ -5183,11 +5185,15 @@ SUBROUTINE mp_rget_${nametype1}$v(base, source, win, win_data, myproc, disp, req
#endif
IF (do_local_copy) THEN
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(base,win_data,disp_aint,len)
!$ IF (.NOT. omp_in_parallel()) THEN
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(base,win_data,disp_aint,len)
base(:) = win_data(disp_aint + 1:disp_aint + len)
!$OMP END PARALLEL WORKSHARE
!$ ELSE
#endif
base(:) = win_data(disp_aint + 1:disp_aint + len)
base(:) = win_data(disp_aint + 1:disp_aint + len)
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP END PARALLEL WORKSHARE
!$ END IF
#endif
request = mp_request_null
ierr = 0
Expand Down
56 changes: 31 additions & 25 deletions src/ops/dbcsr_operations.F
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ MODULE dbcsr_operations
mp_sum
#include "base/dbcsr_base_uses.f90"

!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_get_num_threads
!$ USE OMP_LIB, ONLY: omp_get_thread_num, omp_get_num_threads, omp_in_parallel

IMPLICIT NONE

Expand Down Expand Up @@ -315,35 +315,41 @@ SUBROUTINE dbcsr_zero(matrix_a)
INTEGER :: handle

CALL timeset(routineN, handle)
SELECT CASE (dbcsr_get_data_type(matrix_a))
#if defined(__DBCSR_DISABLE_WORKSHARE)
CASE (dbcsr_type_complex_4)
matrix_a%data_area%d%c_sp = (0.0, 0.0)
CASE (dbcsr_type_complex_8)
matrix_a%data_area%d%c_dp = (0.0_dp, 0.0_dp)
CASE (dbcsr_type_real_4)
matrix_a%data_area%d%r_sp = 0.0
CASE (dbcsr_type_real_8)
matrix_a%data_area%d%r_dp = 0.0_dp
#else
CASE (dbcsr_type_complex_4)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE), SHARED(matrix_a)
matrix_a%data_area%d%c_sp = (0.0, 0.0)
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$ IF (.NOT. omp_in_parallel()) THEN
SELECT CASE (dbcsr_get_data_type(matrix_a))
CASE (dbcsr_type_complex_4)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE) SHARED(matrix_a)
matrix_a%data_area%d%c_sp = (0.0, 0.0)
!$OMP END PARALLEL WORKSHARE
CASE (dbcsr_type_complex_8)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE), SHARED(matrix_a)
matrix_a%data_area%d%c_dp = (0.0_dp, 0.0_dp)
CASE (dbcsr_type_complex_8)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE) SHARED(matrix_a)
matrix_a%data_area%d%c_dp = (0.0_dp, 0.0_dp)
!$OMP END PARALLEL WORKSHARE
CASE (dbcsr_type_real_4)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE), SHARED(matrix_a)
matrix_a%data_area%d%r_sp = 0.0
CASE (dbcsr_type_real_4)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE) SHARED(matrix_a)
matrix_a%data_area%d%r_sp = 0.0
!$OMP END PARALLEL WORKSHARE
CASE (dbcsr_type_real_8)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE), SHARED(matrix_a)
matrix_a%data_area%d%r_dp = 0.0_dp
CASE (dbcsr_type_real_8)
!$OMP PARALLEL WORKSHARE DEFAULT(NONE) SHARED(matrix_a)
matrix_a%data_area%d%r_dp = 0.0_dp
!$OMP END PARALLEL WORKSHARE
END SELECT
!$ ELSE
#endif
SELECT CASE (dbcsr_get_data_type(matrix_a))
CASE (dbcsr_type_complex_4)
matrix_a%data_area%d%c_sp = (0.0, 0.0)
CASE (dbcsr_type_complex_8)
matrix_a%data_area%d%c_dp = (0.0_dp, 0.0_dp)
CASE (dbcsr_type_real_4)
matrix_a%data_area%d%r_sp = 0.0
CASE (dbcsr_type_real_8)
matrix_a%data_area%d%r_dp = 0.0_dp
END SELECT
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$ END IF
#endif
END SELECT
CALL timestop(handle)
END SUBROUTINE dbcsr_zero

Expand Down

0 comments on commit 9105048

Please sign in to comment.