On recording CPU time for each case for the final exam.
One of the requirements of the final exam is to obtain the CPU time used for each different method.
Below I show a template to follow for recording the CPU time per method
You can record the CPU per method, taken at t=0, t=15 and t=30, or just record the CPU time taken at the end, which is at t=30.
Below a simplified fortran template is shown which just records the CPU time at the end of each method.
Use the Fortran function called CPU_TIME() for this. This works on g77 and g95. I did not try it on other Fortran compilers, but it should also work on those as it is a standard function.
To illustrate how to do this, I show below a simple skeleton program with this idea. (Here is the template if you need it source_code )
!*******
!* high level template for MAE 185 final
!*******
PROGRAM MAE185_final
IMPLICIT NONE
INTEGER I
REAL t_start, t_end, cpu_time_used
DO I=1,3
CALL CPU_TIME(t_start) ! get
current CPU time
CALL process( I )
CALL CPU_TIME(t_end) ! get
current CPU time
cpu_time_used = t_end - t_start
WRITE(*,FMT='(A,I2,A,F10.8)') 'CPU TIME used for case', I, ' = ',
cpu_time_used
END DO
END PROGRAM
!**************
!*
!**************
SUBROUTINE process(case_number)
IMPLICIT NONE
INTEGER
case_number,I
! other data declaration here...
SELECT CASE(case_number)
CASE(1)
CALL explicit(.....)
CASE(2)
CALL implicit(.....)
CASE(3)
CALL crank_nicholson(.....)
END SELECT
END SUBROUTINE
!**************
!*
!**************
SUBROUTINE explicit(...)
! other data declrations here
t=0
... write solution to file 'exp0.txt'
at t=0
DO while (t<=30)
... write solution to file 'exp15.txt' at t=15
... write solution to file 'exp30.txt' at t=30
t= t + delta_t
END DO
END SUBROUTINE