where construct

where construct

Hi!

DO k = 1, no_of_trait
If (loc_of_nz(i,k,1) /= 0) THEN
sum_sol(k) = SUM(solutions(loc_of_nz(i,k,:),k))
END IF
END DO

Can I make above code simple using where construct or where statement?

If possible, does this affect running time?

thank you!

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

sum_sol(k) = SUM(solutions(loc_of_nz(i,k,:),k))

I will assume is significantly longer than

If (loc_of_nz(i,k,1) /= 0) THEN

When the large majority of (loc_of_nz(i,k,1)/=0) is .TRUE., or randomly distributed, consider making the DO k= loop a parallel DO loop

!$OMP PARALLEL DO
DO k = 1, no_of_trait
If (loc_of_nz(i,k,1) /= 0) THEN
sum_sol(k) = SUM(solutions(loc_of_nz(i,k,:),k))
END IF
END DO
!$OMP END PARALLEL DO

When a large majority of (loc_of_nz(i,k,1)/=0) is .FALSE., or bunched together, consider making one pass in serialto find the indexes, and a second pass in parallel producing the sums

integer :: k2, kindex(no_of_trait)
...
! find places of interest
k2 = 0
DO k = 1, no_of_trait
If (loc_of_nz(i,k,1) /= 0) THEN
k2 = k2 + 1
kindex(k2) = k
END IF
END DO
! parallel sumation of found places
k2lim = k2
!$OMP PARALLEL DO
DO k2 = 1,k2lim
k = kindex(k2)
sum_sol(k) = SUM(solutions(loc_of_nz(i,k,:),k))
END DO
!$OMP END PARALLEL DO

Jim Dempsey

www.quickthreadprogramming.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today