test3 Program

Uses

  • program~~test3~~UsesGraph program~test3 test3 fortime fortime program~test3->fortime kinds kinds program~test3->kinds module~forinv forinv program~test3->module~forinv module~forinv->kinds forsvd forsvd module~forinv->forsvd

Calls

program~~test3~~CallsGraph program~test3 test3 interface~inv forinv::inv program~test3->interface~inv timer_start timer_start program~test3->timer_start timer_stop timer_stop program~test3->timer_stop proc~pinv_rel forinv::pinv_rel interface~inv->proc~pinv_rel proc~pinvlu_rel forinv::pinvLU_rel proc~pinv_rel->proc~pinvlu_rel proc~pinvsvd_rel forinv::pinvSVD_rel proc~pinv_rel->proc~pinvsvd_rel proc~gemm forinv::gemm proc~pinvlu_rel->proc~gemm proc~invlu_rel forinv::invLU_rel proc~pinvlu_rel->proc~invlu_rel svd svd proc~pinvsvd_rel->svd

Variables

Type Attributes Name Initial
real(kind=rk), dimension(:,:), allocatable :: A
real(kind=rk), dimension(:,:), allocatable :: Ainv
integer :: m
integer :: n
type(timer) :: w

Source Code

program test3

  ! This Fortran test code demonstrates the usage of the inv function to calculate the matrix inverse
  ! of a randomly generated matrix.

  use kinds                 ! Import the module 'kinds' for precision types
  use forinv, only: inv     ! Import only the 'inv' function from the 'forinv' module
  use fortime

  implicit none

  real(rk), dimension(:,:), allocatable :: A, Ainv  ! Define dynamically allocated matrices A and Ainv
  integer                               :: m, n     ! Define variables for matrix dimensions
  type(timer)                           :: w        ! Define a watchtype object for timing measurements

  m = 2000                    ! Set the number of rows for matrix A
  n = 200                     ! Set the number of columns for matrix A
  allocate(A(m,n))            ! Allocate memory for matrix A
  call random_number(A)       ! Fill matrix A with random numbers between 0 and 1

  call timer_start(w)

  Ainv = inv(A*10)          ! Calculate the matrix inverse of A using the 'inv' function

  call timer_stop(w,message=' Elapsed time (2000*200 , gesvd):')

  call timer_start(w)

  Ainv = inv(A*10, method='getrf')          ! Calculate the matrix inverse of A using the 'inv' function and the getrf method

  call timer_stop(w,message=' Elapsed time (2000*200 , getrf):')

  deallocate(Ainv)            ! Deallocate memory for matrix Ainv
  deallocate(A)               ! Deallocate memory for matrix A

  m = 2000                    ! Set the number of rows for matrix A
  n = 1800                    ! Set the number of columns for matrix A
  allocate(A(m,n))            ! Allocate memory for matrix A
  call random_number(A)       ! Fill matrix A with random numbers between 0 and 1

  call timer_start(w)

  Ainv = inv(A*10)           ! Calculate the matrix inverse of A using the 'inv' function

  call timer_stop(w,message=' Elapsed time (2000*1800, gesvd):')

  call timer_start(w)

  Ainv = inv(A*10, method='getrf')          ! Calculate the matrix inverse of A using the 'inv' function and the getrf method

  call timer_stop(w,message=' Elapsed time (2000*1800, getrf):')

  deallocate(Ainv)            ! Deallocate memory for matrix Ainv
  deallocate(A)               ! Deallocate memory for matrix A

  print *, "Test 3 passed."

end program test3