File: kmp_doacross_check.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (62 lines) | stat: -rw-r--r-- 1,770 bytes parent folder | download | duplicates (26)
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
// RUN: %libomp-compile-and-run
// UNSUPPORTED: gcc
// This test is incompatible with gcc because of the explicit call to
// __kmpc_doacross_fini().  gcc relies on an implicit call to this function
// when the last iteration is executed inside the GOMP_loop_*_next() functions.
// Hence, in gcc, having the explicit call leads to __kmpc_doacross_fini()
// being called twice.
#include <stdio.h>

#define N   1000

struct dim {
  long long lo; // lower
  long long up; // upper
  long long st; // stride
};
extern void __kmpc_doacross_init(void*, int, int, struct dim *);
extern void __kmpc_doacross_wait(void*, int, long long*);
extern void __kmpc_doacross_post(void*, int, long long*);
extern void __kmpc_doacross_fini(void*, int);
extern int __kmpc_global_thread_num(void*);

int main()
{
  int i;
  int iter[N];
  struct dim dims;
  for( i = 0; i < N; ++i )
    iter[i] = 1;
  dims.lo = 1;
  dims.up = N-1;
  dims.st = 1;
  #pragma omp parallel num_threads(4)
  {
    int i, gtid;
    long long vec;
    gtid = __kmpc_global_thread_num(NULL);
    __kmpc_doacross_init(NULL,gtid,1,&dims); // thread starts the loop
    #pragma omp for nowait schedule(dynamic)
    for( i = 1; i < N; ++i )
    {
      // runtime call corresponding to #pragma omp ordered depend(sink:i-1)
      vec=i-1;
      __kmpc_doacross_wait(NULL,gtid,&vec);
      // user's code
      iter[i] = iter[i-1] + 1;
      // runtime call corresponding to #pragma omp ordered depend(source)
      vec=i;
      __kmpc_doacross_post(NULL,gtid,&vec);
    }
    // thread finishes the loop (should be before the loop barrier)
    __kmpc_doacross_fini(NULL,gtid);
  }
  if( iter[N-1] == N ) {
    printf("passed\n");
  } else {
    printf("failed %d != %d\n", iter[N-1], N);
    return 1;
  }
  return 0;
}