diff --git a/DirectProgramming/Fortran/Jupyter/OpenMP-offload-training/USM/main.f90 b/DirectProgramming/Fortran/Jupyter/OpenMP-offload-training/USM/main.f90 index dd836b0cb1..1ce7fbbfff 100644 --- a/DirectProgramming/Fortran/Jupyter/OpenMP-offload-training/USM/main.f90 +++ b/DirectProgramming/Fortran/Jupyter/OpenMP-offload-training/USM/main.f90 @@ -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