	PROGRAM LAPLACE
	parameter(N=400)
	
        real A(N,N),B(N,N),tolerence,error
	integer niter
        integer, parameter :: np =1

        data tolerance /0.001/ 
!        data tolerance /0.01/ 

!HPF$      PROCESSORS PRC(NP)
!HPF$      TEMPLATE TEMP(N)
!HPF$	   DISTRIBUTE TEMP(BLOCK)
!HPF$	   ALIGN A(i,*) with TEMP(i)
!HPF$	   ALIGN B(i,*) with TEMP(i)

        real t1(NP), t2(NP)
!HPF$   distribute t1(block)
!HPF$   distribute t2(block)

       interface
       extrinsic(hpf_local) subroutine timer(return_time, initial_time)
       real, dimension(:), intent(in)  :: initial_time
       real, dimension(:), intent(out) :: return_time
!HPF$ distribute *(block) :: initial_time
!HPF$ align return_time with initial_time
       end subroutine
       end interface

       t1 = 0.0
      call timer(t2, t1)

        error=100.0
        niter=0
	forall (i=1:N) B(i,1)=8.0
	forall (i=1:N) B(i,N)=8.0
        forall (j=1:N) B(1,j)=8.0
        forall (j=1:N) B(N,j)=8.0
        forall (i=2:N-1,j=2:N-1) b(i,j) = 0.0

	DO WHILE (error>tolerance)
        niter=niter+1
        A=B
	forall (i=2:N-1,j=2:N-1) B(i,j) = &
       ((A(i,j-1) + A(i,j+1) + A(i-1,j) + A(i+1,j))*0.25 )
        error=maxval(abs(b-a))
	enddo
	
	
!         stop_timer
          call timer(t1, t2)
      print *,'time',t1,' seconds'


        write(6,*) 'convergence after',niter,' iterations'
        write(6,*) B(N/2,N/2)
        end


       extrinsic(hpf_local) subroutine timer(return_time, initial_time)
       real, dimension(:), intent(in)  :: initial_time
       real, dimension(:), intent(out) :: return_time

       return_time(lbound(return_time, 1)) = &
            secnds(initial_time(lbound(initial_time, 1)))

       end









