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
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
// RUN: %libomp-compile && %libomp-run 7
// RUN: %libomp-run 0 && %libomp-run -1
// RUN: %libomp-run 1 && %libomp-run 2 && %libomp-run 5
// RUN: %libomp-compile -DMY_SCHEDULE=guided && %libomp-run 7
// RUN: %libomp-run 1 && %libomp-run 2 && %libomp-run 5
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
#include <limits.h>
#include "omp_testsuite.h"

#define INCR 7
#define MY_MAX 200
#define MY_MIN -200
#ifndef MY_SCHEDULE
# define MY_SCHEDULE dynamic
#endif

int num_disp_buffers, num_loops;
int a, b, a_known_value, b_known_value;

int test_kmp_set_disp_num_buffers()
{
  int success = 1;
  a = 0;
  b = 0;
  // run many small dynamic loops to stress the dispatch buffer system
  #pragma omp parallel
  {
    int i,j;
    for (j = 0; j < num_loops; j++) {
      #pragma omp for schedule(MY_SCHEDULE) nowait
      for (i = MY_MIN; i < MY_MAX; i+=INCR) {
        #pragma omp atomic
        a++;
      }
      #pragma omp for schedule(MY_SCHEDULE) nowait
      for (i = MY_MAX; i >= MY_MIN; i-=INCR) {
        #pragma omp atomic
        b++;
      }
    }
  }
  // detect failure
  if (a != a_known_value || b != b_known_value) {
    success = 0;
    printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value,
           b, b_known_value);
  }
  return success;
}

int main(int argc, char** argv)
{
  int i,j;
  int num_failed=0;

  if (argc != 2) {
    fprintf(stderr, "usage: %s num_disp_buffers\n", argv[0]);
    exit(1);
  }

  // set the number of dispatch buffers
  num_disp_buffers = atoi(argv[1]);
  kmp_set_disp_num_buffers(num_disp_buffers);

  // figure out the known values to compare with calculated result
  a_known_value = 0;
  b_known_value = 0;

  // if specified to use bad num_disp_buffers set num_loops
  // to something reasonable
  if (num_disp_buffers <= 0)
    num_loops = 10;
  else
    num_loops = num_disp_buffers*10;

  for (j = 0; j < num_loops; j++) {
    for (i = MY_MIN; i < MY_MAX; i+=INCR)
      a_known_value++;
    for (i = MY_MAX; i >= MY_MIN; i-=INCR)
      b_known_value++;
  }

  for(i = 0; i < REPETITIONS; i++) {
    if(!test_kmp_set_disp_num_buffers()) {
      num_failed++;
    }
  }
  return num_failed;
}