OpenMP is an interface for developing parallel applications on shared memory systems.
Parallel do
loops are as simple as adding an OMP
directive before and after the loop, as in the following example.
program omp_par_do
implicit none
integer, parameter :: n = 100
real, dimension(n) :: dat, result
integer :: i
!$OMP PARALLEL DO
do i = 1, n
result(i) = my_function(dat(i))
end do
!$OMP END PARALLEL DO
contains
function my_function(d) result(y)
real, intent(in) :: d
real :: y
! do something complex with data to calculate y
end function my_function
end program omp_par_do
You must enable OpenMP during compilation. See the documentation for your compiler for details. With GFortran, this is accomplished with the -fopenmp
flag as follows:
% gfortran -fopenmp -o omp_par_do omp_par_do.f90