routine_name2id Function

private function routine_name2id(routineN) result(routine_id)

Internal routine used by timeset_handler and timings_setup_tracing. If no routine with given name is found in timer_env%routine_names then a new entry is created.

Arguments

TypeIntentOptionalAttributesName
character(len=default_string_length), intent(in) :: routineN

Return Value integer


Contents

Source Code


Source Code

   FUNCTION routine_name2id(routineN) RESULT(routine_id)
      !! Internal routine used by timeset_handler and timings_setup_tracing.
      !! If no routine with given name is found in timer_env%routine_names
      !! then a new entry is created.

      CHARACTER(LEN=default_string_length), INTENT(IN)   :: routineN
      INTEGER                                            :: routine_id

      INTEGER                                            :: stat
      TYPE(routine_stat_type), POINTER                   :: r_stat
      TYPE(timer_env_type), POINTER                      :: timer_env

      timer_env => list_peek(timers_stack)
      routine_id = dict_get(timer_env%routine_names, routineN, default_value=-1)

      IF (routine_id /= -1) RETURN ! found an id - let's return it
      ! routine not found - let's create it

      ! enforce space free timer names, to make the output of trace/timings of a fixed number fields
      IF (INDEX(routineN(1:LEN_TRIM(routineN)), ' ') /= 0) THEN
         DBCSR_ABORT("timings_name2id: routineN contains spaces: "//routineN)
      END IF

      ! register routine_name_dsl with new routine_id
      routine_id = dict_size(timer_env%routine_names) + 1
      CALL dict_set(timer_env%routine_names, routineN, routine_id)

      ALLOCATE (r_stat, stat=stat)
      IF (stat /= 0) &
         DBCSR_ABORT("timings_name2id: allocation failed")
      r_stat%routine_id = routine_id
      r_stat%routineN = routineN
      r_stat%active_calls = 0
      r_stat%excl_walltime_accu = 0.0_dp
      r_stat%incl_walltime_accu = 0.0_dp
      r_stat%excl_energy_accu = 0.0_dp
      r_stat%incl_energy_accu = 0.0_dp
      r_stat%total_calls = 0
      r_stat%stackdepth_accu = 0
      r_stat%trace = .FALSE.
      CALL list_push(timer_env%routine_stats, r_stat)
      IF (list_size(timer_env%routine_stats) /= dict_size(timer_env%routine_names)) &
         DBCSR_ABORT("timings_name2id: assertion failed")
   END FUNCTION routine_name2id