Leeds-MONC / monc

MONC (Leeds fork)
BSD 3-Clause "New" or "Revised" License
5 stars 18 forks source link

Create MONC IO side of diagnostics in Fortran #3

Open leifdenby opened 6 years ago

leifdenby commented 6 years ago

Instead of having to define in XML which MPI reduction and local reduction operations the aim is to be able to do this in Fortran. These definitions will reside inside the individual component which currently make their "component fields" visible to the MONC server. By having these definitions together in the same source file and both in Fortran the hope is that development and maintenance will be easier.

Resources:

leifdenby commented 6 years ago

The current steps to get a component field (e.g. horizontal mean theta profile) written to output is:

  1. profile_diagnostics_get_descriptor: the component indicates which fields it publishes and where to get information and data on these fields

  2. field_information_retrieval_callback Ensure that the "component field" is "enabled" so that the IO server knows it can request its data

  3. timestep_callback On every timestep update local value which is to be sent to IO server based on "current state"

  4. field_value_retrieval_callback provide local value so that it can be sent to the IO server

  5. data-definition: indicate which "component fields" the IO server expects from MONC and at what frequency

  6. data-handling: do MPI and local reductions of received fields and create a new "IO field" only available to the IO server

  7. group & data-writing create field groups of fields available on IO server and indicate which files will include field groups

I'm a suggesting that 4. and 5. will be handled in Fortran in future by:

  1. data-definition: indicate which "component fields" the IO server expects from MONC and at what frequency

    • add in profile_diagnostics_get_descriptor a pointer to the subroutine which on the IO server should handle data reduction and which component fields it will need
  2. data-handling: do MPI and local reductions of received fields and create a new "IO field" only available to the IO server

    • add new subroutine in component module which handles MPI and local reductions using fortran routines and "publishes" "IO fields" (making them only available locally on the IO server)

      • created as linked list, each io operation is a function which takes the last operation as an argument and returns a new one with the operation added
leifdenby commented 6 years ago

Practically this could be achieved by making MONC components register their IO-server side operations on init. Similarly to how a subroutine from each component is automatically called when MONC is initialised a routine which indicates which IO-server side operations are needed (to produce IO-server fields) could be added.

This could look something like:

subroutine register_IO_server_operations(io_server_operations)
    io_server_operations%num_operations = 1

    io_server_operation%operation_definition => io__for_global_theta_horizontal_mean
    io_server_operation%name = "theta_mean"
    io_server_operation%namespace = "profile_fields"
    io_server_operation%generation_timestep_frequency = 1

    io_server_operations%operations(1) = io_server_operation
end subroutine register_IO_server_operations

subroutine io__for_global_theta_horizontal_mean(root)
    type(io_operation_type), intent(in) :: root
    type(io_operation_type) :: last_op

    last_op = io_require(from=root, field="theta_total_local")
    last_op = io_sum(from=last_op, location="local")  ! local/global denoting whether the reduction is across all MONC IO server or on each individually
    last_op = io_scale(from=last_op, by="domain_size")
end subroutine

The final subroutine simply defines (using a linked-list datatype) first what MONC component fields are needed and what operations should be done.

These subroutines which define the io-server side operations could then be generalised and re-used across-multiple components and could even by combined with the MONC-side definition so that producing a horizontal mean profile for e.g. theta could be achieved simply trough one instruction. The MONC-side and IO server-side operations could then be called automatically.