File: omp_record_replay_deps.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (63 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (11)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// REQUIRES: ompx_taskgraph
// RUN: %libomp-cxx-compile-and-run
#include <iostream>
#include <cassert>
#define NT 100
#define MULTIPLIER 100
#define DECREMENT 5

int val;
// Compiler-generated code (emulation)
typedef struct ident {
    void* dummy;
} ident_t;


#ifdef __cplusplus
extern "C" {
  int __kmpc_global_thread_num(ident_t *);
  int __kmpc_start_record_task(ident_t *, int, int, int);
  void __kmpc_end_record_task(ident_t *, int, int, int);
}
#endif

void sub() {
  #pragma omp atomic
  val -= DECREMENT;
}

void add() {
  #pragma omp atomic
  val += DECREMENT;
}

void mult() {
  // no atomicity needed, can only be executed by 1 thread
  // and no concurrency with other tasks possible
  val *= MULTIPLIER;
}

int main() {
  val = 0;
  int *x, *y;
  #pragma omp parallel
  #pragma omp single
  for (int iter = 0; iter < NT; ++iter) {
    int gtid = __kmpc_global_thread_num(nullptr);
    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0);
    if (res) {
      #pragma omp task depend(out:y)
      add();
      #pragma omp task depend(out:x)
      sub();
      #pragma omp task depend(in:x,y)
      mult();
    }
    __kmpc_end_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0);
  }
  assert(val==0);

  std::cout << "Passed" << std::endl;
  return 0;
}
// CHECK: Passed