LLVM OpenMP 19.0.0git
omp_for_schedule_dynamic.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run
2// RUN: env KMP_AFFINITY=compact,0 %libomp-run
3/*
4 * Test for dynamic scheduling with chunk size
5 * Method: calculate how many times the iteration space is dispatched
6 * and judge if each dispatch has the requested chunk size
7 * unless it is the last one.
8 * It is possible for two adjacent chunks are assigned to the same thread
9 * Modified by Chunhua Liao
10 */
11#include <stdio.h>
12#include <omp.h>
13#include <stdlib.h>
14#include "omp_testsuite.h"
15
16#define CFDMAX_SIZE 100
17const int chunk_size = 7;
18
20{
21 int tid;
22 int *tids;
23 int i;
24 int tidsArray[CFDMAX_SIZE];
25 int count = 0;
26 int tmp_count = 0; /*dispatch times*/
27 int *tmp; /*store chunk size for each dispatch*/
28 int result = 0;
29
30 tids = tidsArray;
31
32 #pragma omp parallel private(tid) shared(tids)
33 { /* begin of parallel */
34 int tid;
35 tid = omp_get_thread_num ();
36 #pragma omp for schedule(dynamic,chunk_size)
37 for (i = 0; i < CFDMAX_SIZE; i++) {
38 tids[i] = tid;
39 }
40 }
41
42 for (i = 0; i < CFDMAX_SIZE - 1; ++i) {
43 if (tids[i] != tids[i + 1]) {
44 count++;
45 }
46 }
47
48 tmp = (int *) malloc (sizeof (int) * (count + 1));
49 tmp[0] = 1;
50
51 for (i = 0; i < CFDMAX_SIZE - 1; ++i) {
52 if (tmp_count > count) {
53 printf ("--------------------\nTestinternal Error: List too small!!!\n--------------------\n"); /* Error handling */
54 break;
55 }
56 if (tids[i] != tids[i + 1]) {
57 tmp_count++;
58 tmp[tmp_count] = 1;
59 } else {
60 tmp[tmp_count]++;
61 }
62 }
63 /* is dynamic statement working? */
64 for (i = 0; i < count; i++) {
65 if ((tmp[i]%chunk_size)!=0) {
66 /* it is possible for 2 adjacent chunks assigned to a same thread */
67 result++;
68 fprintf(stderr,"The intermediate dispatch has wrong chunksize.\n");
69 /* result += ((tmp[i] / chunk_size) - 1); */
70 }
71 }
72 if ((tmp[count]%chunk_size)!=(CFDMAX_SIZE%chunk_size)) {
73 result++;
74 fprintf(stderr,"the last dispatch has wrong chunksize.\n");
75 }
76 /* for (int i=0;i<count+1;++i) printf("%d\t:=\t%d\n",i+1,tmp[i]); */
77 return (result==0);
78}
79int main()
80{
81 int i;
82 int num_failed=0;
83
84 for(i = 0; i < REPETITIONS; i++) {
86 num_failed++;
87 }
88 }
89 return num_failed;
90}
int result[2]
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t count
#define i
Definition: kmp_stub.cpp:87
#define CFDMAX_SIZE
int test_omp_for_schedule_dynamic()
const int chunk_size
int main()
#define REPETITIONS
Definition: omp_testsuite.h:13