Initialize the benchmark object.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(benchmark), | intent(inout) | :: | this |
Benchmark object |
||
integer, | intent(in) | :: | nmarks |
Number of methods being benchmarked |
||
character(len=*), | intent(in), | optional | :: | title |
Title of the benchmark |
|
character(len=*), | intent(in), | optional | :: | filename |
Filename for storing the 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) |
elemental impure subroutine init(this, nmarks, title, filename, nloops, timer) !! author: Seyed Ali Ghasemi !! Initialize the benchmark object. !! use, intrinsic :: iso_fortran_env, only: compiler_version, compiler_options class(benchmark), intent(inout) :: this !! Benchmark object integer, intent(in) :: nmarks !! Number of methods being benchmarked character(*), intent(in), optional :: title !! Title of the benchmark character(*), intent(in), optional :: filename !! Filename for storing the benchmark data integer, intent(in), optional :: nloops !! Number of loops for each benchmark (default: 10) character(*), intent(in), optional :: timer !! Timer object for measuring time (default: wall) integer :: nunit !! Unit number for file access integer :: iostat !! I/O status character(10) :: im_chr !! Character representation of the image number integer :: which_compiler !! Logical variables for compiler detection character(:), allocatable :: compiler !! Compiler name if (nmarks <= 0) error stop 'nmarks must be greater than zero.' compiler ='' which_compiler = index(compiler_version(), 'Intel(R) Fortran Compiler') if (which_compiler /= 0) compiler = '_ifx' which_compiler = index(compiler_version(), 'Intel(R) Fortran Intel(R)') if (which_compiler /= 0) compiler = '_ifort' which_compiler = index(compiler_version(), 'GCC') if (which_compiler /= 0) compiler = '_gfortran' which_compiler = index(compiler_version(), 'nvfortran') if (which_compiler /= 0) compiler = '_nvfortran' write (im_chr, '(i0)') this_image() if (present(filename)) then this%filename_image = trim(filename//compiler//'_im'//trim(im_chr)//'.data') this%filename = trim(filename//compiler//'_co'//'.data') else this%filename_image = trim('benchmark'//compiler//'_im'//trim(im_chr)//'.data') this%filename = trim('benchmark'//compiler//'_co'//'.data') end if if (present(nloops)) then if (nloops <= 0) error stop 'nloops must be greater than zero.' this%nloops = nloops else this%nloops = 10 end if if (present(timer)) then select case (trim(timer)) case ('wall') this%timer = 'wall' case ('date_and_time') this%timer = 'date_and_time' case ('cpu') this%timer = 'cpu' case ('omp') #if defined(USE_OMP) this%timer = 'omp' #else error stop 'Use -DUSE_OMP to enable OpenMP.' #endif case ('mpi') #if defined(USE_MPI) this%timer = 'mpi' #else error stop 'Use -DUSE_MPI to enable MPI.' #endif case default error stop 'timer is not valid. Valid options are: wall, date_and_time, cpu, omp, mpi.' end select else this%timer = 'wall' end if allocate(this%marks_co(nmarks)[*]) allocate(this%marks(nmarks)) inquire(file=this%filename_image, iostat=iostat) if (iostat /= 0) then error stop 'file '//trim(this%filename_image)//' cannot be accessed.' end if open (newunit = nunit, file = this%filename_image) write(nunit,'(a)') '-----------------------------------------------------' write(nunit,'(a)') 'ForBenchmark - https://github.com/gha3mi/forbenchmark' write(nunit,'(a)') '-----------------------------------------------------' write(nunit,'(a)') '' if (present(title)) then write(nunit,'(a)') trim(title) else write(nunit,'(a)') 'ForBenchmark' end if write(nunit,'(a)') current_date_and_time() write(nunit,'(a)') '' write(nunit,'(a,a)') 'compiler_version: ', compiler_version() write(nunit,'(a,a)') 'compiler_options: ', compiler_options() write(nunit,'(a,g0,a,g0)') 'image: ',this_image(),' of ',num_images() write(nunit,'(a)') '' write(nunit,'(a)') & &' METHOD |& & TIME(image) |& & GFLOPS(image) |& & NLOOPS |& & ARGI ' close(nunit) if (this_image() == 1) then inquire(file=this%filename, iostat=iostat) if (iostat /= 0) then error stop 'file '//trim(this%filename)//' cannot be accessed.' end if open (newunit = nunit, file = this%filename) write(nunit,'(a)') '-----------------------------------------------------' write(nunit,'(a)') 'ForBenchmark - https://github.com/gha3mi/forbenchmark' write(nunit,'(a)') '-----------------------------------------------------' write(nunit,'(a)') '' if (present(title)) then write(nunit,'(a)') trim(title) else write(nunit,'(a)') 'ForBenchmark' end if write(nunit,'(a)') current_date_and_time() write(nunit,'(a)') '' write(nunit,'(a,a)') 'compiler_version: ', compiler_version() write(nunit,'(a,a)') 'compiler_options: ', compiler_options() write(nunit,'(a,g0)') 'num_image: ', num_images() write(nunit,'(a)') '' write(nunit,'(a)') & &' METHOD |& & SPEEDUP(max) |& & TIME(max) |& & TIME(min) |& & TIME(avg) |& & GFLOPS(tot) |& & NLOOPS |& & ARGI ' close(nunit) end if end subroutine init