demo Program

Uses

  • program~~demo~~UsesGraph program~demo demo iso_fortran_env iso_fortran_env program~demo->iso_fortran_env

Calls

program~~demo~~CallsGraph program~demo demo proc~pure_subroutine pure_subroutine program~demo->proc~pure_subroutine interface~ptimer_start ptimer_start proc~pure_subroutine->interface~ptimer_start interface~ptimer_stop ptimer_stop proc~pure_subroutine->interface~ptimer_stop interface~pwrite pwrite proc~pure_subroutine->interface~pwrite

Variables

Type Attributes Name Initial
real(kind=rk), dimension(:), allocatable :: y

Subroutines

pure subroutine pure_subroutine(x, n, y)

Arguments

Type IntentOptional Attributes Name
real(kind=rk), intent(in) :: x
integer, intent(in) :: n
real(kind=rk), intent(out), allocatable :: y(:)

Source Code

program demo
   use iso_fortran_env, only: rk => real64
   implicit none

   real(rk), dimension(:), allocatable :: y

   call pure_subroutine(10.0_rk, 7, y)

contains

   pure subroutine pure_subroutine(x, n, y)

      use fordebug
      implicit none

      real(rk), intent(in)               :: x
      integer,  intent(in)               :: n
      real(rk), intent(out), allocatable :: y(:)
      integer                            :: i
      type(timer)                        :: t

      ! Print Rank 0 real64 with a message and format. message and format are optional
      call pwrite(message='x = ', R0r64=x, format='(a,f7.3)')

      ! Write Rank 0 real64 with a message and format to a file. message and format are optional
      call pwrite(message='x = ', R0r64=x, format='(a,f7.3)', file='example/demo.txt', access='append')

      ! Print Rank 0 int32 with a message and format. message and format are optional
      call pwrite(message='n = ', R0i32=n, format='(a,i3)')

      ! Write Rank 0 int32 with a message and format to a file. message and format are optional
      call pwrite(message='n = ', R0i32=n, format='(a,i3)', file='example/demo.txt', access='append')
      
      ! Print Rank 0 character with a format. format is optional
      call pwrite(R0ch='start loop', format='(a)')

      ! Write Rank 0 character with a format to a file. format, access are optional
      call pwrite(R0ch='start loop', format='(a)', file='example/demo.txt', access='append')

      allocate(y(n))
      y(1) = 0.0_rk

      ! start pure timer
      call ptimer_start(t)

      do concurrent (i=2:n)
         y(i) = y(i-1) + x

         ! Print Rank 0 real64 with a message and format. message and format are optional
         call pwrite(message='y(i) = ', R0r64=y(i), format='(a,f7.3)')

         ! Write Rank 0 real64 with a message and format to a file. message and format are optional
         call pwrite(message='y(i) = ', R0r64=y(i), format='(a,f7.3)', file='example/demo.txt', access='append')
      end do

      ! stop pure timer
      call ptimer_stop(t)

      ! Print Rank 0 real64 with a message and format. message and format are optional
      call pwrite(R0ch='end loop', format='(a)') ! format is optional

      ! Write Rank 0 real64 with a message and format to a file. message and format are optional
      call pwrite(R0ch='end loop', format='(a)', file='example/demo.txt', access='append')

      ! Print Rank 0 real64 with a message and format. message and format are optional
      call pwrite(message='y = ',R1r64=y)

      ! Write Rank 0 real64 with a message and format to a file. message and format are optional
      call pwrite(message='y = ',R1r64=y, file='example/demo.txt', access='append')
   end subroutine pure_subroutine

end program demo