File: omp_taskloop_num_tasks.c

package info (click to toggle)
llvm-toolchain-7 1%3A7.0.1-8~deb9u3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 733,456 kB
  • sloc: cpp: 3,776,651; ansic: 633,271; asm: 350,301; python: 142,716; objc: 107,612; sh: 22,626; lisp: 11,056; perl: 7,999; pascal: 6,742; ml: 5,537; awk: 3,536; makefile: 2,557; cs: 2,027; xml: 841; ruby: 156
file content (71 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download | duplicates (3)
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
// RUN: %libomp-compile-and-run
// RUN: %libomp-compile && env KMP_TASKLOOP_MIN_TASKS=1 %libomp-run

// These compilers don't support the taskloop construct
// UNSUPPORTED: gcc-4, gcc-5, icc-16

/*
 * Test for taskloop
 * Method: caculate how many times the iteration space is dispatched
 *     and judge if each dispatch has the requested grainsize
 * It is possible for two adjacent chunks are executed by the same thread
 */
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
#include "omp_testsuite.h"

#define CFDMAX_SIZE 1120

int test_omp_taskloop_num_tasks()
{
  int i;
  int *tids;
  int *tidsArray;
  int count;
  int result = 0;
  int num_tasks;

  for (num_tasks = 1; num_tasks < 120; ++num_tasks) {
    count = 0;
    tidsArray = (int *)malloc(sizeof(int) * CFDMAX_SIZE);
    tids = tidsArray;

    #pragma omp parallel shared(tids)
    {
      int i;
      #pragma omp master
      #pragma omp taskloop num_tasks(num_tasks)
      for (i = 0; i < CFDMAX_SIZE; i++) {
        tids[i] = omp_get_thread_num();
      }
    }

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

    if (count > num_tasks) {
      fprintf(stderr, "counted too many tasks: (wanted %d, got %d)\n",
              num_tasks, count);
      result++;
    }
  }

  return (result==0);
}

int main()
{
  int i;
  int num_failed=0;

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