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