      subroutine STD_CALC_PI (N, N_DDSP)
      integer*4 N
      integer*4 I
      real*8 W
      real*8 GSUM
      real*8 V
      real*4 TSTART
      real*4 TSTOP
      external DALIB_pid
      integer*4 DALIB_pid
      integer*4 N_DDSP
      integer*4 DALIB_0
      common /DALIB_data0/ DALIB_0
      call DALIB_start_subroutine ('STD_CALC_PI',11)
      if (DALIB_pid() .eq. 1) then
         call DALIB_push_host_context ()
         call DALIB_CPU_TIME (TSTART)
         call DALIB_pop_host_context ()
      end if
      call DALIB_broadcast (TSTART,4,1)
      W = DBLE(1.0/REAL(N))
      GSUM = 0.0d0
      do I=1,N
         V = (DBLE(I)-0.5d0)*W
         V = 4.0d0/(1.0d0+V*V)
         GSUM = GSUM+V
      end do
      if (DALIB_pid() .eq. 1) then
         call DALIB_push_host_context ()
         call DALIB_CPU_TIME (TSTOP)
         call DALIB_pop_host_context ()
      end if
      call DALIB_broadcast (TSTOP,4,1)
      if (DALIB_pid() .eq. 1) then
         print *,'-- Linear version: --'
         print *,'pi ist approximated with ',GSUM*W
         print *,'time   = ',TSTOP-TSTART,' seconds'
      end if
      call DALIB_end_subroutine ()
      end

      program CALC_PI
      integer*4 I
      integer*4 N
      real*8 W
      real*8 GSUM
      real*8 V
      integer*4 NP
      real*4 TSTART
      real*4 TSTOP
      real*8 TMP1
      integer*4 TMP2_DSP
      integer*4 TMP2_STOP1
      integer*4 TMP2_START1
      external DALIB_pid
      integer*4 DALIB_pid
      character*2 DALIB_1
      common /DALIB_data1/ DALIB_1
      external DALIB_all_procs
      integer*4 DALIB_all_procs
      integer*4 DALIB_0
      common /DALIB_data0/ DALIB_0
      call DALIB_init (4,4,4)
      call DALIB_set_present (DALIB_0,DALIB_1)
      call DALIB_start_subroutine ('CALC_PI',7)
      if (DALIB_pid() .eq. 1) then
         print *,'Input number of stripes : '
         read *, N
      end if
      call DALIB_broadcast (N,4,1)
      if (DALIB_pid() .eq. 1) then
         call DALIB_push_host_context ()
         call DALIB_CPU_TIME (TSTART)
         call DALIB_pop_host_context ()
      end if
      call DALIB_broadcast (TSTART,4,1)
      W = DBLE(1.0/REAL(N))
      GSUM = 0.0d0
      TMP1 = 0.0d0
      call DALIB_array_make_dsp (TMP2_DSP,1,0,'TMP2',4)
      call DALIB_distribute (TMP2_DSP,1,1,0,0,0)
      call DALIB_array_define (TMP2_DSP,1,N)
      call DALIB_array_lslice (TMP2_DSP,1,1,N,TMP2_START1,TMP2_STOP1)
      do I=TMP2_START1,TMP2_STOP1
         V = (DBLE(I)-0.5d0)*W
         V = 4.0d0/(1.0d0+V*V)
         TMP1 = TMP1+V
      end do
      call DALIB_array_free (TMP2_DSP)
      call DALIB_top_reduction (1,1,TMP1,9)
      GSUM = GSUM+TMP1
      if (DALIB_pid() .eq. 1) then
         call DALIB_push_host_context ()
         call DALIB_CPU_TIME (TSTOP)
         call DALIB_pop_host_context ()
      end if
      call DALIB_broadcast (TSTOP,4,1)
      NP = DALIB_all_procs(DALIB_0)
      if (DALIB_pid() .eq. 1) then
         print *,'pi ist approximated with ',GSUM*W
         print *,'time   = ',TSTOP-TSTART,' seconds'
      end if
      call STD_CALC_PI (N,DALIB_0)
      call DALIB_end_subroutine ()
      call DALIB_exit ()
      end

