| 21 | } |
| 22 | |
| 23 | int64_t fib(const int64_t n) { |
| 24 | if (n <= 20) return fib_sequential(n); |
| 25 | |
| 26 | int64_t n1; |
| 27 | parallel::spawn([&]() { |
| 28 | n1 = fib(n - 1); |
| 29 | TSAN_ANNOTATE_HAPPENS_BEFORE(&n1); |
| 30 | }); |
| 31 | |
| 32 | int64_t n2 = fib(n - 2); |
| 33 | TSAN_ANNOTATE_HAPPENS_BEFORE(&n2); |
| 34 | |
| 35 | parallel::sync(); |
| 36 | |
| 37 | TSAN_ANNOTATE_HAPPENS_AFTER(&n1); |
| 38 | TSAN_ANNOTATE_HAPPENS_AFTER(&n2); |
| 39 | // printf("fib(%ld) = %ld + %ld = %ld\n", n, n1, n2, n1 + n2); |
| 40 | return n1 + n2; |
| 41 | } |
| 42 | #if 0 |
| 43 | int64_t fib_omp(const int64_t n) { |
| 44 | if (n <= 20) return fib_sequential(n); |
no test coverage detected