Debian Codegraph @

libgomp/testsuite/libgomp.c/omp_alloc-2.c

raw
1 /* { dg-do run } */
2
3 /* Test concurrent and repeated allocations. */
4
5 #include <omp.h>
6
7 #pragma omp requires dynamic_allocators
8
9 void
10 test (int n, omp_allocator_handle_t allocator)
11 {
12 #pragma omp target map(to:n) map(to:allocator)
13 {
14 int **a;
15 a = (int **) omp_alloc (n * sizeof (int *), allocator);
16
17 #pragma omp parallel for
18 for (int i = 0; i < n; i++)
19 {
20 /*Use 10x to ensure we do activate low-latency fall-back. */
21 a[i] = omp_alloc (sizeof (int) * 10, allocator);
22 a[i][0] = i;
23 }
24
25 for (int i = 0; i < n; i++)
26 if (a[i][0] != i)
27 {
28 __builtin_printf ("data mismatch at %i\n", i);
29 __builtin_abort ();
30 }
31
32 #pragma omp parallel for
33 for (int i = 0; i < n; i++)
34 omp_free (a[i], allocator);
35
36 omp_free (a, allocator);
37 }
38 }
39
40 int
41 main ()
42 {
43 /* omp_low_lat_mem_alloc doesn't actually get low-latency memory on GPU. */
44 omp_alloctrait_t traits[1] = { { omp_atk_access, omp_atv_cgroup } };
45 omp_allocator_handle_t gpu_lowlat;
46 #pragma omp target map(from:gpu_lowlat)
47 gpu_lowlat = omp_init_allocator (omp_low_lat_mem_space, 1, traits);
48
49 // Smaller than low-latency memory limit
50 test (10, omp_default_mem_alloc);
51 test (10, omp_large_cap_mem_alloc);
52 test (10, omp_const_mem_alloc);
53 test (10, omp_high_bw_mem_alloc);
54 test (10, omp_low_lat_mem_alloc);
55 test (10, gpu_lowlat);
56 test (10, omp_cgroup_mem_alloc);
57 test (10, omp_pteam_mem_alloc);
58 test (10, omp_thread_mem_alloc);
59
60 // Larger than low-latency memory limit (on aggregate)
61 test (1000, omp_default_mem_alloc);
62 test (1000, omp_large_cap_mem_alloc);
63 test (1000, omp_const_mem_alloc);
64 test (1000, omp_high_bw_mem_alloc);
65 test (1000, omp_low_lat_mem_alloc);
66 test (1000, gpu_lowlat);
67 test (1000, omp_cgroup_mem_alloc);
68 test (1000, omp_pteam_mem_alloc);
69 test (1000, omp_thread_mem_alloc);
70
71 return 0;
72 }