write_cantera_cache_stats Subroutine

public subroutine write_cantera_cache_stats(flow)

Print bridge-level Cantera cache statistics, summed over flow ranks.

The counters are diagnostic only. They help determine whether Cantera transport, thermo-sync, and species-enthalpy caches are doing useful work before attempting further performance changes.

Arguments

Type IntentOptional Attributes Name
type(flow_mpi_t), intent(in) :: flow

Source Code

   subroutine write_cantera_cache_stats(flow)
      type(flow_mpi_t), intent(in) :: flow

      integer, parameter :: nstats = 16
      real(c_double) :: local_stats(nstats), global_stats(nstats)
      integer :: ierr

      local_stats = 0.0_c_double
      global_stats = 0.0_c_double

      call cantera_get_cache_stats_c(local_stats, nstats)
      call MPI_Reduce(local_stats, global_stats, nstats, MPI_DOUBLE_PRECISION, MPI_SUM, 0, flow%comm, ierr)
      if (ierr /= MPI_SUCCESS) call fatal_error('energy', 'MPI_Reduce failed for Cantera cache statistics')

      if (flow%rank /= 0) return
      if (sum(global_stats) <= 0.0_c_double) return

      write(output_unit,'(a)') ' ======================================================================'
      write(output_unit,'(a)') '  CANTERA CACHE STATISTICS'
      write(output_unit,'(a)') '  Counts are summed over flow ranks; hits/misses are cell/point states.'
      write(output_unit,'(a)') ' ======================================================================'
      write(output_unit,'(a)') '                         Cache          Calls         Points           Hits         Misses     Hit%'
      write(output_unit,'(a)') ' ----------------------------------------------------------------------'
      call print_cache_row('Transport_mu_Dk', 1)
      call print_cache_row('Energy_ThermoSync', 5)
      call print_cache_row('SpeciesH_Bulk', 9)
      call print_cache_row('SpeciesH_Point', 13)
      write(output_unit,'(a)') ' ======================================================================'

   contains

      subroutine print_cache_row(name, offset)
         character(len=*), intent(in) :: name
         integer, intent(in) :: offset

         real(c_double) :: calls, points, hits, misses, hit_rate

         calls = global_stats(offset)
         points = global_stats(offset + 1)
         hits = global_stats(offset + 2)
         misses = global_stats(offset + 3)

         if (calls <= 0.0_c_double .and. points <= 0.0_c_double) return

         if (hits + misses > 0.0_c_double) then
            hit_rate = 100.0_c_double * hits / (hits + misses)
         else
            hit_rate = 0.0_c_double
         end if

         write(output_unit,'(2x,a24,1x,f12.0,1x,f14.0,1x,f14.0,1x,f14.0,1x,f8.2)') &
            trim(name), calls, points, hits, misses, hit_rate
      end subroutine print_cache_row

   end subroutine write_cantera_cache_stats