benchmark Derived Type

type, public :: benchmark

Derived type for benchmarking and performance evaluation.


Inherits

type~~benchmark~2~~InheritsGraph type~benchmark~2 benchmark type~mark~2 mark type~benchmark~2->type~mark~2 marks timer timer type~mark~2->timer time

Components

Type Visibility Attributes Name Initial
type(mark), public, dimension(:), allocatable :: marks

Array of marks to store benchmark data

character(len=:), public, allocatable :: filename

Filename for storing benchmark data

integer, public :: nloops

Number of loops for each benchmark

integer(kind=ik), public, dimension(:), allocatable :: argi

Integer arguments for benchmarks

real(kind=rk), public, dimension(:), allocatable :: argr

Real arguments for benchmarks

character(len=:), public, allocatable :: timer

Timer object for measuring time

integer, public :: imark

Index of current benchmark mark


Type-Bound Procedures

procedure, public :: init

Initialize the benchmark object

  • private impure elemental subroutine init(this, nmarks, title, filename, nloops, timer)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause License

    Initialize the benchmark object.

    Arguments

    Type IntentOptional Attributes Name
    class(benchmark), intent(inout) :: this

    Benchmark object

    integer, intent(in) :: nmarks

    Number of methods to be benchmarked

    character(len=*), intent(in), optional :: title

    Title of the benchmark

    character(len=*), intent(in), optional :: filename

    Filename for storing benchmark data

    integer, intent(in), optional :: nloops

    Number of loops for each benchmark (default: 10)

    character(len=*), intent(in), optional :: timer

    Timer object for measuring time (default: wall). The timer options available are 'wall', 'date_and_time', 'cpu', 'omp', and 'mpi'.

procedure, public :: start_benchmark

Start a benchmark

  • private impure subroutine start_benchmark(this, imark, method, description, argi, argr)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause License

    Start a specific benchmark

    Arguments

    Type IntentOptional Attributes Name
    class(benchmark), intent(inout) :: this

    Benchmark object

    integer, intent(in) :: imark

    Index of the current method

    character(len=*), intent(in) :: method

    Name of the method being benchmarked

    character(len=*), intent(in), optional :: description

    Description of the method being benchmarked (optional)

    integer(kind=ik), intent(in), optional, dimension(:) :: argi

    Integer arguments for the benchmark (optional)

    real(kind=rk), intent(in), optional, dimension(:) :: argr

    Real arguments for the benchmark (optional)

procedure, public :: stop_benchmark

Stop a benchmark

  • private impure subroutine stop_benchmark(this, flops)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause License

    Stops the currently active benchmark, calculates performance metrics, and writes the results to the file and terminal.

    Arguments

    Type IntentOptional Attributes Name
    class(benchmark), intent(inout) :: this

    Benchmark object

    procedure(Fun), optional :: flops

    Function to calculate Floating Point Operations Per Second (optional)

procedure, private :: write_benchmark

Write benchmark data to file

  • private impure subroutine write_benchmark(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause License

    Writes the benchmark data to a specified file, including method, speedup, elapsed time, flops, and other details.

    Arguments

    Type IntentOptional Attributes Name
    class(benchmark), intent(inout) :: this

    Benchmark object

procedure, public :: finalize

Finalize the benchmark object

  • private impure elemental subroutine finalize(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause License

    Finalizes the benchmark object by deallocating memory and performs necessary cleanup.

    Arguments

    Type IntentOptional Attributes Name
    class(benchmark), intent(inout) :: this

    Benchmark object to be finalized

Source Code

   type :: benchmark
      !! author: Seyed Ali Ghasemi
      !! Derived type for benchmarking and performance evaluation.
      !!
      type(mark),  dimension(:), allocatable :: marks     !! Array of marks to store benchmark data
      character(:),              allocatable :: filename  !! Filename for storing benchmark data
      integer                                :: nloops    !! Number of loops for each benchmark
      integer(ik), dimension(:), allocatable :: argi      !! Integer arguments for benchmarks
      real(rk),    dimension(:), allocatable :: argr      !! Real arguments for benchmarks
      character(:),              allocatable :: timer     !! Timer object for measuring time
      integer                                :: imark     !! Index of current benchmark mark
   contains
      procedure          :: init             !! Initialize the benchmark object
      procedure          :: start_benchmark  !! Start a benchmark
      procedure          :: stop_benchmark   !! Stop a benchmark
      procedure, private :: write_benchmark  !! Write benchmark data to file
      procedure          :: finalize         !! Finalize the benchmark object
   end type benchmark