MPI-SCATCI  2.0
An MPI version of SCATCI
BaseManager_module.f90
Go to the documentation of this file.
1 ! Copyright 2019
2 !
3 ! For a comprehensive list of the developers that contributed to these codes
4 ! see the UK-AMOR website.
5 !
6 ! This file is part of UKRmol-in (UKRmol+ suite).
7 !
8 ! UKRmol-in is free software: you can redistribute it and/or modify
9 ! it under the terms of the GNU General Public License as published by
10 ! the Free Software Foundation, either version 3 of the License, or
11 ! (at your option) any later version.
12 !
13 ! UKRmol-in is distributed in the hope that it will be useful,
14 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ! GNU General Public License for more details.
17 !
18 ! You should have received a copy of the GNU General Public License
19 ! along with UKRmol-in (in source/COPYING). Alternatively, you can also visit
20 ! <https://www.gnu.org/licenses/>.
21 
32 
33  use precisn, only: longint
34  use basempi_module, only: basempi
35 
36  implicit none
37 
38  public basemanager, memory_man
39 
40  private
41 
43  type, extends(basempi) :: basemanager
44  private
45  integer(longint) :: total_local_memory
46  integer(longint) :: available_local_memory
47  contains
48  private
49  procedure :: basemanager_ctor
50  procedure :: init_memory
51  procedure :: track_memory
52  procedure :: free_memory
53  procedure :: get_available_memory
55  generic, public :: construct => basemanager_ctor
56  end type basemanager
57 
58  !Declare a static BaseManager for entire program scope
60 
61  !interface BaseManager
62  ! procedure :: BaseManager_ctor
63  !end interface
64 
65 contains
66 
71  subroutine basemanager_ctor (this, total_memory)
72  class(basemanager) :: this
73  integer(longint), intent(in) :: total_memory
74 
75  this % total_local_memory = total_memory
76  this % available_local_memory = this % total_local_memory
77  call this % construct
78 
79  end subroutine
80 
81 
86  subroutine init_memory (this, total_memory)
87  class(basemanager) :: this
88  integer(longint), intent(in) :: total_memory
89 
90  this % total_local_memory = total_memory
91  this % available_local_memory = this % total_local_memory
92 
93  end subroutine init_memory
94 
95 
100  subroutine track_memory (this, alloc_memory, error)
101  class(basemanager) :: this
102  integer(longint), intent(in) :: alloc_memory
103  integer, intent(out) :: error
104 
105  this % available_local_memory = this % available_local_memory - alloc_memory
106 
107  if (this % available_local_memory < 0) then
108  error = -1
109  call this % verbose_log_message('Run out of memory')
110  else
111  error = 0
112  end if
113 
114  end subroutine track_memory
115 
116 
121  subroutine free_memory (this, alloc_memory, error)
122  class(basemanager) :: this
123  integer(longint), intent(in) :: alloc_memory
124  integer, intent(out) :: error
125 
126  this % available_local_memory = this % available_local_memory + alloc_memory
127 
128  if (this % available_local_memory > this % total_local_memory) then
129  error = -1
130  call this % verbose_log_message('Memory mismatch')
131  else
132  error = 0
133  end if
134 
135  end subroutine free_memory
136 
137 
142  integer(longint) function get_available_memory (this)
143  class(basemanager) :: this
144 
145  get_available_memory = this % available_local_memory
146 
147  end function get_available_memory
148 
149 
154  integer(longint) function get_available_global_memory (this)
155  class(basemanager) :: this
156  integer(longint) :: local(1), global(1)
157 
158  local = this % available_local_memory
159  !call mpi_reduceall_inplace_sum_cfp(local,1)
160  get_available_global_memory = local(1)
161 
162  end function get_available_global_memory
163 
164 end module basemanager_module
basemanager_module::basemanager_ctor
subroutine basemanager_ctor(this, total_memory)
Type constructor.
Definition: BaseManager_module.f90:72
basemanager_module
Base manager type.
Definition: BaseManager_module.f90:31
basemanager_module::basemanager
This is a simple class to handle memory management tracking.
Definition: BaseManager_module.f90:43
basempi_module::basempi
Base MPI type.
Definition: BaseMPI_module.f90:44
basemanager_module::free_memory
subroutine free_memory(this, alloc_memory, error)
Free memory.
Definition: BaseManager_module.f90:122
basempi_module
Base MPI module.
Definition: BaseMPI_module.f90:30
basemanager_module::get_available_global_memory
integer(longint) function get_available_global_memory(this)
Obtain available global memory.
Definition: BaseManager_module.f90:155
basemanager_module::init_memory
subroutine init_memory(this, total_memory)
Initialize memory.
Definition: BaseManager_module.f90:87
basemanager_module::track_memory
subroutine track_memory(this, alloc_memory, error)
Track memory.
Definition: BaseManager_module.f90:101
basemanager_module::memory_man
type(basemanager), public memory_man
Definition: BaseManager_module.f90:59
basemanager_module::get_available_memory
integer(longint) function get_available_memory(this)
Obtain available local memory.
Definition: BaseManager_module.f90:143