1C****************************************************************************** 2C FILE: omp_workshare1.f 3C DESCRIPTION: 4C OpenMP Example - Loop Work-sharing - Fortran Version 5C In this example, the iterations of a loop are scheduled dynamically 6C across the team of threads. A thread will perform CHUNK iterations 7C at a time before being scheduled for the next CHUNK of work. 8C AUTHOR: Blaise Barney 5/99 9C LAST REVISED: 01/09/04 10C****************************************************************************** 11 12 PROGRAM WORKSHARE1 13 14 INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS, 15 + OMP_GET_THREAD_NUM, N, CHUNKSIZE, CHUNK, I 16 PARAMETER (N=100) 17 PARAMETER (CHUNKSIZE=10) 18 REAL A(N), B(N), C(N) 19 20! Some initializations 21 DO I = 1, N 22 A(I) = I * 1.0 23 B(I) = A(I) 24 ENDDO 25 CHUNK = CHUNKSIZE 26 27!$OMP PARALLEL SHARED(A,B,C,NTHREADS,CHUNK) PRIVATE(I,TID) 28 29 TID = OMP_GET_THREAD_NUM() 30 IF (TID .EQ. 0) THEN 31 NTHREADS = OMP_GET_NUM_THREADS() 32 PRINT *, 'Number of threads =', NTHREADS 33 END IF 34 PRINT *, 'Thread',TID,' starting...' 35 36!$OMP DO SCHEDULE(DYNAMIC,CHUNK) 37 DO I = 1, N 38 C(I) = A(I) + B(I) 39 WRITE(*,100) TID,I,C(I) 40 100 FORMAT(' Thread',I2,': C(',I3,')=',F8.2) 41 ENDDO 42!$OMP END DO NOWAIT 43 44 PRINT *, 'Thread',TID,' done.' 45 46!$OMP END PARALLEL 47 48 END 49