summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cilk-plus/CK/pr66326.cc
blob: 1114ebdda8236b55602ed90207c022254f710763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* { dg-options "-fcilkplus" } */
/* { dg-do run { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* } } } */

#include <cilk/cilk.h>
#include <vector>
#include <random>

template <class T>
void do_not_optimize_away(T&& x) {
  asm volatile("" : "+r"(x));
}

const int N = 1'000'000;

auto compute() {
  std::vector<double> v(N);
  auto rng = std::mt19937{std::random_device{}()};
  std::uniform_real_distribution<double> dist(0, 1);
  for (int i = 0; i < N; ++i) v[i] = std::log(std::sqrt(dist(rng)));
  return v;
}

int main() {
  std::vector<double> v1, v2, v3;
  cilk_spawn [&] { v1 = compute(); }();
  cilk_spawn [&] { v2 = compute(); }();
  v3 = compute();
  do_not_optimize_away(v1.data());
  do_not_optimize_away(v2.data());
  do_not_optimize_away(v3.data());
  return 0;
}