MONC
allreduction-inter-io.F90
Go to the documentation of this file.
1 
14  implicit none
15 
16 #ifndef TEST_MODE
17  private
18 #endif
19 
21  integer :: root
22  procedure(handle_completion), pointer, nopass :: completion_procedure
23  end type allreduce_type
24 
25  logical, volatile :: initialised=.false.
26 
27  integer, volatile :: allreduce_rwlock
28  type(hashmap_type), volatile :: allreduce_types
29 
32 contains
33 
36  subroutine init_allreduction_inter_io(io_configuration)
37  type(io_configuration_type), intent(inout) :: io_configuration
38 
39  if (.not. initialised) then
40  initialised=.true.
42  end if
43  call init_reduction_inter_io(io_configuration)
44  call init_broadcast_inter_io(io_configuration)
45  end subroutine init_allreduction_inter_io
46 
49  subroutine finalise_allreduction_inter_io(io_configuration)
50  type(io_configuration_type), intent(inout) :: io_configuration
51 
52  if (initialised) then
53  initialised=.false.
55  end if
56  call finalise_reduction_inter_io(io_configuration)
58  end subroutine finalise_allreduction_inter_io
59 
63  logical function check_allreduction_inter_io_for_completion(io_configuration)
64  type(io_configuration_type), intent(inout) :: io_configuration
65 
70 
80  subroutine perform_inter_io_allreduction(io_configuration, field_values, field_size, field_name, reduction_op, root, &
81  timestep, completion_procedure)
82  type(io_configuration_type), intent(inout) :: io_configuration
83  real(kind=DOUBLE_PRECISION), dimension(:) :: field_values
84  integer, intent(in) :: field_size, reduction_op, root, timestep
85  character(len=*), intent(in) :: field_name
86  procedure(handle_completion) :: completion_procedure
87 
88  if (io_configuration%my_io_rank .eq. root) then
89  call add_allreduce_information_if_needed(field_name, timestep, root, completion_procedure)
90  end if
91  call perform_inter_io_reduction(io_configuration, field_values, field_size, field_name, reduction_op, &
93  if (io_configuration%my_io_rank .ne. root) then
94  ! None root processes issue a broadcast
95  call perform_inter_io_broadcast(io_configuration, field_values, size(field_values), field_name, root, &
96  timestep, completion_procedure)
97  end if
98  end subroutine perform_inter_io_allreduction
99 
105  subroutine internal_reduction_completion_procedure(io_configuration, values, field_name, timestep)
106  type(io_configuration_type), intent(inout) :: io_configuration
107  real(DEFAULT_PRECISION), dimension(:) :: values
108  character(len=*) :: field_name
109  integer :: timestep
110 
111  type(allreduce_type), pointer :: allreduce_information
112 
113  allreduce_information=>find_allreduce_information(field_name, timestep, .true.)
114  call perform_inter_io_broadcast(io_configuration, values, size(values), field_name, &
115  allreduce_information%root, timestep, allreduce_information%completion_procedure)
116  call remove_allreduce_information(field_name, timestep, .true.)
118 
124  subroutine add_allreduce_information_if_needed(field_name, timestep, root, completion_procedure)
125  character(len=*), intent(in) :: field_name
126  integer, intent(in) :: timestep, root
127  procedure(handle_completion) :: completion_procedure
128 
129  type(allreduce_type), pointer :: allreduce_information
130  class(*), pointer :: generic
131 
132  allreduce_information=>find_allreduce_information(field_name, timestep, .true.)
133  if (.not. associated(allreduce_information)) then
135  allreduce_information=>find_allreduce_information(field_name, timestep, .false.)
136  if (.not. associated(allreduce_information)) then
137  allocate(allreduce_information)
138  allreduce_information%completion_procedure=>completion_procedure
139  allreduce_information%root=root
140  generic=>allreduce_information
141  call c_put_generic(allreduce_types, trim(field_name)//"#"//conv_to_string(timestep), generic, .true.)
142  end if
144  end if
146 
152  function find_allreduce_information(field_name, timestep, dolock)
153  character(len=*), intent(in) :: field_name
154  integer, intent(in) :: timestep
155  logical, intent(in) :: dolock
156  type(allreduce_type), pointer :: find_allreduce_information
157 
158  class(*), pointer :: generic
159 
161  generic=>c_get_generic(allreduce_types, trim(field_name)//"#"//conv_to_string(timestep))
163 
164  if (associated(generic)) then
165  select type(generic)
166  type is (allreduce_type)
167  find_allreduce_information=>generic
168  end select
169  else
170  find_allreduce_information=>null()
171  end if
172  end function find_allreduce_information
173 
178  subroutine remove_allreduce_information(field_name, timestep, dolock)
179  character(len=*), intent(in) :: field_name
180  integer, intent(in) :: timestep
181  logical, intent(in) :: dolock
182 
184  call c_remove(allreduce_types, trim(field_name)//"#"//conv_to_string(timestep))
186  end subroutine remove_allreduce_information
187 end module allreduction_inter_io_mod
logical function, public check_allreduction_inter_io_for_completion(io_configuration)
Determines whether this all reduction inter IO functionality has completed or not.
integer function forthread_rwlock_init(rwlock_id, attr_id)
Definition: forthread.F90:504
All reduction, which does a reduce and then broadcasts the data to all IO servers.
Gets a specific generic element out of the list, stack, queue or map with the corresponding key...
Returns whether a collection is empty.
subroutine, public init_reduction_inter_io(io_configuration)
Initialises the reduction action.
subroutine, public perform_inter_io_reduction(io_configuration, field_values, field_size, reduction_field_name, reduction_op, root, timestep, completion_procedure)
Actually handles the processing for this data wrt the vertical reduction.
logical function, public check_reduction_inter_io_for_completion(io_configuration)
Checks this action for completion, when all are completed then the IO server can shutdown as this is ...
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17
integer function forthread_rwlock_rdlock(lock_id)
Definition: forthread.F90:514
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
A hashmap structure, the same as a map but uses hashing for greatly improved performance when storing...
Definition: collections.F90:94
subroutine, public finalise_broadcast_inter_io()
Finalises the broadcast inter IO functionality.
Conversion between common inbuilt FORTRAN data types.
Definition: conversions.F90:5
Converts data types to strings.
Definition: conversions.F90:36
integer function forthread_rwlock_wrlock(lock_id)
Definition: forthread.F90:532
subroutine, public finalise_allreduction_inter_io(io_configuration)
Finalises the all reduction inter IO functionality.
integer, parameter, public double_precision
Double precision (64 bit) kind.
Definition: datadefn.F90:14
Broadcast inter IO communication which sends a value from one IO server to all others. This tracks field name and timestep and only issues one call (and one results call to completion) for that combination.
This is a thread pool and the single management "main" thread will spawn out free threads in the pool...
Definition: threadpool.F90:5
subroutine internal_reduction_completion_procedure(io_configuration, values, field_name, timestep)
Internal completion, called after the reduce has completed (on root) and calls out to broadcast...
subroutine, public check_thread_status(ierr)
Checks the error status of any thread operation and reports an error if it failed.
Definition: threadpool.F90:229
subroutine, public perform_inter_io_broadcast(io_configuration, field_values, field_size, field_name, root, timestep, completion_procedure)
Performs an inter IO broadcast of data from the root to all other IO servers. Note that this is on th...
Collection data structures.
Definition: collections.F90:7
subroutine, public init_broadcast_inter_io(io_configuration)
Initialises the broadcast inter IO functionality.
integer, parameter, public string_length
Default length of strings.
Definition: datadefn.F90:10
Inter IO server communication specific functionality. This manages all of the communication that migh...
subroutine remove_allreduce_information(field_name, timestep, dolock)
Removes an all reduce status information based on the field name and timestep.
subroutine, public init_allreduction_inter_io(io_configuration)
Initialises the all reduction inter IO functionality.
integer function forthread_rwlock_destroy(rwlock_id)
Definition: forthread.F90:495
subroutine, public finalise_reduction_inter_io(io_configuration)
Finalises the reduction action, waiting for all outstanding requests and then freeing data...
integer function forthread_rwlock_unlock(lock_id)
Definition: forthread.F90:550
Reduction inter IO action which will perform reductions between IO servers. This is not as trivial as...
Puts a generic key-value pair into the map.
integer function, public get_reduction_operator(op_string)
Given the map of action attributes this procedure will identify the reduction operator that has been ...
type(hashmap_type), volatile allreduce_types
subroutine, public perform_inter_io_allreduction(io_configuration, field_values, field_size, field_name, reduction_op, root, timestep, completion_procedure)
Performs the all reduction inter IO reduction.
Parses the XML configuration file to produce the io configuration description which contains the data...
type(allreduce_type) function, pointer find_allreduce_information(field_name, timestep, dolock)
Finds an all reduce status information based on the field name and timestep, or returns null if none ...
Removes a specific element from the list or map.
subroutine add_allreduce_information_if_needed(field_name, timestep, root, completion_procedure)
Adds an all reduce information to the status if it does not exist.