Skip to content
Snippets Groups Projects
Commit 0613e055 authored by Mathieu Peybernes's avatar Mathieu Peybernes
Browse files

Add examples for compilation

parent ff39eec1
No related branches found
No related tags found
No related merge requests found
File added
! Main program
program main
use iso_fortran_env, only: di=>int64, dp=>real64
use saxpy_mod
integer nmax
parameter (nmax=1000000)
real(dp) x(nmax), y(nmax), z(nmax)
real(dp) rate
integer(di) :: startc, endc
z=0._dp
x=1._dp
y=2._dp
call system_clock(count_rate=rate)
call system_clock(startc)
call saxpy(nmax, 2.0_dp, x, y, z)
call system_clock(endc)
print*, "L2 norm of z = ",norm2(z)
write(*,*) "timing for saxpy: ", real(endc-startc, dp)/rate*1000, "ms"
end program main
! saxpy routine
module saxpy_mod
use iso_fortran_env, only: di=>int64, dp=>real64
contains
subroutine saxpy(n, a, x, y, z)
integer, intent(in) :: n
real(dp), intent(in) :: x(:), y(:), a
real(dp), intent(out) :: z(:)
integer :: i
do i=1,n
z(i) = a*x(i)+y(i)
enddo
end subroutine saxpy
end module saxpy_mod
! Main program
program main
use iso_fortran_env, only: di=>int64, dp=>real64
use saxpy_mod
integer nmax
parameter (nmax=100000000)
real(dp) x(nmax), y(nmax), z(nmax)
real(dp) rate
integer(di) :: startc, endc
z=0._dp
x=1._dp
y=2._dp
call system_clock(count_rate=rate)
call system_clock(startc)
call saxpy(nmax, 2.0_dp, x, y, z)
call system_clock(endc)
print*, "L2 norm of z = ",norm2(z)
write(*,*) "timing for saxpy: ", real(endc-startc, dp)/rate*1000, "ms"
end program main
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment