dbcsr_log_handling Module

various routines to log and control the output. The idea is that decisions about where to log should not be done in the code that generates the log, but should be globally changeable a central place. So some care has been taken to have enough information about the place from where the log comes so that in the future intelligent and flexible decisions can be taken by the logger, without having to change other code.

Note

contains also routines to convert to a string. in my idea they should have been with variable length, (i.e. they should have returned a trim(adjustl(actual_result))) As a logger should be robust, at the moment I have given up. At the moment logging and output refer to the same object (dbcsr_logger_type) as these are actually different it might be better to separate them (they have already separate routines in a separate module @see dbcsr_output_handling). some practices (use of print *, no dbcsr_error_type, manual retain release of some objects) are dictated by the need to have minimal dependency

@see dbcsr_error_handling @version 12.2001



Variables

Type Visibility Attributes Name Initial
character(len=*), private, parameter :: moduleN = 'dbcsr_log_handling'
logical, private, parameter :: debug_this_module = .FALSE.

level of an error

integer, public, parameter :: dbcsr_fatal_level = 3

level of a failure

integer, public, parameter :: dbcsr_failure_level = 2

level of a warning

integer, public, parameter :: dbcsr_warning_level = 1

level of a note

integer, public, parameter :: dbcsr_note_level = 0

a generic function to trasform different types to strings

integer, private :: stack_pointer = 0
integer, private, parameter :: max_stack_pointer = 10
type(default_logger_stack_type), private, SAVE, DIMENSION(max_stack_pointer) :: default_logger_stack
integer, private, SAVE :: last_logger_id_nr = 0

Interfaces

public interface dbcsr_to_string

  • private function dbcsr_int_to_string(i) result(res)

    converts an int to a string (should be a variable length string, but that does not work with all the compilers)

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in) :: i

    the integer to convert

    Return Value character(len=6)

  • private function dbcsr_real_dp_to_string(val) result(res)

    convert a double precision real in a string (should be a variable length string, but that does not work with all the compilers)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(in) :: val

    the number to convert

    Return Value character(len=11)

  • private function dbcsr_logical_to_string(val) result(res)

    convert a logical in a string ('T' or 'F')

    Arguments

    Type IntentOptional Attributes Name
    logical, intent(in) :: val

    the number to convert

    Return Value character(len=1)


Derived Types

type, public ::  dbcsr_logger_type

type of a logger, at the moment it contains just a print level starting at which level it should be logged (0 note, 1 warning, 2 failure, 3 fatal) it could be expanded with the ability to focus on one or more module/object/thread/processor

Read more…

Components

Type Visibility Attributes Name Initial
integer, public :: id_nr = -1

unique number to identify the logger reference count (see cp2k/doc/ReferenceCounting.html)

integer, public :: ref_count = -1

unique number to identify the logger reference count (see cp2k/doc/ReferenceCounting.html)

integer, public :: print_level = -1

the level starting at which something gets printed

integer, public :: default_local_unit_nr = -1

default unit for local logging (-1 if not yet initialized). Local logging guarantee to each task its own file.

integer, public :: default_global_unit_nr = -1

default unit for global logging (-1 if not yet initialized). This unit is valid only on the processor with %mp_env%mp%mynode==%mv_env%mp%source.

logical, public :: close_local_unit_on_dealloc = .FALSE.

if the local unit should be closed when this logger is deallocated whether the global unit should be closed when this logger is deallocated

logical, public :: close_global_unit_on_dealloc = .FALSE.

if the local unit should be closed when this logger is deallocated whether the global unit should be closed when this logger is deallocated

character(len=default_string_length), public :: suffix = ""

a short string that is used as suffix in all the filenames created by this logger. Can be used to guarantee the uniqueness of generated filename

character(len=default_path_length), public :: local_filename = ""

the root of the name of the file used for local logging (can be different from the name of the file corresponding to default_local_unit_nr, only the one used if the unit needs to be opened) the root of the name of the file used for global logging (can be different from the name of the file corresponding to default_global_unit_nr, only the one used if the unit needs to be opened)

character(len=default_path_length), public :: global_filename = ""

the root of the name of the file used for local logging (can be different from the name of the file corresponding to default_local_unit_nr, only the one used if the unit needs to be opened) the root of the name of the file used for global logging (can be different from the name of the file corresponding to default_global_unit_nr, only the one used if the unit needs to be opened)

type(dbcsr_mp_obj), public :: mp_env = dbcsr_mp_obj()

the parallel environment for the output.

type(dbcsr_iteration_info_type), public, POINTER :: iter_info => NULL()

type, public ::  dbcsr_logger_p_type

Components

Type Visibility Attributes Name Initial
type(dbcsr_logger_type), public, POINTER :: p => Null()

type, private ::  default_logger_stack_type

Components

Type Visibility Attributes Name Initial
type(dbcsr_logger_type), public, POINTER :: dbcsr_default_logger => Null()

Functions

public function dbcsr_default_logger_stack_size() result(res)

Arguments

None

Return Value integer

public function dbcsr_get_default_logger() result(res)

returns the default logger

Read more…

Arguments

None

Return Value type(dbcsr_logger_type), POINTER

public function dbcsr_logger_would_log(logger, level) result(res)

this function can be called to check if the logger would log a message with the given level from the given source you should use this function if you do direct logging (without using dbcsr_logger_log), or if you want to know if the generation of some costly log info is necessary

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

