|
4 | 4 | ! RUN: %libomptarget-compile-fortran-run-and-check-generic |
5 | 5 |
|
6 | 6 | program test_openmp_mapper |
7 | | - implicit none |
8 | | - integer, parameter :: n = 1024 |
9 | | - type :: mytype |
10 | | - integer :: data(n) |
11 | | - end type mytype |
12 | | - |
13 | | - ! Declare a custom mapper for the derived type `mytype` with the name `my_mapper` |
14 | | - !$omp declare mapper(my_mapper : mytype :: t) map(to: t%data) |
15 | | - |
16 | | - type(mytype) :: obj |
17 | | - integer :: i, sum_host, sum_device |
18 | | - |
19 | | - ! Initialize the host data |
20 | | - do i = 1, n |
21 | | - obj%data(i) = 1 |
22 | | - end do |
23 | | - |
24 | | - ! Compute the sum on the host for verification |
25 | | - sum_host = sum(obj%data) |
26 | | - |
27 | | - ! Offload computation to the device using the named mapper `my_mapper` |
28 | | - sum_device = 0 |
29 | | - !$omp target map(tofrom: sum_device) map(mapper(my_mapper) : obj) |
30 | | - do i = 1, n |
31 | | - sum_device = sum_device + obj%data(i) |
32 | | - end do |
33 | | - !$omp end target |
34 | | - |
35 | | - ! Check results |
36 | | - print *, "Sum on host: ", sum_host |
37 | | - print *, "Sum on device: ", sum_device |
38 | | - |
39 | | - if (sum_device == sum_host) then |
40 | | - print *, "Test passed!" |
41 | | - else |
42 | | - print *, "Test failed!" |
43 | | - end if |
44 | | -end program test_openmp_mapper |
| 7 | + implicit none |
| 8 | + integer, parameter :: n = 1024 |
| 9 | + type :: mytype |
| 10 | + integer :: data(n) |
| 11 | + end type mytype |
| 12 | + |
| 13 | + ! Declare custom mappers for the derived type `mytype` |
| 14 | + !$omp declare mapper(my_mapper1 : mytype :: t) map(to: t%data) |
| 15 | + !$omp declare mapper(my_mapper2 : mytype :: t) map(mapper(my_mapper1): t%data) |
| 16 | + |
| 17 | + type(mytype) :: obj |
| 18 | + integer :: i, sum_host, sum_device |
| 19 | + |
| 20 | + ! Initialize the host data |
| 21 | + do i = 1, n |
| 22 | + obj%data(i) = 1 |
| 23 | + end do |
| 24 | + |
| 25 | + ! Compute the sum on the host for verification |
| 26 | + sum_host = sum(obj%data) |
| 27 | + |
| 28 | + ! Offload computation to the device using the named mapper `my_mapper2` |
| 29 | + sum_device = 0 |
| 30 | + !$omp target map(tofrom: sum_device) map(mapper(my_mapper2) : obj) |
| 31 | + do i = 1, n |
| 32 | + sum_device = sum_device + obj%data(i) |
| 33 | + end do |
| 34 | + !$omp end target |
| 35 | + |
| 36 | + ! Check results |
| 37 | + print *, "Sum on host: ", sum_host |
| 38 | + print *, "Sum on device: ", sum_device |
| 39 | + |
| 40 | + if (sum_device == sum_host) then |
| 41 | + print *, "Test passed!" |
| 42 | + else |
| 43 | + print *, "Test failed!" |
| 44 | + end if |
| 45 | + end program test_openmp_mapper |
45 | 46 |
|
46 | 47 | ! CHECK: Test passed! |
0 commit comments