omp_hello.f 1.2 KB

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