reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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