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

Example to compile with Makefile

parent 0613e055
No related branches found
No related tags found
No related merge requests found
FC=gfortran # set Fortran compiler
EXEC=my_exec # set executable name
FFLAGS= # Fortran flags
all: $(EXEC)
my_exec: saxpy.o main.o
$(FC) -o my_exec saxpy.o main.o
saxpy.o: saxpy.F90
$(FC) -c saxpy.F90
main.o: main.F90
$(FC) -c main.F90
clean:
rm -f *.o
mrproper: clean
rm -f $(EXEC)
! 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
! 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
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