Debian Codegraph @

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

raw
1 /* algorithms pre c++20 */
2
3 #include <algorithm>
4 #include <vector>
5
6 #include "target-flex-common.h"
7
8 template<typename T, std::size_t Size>
9 bool test(const T (&arr)[Size])
10 {
11 bool ok;
12 T out_2x_arr[Size];
13 T out_shifted_arr[Size];
14 #pragma omp target map(from: ok, out_2x_arr[:Size], out_shifted_arr[:Size]) \
15 map(to: arr[:Size])
16 {
17 std::vector<T> vec(Size);
18 std::vector<T> mutated(Size);
19 bool inner_ok = true;
20 {
21 std::copy(arr, arr + Size, vec.begin());
22 VERIFY (std::equal(arr, arr + Size, vec.begin()));
23 std::transform(vec.begin(), vec.end(), mutated.begin(),
24 [](const T& v){ return v * 2; });
25 std::copy(mutated.begin(), mutated.end(), out_2x_arr);
26 std::rotate(vec.begin(), std::next(vec.begin(), Size / 2), vec.end());
27 std::copy(vec.begin(), vec.end(), out_shifted_arr);
28 }
29 end:
30 ok = inner_ok;
31 }
32 if (!ok)
33 return false;
34 VERIFY_NON_TARGET (std::equal(arr, arr + Size, out_2x_arr,
35 [](const T& a, const T& b){ return a * 2 == b; }));
36 std::vector<T> shifted(arr, arr + Size);
37 std::rotate(shifted.begin(), std::next(shifted.begin(), Size / 2), shifted.end());
38 VERIFY_NON_TARGET (std::equal(out_shifted_arr, out_shifted_arr + Size, shifted.begin()));
39 return true;
40 }
41
42 int main()
43 {
44 int arr[] = {0, 1, 2, 3, 4, 5, 6, 7};
45 return test(arr) ? 0 : 1;
46 }