summaryrefslogtreecommitdiffstats
path: root/openmp/testsuite/fortran/do_schedule_dynamic.f
blob: 18f8ba7475236a6acd9c94a0feae21abb5a8e0b2 (plain)
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
<ompts:test>
<ompts:testdescription>Test which checks the dynamic option of the omp do schedule directive.</ompts:testdescription>
<ompts:ompversion>2.0</ompts:ompversion>
<ompts:directive>omp do schedule(dynamic)</ompts:directive>
<ompts:dependences>omp flush,omp do nowait,omp critical,omp single</ompts:dependences>
<ompts:testcode>


      INTEGER FUNCTION <ompts:testcode:functionname>do_schedule_dynamic</ompts:testcode:functionname>()
        IMPLICIT NONE
        CHARACTER*30 logfile
        INTEGER omp_get_thread_num,omp_get_num_threads
        INTEGER threads
        INTEGER count, tmp_count
        INTEGER,ALLOCATABLE:: tmp(:)
        INTEGER ii
        INTEGER result

<ompts:orphan:vars>
        INTEGER CFDMAX_SIZE
        PARAMETER (CFDMAX_SIZE = 1000)
        INTEGER i,tids(0:CFDMAX_SIZE-1),tid,chunk_size
        COMMON /orphvars/ i,tids,tid,chunk_size
</ompts:orphan:vars>

        chunk_size = 7
        count = 0
        tmp_count = 0
        result = 0
        ii = 0

!$omp parallel private(tid)
        tid = omp_get_thread_num()
<ompts:orphan>
!$omp do <ompts:check>schedule(dynamic,chunk_size)</ompts:check>
        DO i=0, CFDMAX_SIZE-1
          tids(i) = tid
        END DO
!$omp end do
</ompts:orphan>
!$omp end parallel

        DO i=0, CFDMAX_SIZE - 2
          IF ( tids(i) .ne. tids(i+1) ) THEN
            count = count + 1
          END IF
        END DO
 
        ALLOCATE( tmp(0:count) )
        tmp(0) = 1
 
        DO i = 0, CFDMAX_SIZE - 2
          IF ( tmp_count .GT. count ) THEN
            WRITE(*,*) "--------------------"
            WRITE(*,*) "Testinternal Error: List too small!!!"
            WRITE(*,*) "--------------------"
            GOTO 10
          END If
          IF ( tids(i) .NE. tids(i+1) ) then
            tmp_count = tmp_count + 1
            tmp(tmp_count) = 1
          ELSE
            tmp(tmp_count) = tmp(tmp_count) +1
          END IF 
        END DO          

!... is dynamic statement working? 

 10     DO i=0, count -1
          IF ( MOD(tmp(i),chunk_size) .ne. 0 ) THEN
! ... it is possible for 2 adjacent chunks assigned to a same thread 
            result = result + 1
            WRITE(1,*) "The intermediate dispatch has wrong chunksize."
          END IF
        END DO

        IF ( MOD(tmp(count), chunk_size) .NE. 
     &     MOD (CFDMAX_SIZE, chunk_size) ) THEN
          result = result + 1
          WRITE(1,*) "the last dispatch has wrong chunksize."
        END IF
         
        IF ( result .eq. 0) THEN
          <testfunctionname></testfunctionname> = 1
        ELSE
          <testfunctionname></testfunctionname> = 0
        END IF
      END FUNCTION
</ompts:testcode>
</ompts:test>
OpenPOWER on IntegriCloud