1 // RUN: %libomp-compile-and-run
3 // https://bugs.llvm.org/show_bug.cgi?id=26540 requested
4 // stack size to be propagated from master to workers.
5 // Library implements propagation of not too big stack
6 // for Linux x86_64 platform (skipped Windows for now).
8 // The test checks that workers can use more than 4MB
9 // of stack (4MB - was historical default for
10 // stack size of worker thread in runtime library).
15 #include <sys/resource.h> // getrlimit
20 double foo(int n
, int th
)
25 for (i
= 0; i
< n
; ++i
) {
26 arr
[i
] = (double)i
/ (n
+ 2);
28 for (i
= 0; i
< n
; ++i
) {
34 int main(int argc
, char *argv
[])
38 printf("stack propagation not implemented, skipping test...\n");
43 int m
= STK
/ 8; // > 4800000 bytes per thread
44 // read stack size of calling thread, save it as default
46 status
= getrlimit(RLIMIT_STACK
, &rlim
);
47 if (sizeof(void *) > 4 && // do not test 32-bit systems,
48 status
== 0 && rlim
.rlim_cur
> STK
) { // or small initial stack size
49 #pragma omp parallel reduction(+:val)
51 val
+= foo(m
, omp_get_thread_num());
54 printf("too small stack size limit (needs about 8MB), skipping test...\n");
61 printf("failed, val = %f\n", val
);