2.3. Fortran Comments (Fixed Source Form)#

OpenMP directives in Fortran codes with fixed source form are specified as comments with one of the !$omp, c$omp, and *$omp sentinels, followed by a directive name, and required and optional clauses. The sentinel must begin in column 1.

In the example below the first directive (DIR 1) specifies the parallel do combined directive, with a num_threads clause, and a comment. The second directive (DIR 2) shows the same directive split across two lines. The next nested directives (DIR 3 and 4) show the previous combined directive as two separate directives. Here, an end directive (end parallel) must be specified to demarcate the range (region) of the parallel directive.

!!%compiler: gfortran
!!%cflags: -fopenmp

! name: directive_syntax_F_fixed_comment.1
! type: F-fixed
      program main
      include 'omp_lib.h'
      integer NT

      NT =4

c     sentinel c$omp or *$omp can also be used

c$omp parallel do num_threads(NT) !comments allowed here   DIR 1
      do i = 1,NT
        write(*,'("thrd no", i2)') omp_get_thread_num()
      end do

!$omp parallel do
!$omp+ num_threads(NT)          !cont. w. char in col. 6   DIR 2
      do i = 1,NT
        write(*,'("thrd no", i2)') omp_get_thread_num()
      end do

*$omp parallel num_threads(NT)  !multi-directive form      DIR 3
*$omp do                        !                          DIR 4
      do i = 1,NT
         write(*,'("thrd no", i2)') omp_get_thread_num()
      end do
*$omp end parallel
      end
!     repeated 3 times, any order
!     OUTPUT: thrd no  0
!     OUTPUT: thrd no  1
!     OUTPUT: thrd no  2
!     OUTPUT: thrd no  3