MODFLOW 6  version 6.7.0.dev1
USGS Modular Hydrologic Model
mpiunitcachemodule Module Reference

Data Types

type  mpiunitcachetype
 

Functions/Subroutines

subroutine cc_init (this, nr_stages, nr_msg_types)
 Initialize the unit cache. More...
 
integer function cc_get_cached (this, rank, stage, msg_id)
 Get the cached mpi type for this rank and. More...
 
subroutine cc_cache (this, rank, stage, msg_id, mpi_type)
 Cache the mpi datatype for this particular rank and stage. The datatype should be committed. More...
 
logical(lgp) function is_rank_cached (this, rank)
 
subroutine add_rank_cache (this, rank)
 
integer(i4b) function get_rank_index (this, rank)
 @Brief returns -1 when not present More...
 
integer(i4b) function get_msg_index (this, rank, stage, msg_id)
 @Brief returns -1 when not present More...
 
subroutine cc_clear (this)
 Clear the cache: free MPI types. More...
 
subroutine cc_destroy (this)
 Destroy unit cache. More...
 

Variables

integer(i4b), parameter, public no_cached_value = -1
 

Function/Subroutine Documentation

◆ add_rank_cache()

subroutine mpiunitcachemodule::add_rank_cache ( class(mpiunitcachetype this,
integer(i4b)  rank 
)
private

Definition at line 100 of file MpiUnitCache.f90.

101  class(MpiUnitCacheType) :: this
102  integer(I4B) :: rank
103  ! local
104  integer(I4B) :: i, j
105 
106  call this%cached_ranks%push_back(rank)
107  do i = 1, this%nr_stages
108  do j = 1, this%nr_msg_types
109  call this%cached_messages%push_back(no_cached_value)
110  end do
111  end do
112 

◆ cc_cache()

subroutine mpiunitcachemodule::cc_cache ( class(mpiunitcachetype this,
integer(i4b)  rank,
integer(i4b)  stage,
integer(i4b)  msg_id,
integer  mpi_type 
)
private

Definition at line 70 of file MpiUnitCache.f90.

71  class(MpiUnitCacheType) :: this
72  integer(I4B) :: rank
73  integer(I4B) :: stage
74  integer(I4B) :: msg_id
75  integer :: mpi_type
76  ! local
77  integer(I4B) :: msg_idx
78 
79  ! add if rank not present in cache yet
80  if (.not. this%is_rank_cached(rank)) then
81  call this%add_rank_cache(rank)
82  end if
83 
84  ! rank has been added to cache, now set
85  ! mpi datatype for this stage's message:
86  msg_idx = this%get_msg_index(rank, stage, msg_id)
87  call this%cached_messages%set(msg_idx, mpi_type)
88 

◆ cc_clear()

subroutine mpiunitcachemodule::cc_clear ( class(mpiunitcachetype this)
private

Definition at line 150 of file MpiUnitCache.f90.

151  class(MpiUnitCacheType) :: this
152  ! local
153  integer(I4B) :: i
154  integer :: mpi_type, ierr
155 
156  do i = 1, this%cached_messages%size
157  mpi_type = this%cached_messages%at(i)
158  if (mpi_type /= no_cached_value) then
159  call mpi_type_free(mpi_type, ierr)
160  call check_mpi(ierr)
161  end if
162  end do
163  call this%cached_messages%clear()
164 
Here is the call graph for this function:

◆ cc_destroy()

subroutine mpiunitcachemodule::cc_destroy ( class(mpiunitcachetype this)
private

Definition at line 169 of file MpiUnitCache.f90.

170  class(MpiUnitCacheType) :: this
171 
172  call this%cached_ranks%destroy()
173  call this%cached_messages%destroy()
174 

◆ cc_get_cached()

integer function mpiunitcachemodule::cc_get_cached ( class(mpiunitcachetype this,
integer(i4b)  rank,
integer(i4b)  stage,
integer(i4b)  msg_id 
)
private

Definition at line 50 of file MpiUnitCache.f90.

51  class(MpiUnitCacheType) :: this
52  integer(I4B) :: rank
53  integer(I4B) :: stage
54  integer(I4B) :: msg_id
55  integer :: mpi_type
56  ! local
57  integer(I4B) :: msg_idx
58 
59  mpi_type = no_cached_value
60  msg_idx = this%get_msg_index(rank, stage, msg_id)
61  if (msg_idx > 0) then
62  mpi_type = this%cached_messages%at(msg_idx)
63  end if
64 

◆ cc_init()

subroutine mpiunitcachemodule::cc_init ( class(mpiunitcachetype this,
integer(i4b)  nr_stages,
integer(i4b)  nr_msg_types 
)
Parameters
nr_stagesnumber of (simulation) stages
nr_msg_typesnumber of message types to be cached during a stage

Definition at line 36 of file MpiUnitCache.f90.

37  class(MpiUnitCacheType) :: this
38  integer(I4B) :: nr_stages !< number of (simulation) stages
39  integer(I4B) :: nr_msg_types !< number of message types to be cached during a stage
40 
41  this%nr_stages = nr_stages
42  this%nr_msg_types = nr_msg_types
43  call this%cached_ranks%init()
44  call this%cached_messages%init()
45 

◆ get_msg_index()

integer(i4b) function mpiunitcachemodule::get_msg_index ( class(mpiunitcachetype this,
integer(i4b)  rank,
integer(i4b)  stage,
integer(i4b)  msg_id 
)
private

Definition at line 128 of file MpiUnitCache.f90.

129  class(MpiUnitCacheType) :: this
130  integer(I4B) :: rank
131  integer(I4B) :: stage
132  integer(I4B) :: msg_id
133  integer(I4B) :: msg_index
134  ! local
135  integer(I4B) :: rank_idx
136  integer(I4B) :: rank_offset, stage_offset
137 
138  msg_index = -1
139  rank_idx = this%get_rank_index(rank)
140  if (rank_idx < 1) return
141 
142  rank_offset = (rank_idx - 1) * (this%nr_stages * this%nr_msg_types)
143  stage_offset = (stage - 1) * this%nr_msg_types
144  msg_index = rank_offset + stage_offset + msg_id
145 

◆ get_rank_index()

integer(i4b) function mpiunitcachemodule::get_rank_index ( class(mpiunitcachetype this,
integer(i4b)  rank 
)
private

Definition at line 117 of file MpiUnitCache.f90.

118  class(MpiUnitCacheType) :: this
119  integer(I4B) :: rank
120  integer(I4B) :: rank_index
121 
122  rank_index = this%cached_ranks%get_index(rank)
123 

◆ is_rank_cached()

logical(lgp) function mpiunitcachemodule::is_rank_cached ( class(mpiunitcachetype this,
integer(i4b)  rank 
)
private

Definition at line 91 of file MpiUnitCache.f90.

92  class(MpiUnitCacheType) :: this
93  integer(I4B) :: rank
94  logical(LGP) :: in_cache
95 
96  in_cache = this%cached_ranks%contains(rank)
97 

Variable Documentation

◆ no_cached_value

integer(i4b), parameter, public mpiunitcachemodule::no_cached_value = -1

Definition at line 11 of file MpiUnitCache.f90.

11  integer(I4B), public, parameter :: NO_CACHED_VALUE = -1