1C****************************************************************************** 2C FILE: omp_hello.f 3C DESCRIPTION: 4C OpenMP Example - Hello World - Fortran Version 5C In this simple example, the master thread forks a parallel region. 6C All threads in the team obtain their unique thread number and print it. 7C The master thread only prints the total number of threads. Two OpenMP 8C library routines are used to obtain the number of threads and each 9C thread's number. 10C AUTHOR: Blaise Barney 5/99 11C LAST REVISED: 12C****************************************************************************** 13 14 PROGRAM HELLO 15 16 INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS, 17 + OMP_GET_THREAD_NUM 18 19C Fork a team of threads giving them their own copies of variables 20!$OMP PARALLEL PRIVATE(NTHREADS, TID) 21 22 23C Obtain thread number 24 TID = OMP_GET_THREAD_NUM() 25 PRINT *, 'Hello World from thread = ', TID 26 27C Only master thread does this 28 IF (TID .EQ. 0) THEN 29 NTHREADS = OMP_GET_NUM_THREADS() 30 PRINT *, 'Number of threads = ', NTHREADS 31 END IF 32 33C All threads join master thread and disband 34!$OMP END PARALLEL 35 36 END 37