File: lambda_by_value.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (49 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download | duplicates (13)
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
// RUN: %libomptarget-compilexx-run-and-check-generic

#include <stdint.h>
#include <stdio.h>

// CHECK: before: [[V1:111]] [[V2:222]] [[PX:0x[^ ]+]] [[PY:0x[^ ]+]]
// CHECK: lambda: [[V1]] [[V2]] [[PX_TGT:0x[^ ]+]] 0x{{.*}}
// CHECK: tgt   : [[V2]] [[PX_TGT]] 1
// CHECK: out   : [[V2]] [[V2]] [[PX]] [[PY]]

#pragma omp begin declare target
int a = -1, *c;
long b = -1;
const long *d;
int e = -1, *f, g = -1;
#pragma omp end declare target

int main() {
  int x[10];
  long y[8];
  x[1] = 111;
  y[1] = 222;

  auto lambda = [&x, y]() {
    a = x[1];
    b = y[1];
    c = &x[0];
    d = &y[0];
    printf("lambda: %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);
    x[1] = y[1];
  };
  printf("before: %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);

  intptr_t xp = (intptr_t)&x[0];
#pragma omp target firstprivate(xp)
  {
    lambda();
    e = x[1];
    f = &x[0];
    g = (&x[0] != (int *)xp);
    printf("tgt   : %d %p %d\n", x[1], &x[0], (&x[0] != (int *)xp));
  }
#pragma omp target update from(a, b, c, d, e, f, g)
  printf("lambda: %d %ld %p %p\n", a, b, c, d);
  printf("tgt   : %d %p %d\n", e, f, g);
  printf("out   : %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);

  return 0;
}