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

WIP: Make Fortran USM example similar to C++ #1689

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,61 @@
! =============================================================
program main
use omp_lib
implicit none
integer, parameter :: N=16
integer :: correct_count=0
integer :: i
integer, allocatable :: x(:)
logical :: is_cpu = .true.
integer, allocatable :: x(:), y(:)
double precision :: te, tb

!$omp allocate allocator(omp_target_shared_mem_alloc)
allocate(x(N))
allocate(x(N),y(N))

print *,'Number of OpenMP Devices ',omp_get_num_devices()

tb = omp_get_wtime()

do i=1,N
x(i) = 1
end do

do i=1,N
x(i) = i
end do
y(i) = 1
end do

!$omp target map(tofrom: is_cpu) has_device_addr(x)
!$omp target map(tofrom: is_cpu) has_device_addr(y)
!$omp teams distribute parallel do
do i=1,N
if ((i==1) .and. (.not.(omp_is_initial_device()))) is_cpu=.false.
x(i) = x(i) * 2
x(i) = x(i) + y(i)
end do
!$omp end target

do i=1,N
y(i) = 2
end do

if (is_cpu) then
print *, "Running on CPU"
else
print *, "Running on GPU"
end if

!$omp target map(tofrom: is_cpu) has_device_addr(y)
!$omp teams distribute parallel do
do i=1,N
print *, x(i)
x(i) = x(i) + y(i)
end do
!$omp end target

te = omp_get_wtime()
print *,'Time of kernel ',te-tb,' seconds'

do i=1,N
if (x(i)==4) then
correct_count = correct_count + 1
end if
end do

if (correct_count==N) then
print *, 'Test: PASSED'
else
print *, 'Test: Failed'
endif

deallocate(x)
deallocate(x,y)
end program main