I'm working on a CFD code, operating on several large 3D arrays. Coming from C background, I was thinking to encapsulate these arrays into a derived type:
type variables integer :: nx, ny, nz ! Grid size. real, allocatable, dimension(:, :, :) :: p_1 ! Pressure at t = t. real, allocatable, dimension(:, :, :) :: p_2 ! Pressure at t = t + dt. ! etc. end type
At the end of each simulation time step, I'm updating arrays to prepare for the next time step:
type(variables) :: vars ! ... !$OMP PARALLEL WORKSHARE vars%p_1 = vars%p_2 ! etc. !$OMP END PARALLEL WORKSHARE
That was working fine with GNU Fortran (version 4.4.7), however with Intel Fortran (version 13.0.1 20121010) the code will crash within OpenMP region. Looking further into the issue, I learned that using derived types with allocatable components is unsupported with OpenMP, and am looking now into how to overcome the issue. I would still prefer to keep arrays encapsulated into this derived type. I've noticed that the crash is avoided if I create a subroutine for OpenMP region above:
subroutine update(nx, ny, nz, p_1, p_2) integer, intent(in) :: nx, ny, nz real, dimension(nx, ny, nz), intent(out) :: p_1 real, dimension(nx, ny, nz), intent(in) :: p_2 !$OMP PARALLEL WORKSHARE p_1 = p_2 !$OMP END PARALLEL WORKSHARE end subroutine
and if I just pass arrays from derived type into this subroutine:
call update(nx, ny, nz, vars%p_1, vars%p_2)
It's somewhat cumbersome approach, still I'm OK with it. But, my question is: is this code now valid, is there any undefined behavior left here?
Thanks.