C****************************************************************************** C TotalView Exercise 3 - OpenMP Example - Fortran Version C FILE: tvEx3omp.f C DESCRIPTION: C In this example, the iterations of a loop are scheduled dynamically C across the team of threads. A thread will perform CHUNK iterations C at a time before being scheduled for the next CHUNK of work. C LAST REVISED: 11/30/2001 Blaise Barney C****************************************************************************** PROGRAM WORKSHARE1 INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS, + OMP_GET_THREAD_NUM, N, CHUNK, CHUNKSIZE, I, ITER, MAXTIDS PARAMETER (N=100) PARAMETER (CHUNKSIZE=10) PARAMETER (MAXTIDS=64) REAL A(N), B(N), C(N) INTEGER COUNT(MAXTIDS) ! Some initializations CHUNK = CHUNKSIZE DO I = 1, N A(I) = I * 1.0 B(I) = A(I) END DO DO I = 1, MAXTIDS COUNT(I) = 0 END DO ITER = N PRINT *, 'Forking parallel region...' !\$OMP PARALLEL SHARED(A,B,C,CHUNK,ITER,COUNT) PRIVATE(I,NTHREADS,TID) TID = OMP_GET_THREAD_NUM() IF (TID .EQ. 0) THEN NTHREADS = OMP_GET_NUM_THREADS() PRINT *, 'Number of threads = ', NTHREADS END IF !\$OMP DO SCHEDULE(DYNAMIC,CHUNK) DO I = 1, ITER C(I) = A(I) + B(I) COUNT(TID) = COUNT(TID) + 1 PRINT *, 'thread= ',TID,'I= ',I,'C(I)= ',C(I) END DO !\$OMP END DO PRINT *, 'Thread',TID,'did',COUNT(TID),'loop iterations. Done.' !\$OMP END PARALLEL PRINT *, 'Parallel region and program now completed.' END