mat_inv Module

A module to hold different routines which can be used to invert a matrix

Really we should provide an interface to different versions of these routines for different data types, doing things in-place or not and with assumed arrays and not etc.

If our code were needs to do lots of inverts then it may make sense to create a small timing routine which can be used to select the most efficient method for a given size on the current machine etc. This could then be used with a generic invert routine, the basic idea being: subroutine invert(a) : !If this is the first call then do some timing to pick best method if(first) call pick_best_method !This will set a module level variable identifying the best routine select case(best_method) case(0) call invert_type_1(a) : end select : end subroutine Of course the best method may change with matrix size so we may need to calculate best_method for a number of sizes and then pick the one corresponding to the closest sized array to the one we have.

Generic wrapper Specific methods


Contents


Variables

Type Visibility Attributes Name Initial
type(matrix_inversion_method_type), public, parameter :: mat_inv_serial_lapack = matrix_inversion_method_type(flag=1, name='Lapack')
type(matrix_inversion_method_type), public, parameter :: mat_inv_serial_gauss_jordan = matrix_inversion_method_type(flag=2, name='Serial GJ')
type(matrix_inversion_method_type), public, parameter :: mat_inv_serial_block = matrix_inversion_method_type(flag=3, name='Block')
type(matrix_inversion_method_type), public, parameter :: mat_inv_omp_gauss_jordan = matrix_inversion_method_type(flag=4, name='OMP GJ')
type(matrix_inversion_method_type), public, parameter, dimension(*) :: inversion_methods = [mat_inv_serial_gauss_jordan, mat_inv_serial_block, mat_inv_omp_gauss_jordan]

Array of all available methods


Derived Types

type, public ::  matrix_inversion_method_type

A simple wrapper type around an integer to represent different inversion methods. We could consider deriving from this and binding the specific inversion methods to the type, but that is perhaps more complication than required.

Components

Type Visibility Attributes Name Initial
integer, private :: flag = 0
character(len=16), private :: name = "UNSET NAME"

Type-Bound Procedures

procedure , public :: get_flag => matrix_inversion_method_get_flag Function
procedure , public :: get_name => matrix_inversion_method_get_name Function

Functions

private elemental function matrix_inversion_method_get_flag(self) result(flag)

Helper routine to get access to the matrix_inversion_method's flag in a read-only way. Primarily used for testing.

Arguments

Type IntentOptional Attributes Name
class(matrix_inversion_method_type), intent(in) :: self

Return Value integer

private elemental function matrix_inversion_method_get_name(self) result(name)

Helper routine to get access to the matrix_inversion_method's name in a read-only way. Primarily used for testing.

Arguments

Type IntentOptional Attributes Name
class(matrix_inversion_method_type), intent(in) :: self

Return Value character(len=16)

public function recommend_inversion_method(trial_size, repeats, display_times) result(method)

Times each available method for the given problem size and returns the flag of the fastest one.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: trial_size
integer, intent(in), optional :: repeats
logical, intent(in), optional :: display_times

Return Value type(matrix_inversion_method_type)


Subroutines

public subroutine invert_serial(a, n, method)

Serial Provides a wrapper around the various serial inversion routines.

Arguments

Type IntentOptional Attributes Name
complex, intent(inout), dimension(n,n) :: a
integer, intent(in) :: n
type(matrix_inversion_method_type), intent(in), optional :: method

public subroutine invert_lapack(a, n)

A routine to invert a matrix using lapack routines.

Read more…

Arguments

Type IntentOptional Attributes Name
complex, intent(inout), dimension(n, n) :: a
integer, intent(in) :: n

public subroutine invert_gauss_jordan(a, n)

Serial Gauss-Jordan elimination

Arguments

Type IntentOptional Attributes Name
complex, intent(inout), dimension(n,n) :: a

DD>Tagged

integer, intent(in) :: n

DD>Tagged

public recursive subroutine invert_block(a, n, m_in)

Serial Block inverse

Read more…

Arguments

Type IntentOptional Attributes Name
complex, intent(inout), dimension(n, n), target :: a
integer, intent(in) :: n
integer, intent(in), optional :: m_in

public subroutine invert_gauss_jordan_omp(a, n)

openmp Gauss-Jordan elimination

Arguments

Type IntentOptional Attributes Name
complex, intent(inout), dimension(n,n) :: a

DD>Tagged

integer, intent(in) :: n

DD>Tagged