Commit dff36bce authored by Budiardja, Reuben's avatar Budiardja, Reuben
Browse files

OpenMP offload Array Reduction test case.

parent 15970fd3
program TargetArrayReduction
use OMP_LIB
implicit none
integer :: &
iV, jV, kV, &
StopCode
real, dimension ( :, : ), allocatable :: &
FEP_1, FEP_2, FEP_3
real, dimension ( : ), allocatable :: &
D_MaxSpeed, &
H_MaxSpeed
StopCode = 0
allocate ( FEP_1 ( 32, 8 ) )
allocate ( FEP_2 ( 32, 8 ) )
allocate ( FEP_3 ( 32, 8 ) )
allocate ( D_MaxSpeed ( 8 ), H_MaxSpeed ( 8 ) )
call random_number ( FEP_1 )
call random_number ( FEP_2 )
call random_number ( FEP_3 )
!$OMP target enter data map ( to: FEP_1, FEP_2, FEP_3 )
D_MaxSpeed = - huge ( 1.0 )
H_MaxSpeed = - huge ( 1.0 )
print*, 'Num devices: ', omp_get_num_devices()
!-- Device reduction
!$OMP target teams distribute parallel do simd &
!$OMP schedule ( static, 1 ) &
!$OMP reduction ( max : D_MaxSpeed ) map ( D_MaxSpeed )
do jV = 1, size ( FEP_1, dim = 2 )
do iV = 1, size ( FEP_1, dim = 1 )
D_MaxSpeed ( jV ) &
= max ( FEP_1 ( iV, jV ), FEP_2 ( iV, jV ), &
FEP_3 ( iV, jV ), D_MaxSpeed ( jV ) )
end do
end do
!$OMP end target teams distribute parallel do simd
!-- Host reduction ( with Fortran )
H_MaxSpeed = max ( maxval ( FEP_1, dim = 1 ), &
maxval ( FEP_2, dim = 1 ), &
maxval ( FEP_3, dim = 1 ) )
print*, 'MaxSpeed reduced on device ', D_MaxSpeed
print*, 'MaxSpeed reduced on host ', H_MaxSpeed
if ( all ( D_MaxSpeed == H_MaxSpeed ) ) then
print*, 'Reduction on device: PASSED'
else
print*, 'Reduction on device: FAILED'
end if
!if ( StopCode /= 0 ) stop StopCode
end program TargetArrayReduction
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment