Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

3D matrix and multiple do loops.

Intel_C_Intel
Employee
752 Views

Can someone help me with parallelizing multiple do loops which is inside each other and 3D matrix calculation?

For example:

INTEGER :: Array_size, nnnode

REAL*8, ALLOCATABLE, dimension ( : ) :: Array( :, :, : )

ALLOCATE (Array( 580, 580, 580 ))

Array_size = 580

nnode=omp_get_num_procs()

CALL omp_set_num_threads(nnode)

!$OMP parallel default(private) shared(Array)

!$OMP do private(I, j, k)

do 120 i = 1, Array_size

do 120 j = 2, Array_size

!calculation

do 110 k = j, Array_size

Array(I, j, k) = !do some calculation here.

110 !Some calculationg here..

120 !Other calculation here..

!$OMP end do

!$OMP end parallel

DEALLOCATE (Array)

Would OMP DO paralelize all the loop which is inside or not? And what is the best way to paralelize 3D matrixes.

Thanks in advance.

0 Kudos
4 Replies
TimP
Honored Contributor III
752 Views
I take it from your comments that your loops could be parallelized over any of the 3 indices.
OpenMP would parallelize the outer loop, so you would need to correct the loop nesting. This is particularly important, if the loop would be vectorizable when re-nested with the i loop inside. The slogan from 20 years ago was "concurrent [threaded] outer, vector inner," and nothing has changed this recommendation.
If your objective is to show maximum gain from threading by minimizing the unthreaded performance, you can still do that by -O0.
ifort -O3, without openmp, can perform some multi-level loop optimizations, but openmp would prevent changing the outer loop.
0 Kudos
Intel_C_Intel
Employee
752 Views

So it's mean that I can't use OpenMp to parallelize multiple do loops which inside each other. Can you post some link for using ifort -O3.

Thanks in advance.
0 Kudos
TimP
Honored Contributor III
752 Views
You could enabled nested OpenMP, but it makes little sense (none if you don't get the loop nesting right).
0 Kudos
jimdempseyatthecove
Honored Contributor III
752 Views

Consider reordering the indexing (by swaping order of do loops) if possible.

In Array(I, j, k), elements Array(I, j, k) and Array(I+1, j, k) would be in adjacent memory cells and therefore are potential for vectorization. Therefore, placing the "do I" loop as inner loop would increase the prospect of vectorization.

Jim Dempsey

0 Kudos
Reply