Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_buffer_loader_utilities.F90
Go to the documentation of this file.
1 
2 
4 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 #include "sll_memory.h"
6 #include "sll_working_precision.h"
7 
8  use sll_m_collective, only: &
12 
13  use sll_m_remapper, only: &
14  sll_o_get_layout_collective, &
15  sll_o_get_layout_i_max, &
16  sll_o_get_layout_i_min, &
17  sll_o_get_layout_j_max, &
18  sll_o_get_layout_j_min, &
19  sll_o_get_layout_k_max, &
20  sll_o_get_layout_k_min, &
21  sll_t_layout_2d, &
22  sll_t_layout_3d
23 
24  implicit none
25 
26  public :: &
34 
35  private
36 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37 
38 contains
39 
42  subroutine sll_s_compute_displacements_array_2d(layout, collective_size, disps)
43  type(sll_t_layout_2d), pointer :: layout
44  sll_int32, intent(in) :: collective_size
45  sll_int32, dimension(collective_size), intent(out) :: disps
46  sll_int32 :: imin, imax
47  sll_int32 :: jmin, jmax
48  sll_int32 :: size_i, size_j
49  !sll_int32 :: i,j
50  sll_int32 :: counter
51  sll_int32 :: rank
52 
53  counter = 0
54  disps(1) = counter
55  do rank = 1, collective_size - 1
56  imin = sll_o_get_layout_i_min(layout, rank - 1)
57  imax = sll_o_get_layout_i_max(layout, rank - 1)
58  jmin = sll_o_get_layout_j_min(layout, rank - 1)
59  jmax = sll_o_get_layout_j_max(layout, rank - 1)
60  size_i = imax - imin + 1
61  size_j = jmax - jmin + 1
62  counter = counter + size_i*size_j
63  disps(rank + 1) = counter
64  end do
66 
69  subroutine sll_s_load_buffer_2d(layout, data, buffer)
70  type(sll_t_layout_2d), pointer :: layout
71  sll_real64, dimension(:, :), intent(in) :: data
72  sll_real64, dimension(:), intent(out) :: buffer
73  sll_int32 :: myrank
74  sll_int32 :: data_size
75  !sll_int32 :: send_size
76  type(sll_t_collective_t), pointer :: col
77  sll_int32 :: imin, imax
78  sll_int32 :: jmin, jmax
79  sll_int32 :: size_i, size_j
80  sll_int32 :: i, j
81  sll_int32 :: counter
82 
83  col => sll_o_get_layout_collective(layout)
84  myrank = sll_f_get_collective_rank(col)
85  data_size = size(data, 1)*size(data, 2)
86 
87  imin = sll_o_get_layout_i_min(layout, myrank)
88  imax = sll_o_get_layout_i_max(layout, myrank)
89  jmin = sll_o_get_layout_j_min(layout, myrank)
90  jmax = sll_o_get_layout_j_max(layout, myrank)
91  size_i = imax - imin + 1
92  size_j = jmax - jmin + 1
93 
94  counter = 0
95  do j = 1, size_j
96  do i = 1, size_i
97  counter = counter + 1
98  buffer(counter) = data(i, j)
99  end do
100  end do
101 
102  end subroutine sll_s_load_buffer_2d
103 
104  subroutine sll_s_load_buffer32_2d(layout, data, buffer)
105  type(sll_t_layout_2d), pointer :: layout
106  sll_real32, dimension(:, :), intent(in) :: data
107  sll_real32, dimension(:), intent(out) :: buffer
108  sll_int32 :: myrank
109  sll_int32 :: data_size
110  !sll_int32 :: send_size
111  type(sll_t_collective_t), pointer :: col
112  sll_int32 :: imin, imax
113  sll_int32 :: jmin, jmax
114  sll_int32 :: size_i, size_j
115  sll_int32 :: i, j
116  sll_int32 :: counter
117 
118  col => sll_o_get_layout_collective(layout)
119  myrank = sll_f_get_collective_rank(col)
120  data_size = size(data, 1)*size(data, 2)
121 
122  imin = sll_o_get_layout_i_min(layout, myrank)
123  imax = sll_o_get_layout_i_max(layout, myrank)
124  jmin = sll_o_get_layout_j_min(layout, myrank)
125  jmax = sll_o_get_layout_j_max(layout, myrank)
126  size_i = imax - imin + 1
127  size_j = jmax - jmin + 1
128 
129  counter = 0
130  do j = 1, size_j
131  do i = 1, size_i
132  counter = counter + 1
133  buffer(counter) = data(i, j)
134  end do
135  end do
136 
137  end subroutine sll_s_load_buffer32_2d
138 
141  subroutine sll_s_load_buffer_3d(layout, data, buffer)
142  type(sll_t_layout_3d), pointer :: layout
143  sll_real64, dimension(:, :, :), intent(in) :: data
144  sll_real64, dimension(:), intent(out) :: buffer
145  sll_int32 :: myrank
146  sll_int32 :: data_size
147  !sll_int32 :: send_size
148  type(sll_t_collective_t), pointer :: col
149  sll_int32 :: imin, imax
150  sll_int32 :: jmin, jmax
151  sll_int32 :: kmin, kmax
152  sll_int32 :: size_i, size_j, size_k
153  sll_int32 :: i, j, k
154  sll_int32 :: counter
155 
156  col => sll_o_get_layout_collective(layout)
157  myrank = sll_f_get_collective_rank(col)
158  data_size = size(data, 1)*size(data, 2)*size(data, 3)
159  imin = sll_o_get_layout_i_min(layout, myrank)
160  imax = sll_o_get_layout_i_max(layout, myrank)
161  jmin = sll_o_get_layout_j_min(layout, myrank)
162  jmax = sll_o_get_layout_j_max(layout, myrank)
163  kmin = sll_o_get_layout_k_min(layout, myrank)
164  kmax = sll_o_get_layout_k_max(layout, myrank)
165  size_i = imax - imin + 1
166  size_j = jmax - jmin + 1
167  size_k = kmax - kmin + 1
168  counter = 0
169  do k = 1, size_k
170  do j = 1, size_j
171  do i = 1, size_i
172  counter = counter + 1
173  buffer(counter) = data(i, j, k)
174  end do
175  end do
176  end do
177  end subroutine sll_s_load_buffer_3d
178 
181  function sll_f_receive_counts_array_2d(layout, n) result(rc)
182  type(sll_t_layout_2d), pointer :: layout
183  sll_int32, intent(in) :: n
184  sll_int32, dimension(n) :: rc
185  sll_int32 :: i
186  sll_int32 :: imin, imax
187  sll_int32 :: jmin, jmax
188  sll_int32 :: size_i, size_j
189 
190  do i = 0, n - 1
191  imin = sll_o_get_layout_i_min(layout, i)
192  imax = sll_o_get_layout_i_max(layout, i)
193  jmin = sll_o_get_layout_j_min(layout, i)
194  jmax = sll_o_get_layout_j_max(layout, i)
195  size_i = imax - imin + 1
196  size_j = jmax - jmin + 1
197  rc(i + 1) = size_i*size_j
198  end do
199  end function sll_f_receive_counts_array_2d
200 
201  !this routine takes 1D array and stores it in a 2D array
202 
203  subroutine sll_s_unload_buffer_2d(layout, buffer, data)
204  type(sll_t_layout_2d), pointer :: layout
205  sll_real64, dimension(:, :), intent(out) :: data
206  sll_real64, dimension(:), intent(in) :: buffer
207  sll_int32 :: col_sz
208  type(sll_t_collective_t), pointer :: col
209  sll_int32 :: i, j
210  sll_int32 :: box
211  sll_int32 :: imin, imax
212  sll_int32 :: jmin, jmax
213  !sll_int32 :: size_i, size_j
214  sll_int32 :: pos ! position in buffer
215  col => sll_o_get_layout_collective(layout)
216  col_sz = sll_f_get_collective_size(col)
217 
218  ! loop over all the boxes in the layout and fill the data array by chunks.
219  pos = 1
220  do box = 0, col_sz - 1
221  imin = sll_o_get_layout_i_min(layout, box)
222  imax = sll_o_get_layout_i_max(layout, box)
223  jmin = sll_o_get_layout_j_min(layout, box)
224  jmax = sll_o_get_layout_j_max(layout, box)
225  ! this will fill the data array in whatever order that the boxes
226  ! are ordered.
227  do j = jmin, jmax
228  do i = imin, imax
229  data(i, j) = buffer(pos)
230  pos = pos + 1
231  end do
232  end do
233  end do
234  end subroutine sll_s_unload_buffer_2d
235 
238  subroutine sll_s_unload_buffer_3d(layout, buffer, data)
239  type(sll_t_layout_3d), pointer :: layout
240  sll_real64, dimension(:, :, :), intent(out) :: data
241  sll_real64, dimension(:), intent(in) :: buffer
242  sll_int32 :: col_sz
243  type(sll_t_collective_t), pointer :: col
244  sll_int32 :: i, j, k
245  sll_int32 :: imin, imax
246  sll_int32 :: jmin, jmax
247  sll_int32 :: kmin, kmax
248  sll_int32 :: size_i, size_j, size_k
249  sll_int32 :: pos ! position in buffer
250  sll_int32 :: myrank
251  col => sll_o_get_layout_collective(layout)
252  col_sz = sll_f_get_collective_size(col)
253  myrank = sll_f_get_collective_rank(col)
254  ! loop over all the boxes in the layout and fill the data array by chunks.
255  pos = 1
256  !do box=0,col_sz-1
257  imin = sll_o_get_layout_i_min(layout, myrank)
258  imax = sll_o_get_layout_i_max(layout, myrank)
259  jmin = sll_o_get_layout_j_min(layout, myrank)
260  jmax = sll_o_get_layout_j_max(layout, myrank)
261  kmin = sll_o_get_layout_k_min(layout, myrank)
262  kmax = sll_o_get_layout_k_max(layout, myrank)
263  size_i = imax - imin + 1
264  size_j = jmax - jmin + 1
265  size_k = kmax - kmin + 1
266  !print *,'kmin=',kmin,kmax
267  ! this will fill the data array in whatever order that the boxes
268  ! are ordered.
269  do k = 1, size_k !k=kmin,kmax
270  do j = 1, size_j !j=jmin,jmax
271  do i = 1, size_i !i=imin,imax
272  data(i, j, k) = buffer(pos)
273  pos = pos + 1
274  end do
275  end do
276  end do
277  !end do
278  end subroutine sll_s_unload_buffer_3d
279 
subroutine, public sll_s_load_buffer_2d(layout, data, buffer)
this subroutine loads 2D array into a 1D buffer for use in collective communications
subroutine, public sll_s_unload_buffer_3d(layout, buffer, data)
this routine takes 1D array and stores it in a 3D array warning definition changes are done wrt sll_s...
integer(kind=i32) function, dimension(n), public sll_f_receive_counts_array_2d(layout, n)
this function is also a helper for collective routines for example gatherv should be change into subr...
subroutine, public sll_s_load_buffer_3d(layout, data, buffer)
this subroutine loads 3D array into a 1D buffer for use in collective communications
subroutine, public sll_s_load_buffer32_2d(layout, data, buffer)
subroutine, public sll_s_compute_displacements_array_2d(layout, collective_size, disps)
the objective of this subroutine is to help to prepare data for gatherv operations for example
subroutine, public sll_s_unload_buffer_2d(layout, buffer, data)
Parallelizing facility.
integer(kind=i32) function, public sll_f_get_collective_rank(col)
Determines the rank of the calling process in the communicator.
integer(kind=i32) function, public sll_f_get_collective_size(col)
Determines the size of the group associated with a communicator.
Wrapper around the communicator.
    Report Typos and Errors