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~2~~CallsGraph proc~finalize~2 forbenchmark_coarray::benchmark%finalize proc~finalize_mark~2 forbenchmark_coarray::mark%finalize_mark proc~finalize~2->proc~finalize_mark~2

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_image, exist=exist, iostat=iostat)
      if (iostat /= 0 .or. .not. exist) then
         error stop 'file '//trim(this%filename_image)//' does not exist or cannot be accessed.'
      end if
      open (newunit = nunit, file = this%filename_image, access = 'append')
      write(nunit,'(a)') 'end of benchmark'
      close(nunit)

      if (this_image() == 1) then
         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)
      end if

      if (allocated(this%marks_co)) deallocate(this%marks_co)
      call this%marks%finalize_mark()
      if (allocated(this%marks)) deallocate(this%marks)
      if (allocated(this%filename_image)) deallocate(this%filename_image)
      if (allocated(this%argi)) deallocate(this%argi)
      if (allocated(this%argr)) deallocate(this%argr)

      if (this_image() == 1) print'(a)', 'end of benchmark'

   end subroutine finalize