I wrote these two programs to test OMP PARALLEL:
1 : my_idx
is declared at the beginning of the program and after a private copy for eah thread is done.
program my_pgm
use omp_lib
implicit none
integer :: my_idx
CALL OMP_set_dynamic(.FALSE.)
CALL OMP_set_num_threads(2)
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(my_idx)
DO my_idx = 0, 3
WRITE(*,*) 'my_idx , thread_num, ',my_idx,omp_get_thread_num()
END DO
!$OMP END PARALLEL
end program my_pgm
2 : my_idx
is declared in a BLOCK
after !$OMP PARALLEL
program my_pgm
use omp_lib
implicit none
CALL OMP_set_dynamic(.FALSE.)
CALL OMP_set_num_threads(2)
!$OMP PARALLEL DEFAULT(SHARED)
BLOCK
integer :: my_idx
DO my_idx = 0, 3
WRITE(*,*) 'my_idx , thread_num, ',my_idx,omp_get_thread_num()
END DO
END BLOCK
!$OMP END PARALLEL
end program my_pgm
What are the pros and the cons of these two programs ? Or are they equivalent ?