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

Pinned allocation with omp_alloc() routine.

parent dff36bce
......@@ -7,7 +7,7 @@ program OpenMP_PinnedAllocation
integer, parameter :: &
N_VALUES = 256 ** 3, &
N_VARIABLES = 20
N_VARIABLES = 40
real ( real64 ) :: &
TimeStart, &
TimeStop
......
program OpenMP_PinnedAllocation
use omp_lib
use iso_fortran_env
use iso_c_binding
implicit none
integer, parameter :: &
N_VALUES = 256 ** 3, &
N_VARIABLES = 40
real ( real64 ) :: &
TimeStart, &
TimeStop
real ( real64 ), dimension ( :, : ), pointer :: &
A_Pinned, &
A_NonPinned
integer ( omp_allocator_handle_kind ) :: &
OMP_AllocHandle
type ( c_ptr ) :: &
A_Pinned_C_Ptr
type ( omp_alloctrait ) :: &
OMP_TraitHandle = omp_alloctrait ( omp_atk_pinned, omp_atv_true )
OMP_AllocHandle &
= omp_init_allocator ( omp_default_mem_space, 1, [ OMP_TraitHandle ] )
!-- Pinned allocation
A_Pinned_C_Ptr &
= omp_alloc ( c_sizeof ( 1.0_real64 ) * N_VALUES * N_VARIABLES, &
OMP_AllocHandle )
call c_f_pointer ( A_Pinned_C_Ptr, A_Pinned, [ N_VALUES, N_VARIABLES ] )
allocate ( A_NonPinned ( N_VALUES, N_VARIABLES ) )
!$OMP target enter data map ( alloc : A_Pinned, A_NonPinned )
call random_number ( A_Pinned )
call random_number ( A_NonPinned )
TimeStart = omp_get_wtime ( )
!$OMP target update to ( A_Pinned )
!$OMP barrier
TimeStop = omp_get_wtime ( )
print*, 'Pinned timing (s) :', TimeStop - TimeStart
TimeStart = omp_get_wtime ( )
!$OMP target update to ( A_NonPinned )
!$OMP barrier
TimeStop = omp_get_wtime ( )
print*, 'NonPinned timing (s) :', TimeStop - TimeStart
end program OpenMP_PinnedAllocation
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