! Summation in the correct order using CAF IMPLICIT NONE REAL, DIMENSION[*] :: PART_SUM, TIME1, TIME2 REAL, EXTERNAL :: WTIME REAL :: WHOLE_SUM, TIME_SUM, TIME3, TIME4 Integer :: NUMBER, I, N !call caf_init() call sync_images() N = num_images() ! = number of processors NUMBER = 2000000 ! = total number of elements to sum PART_SUM = 0.0 call sync_images() TIME3 = WTIME() ! Wall clock for the start call cpu_time(TIME1) ! CPU clock for the start do I = NUMBER + 1 - this_image(), 1, -N ! Backwards ! Summation of each, each other, each third, ... element ! on the respective processor if N = 1, 2, 3, ... PART_SUM = PART_SUM + 1.0/REAL(I)**2 end do call cpu_time(TIME2) ! CPU clock for the finish TIME4 = WTIME() ! Wall clock for the finish call sync_images() ! Assemble the results on processor 1 if ( this_image() == 1 ) then WHOLE_SUM = 0.0 TIME_SUM = 0.0 do I = 1, N WHOLE_SUM = WHOLE_SUM + PART_SUM[I] TIME_SUM = TIME_SUM + TIME2[I] - TIME1[I] end do write(*,10) N, WHOLE_SUM, TIME_SUM, TIME4 - TIME3 10 FORMAT(2X,'NUMBER OF PROCESSORS',5X,'WHOLE_SUM',9X, & & 'TOTAL CPU TIME',5X, 'WALL CLOCK TIME',/ & & 5X,I5,15X,F16.12,F12.6,7X,F12.6) end if end