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
// RUN: %libomp-compile-and-run
/*
 * Test for dynamic scheduling with chunk size
 * Method: caculate how many times the iteration space is dispatched
 *     and judge if each dispatch has the requested chunk size
 *     unless it is the last one.
 * It is possible for two adjacent chunks are assigned to the same thread
 * Modified by Chunhua Liao
 */
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
#include "omp_testsuite.h"

#define CFDMAX_SIZE 100
const int chunk_size = 7;

int test_omp_for_schedule_dynamic()
{
  int tid;
  int *tids;
  int i;
  int tidsArray[CFDMAX_SIZE];
  int count = 0;
  int tmp_count = 0; /*dispatch times*/
  int *tmp;  /*store chunk size for each dispatch*/
  int result = 0;

  tids = tidsArray;

  #pragma omp parallel private(tid) shared(tids)
  {        /* begin of parallel */
    int tid;
    tid = omp_get_thread_num ();
    #pragma omp for schedule(dynamic,chunk_size)
    for (i = 0; i < CFDMAX_SIZE; i++) {
      tids[i] = tid;
    }
  }

  for (i = 0; i < CFDMAX_SIZE - 1; ++i) {
    if (tids[i] != tids[i + 1]) {
      count++;
    }
  }

  tmp = (int *) malloc (sizeof (int) * (count + 1));
  tmp[0] = 1;

  for (i = 0; i < CFDMAX_SIZE - 1; ++i) {
    if (tmp_count > count) {
      printf ("--------------------\nTestinternal Error: List too small!!!\n--------------------\n");  /* Error handling */
      break;
    }
    if (tids[i] != tids[i + 1]) {
      tmp_count++;
      tmp[tmp_count] = 1;
    } else {
      tmp[tmp_count]++;
    }
  }
  /* is dynamic statement working? */
  for (i = 0; i < count; i++) {
    if ((tmp[i]%chunk_size)!=0) {
      /* it is possible for 2 adjacent chunks assigned to a same thread */
      result++;
      fprintf(stderr,"The intermediate dispatch has wrong chunksize.\n");
      /* result += ((tmp[i] / chunk_size) - 1); */
    }
  }
  if ((tmp[count]%chunk_size)!=(CFDMAX_SIZE%chunk_size)) {
    result++;
    fprintf(stderr,"the last dispatch has wrong chunksize.\n");
  }
  /* for (int i=0;i<count+1;++i) printf("%d\t:=\t%d\n",i+1,tmp[i]); */
  return (result==0);
}
int main()
{
  int i;
  int num_failed=0;

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