leq_solve_times.f90

This part show how measure cpu times with times module. More details about this example.

00001 
00015 program leq_solve_times
00016 #include "fml_constants.h" 
00017  use mod_linear_equation     ! use linear_equation module
00018  use mod_times
00019   implicit none
00020 
00021   !********************************************* declaration  
00022   integer :: size_ab=100 !by default
00023   type(matrix) :: A  !main square matrix
00024   type(vector) :: b  !second member
00025   type(vector) :: x  !solution 
00026   
00027  !decalre time variable
00028   type(t_time) :: time_gj, time_ls, time_lsqr    
00029   type(t_time) :: time_pinvsvd, time_pinvchol
00030   type(t_time) :: time_lu, time_qr, time_chol
00031  !****************************************************init times
00032  character(len=30) time_name;
00033  time_name='time_gj'; call ft_create_time(time_gj,time_name,0,0)
00034  time_name='time_ls'; call ft_create_time(time_ls,time_name,0,0) 
00035  time_name='time_lsqr'; call ft_create_time(time_lsqr,time_name,0,0) 
00036  time_name='time_pinvchol'; call ft_create_time(time_pinvchol,time_name,0,0)      
00037  time_name='time_lu'; call ft_create_time(time_lu,time_name,0,0) 
00038  time_name='time_qr'; call ft_create_time(time_qr,time_name,0,0) 
00039  time_name='time_chol'; call ft_create_time(time_chol,time_name,0,0)   
00040   
00041   print*, "*************************** Solve linear equation Ax = b" 
00042     
00043   write(*,fmt='(A20)',advance='no') "Enter size = "
00044   read(*,fmt='(I4)')size_ab  !read on keybord
00045   print*, "size : ",  size_ab, " x ", size_ab, " = ", size_ab 
00046       
00047   !********************************************* body 
00048   call init(A,size_ab,size_ab); !init:=m_init
00049   call init(b,size_ab); !init:=v_init 
00050   !initialize A by random values between 1.0 and 10.0 (dominant diagonal)
00051   call mc_diagDominant(A,size_ab,low=p_notcast(1.0),high=p_notcast(6.5))
00052   !initialize b by random values between 1.0 and 5.0
00053   call random(b,low=p_notcast(1.0),high=p_notcast(6.5)) 
00054   
00055   print*; !newline 
00056   !let's see the function prototype for more options 
00057   print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> solve :: Gauss-Jourdan"
00058   call ft_begin(time_gj); !start gj times
00059   x=linsolve(A,b,meth_solve='gj')  
00060   call ft_end(time_gj);   !end gj times
00061   print*; !newline 
00062 
00063   print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> solve :: least-square"
00064   call ft_begin(time_ls); !start ls times
00065   x=linsolve(A,b,meth_solve='ls')  
00066   call ft_end(time_ls);   !end  times  
00067   print*; !newline 
00068   
00069   print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> solve :: least-square (QR factorization)"
00070   call ft_begin(time_lsqr); !start lsqr times
00071   x=linsolve(A,b,meth_solve='lsqr')  
00072   call ft_end(time_lsqr);   !end  times
00073   print*; !newline 
00074   
00075   print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> solve :: pseudo-inverse by cholesky decomposition  "
00076   call ft_begin(time_pinvchol); !start pinvchol times
00077   x=linsolve(A,b,meth_solve='pinvchol')  
00078   call ft_end(time_pinvchol);   !end pinvchol times
00079   print*; !newline 
00080 
00081   print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> solve :: LU decomposition  "
00082   call ft_begin(time_lu); !start lu times
00083   x=linsolve(A,b,meth_solve='lu')  
00084   call ft_end(time_lu);   !end lu times
00085   print*; !newline 
00086    
00087   print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> solve :: QR decomposition  "
00088   call ft_begin(time_qr); !start qr times
00089   x=linsolve(A,b,meth_solve='qr')  
00090   call ft_end(time_qr);   !end qr times
00091   print*; !newline
00092   
00093   print*, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> solve :: cholesky decomposition  "
00094   call ft_begin(time_chol); !start chol times
00095   x=linsolve(A,b,meth_solve='chol')  
00096   call ft_end(time_chol);   !end chol times
00097   print*; !newline 
00098 
00099   print*, "********************************** timing :   "
00100   
00101   call ft_print(time_gj);
00102   call ft_print(time_ls);
00103   call ft_print(time_lsqr);
00104   call ft_print(time_pinvchol);
00105   call ft_print(time_lu);
00106   call ft_print(time_qr);
00107   call ft_print(time_chol);
00108   
00109   call destruct(A)  ! destruct the matrix A  (don't forget to destruct the matrix)
00110   call destruct(b)
00111   call destruct(x)
00112 end program leq_solve_times
 All Classes Namespaces Files Functions Variables Defines