MODFLOW 6  version 6.6.0.dev0
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 mc_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_destroy (this)
 Clean up the 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 98 of file MpiUnitCache.f90.

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

◆ cc_destroy()

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

Definition at line 148 of file MpiUnitCache.f90.

149  class(MpiUnitCacheType) :: this
150  ! local
151  integer(I4B) :: i
152  integer :: mpi_type, ierr
153 
154  do i = 1, this%cached_messages%size
155  mpi_type = this%cached_messages%at(i)
156  if (mpi_type /= no_cached_value) then
157  call mpi_type_free(mpi_type, ierr)
158  end if
159  end do
160 
161  call this%cached_ranks%destroy()
162  call this%cached_messages%destroy()
163 

◆ 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 48 of file MpiUnitCache.f90.

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

◆ 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 34 of file MpiUnitCache.f90.

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

◆ 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 126 of file MpiUnitCache.f90.

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

◆ get_rank_index()

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

Definition at line 115 of file MpiUnitCache.f90.

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

◆ is_rank_cached()

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

Definition at line 89 of file MpiUnitCache.f90.

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

◆ mc_cache()

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

Definition at line 68 of file MpiUnitCache.f90.

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

Variable Documentation

◆ no_cached_value

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

Definition at line 10 of file MpiUnitCache.f90.

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