the logger you want to log in

integer, intent(in) :: level

describes the of the message: dbcsr_fatal_level(3), dbcsr_failure_level(2), dbcsr_warning_level(1), dbcsr_note_level(0).

Return Value logical

public function dbcsr_logger_get_unit_nr(logger, local) result(res)

returns the unit nr for the requested kind of log.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

the logger you want to log in

logical, intent(in), optional :: local

if true returns a local logger (one per task), otherwise returns a global logger (only the process with mp_env%mp%mynode== mp_env%mp%source should write to the global logger). Defaults to false

Return Value integer

public function dbcsr_logger_get_default_io_unit(logger) result(res)

returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs calling this function is not the ionode

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), optional, POINTER :: logger

the logger you want to log in

Return Value integer

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

Type IntentOptional Attributes Name
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

private function dbcsr_int_to_string(i) result(res)

converts an int to a string (should be a variable length string, but that does not work with all the compilers)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: i

the integer to convert

Return Value character(len=6)

private function dbcsr_real_dp_to_string(val) result(res)

convert a double precision real in a string (should be a variable length string, but that does not work with all the compilers)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: val

the number to convert

Return Value character(len=11)

private function dbcsr_logical_to_string(val) result(res)

convert a logical in a string ('T' or 'F')

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: val

the number to convert

Return Value character(len=1)


Subroutines

public subroutine dbcsr_add_default_logger(logger)

adds a default logger. MUST be called before logging occurs

Read more…

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

public subroutine dbcsr_rm_default_logger()

the cousin of dbcsr_add_default_logger, decrements the stack, so that the default logger is what it has been

Arguments

None

public subroutine dbcsr_logger_create(logger, mp_env, print_level, default_global_unit_nr, default_local_unit_nr, global_filename, local_filename, close_global_unit_on_dealloc, iter_info, close_local_unit_on_dealloc, suffix, template_logger)

initializes a logger

Read more…

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

the logger to initialize

type(dbcsr_mp_obj), optional :: mp_env

the parallel environment (this is most likely the global parallel environment

integer, intent(in), optional :: print_level

the level starting with which something is written (defaults to dbcsr_note_level) the default unit_nr for output (if not given, and no file is given defaults to the standard output) the default unit number for local (i.e. task) output. If not given defaults to a out.taskid file created upon

integer, intent(in), optional :: default_global_unit_nr

the level starting with which something is written (defaults to dbcsr_note_level) the default unit_nr for output (if not given, and no file is given defaults to the standard output) the default unit number for local (i.e. task) output. If not given defaults to a out.taskid file created upon

integer, intent(in), optional :: default_local_unit_nr

the level starting with which something is written (defaults to dbcsr_note_level) the default unit_nr for output (if not given, and no file is given defaults to the standard output) the default unit number for local (i.e. task) output. If not given defaults to a out.taskid file created upon

character(len=*), intent(in), optional :: global_filename

a new file to open (can be given instead of the global_unit_nr) a new file to open (with suffix and mp_env%mp%mynode appended). Can be given instead of the default_local_unit_nr). the file is created only upon the first local logging request

character(len=*), intent(in), optional :: local_filename

a new file to open (can be given instead of the global_unit_nr) a new file to open (with suffix and mp_env%mp%mynode appended). Can be given instead of the default_local_unit_nr). the file is created only upon the first local logging request

logical, intent(in), optional :: close_global_unit_on_dealloc

if the unit should be closed when the logger is deallocated (defaults to true if a local_filename is given, to false otherwise)

type(dbcsr_iteration_info_type), optional, POINTER :: iter_info
logical, intent(in), optional :: close_local_unit_on_dealloc

if the unit should be closed when the logger is deallocated (defaults to true)

character(len=*), intent(in), optional :: suffix

the suffix that should be added to all the generated filenames

type(dbcsr_logger_type), optional, POINTER :: template_logger

a logger from where to take the unspecified things

public subroutine dbcsr_logger_retain(logger)

retains the given logger (to be called to keep a shared copy of the logger)

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

the logger to retain

public subroutine dbcsr_logger_release(logger)

releases this logger

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

the logger to release

public subroutine dbcsr_logger_set_log_level(logger, level)

changes the logging level. Log messages with a level less than the one given wo not be printed.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

the logger to change

integer, intent(in) :: level

the new logging level for the logger

public subroutine dbcsr_logger_generate_filename(logger, res, root, postfix, local)

generates a unique filename (ie adding eventual suffixes and process ids)

Read more…

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger
character(len=*), intent(inout) :: res

the resulting string

character(len=*), intent(in) :: root

the start of filename the end of the name

character(len=*), intent(in) :: postfix

the start of filename the end of the name

logical, intent(in), optional :: local

if the name should be local to this task (defaults to false)

public subroutine dbcsr_logger_set(logger, local_filename, global_filename)

sets various attributes of the given logger

Arguments

Type IntentOptional Attributes Name
type(dbcsr_logger_type), POINTER :: logger

the logger you want to change

character(len=*), intent(in), optional :: local_filename

the root of the name of the file used for local logging the root of the name of the file used for global logging

character(len=*), intent(in), optional :: global_filename

the root of the name of the file used for local logging the root of the name of the file used for global logging