matrix_multiply Module

Provides a consistent wrapper to different matrix multiply implementations


Contents


Variables

Type Visibility Attributes Name Initial
type(matrix_multiply_method_type), public, parameter :: matmul_lapack = matrix_multiply_method_type(flag=1, name='Lapack')

Method calling blas' gemm directly

type(matrix_multiply_method_type), public, parameter :: matmul_intrinsic = matrix_multiply_method_type(flag=2, name='Intrinsic')

Method simply calling intrinsic matmul

type(matrix_multiply_method_type), public, parameter :: matmul_custom = matrix_multiply_method_type(flag=3, name='Custom')

Method using explicit loops with OpenMP parallelisation. Could do with a better name.

type(matrix_multiply_method_type), public, parameter, dimension(*) :: multiply_methods = [matmul_intrinsic, matmul_custom]

Array of all available methods

type(matrix_multiply_method_type), private :: matmul_default_method = matmul_intrinsic

Used to store the default method to use if not passed to matmul_wrapper. This way we can override the default (e.g. after timing performance) whilst still having a reasonable default


Interfaces

public interface matmul_wrapper

Provides a wrapper to different matrix multiplication methods

  • private function matmul_wrapper_complex_2d(a, b, method) result(output)

    Wrapper to complex matrix multiplication with two 2D matrices

    Arguments

    Type IntentOptional Attributes Name
    complex, intent(in), dimension(:, :) :: a
    complex, intent(in), dimension(:, :) :: b
    type(matrix_multiply_method_type), intent(in), optional :: method

    Return Value complex, dimension(:, :), allocatable


Derived Types

type, public ::  matrix_multiply_method_type

A simple wrapper type around an integer to represent different multiply methods.

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_multiply_method_get_flag Function
procedure , public :: get_name => matrix_multiply_method_get_name Function

Functions

private elemental function matrix_multiply_method_get_flag(self) result(flag)

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

Arguments

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

Return Value integer

private elemental function matrix_multiply_method_get_name(self) result(name)

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

Arguments

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

Return Value character(len=16)

public function recommend_multiplication_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_multiply_method_type)

private function matmul_wrapper_complex_2d(a, b, method) result(output)

Wrapper to complex matrix multiplication with two 2D matrices

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension(:, :) :: a
complex, intent(in), dimension(:, :) :: b
type(matrix_multiply_method_type), intent(in), optional :: method

Return Value complex, dimension(:, :), allocatable