dbcsr_logger_get_default_unit_nr Function

public recursive function dbcsr_logger_get_default_unit_nr(logger, local, skip_not_ionode) result(res)

asks the default unit number of the given logger. try to use dbcsr_logger_get_unit_nr

Arguments

TypeIntentOptionalAttributesName
type(dbcsr_logger_type), optional POINTER:: logger

the logger you want info from

logical, intent(in), optional :: local

if you want the local unit nr (defaults to false)

logical, intent(in), optional :: skip_not_ionode

if you want the local unit nr (defaults to false)

Return Value integer


Contents


Source Code

   RECURSIVE FUNCTION dbcsr_logger_get_default_unit_nr(logger, local, skip_not_ionode) RESULT(res)
      !! asks the default unit number of the given logger.
      !! try to use dbcsr_logger_get_unit_nr

      TYPE(dbcsr_logger_type), OPTIONAL, POINTER         :: logger
         !! the logger you want info from
      LOGICAL, INTENT(in), OPTIONAL                      :: local, skip_not_ionode
         !! if you want the local unit nr (defaults to false)
      INTEGER                                            :: res

      CHARACTER(len=*), PARAMETER :: routineN = 'dbcsr_logger_get_default_unit_nr', &
                                     routineP = moduleN//':'//routineN

      CHARACTER(len=default_path_length)                 :: filename, host_name
      INTEGER                                            :: iostat, pid
      LOGICAL                                            :: loc, skip
      TYPE(dbcsr_logger_type), POINTER                   :: lggr

      loc = .TRUE.
      skip = .FALSE.
      IF (PRESENT(logger)) THEN
         lggr => logger
      ELSE
         NULLIFY (lggr)
      END IF
      IF (.NOT. ASSOCIATED(lggr)) lggr => dbcsr_get_default_logger()
      IF (lggr%ref_count < 1) &
         DBCSR_ABORT(routineP//" logger%ref_count<1")

      IF (PRESENT(local)) loc = local
      IF (PRESENT(skip_not_ionode)) skip = skip_not_ionode
      IF (.NOT. loc) THEN
         IF (lggr%default_global_unit_nr <= 0) THEN
            IF (lggr%mp_env%mp%mynode == lggr%mp_env%mp%source) THEN
               CALL dbcsr_logger_generate_filename(lggr, filename, lggr%global_filename, &
                                                   ".out", local=.FALSE.)
               CALL open_file(TRIM(filename), file_status="unknown", &
                              file_action="WRITE", file_position="APPEND", &
                              unit_number=lggr%default_global_unit_nr)
            ELSE IF (.NOT. skip) THEN
               lggr%default_global_unit_nr = dbcsr_logger_get_default_unit_nr(lggr, .TRUE.)
               lggr%close_global_unit_on_dealloc = .FALSE.
            ELSE
               lggr%default_global_unit_nr = -1
               lggr%close_global_unit_on_dealloc = .FALSE.
            END IF
         END IF
         IF ((lggr%mp_env%mp%mynode /= lggr%mp_env%mp%source) .AND. (.NOT. skip)) THEN
            WRITE (UNIT=lggr%default_global_unit_nr, FMT='(/,T2,A)', IOSTAT=iostat) &
               ' *** WARNING non ionode asked for global logger ***'
            IF (iostat /= 0) THEN
               CALL m_getpid(pid)
               CALL m_hostnm(host_name)
               PRINT *, " *** Error trying to WRITE to the local logger ***"
               PRINT *, " *** MPI_id           = ", lggr%mp_env%mp%mynode
               PRINT *, " *** MPI_Communicator = ", lggr%mp_env%mp%mp_group
               PRINT *, " *** PID              = ", pid
               PRINT *, " *** Hostname         = "//TRIM(host_name)
               CALL print_stack(default_output_unit)
            ELSE
               CALL print_stack(lggr%default_global_unit_nr)
            END IF
         END IF
         res = lggr%default_global_unit_nr
      ELSE
         IF (lggr%default_local_unit_nr <= 0) THEN
            CALL dbcsr_logger_generate_filename(lggr, filename, lggr%local_filename, &
                                                ".out", local=.TRUE.)
            CALL open_file(TRIM(filename), file_status="unknown", &
                           file_action="WRITE", &
                           file_position="APPEND", &
                           unit_number=lggr%default_local_unit_nr)
            WRITE (UNIT=lggr%default_local_unit_nr, FMT='(/,T2,A,I0,A,I0,A)', IOSTAT=iostat) &
               '*** Local logger file of MPI task ', lggr%mp_env%mp%mynode, &
               ' in communicator ', lggr%mp_env%mp%mp_group, ' ***'
            IF (iostat == 0) THEN
               CALL m_getpid(pid)
               CALL m_hostnm(host_name)
               WRITE (UNIT=lggr%default_local_unit_nr, FMT='(T2,A,I0)', IOSTAT=iostat) &
                  '*** PID      = ', pid, &
                  '*** Hostname = '//host_name
               CALL print_stack(lggr%default_local_unit_nr)
            END IF
            IF (iostat /= 0) THEN
               CALL m_getpid(pid)
               CALL m_hostnm(host_name)
               PRINT *, " *** Error trying to WRITE to the local logger ***"
               PRINT *, " *** MPI_id           = ", lggr%mp_env%mp%mynode
               PRINT *, " *** MPI_Communicator = ", lggr%mp_env%mp%mp_group
               PRINT *, " *** PID              = ", pid
               PRINT *, " *** Hostname         = "//TRIM(host_name)
               CALL print_stack(default_output_unit)
            END IF

         END IF
         res = lggr%default_local_unit_nr
      END IF
   END FUNCTION dbcsr_logger_get_default_unit_nr