- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page