OpenMP_PinnedAllocationDirective.f90 1.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
program OpenMP_PinnedAllocation

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