brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · ac289b5 Raw
66 lines · c
1// RUN: %libomp-compile-and-run2 3// https://bugs.llvm.org/show_bug.cgi?id=26540 requested4// stack size to be propagated from master to workers.5// Library implements propagation of not too big stack6// for Linux x86_64 platform (skipped Windows for now).7//8// The test checks that workers can use more than 4MB9// of stack (4MB - was historical default for10// stack size of worker thread in runtime library).11 12#include <stdio.h>13#include <omp.h>14#if !defined(_WIN32)15#include <sys/resource.h> // getrlimit16#endif17 18#define STK 480000019 20double foo(int n, int th)21{22  double arr[n];23  int i;24  double res = 0.0;25  for (i = 0; i < n; ++i) {26    arr[i] = (double)i / (n + 2);27  }28  for (i = 0; i < n; ++i) {29    res += arr[i] / n;30  }31  return res;32}33 34int main(int argc, char *argv[])35{36#if defined(_WIN32)37  // don't test Windows38  printf("stack propagation not implemented, skipping test...\n");39  return 0;40#else41  int status;42  double val = 0.0;43  int m = STK / 8; // > 4800000 bytes per thread44  // read stack size of calling thread, save it as default45  struct rlimit rlim;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 size49#pragma omp parallel reduction(+:val)50    {51      val += foo(m, omp_get_thread_num());52    }53  } else {54    printf("too small stack size limit (needs about 8MB), skipping test...\n");55    return 0;56  }57  if (val > 0.1) {58    printf("passed\n");59    return 0;60  } else {61    printf("failed, val = %f\n", val);62    return 1;63  }64#endif // _WIN3265}66