Skip to content

Commit

Permalink
#857: conditionally rely on PARALLEL WORKSHARE
Browse files Browse the repository at this point in the history
- Avoid nested parallelism (dbcsr_acc_set_active_device).
- Rely on omp_get_level (instead of omp_in_parallel),
  omp_in_parallel only accounts for active regions.
- Avoid IF-condition as part of the WORKSHARE-directive.
- Removed (nested) PARALLEL WORKSHARE constructs.
  • Loading branch information
hfp committed Dec 6, 2024
1 parent 718c1cd commit c960839
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 44 deletions.
13 changes: 10 additions & 3 deletions src/acc/dbcsr_acc_device.F
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ MODULE dbcsr_acc_device
#endif
#include "base/dbcsr_base_uses.f90"

!$ USE OMP_LIB, ONLY: omp_get_level

IMPLICIT NONE

PUBLIC :: dbcsr_acc_get_ndevices, dbcsr_acc_set_active_device, dbcsr_acc_clear_errors
Expand Down Expand Up @@ -83,11 +85,16 @@ SUBROUTINE dbcsr_acc_set_active_device(device_id)
#if defined (__DBCSR_ACC)
INTEGER :: istat

!$OMP PARALLEL DEFAULT(NONE) PRIVATE(istat) SHARED(device_id)
istat = acc_set_active_device_cu(device_id)
!$ IF (0 == omp_get_level()) THEN
istat = 0
!$OMP PARALLEL DEFAULT(NONE) SHARED(device_id) REDUCTION(MAX:istat)
istat = acc_set_active_device_cu(device_id)
!$OMP END PARALLEL
!$ ELSE
istat = acc_set_active_device_cu(device_id)
!$ END IF
IF (istat /= 0) &
DBCSR_ABORT("dbcsr_acc_set_active_device: failed")
!$OMP END PARALLEL

#else
MARK_USED(device_id)
Expand Down
16 changes: 1 addition & 15 deletions src/data/dbcsr_ptr_util.F
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ 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

IMPLICIT NONE

PRIVATE
Expand Down Expand Up @@ -294,15 +292,9 @@ 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)
#endif
dst(:) = src(:)
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP END PARALLEL WORKSHARE
#endif
END SUBROUTINE mem_copy_${nametype1}$

SUBROUTINE mem_zero_${nametype1}$ (dst, n)
Expand All @@ -312,13 +304,7 @@ SUBROUTINE mem_zero_${nametype1}$ (dst, n)
!! length of elements to zero
${type1}$, DIMENSION(1:n), INTENT(OUT) :: dst
!! destination memory
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(dst)
#endif
dst(:) = ${zero1}$
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP END PARALLEL WORKSHARE
#endif
END SUBROUTINE mem_zero_${nametype1}$

SUBROUTINE mem_alloc_${nametype1}$ (mem, n, mem_type)
Expand Down
6 changes: 0 additions & 6 deletions src/mpi/dbcsr_mpiwrap.F
Original file line number Diff line number Diff line change
Expand Up @@ -5182,13 +5182,7 @@ SUBROUTINE mp_rget_${nametype1}$v(base, source, win, win_data, myproc, disp, req
MARK_USED(myproc)
#endif
IF (do_local_copy) THEN
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP PARALLEL WORKSHARE DEFAULT(none) SHARED(base,win_data,disp_aint,len)
#endif
base(:) = win_data(disp_aint + 1:disp_aint + len)
#if !defined(__DBCSR_DISABLE_WORKSHARE)
!$OMP END PARALLEL WORKSHARE
#endif
request = mp_request_null
ierr = 0
ELSE
Expand Down
21 changes: 1 addition & 20 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

IMPLICIT NONE

Expand Down Expand Up @@ -316,7 +316,6 @@ SUBROUTINE dbcsr_zero(matrix_a)

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)
Expand All @@ -325,24 +324,6 @@ SUBROUTINE dbcsr_zero(matrix_a)
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)
!$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)
!$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
!$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
!$OMP END PARALLEL WORKSHARE
#endif
END SELECT
CALL timestop(handle)
END SUBROUTINE dbcsr_zero
Expand Down

0 comments on commit c960839

Please sign in to comment.