program gather_with_HPF integer xmax,ymax,totelem parameter (xmax=100,ymax=100) parameter(niters=1) parameter (totelem=xmax*ymax) double precision A(xmax,ymax) double precision V(totelem) double precision dindex1(totelem),dindex2(totelem) integer index1(totelem),index2(totelem) double precision time_begin,time_end !HPF$ PROCESSORS PROC(NUMBER_OF_PROCESSORS()) !HPF$ DISTRIBUTE (BLOCK,*) ONTO PROC :: A !HPF$ DISTRIBUTE (BLOCK) ONTO PROC :: V,index1,index2 ! ,dindex1,dindex2 call random_number(V) V = 1000000.0*V call random_number(dindex1) call random_number(dindex2) index1 = xmax*dindex1 + 1 index2 = ymax*dindex2 + 1 print *,'beg',elapsed_time() call timer(time_begin) !HPF$ independent, new(i) do i=1,totelem V(i) = a(index1(i),index2(i)) enddo call timer(time_end) print *,'beg',elapsed_time() print *,'Elapsed time for ',niters,' iterations for scatter ' print *,'with HPF For matrix with dimensions',xmax,ymax ,' is' print *,time_end-time_begin end !***************************************************** !***************************************************** real function elapsed_time() integer :: clock_count, clock_rate, clock_max integer, save :: last_count logical, save :: system_clock_not_yet_called = .true. call system_clock(count=clock_count,& count_rate=clock_rate, & count_max=clock_max) if (system_clock_not_yet_called) then system_clock_not_yet_called = .false. elapsed_time = 0.0 else if (clock_count > last_count) then elapsed_time = real(clock_count-last_count)/real(clock_rate) else elapsed_time = real(clock_max-last_count+clock_count)& /real(clock_rate) end if last_count = clock_count return end function elapsed_time subroutine timer(t) integer val(8) double precision t call date_and_time(values=val) t = dble(val(8))*1d-3 + dble(val(7)) + & dble(val(6))*60d0 + dble(val(5))*3600d0 end subroutine timer