finalize Subroutine

private impure elemental subroutine finalize(this)

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

Type Bound

benchmark

Arguments

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

Benchmark object to be finalized


Calls

proc~~finalize~~CallsGraph proc~finalize forbenchmark_default::benchmark%finalize proc~finalize_mark forbenchmark_default::mark%finalize_mark proc~finalize->proc~finalize_mark

Called by

proc~~finalize~~CalledByGraph proc~finalize forbenchmark_default::benchmark%finalize program~demo demo program~demo->proc~finalize

Source Code

   elemental impure subroutine finalize(this)
      !! author: Seyed Ali Ghasemi
      !! Finalizes the benchmark object by deallocating memory and performs necessary cleanup.
      !!
      class(benchmark), intent(inout) :: this   !! Benchmark object to be finalized
      integer                         :: nunit  !! Unit number for file access
      logical                         :: exist  !! Logical variable for file existence
      integer                         :: iostat !! I/O status

      inquire(file=this%filename, exist=exist, iostat=iostat)
      if (iostat /= 0 .or. .not. exist) then
         error stop 'file '//trim(this%filename)//' does not exist or cannot be accessed.'
      end if
      open (newunit = nunit, file = this%filename, access = 'append')
      write(nunit,'(a)') 'end of benchmark'
      close(nunit)

      call this%marks(:)%finalize_mark()
      if (allocated(this%filename)) deallocate(this%filename)
      if (allocated(this%argi)) deallocate(this%argi)
      if (allocated(this%argr)) deallocate(this%argr)

      print'(a)', 'end of benchmark'

   end subroutine finalize