annotate libgomp/testsuite/libgomp.c-c++-common/alloc-1.c @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 #include <omp.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 #include <stdint.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3 #include <stdlib.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5 const omp_alloctrait_t traits2[]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 = { { omp_atk_alignment, 16 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 { omp_atk_sync_hint, omp_atv_default },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8 { omp_atk_access, omp_atv_default },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 { omp_atk_pool_size, 1024 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 { omp_atk_fallback, omp_atv_default_mem_fb },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 { omp_atk_partition, omp_atv_environment } };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 omp_alloctrait_t traits3[]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13 = { { omp_atk_sync_hint, omp_atv_uncontended },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 { omp_atk_alignment, 32 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 { omp_atk_access, omp_atv_all },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 { omp_atk_pool_size, 512 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17 { omp_atk_fallback, omp_atv_allocator_fb },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 { omp_atk_fb_data, 0 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19 { omp_atk_partition, omp_atv_default } };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 const omp_alloctrait_t traits4[]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 = { { omp_atk_alignment, 128 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 { omp_atk_pool_size, 1024 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 { omp_atk_fallback, omp_atv_null_fb } };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 int
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 main ()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 int *volatile p = (int *) omp_alloc (3 * sizeof (int), omp_default_mem_alloc);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 int *volatile q;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 int *volatile r;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 omp_alloctrait_t traits[3]
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 = { { omp_atk_alignment, 64 },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 { omp_atk_fallback, omp_atv_null_fb },
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 { omp_atk_pool_size, 4096 } };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 omp_allocator_handle_t a, a2;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 if ((((uintptr_t) p) % __alignof (int)) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 p[0] = 1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 p[1] = 2;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 p[2] = 3;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 omp_free (p, omp_default_mem_alloc);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 p = (int *) omp_alloc (2 * sizeof (int), omp_default_mem_alloc);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 if ((((uintptr_t) p) % __alignof (int)) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 p[0] = 1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 p[1] = 2;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 omp_free (p, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 omp_set_default_allocator (omp_default_mem_alloc);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50 p = (int *) omp_alloc (sizeof (int), omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 if ((((uintptr_t) p) % __alignof (int)) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 p[0] = 3;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 omp_free (p, omp_get_default_allocator ());
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 a = omp_init_allocator (omp_default_mem_space, 3, traits);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 if (a == omp_null_allocator)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 p = (int *) omp_alloc (3072, a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 if ((((uintptr_t) p) % 64) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 p[0] = 1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 p[3071 / sizeof (int)] = 2;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 if (omp_alloc (3072, a) != NULL)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 omp_free (p, a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 p = (int *) omp_alloc (3072, a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 p[0] = 3;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 p[3071 / sizeof (int)] = 4;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 omp_free (p, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71 omp_set_default_allocator (a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 if (omp_get_default_allocator () != a)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 p = (int *) omp_alloc (3072, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 if (omp_alloc (3072, omp_null_allocator) != NULL)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 omp_free (p, a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 omp_destroy_allocator (a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 a = omp_init_allocator (omp_default_mem_space,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81 sizeof (traits2) / sizeof (traits2[0]),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82 traits2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83 if (a == omp_null_allocator)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85 if (traits3[5].key != omp_atk_fb_data)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87 traits3[5].value = (uintptr_t) a;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88 a2 = omp_init_allocator (omp_default_mem_space,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89 sizeof (traits3) / sizeof (traits3[0]),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 traits3);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91 if (a2 == omp_null_allocator)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93 p = (int *) omp_alloc (420, a2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94 if ((((uintptr_t) p) % 32) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96 p[0] = 5;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 p[419 / sizeof (int)] = 6;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98 q = (int *) omp_alloc (768, a2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99 if ((((uintptr_t) q) % 16) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 q[0] = 7;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102 q[767 / sizeof (int)] = 8;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 r = (int *) omp_alloc (512, a2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
104 if ((((uintptr_t) r) % __alignof (int)) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
105 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
106 r[0] = 9;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
107 r[511 / sizeof (int)] = 10;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
108 omp_free (p, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
109 omp_free (q, a2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
110 omp_free (r, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
111 omp_destroy_allocator (a2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
112 omp_destroy_allocator (a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
113
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
114 a = omp_init_allocator (omp_default_mem_space,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
115 sizeof (traits4) / sizeof (traits4[0]),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
116 traits4);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
117 if (a == omp_null_allocator)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
118 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
119 if (traits3[5].key != omp_atk_fb_data)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
120 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
121 traits3[5].value = (uintptr_t) a;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
122 a2 = omp_init_allocator (omp_default_mem_space,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
123 sizeof (traits3) / sizeof (traits3[0]),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
124 traits3);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
125 if (a2 == omp_null_allocator)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
126 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
127 omp_set_default_allocator (a2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
128 #ifdef __cplusplus
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
129 p = static_cast <int *> (omp_alloc (420));
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
130 #else
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
131 p = (int *) omp_alloc (420, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
132 #endif
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
133 if ((((uintptr_t) p) % 32) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
134 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
135 p[0] = 5;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
136 p[419 / sizeof (int)] = 6;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
137 q = (int *) omp_alloc (768, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
138 if ((((uintptr_t) q) % 128) != 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
139 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
140 q[0] = 7;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
141 q[767 / sizeof (int)] = 8;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
142 if (omp_alloc (768, omp_null_allocator) != NULL)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
143 abort ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
144 #ifdef __cplusplus
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
145 omp_free (p);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
146 omp_free (q);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
147 omp_free (NULL);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
148 #else
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
149 omp_free (p, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
150 omp_free (q, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
151 omp_free (NULL, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
152 #endif
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
153 omp_free (NULL, omp_null_allocator);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
154 omp_destroy_allocator (a2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
155 omp_destroy_allocator (a);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
156 return 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
157 }