Debian Codegraph @

libgomp/testsuite/libgomp.c++/target-flex-61.C

raw
1 /* { dg-additional-options "-std=c++20" } */
2
3 /* ranged algorithms c++20 */
4
5 #include <algorithm>
6 #include <ranges>
7 #include <vector>
8
9 //TODO PR120454 "C++ constexpr vs. OpenMP implicit mapping"
10 #pragma omp declare target(std::ranges::copy, std::ranges::equal, std::ranges::rotate, std::ranges::transform)
11
12 #include "target-flex-common.h"
13
14 namespace stdr = std::ranges;
15
16 template<typename T, std::size_t Size>
17 bool test(const T (&arr)[Size])
18 {
19 bool ok;
20 T out_2x_arr[Size];
21 T out_shifted_arr[Size];
22 #pragma omp target defaultmap(none) \
23 map(from: ok, out_2x_arr[:Size], out_shifted_arr[:Size]) \
24 map(to: arr[:Size])
25 {
26 std::vector<T> vec(Size);
27 std::vector<T> mutated(Size);
28 bool inner_ok = true;
29 {
30 stdr::copy(arr, vec.begin());
31 VERIFY (stdr::equal(arr, vec));
32 stdr::transform(vec, mutated.begin(),
33 [](const T& v){ return v * 2; });
34 stdr::copy(mutated, out_2x_arr);
35 stdr::rotate(vec, std::next(vec.begin(), Size / 2));
36 stdr::copy(vec, out_shifted_arr);
37 }
38 end:
39 ok = inner_ok;
40 }
41 if (!ok)
42 return false;
43 VERIFY_NON_TARGET (stdr::equal(arr, out_2x_arr, stdr::equal_to{}, [](const T& v){ return v * 2; }));
44 std::vector<T> shifted(arr, arr + Size);
45 stdr::rotate(shifted, std::next(shifted.begin(), Size / 2));
46 VERIFY_NON_TARGET (stdr::equal(out_shifted_arr, shifted));
47 return true;
48 }
49
50 int main()
51 {
52 int arr[] = {0, 1, 2, 3, 4, 5, 6, 7};
53 return test(arr) ? 0 : 1;
54 }