Debian Codegraph @

libgomp/testsuite/libgomp.c/omp_alloc-3.c

raw
1 /* { dg-do run } */
2
3 /* Stress-test omp_alloc/omp_malloc under concurrency. */
4
5 #include <omp.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #pragma omp requires dynamic_allocators
10
11 #define N 1000
12
13 void
14 test (omp_allocator_handle_t allocator)
15 {
16 #pragma omp target map(to:allocator)
17 {
18 #pragma omp parallel for
19 for (int i = 0; i < N; i++)
20 for (int j = 0; j < N; j++)
21 {
22 int *p = omp_alloc (sizeof (int), allocator);
23 omp_free (p, allocator);
24 }
25 }
26 }
27
28 int
29 main ()
30 {
31 /* omp_low_lat_mem_alloc doesn't actually get low-latency memory on GPU. */
32 omp_alloctrait_t traits[1] = { { omp_atk_access, omp_atv_cgroup } };
33 omp_allocator_handle_t gpu_lowlat;
34 #pragma omp target map(from:gpu_lowlat)
35 gpu_lowlat = omp_init_allocator (omp_low_lat_mem_space, 1, traits);
36
37 // Smaller than low-latency memory limit
38 test (omp_default_mem_alloc);
39 test (omp_large_cap_mem_alloc);
40 test (omp_const_mem_alloc);
41 test (omp_high_bw_mem_alloc);
42 test (omp_low_lat_mem_alloc);
43 test (gpu_lowlat);
44 test (omp_cgroup_mem_alloc);
45 test (omp_pteam_mem_alloc);
46 test (omp_thread_mem_alloc);
47
48 return 0;
49 }