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

Summing across coarrays

David_DiLaura
Beginner
1,115 Views
Colleagues:
I'm upgrading some legacy engineering code to take advantage of Coarray Fortran. In the routine I've started with there is only one coarray. It executes correctly with eight images and generates the same values as before. I can see the basic speedup in all the work done until, at the very end, I need to sum across the coarray that each image has contributed to. The array is ~ 3000 x 400, with 8 images. The basic work in each image that manipulates the local copy of this array is done in < 1 sec. But the summation performed at the very end of the code (in only the 1st image) takes 10 seconds. 
sync all
if( this_image() == 1 ) then
do I = 2,num_images()
flux = flux + flux
end do
end if
Is coarray summing that inefficient? But I reserved the right to be doing this improperly! It is actually faster (by an order of magnitude) to have each image write out the local copy of the array, and have the 1st image read the files into local array(s) and perform the sum.
Any suggestions? 
0 Kudos
5 Replies
jimdempseyatthecove
Honored Contributor III
1,115 Views
David,

It's Jim by the way.

Untested code

i=2
do while(i .lt. num_images())
sync all
if(mod(ImageNum-1,i) .eq. 0) then
array = array + array
endif
i = i * 2
end do


The idea is to double a stride each iteration with the summation performed by fewer and fewer images.

If you only have 2-8 systems then write it inline without the mod test as this will be clearer to the casual reader of the code.

Jim Dempsey
0 Kudos
David_DiLaura
Beginner
1,115 Views
Even better. Thanks.
(I guess I was thinking about the prize fighter!)
D
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,115 Views
When your code is working, please report the runtimes (before and after). This may help others decide the value of the efforts to finish up respectibly.

Jim Dempsey
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,115 Views
David,

The last untested code is in error. I think the first while test should be .LE. not .LT.
Sorry about the error. I am slipping (two programming errors this week).

Jim
0 Kudos
Not applicable
1,115 Views
 
0 Kudos
Reply