Set num_threads to 50 on 32-bit hppa in two libgomp loop tests
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / alloc-12.c
blobe07de3be6a7daf699ea5313134ead5268da3c4d0
1 /* This testcase is mostly the same as alloc-8.c.
2 However, on systems where the numa and/or memkind libraries are
3 installed, libgomp uses those. This test ensures that the minimal
4 features work. Note: No attempt has been made to verify the parition
5 hints interleaved and nearest as the kernal purposely ignore them once
6 in a while and it would also require a 'dlopen' dance.
8 memkind is used for omp_high_bw_mem_space, omp_large_cap_mem_space
9 and partition = interleaved, albeit it won't be interleaved for
10 omp_large_cap_mem_space.
12 numa is used for partition = nearest, unless memkind is used. */
14 #include <omp.h>
15 #include <stdint.h>
16 #include <stdlib.h>
18 const omp_alloctrait_t traits2[]
19 = { { omp_atk_alignment, 16 },
20 { omp_atk_sync_hint, omp_atv_default },
21 { omp_atk_access, omp_atv_default },
22 { omp_atk_pool_size, 1024 },
23 { omp_atk_fallback, omp_atv_default_mem_fb },
24 { omp_atk_partition, omp_atv_nearest } };
25 omp_alloctrait_t traits3[]
26 = { { omp_atk_sync_hint, omp_atv_uncontended },
27 { omp_atk_alignment, 32 },
28 { omp_atk_access, omp_atv_all },
29 { omp_atk_pool_size, 512 },
30 { omp_atk_fallback, omp_atv_allocator_fb },
31 { omp_atk_fb_data, 0 },
32 { omp_atk_partition, omp_atv_interleaved } };
33 const omp_alloctrait_t traits4[]
34 = { { omp_atk_alignment, 128 },
35 { omp_atk_pool_size, 1024 },
36 { omp_atk_fallback, omp_atv_null_fb } };
38 static void
39 check_all_zero (void *ptr, size_t len)
41 char *p = (char *) ptr;
42 for (size_t i = 0; i < len; i++)
43 if (p[i] != '\0')
44 abort ();
47 int
48 main ()
50 int *volatile p = (int *) omp_aligned_calloc (sizeof (int), 3, sizeof (int), omp_high_bw_mem_alloc);
51 check_all_zero (p, 3*sizeof (int));
52 int *volatile q;
53 int *volatile r;
54 int i;
55 omp_alloctrait_t traits[3]
56 = { { omp_atk_alignment, 64 },
57 { omp_atk_fallback, omp_atv_null_fb },
58 { omp_atk_pool_size, 4096 } };
59 omp_allocator_handle_t a, a2;
61 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] || p[1] || p[2])
62 abort ();
63 p[0] = 1;
64 p[1] = 2;
65 p[2] = 3;
66 omp_free (p, omp_high_bw_mem_alloc);
67 p = (int *) omp_aligned_calloc (2 * sizeof (int), 1, 2 * sizeof (int), omp_large_cap_mem_alloc);
68 check_all_zero (p, 2*sizeof (int));
69 if ((((uintptr_t) p) % (2 * sizeof (int))) != 0 || p[0] || p[1])
70 abort ();
71 p[0] = 1;
72 p[1] = 2;
73 omp_free (p, omp_null_allocator);
74 omp_set_default_allocator (omp_large_cap_mem_alloc);
75 p = (int *) omp_aligned_calloc (1, 1, sizeof (int), omp_null_allocator);
76 check_all_zero (p, sizeof (int));
77 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0])
78 abort ();
79 p[0] = 3;
80 omp_free (p, omp_get_default_allocator ());
82 a = omp_init_allocator (omp_large_cap_mem_space, 3, traits);
83 if (a == omp_null_allocator)
84 abort ();
85 p = (int *) omp_aligned_calloc (32, 3, 1024, a);
86 check_all_zero (p, 3*1024);
87 if ((((uintptr_t) p) % 64) != 0)
88 abort ();
89 for (i = 0; i < 3072 / sizeof (int); i++)
90 if (p[i])
91 abort ();
92 p[0] = 1;
93 p[3071 / sizeof (int)] = 2;
94 if (omp_aligned_calloc (8, 192, 16, a) != NULL)
95 abort ();
96 omp_free (p, a);
97 p = (int *) omp_aligned_calloc (128, 6, 512, a);
98 check_all_zero (p, 6*512);
99 if ((((uintptr_t) p) % 128) != 0)
100 abort ();
101 for (i = 0; i < 3072 / sizeof (int); i++)
102 if (p[i])
103 abort ();
104 p[0] = 3;
105 p[3071 / sizeof (int)] = 4;
106 omp_free (p, omp_null_allocator);
107 omp_set_default_allocator (a);
108 if (omp_get_default_allocator () != a)
109 abort ();
110 p = (int *) omp_aligned_calloc (64, 12, 256, omp_null_allocator);
111 check_all_zero (p, 12*256);
112 for (i = 0; i < 3072 / sizeof (int); i++)
113 if (p[i])
114 abort ();
115 if (omp_aligned_calloc (8, 128, 24, omp_null_allocator) != NULL)
116 abort ();
117 omp_free (p, a);
118 omp_destroy_allocator (a);
120 a = omp_init_allocator (omp_default_mem_space,
121 sizeof (traits2) / sizeof (traits2[0]),
122 traits2);
123 if (a == omp_null_allocator)
124 abort ();
125 if (traits3[5].key != omp_atk_fb_data)
126 abort ();
127 traits3[5].value = (uintptr_t) a;
128 a2 = omp_init_allocator (omp_default_mem_space,
129 sizeof (traits3) / sizeof (traits3[0]),
130 traits3);
131 if (a2 == omp_null_allocator)
132 abort ();
133 p = (int *) omp_aligned_calloc (4, 5, 84, a2);
134 check_all_zero (p, 5*84);
135 for (i = 0; i < 420 / sizeof (int); i++)
136 if (p[i])
137 abort ();
138 if ((((uintptr_t) p) % 32) != 0)
139 abort ();
140 p[0] = 5;
141 p[419 / sizeof (int)] = 6;
142 q = (int *) omp_aligned_calloc (8, 24, 32, a2);
143 check_all_zero (q, 24*32);
144 if ((((uintptr_t) q) % 16) != 0)
145 abort ();
146 for (i = 0; i < 768 / sizeof (int); i++)
147 if (q[i])
148 abort ();
149 q[0] = 7;
150 q[767 / sizeof (int)] = 8;
151 r = (int *) omp_aligned_calloc (8, 64, 8, a2);
152 check_all_zero (r, 64*8);
153 if ((((uintptr_t) r) % 8) != 0)
154 abort ();
155 for (i = 0; i < 512 / sizeof (int); i++)
156 if (r[i])
157 abort ();
158 r[0] = 9;
159 r[511 / sizeof (int)] = 10;
160 omp_free (p, omp_null_allocator);
161 omp_free (q, a2);
162 omp_free (r, omp_null_allocator);
163 omp_destroy_allocator (a2);
164 omp_destroy_allocator (a);
166 a = omp_init_allocator (omp_high_bw_mem_space,
167 sizeof (traits4) / sizeof (traits4[0]),
168 traits4);
169 if (a == omp_null_allocator)
170 abort ();
171 if (traits3[5].key != omp_atk_fb_data)
172 abort ();
173 traits3[5].value = (uintptr_t) a;
174 a2 = omp_init_allocator (omp_high_bw_mem_space,
175 sizeof (traits3) / sizeof (traits3[0]),
176 traits3);
177 if (a2 == omp_null_allocator)
178 abort ();
179 omp_set_default_allocator (a2);
180 #ifdef __cplusplus
181 p = static_cast <int *> (omp_aligned_calloc (4, 21, 20));
182 #else
183 p = (int *) omp_aligned_calloc (4, 21, 20, omp_null_allocator);
184 #endif
185 check_all_zero (p, 21*20);
186 if ((((uintptr_t) p) % 32) != 0)
187 abort ();
188 for (i = 0; i < 420 / sizeof (int); i++)
189 if (p[i])
190 abort ();
191 p[0] = 5;
192 p[419 / sizeof (int)] = 6;
193 q = (int *) omp_aligned_calloc (64, 12, 64, omp_null_allocator);
194 check_all_zero (q, 12*64);
195 if ((((uintptr_t) q) % 128) != 0)
196 abort ();
197 for (i = 0; i < 768 / sizeof (int); i++)
198 if (q[i])
199 abort ();
200 q[0] = 7;
201 q[767 / sizeof (int)] = 8;
202 if (omp_aligned_calloc (8, 24, 32, omp_null_allocator) != NULL)
203 abort ();
204 #ifdef __cplusplus
205 omp_free (p);
206 omp_free (q);
207 omp_free (NULL);
208 #else
209 omp_free (p, omp_null_allocator);
210 omp_free (q, omp_null_allocator);
211 omp_free (NULL, omp_null_allocator);
212 #endif
213 omp_free (NULL, omp_null_allocator);
214 omp_destroy_allocator (a2);
215 omp_destroy_allocator (a);
216 return 0;