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

Draft tests for running on target depending on selector.

parent 1e4f0cc4
!-- Check if using begin/end metadirective with static selector for
! target executes on device and produces correct results.
! This should pass on "ibm", fail elsewhere.
program OpenMP_metadirective_target_test
use omp_lib
use iso_fortran_env
implicit none
integer :: &
iV
real ( real64 ), dimension ( : ), allocatable :: &
A, B, C, &
C_Ref
character ( 1 ) :: &
ibm, cray
allocate ( A ( 1024 ) )
allocate ( B ( 1024 ) )
allocate ( C ( 1024 ) )
call random_number ( A )
call random_number ( B )
call random_number ( C )
allocate ( C_Ref, source = C )
C_Ref = A + B
!$OMP target enter data map ( to: A, B, C )
!-- FIXME: multiple selector seems to confuse IBM XL
!; $OMP begin metadirective &
!; $OMP when ( implementation = { vendor(ibm) } &
!; $OMP : target ) &
!; $OMP when ( implementation = { vendor(cray) } &
!; $OMP : target )
!$OMP begin metadirective &
!$OMP when ( implementation = { vendor(ibm) } &
!$OMP : target )
!$OMP teams distribute parallel do
do iV = 1, size ( A )
C ( iV ) = A ( iV ) + B ( iV )
end do
!$OMP end teams distribute parallel do
!$OMP end metadirective
!$OMP target update from ( C )
if ( all ( C == C_Ref ) ) then
print*, 'PASSED'
else
print*, 'FAILED'
end if
end program OpenMP_metadirective_target_test
!-- Check if using begin/end metadirective with user condition for
! target executes on device and produces correct results.
program OpenMP_beginend_metadirective_user_condition_target
use omp_lib
use iso_fortran_env
implicit none
integer :: &
iV
real ( real64 ), dimension ( : ), allocatable :: &
A, B, C, &
C_Ref
logical :: &
UseDevice, &
OnDevice
allocate ( A ( 1024 ) )
allocate ( B ( 1024 ) )
allocate ( C ( 1024 ) )
call random_number ( A )
call random_number ( B )
call random_number ( C )
allocate ( C_Ref, source = C )
C_Ref = A + B
OnDevice = .false.
UseDevice = .false.
!$OMP target enter data map ( to: A, B, C )
!-- !$OMP begin metadirective &
!-- !$OMP when ( user = { condition ( UseDevice .EQV. .true. ) } &
!-- !$OMP : target map ( from: OnDevice ) )
OnDevice = .not. omp_is_initial_device ( )
!$OMP teams distribute parallel do
do iV = 1, size ( A )
C ( iV ) = A ( iV ) + B ( iV )
end do
!$OMP end teams distribute parallel do
!-- !$OMP end metadirective
if ( OnDevice ) then
print*, 'Run on device : TRUE'
else
print*, 'Run on device : FALSE'
end if
if ( UseDevice ) then
!$OMP target update from ( C )
end if
if ( all ( C == C_Ref ) ) then
print*, 'Correct results : PASSED'
else
print*, 'Correct results : FAILED'
end if
!$OMP target exit data map ( delete: A, B, C )
end program OpenMP_beginend_metadirective_user_condition_target
Supports Markdown
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