OpenMP_PinnedAllocationRoutine.f90 1.43 KB
Newer Older
1
2
3
4
program OpenMP_PinnedAllocation

  use omp_lib
  use iso_fortran_env
5
  use iso_c_binding
6
7
8
9
10
  
  implicit none
  
  integer, parameter :: &
    N_VALUES    = 256 ** 3, &
11
    N_VARIABLES = 40
12
13
14
  real ( real64 ) :: &
    TimeStart, &
    TimeStop
15
  real ( real64 ), dimension ( :, : ), pointer :: &
16
17
18
19
    A_Pinned, &
    A_NonPinned
  integer ( omp_allocator_handle_kind ) :: &
    OMP_AllocHandle
20
21
  type ( c_ptr ) :: &
    A_Pinned_C_Ptr
22
23
24
25
26
  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 ] )
27
28
29
30
31
32
33
34
  
  !-- 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 ) )
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    
  !$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