File: api.c

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,436 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (56 lines) | stat: -rw-r--r-- 1,462 bytes parent folder | download | duplicates (27)
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
// RUN: %libomp-compile-and-run
// RUN: %libomp-run | %python %S/check.py -c 'CHECK' %s

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>

#define XSTR(x) #x
#define STR(x) XSTR(x)

#define streqls(s1, s2) (!strcmp(s1, s2))

#define check(condition)                                                       \
  if (!(condition)) {                                                          \
    fprintf(stderr, "error: %s: %d: " STR(condition) "\n", __FILE__,           \
            __LINE__);                                                         \
    exit(1);                                                                   \
  }

#define BUFFER_SIZE 1024

int main(int argc, char** argv) {
  char buf[BUFFER_SIZE];
  size_t needed;

  omp_set_affinity_format("0123456789");

  needed = omp_get_affinity_format(buf, BUFFER_SIZE);
  check(streqls(buf, "0123456789"));
  check(needed == 10)

  // Check that it is truncated properly
  omp_get_affinity_format(buf, 5);
  check(streqls(buf, "0123"));

  #pragma omp parallel
  {
    char my_buf[512];
    size_t needed = omp_capture_affinity(my_buf, 512, NULL);
    check(streqls(my_buf, "0123456789"));
    check(needed == 10);
    // Check that it is truncated properly
    omp_capture_affinity(my_buf, 5, NULL);
    check(streqls(my_buf, "0123"));
  }

  #pragma omp parallel num_threads(4)
  {
    omp_display_affinity(NULL);
  }

  return 0;
}

// CHECK: num_threads=4 0123456789