OMP Critical Fortran Solution

        integer omp_get_thread_num,omp_get_num_threads,c,iam

        c=0

!$OMP PARALLEL PRIVATE(iam)
          iam=omp_get_thread_num()
!$OMP CRITICAL
        do i = 1,1000
          if(i .eq. 1) then
              c = c + iam
          else
              c=c
          endif
        enddo
!$OMP END CRITICAL

!$OMP BARRIER
!$OMP DO ORDERED SCHEDULE(dynamic)
        do iam = 0, omp_get_num_threads()-1
!$OMP ORDERED
        print *, iam, c
!$OMP END ORDERED
        enddo
!$OMP END DO

!$OMP END PARALLEL
        end