Debian Codegraph @

libgomp/testsuite/libgomp.c++/target-std__flat_multimap-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 <flat_map>
12
13 // Make sure that KEY_MAX is less than N to ensure some duplicate keys.
14 #define N 3000
15 #define KEY_MAX 1000
16
17 void init (int data[], int max)
18 {
19 for (int i = 0; i < N; ++i)
20 data[i] = i % max;
21 }
22
23 bool validate (long long sum, int keys[], int data[])
24 {
25 long long total = 0;
26 for (int i = 0; i < N; ++i)
27 total += (long long) keys[i] * data[i];
28 return sum == total;
29 }
30
31 int main (void)
32 {
33 int keys[N], data[N];
34 std::flat_multimap<int,int> _map;
35
36 srand (time (NULL));
37 init (keys, KEY_MAX);
38 init (data, RAND_MAX);
39
40 #pragma omp target enter data map (to: keys[:N], data[:N]) map (alloc: _map)
41
42 #pragma omp target
43 {
44 #ifndef MEM_SHARED
45 new (&_map) std::flat_multimap<int,int> ();
46 #endif
47 for (int i = 0; i < N; ++i)
48 _map.insert({keys[i], data[i]});
49 }
50
51 long long sum = 0;
52 #pragma omp target teams distribute parallel for reduction (+:sum)
53 for (int i = 0; i < KEY_MAX; ++i)
54 {
55 auto range = _map.equal_range (i);
56 for (auto it = range.first; it != range.second; ++it) {
57 sum += (long long) it->first * it->second;
58 }
59 }
60
61 #ifndef MEM_SHARED
62 #pragma omp target
63 _map.~flat_multimap ();
64 #endif
65
66 #pragma omp target exit data map (release: _map)
67
68 bool ok = validate (sum, keys, data);
69 return ok ? 0 : 1;
70 }