Debian Codegraph @

libgomp/testsuite/libgomp.c++/target-std__flat_map-concurrent.C

raw
1 // { dg-do run }
2 // { dg-additional-options "-std=c++23" }
3 // { dg-additional-options -DMEM_SHARED { target offload_device_shared_as } }
4
5 /* { dg-ice {TODO PR120450} { offload_target_amdgcn && { ! offload_device_shared_as } } }
6 { dg-excess-errors {'mkoffload' failure etc.} { xfail { offload_target_amdgcn && { ! offload_device_shared_as } } } }
7 (For effective-target 'offload_device_shared_as', we've got '-DMEM_SHARED', and therefore don't invoke the constructor with placement new.) */
8
9 #include <stdlib.h>
10 #include <time.h>
11 #include <set>
12 #include <flat_map>
13
14 #define N 3000
15
16 void init (int data[], bool unique)
17 {
18 std::set<int> _set;
19 for (int i = 0; i < N; ++i)
20 {
21 // Avoid duplicates in data array if unique is true.
22 do
23 data[i] = rand ();
24 while (unique && _set.count (data[i]) > 0);
25 _set.insert (data[i]);
26 }
27 }
28
29 bool validate (long long sum, int keys[], int data[])
30 {
31 long long total = 0;
32 for (int i = 0; i < N; ++i)
33 total += (long long) keys[i] * data[i];
34 return sum == total;
35 }
36
37 int main (void)
38 {
39 int keys[N], data[N];
40 std::flat_map<int,int> _map;
41
42 srand (time (NULL));
43 init (keys, true);
44 init (data, false);
45
46 #pragma omp target enter data map (to: keys[:N], data[:N]) map (alloc: _map)
47
48 #pragma omp target
49 {
50 #ifndef MEM_SHARED
51 new (&_map) std::flat_map<int,int> ();
52 #endif
53 for (int i = 0; i < N; ++i)
54 _map[keys[i]] = data[i];
55 }
56
57 long long sum = 0;
58 #pragma omp target teams distribute parallel for reduction (+:sum)
59 for (int i = 0; i < N; ++i)
60 sum += (long long) keys[i] * _map[keys[i]];
61
62 #ifndef MEM_SHARED
63 #pragma omp target
64 _map.~flat_map ();
65 #endif
66
67 #pragma omp target exit data map (release: _map)
68
69 bool ok = validate (sum, keys, data);
70 return ok ? 0 : 1;
71 }