aboutsummaryrefslogtreecommitdiff
path: root/final/testsuite/fortran/do_schedule_static.f
blob: 7ab02f8ef002d9a135d80acfe2f30194a610b3f8 (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
<ompts:test>
<ompts:testdescription>Test which checks the static option of the omp do schedule directive.</ompts:testdescription>
<ompts:ompversion>2.0</ompts:ompversion>
<ompts:directive>omp do schedule(static)</ompts:directive>
<ompts:dependences>omp do nowait,omp flush,omp critical,omp single</ompts:dependences>
<ompts:testcode>

      INTEGER FUNCTION <ompts:testcode:functionname>do_schedule_static</ompts:testcode:functionname>()
        IMPLICIT NONE
        INTEGER omp_get_thread_num,omp_get_num_threads
        CHARACTER*30 logfile
        INTEGER threads
        INTEGER count
        INTEGER ii
        INTEGER result
<ompts:orphan:vars>
        INTEGER CFSMAX_SIZE
        PARAMETER (CFSMAX_SIZE = 1000)
        INTEGER i,tids(0:CFSMAX_SIZE-1), tid, chunk_size
        COMMON /orphvars/ i,tid,tids,chunk_size
</ompts:orphan:vars>

        chunk_size = 7
        result = 0
        ii = 0

!$omp parallel 
!$omp single
        threads = omp_get_num_threads()
!$omp end single
!$omp end parallel

        IF ( threads .LT. 2) THEN
          PRINT *,"This test only works with at least two threads"
          WRITE(1,*) "This test only works with at least two threads"
          <testfunctionname></testfunctionname> = 0
          STOP
        ELSE
          WRITE(1,*) "Using an internal count of ",CFSMAX_SIZE
          WRITE(1,*) "Using a specified chunksize of ",chunk_size
    
!$omp parallel private(tid) shared(tids)
          tid = omp_get_thread_num()
<ompts:orphan>
!$omp do <ompts:check>schedule(static,chunk_size)</ompts:check>
          DO i = 0 ,CFSMAX_SIZE -1
            tids(i) = tid
          END DO
!$omp end do
</ompts:orphan>
!$omp end parallel

          DO i = 0, CFSMAX_SIZE-1
!... round-robin for static chunk
            ii = mod( i/chunk_size,threads)
            IF (tids(i) .NE. ii ) THEN
              result = result + 1
              WRITE(1,*)"Iteration ",i,"should be assigned to ",
     &           ii,"instead of ",tids(i)
            END IF
          END DO
          IF ( result .EQ. 0 )THEN
            <testfunctionname></testfunctionname> = 1
          ELSE
            <testfunctionname></testfunctionname> = 0
          END IF
        END IF
      END FUNCTION
</ompts:testcode>
</ompts:test>