I have a subroutine as below. How can I use OpenMP to parallelize all the loops inside it?
subroutine call_price(n, s, sigma, t, r, k, res)
integer(4) :: n, i1, i2
real(8) :: s, sigma, t, r, k, res, delta_t, u, d, q, stock_tree(n + 1, n + 1), option_tree(n + 1, n + 1)
delta_t = t/n
u = exp(sigma*sqrt(delta_t))
d = exp(-sigma*sqrt(delta_t))
q = (exp(r*delta_t) - d)/(u - d)
!$omp parallel do collapse(2)
do i2 = 1, n + 1
do i1 = 1, n + 1
stock_tree(i1, i2) = 0d0
option_tree(i1, i2) = 0d0
end do
end do
do i2 = 1, n + 1
do i1 = 1, i2
stock_tree(i1, i2) = s*u**(i1 - 1)*d**((i2 - 1) - (i1 - 1))
end do
end do
!$omp parallel do
do i1 = 1, n + 1
option_tree(i1, n + 1) = max(stock_tree(i1, n + 1) - k, 0d0)
end do
do i2 = n, 1, -1
do i1 = 1, i2
option_tree(i1, i2) = ((1d0 - q)*option_tree(i1, i2 + 1) + q*option_tree(i1 + 1, i2 + 1))/exp(r*delta_t)
end do
end do
res = option_tree(1, 1)
end subroutine