60 integer,
allocatable :: nr(:,:)
61 integer,
allocatable :: ll(:)
62 integer,
allocatable :: enlarge(:)
63 integer(int64) :: checksum
64 integer(int64),
pointer :: grid_to_spatial_global(:)
65 integer(int64),
pointer :: spatial_to_grid_global(:)
68 integer,
allocatable :: offset(:)
69 integer,
allocatable :: stride(:)
70 type(MPI_Win) :: window_grid_to_spatial
71 type(MPI_Win) :: window_spatial_to_grid
74 integer,
parameter,
public :: &
81 use,
intrinsic :: iso_fortran_env
84 integer,
intent(in) :: dim
85 integer,
intent(in) :: nbits
86 integer(int64),
intent(in) :: index
87 integer,
intent(out) :: point(*)
91 use,
intrinsic :: iso_fortran_env
94 integer,
intent(in) :: dim
95 integer,
intent(in) :: nbits
96 integer(int64),
intent(out) :: index
97 integer,
intent(in) :: point(*)
101 use,
intrinsic :: iso_fortran_env
104 integer,
intent(in) :: dim
105 integer,
intent(in) :: nbits
106 integer(int32),
intent(in) :: index
107 integer,
intent(out) :: point(*)
111 use,
intrinsic :: iso_fortran_env
114 integer,
intent(in) :: dim
115 integer,
intent(in) :: nbits
116 integer(int32),
intent(out) :: index
117 integer,
intent(in) :: point(*)
125 type(index_t),
intent(inout) :: idx
126 integer,
intent(in) :: dim
130 safe_allocate(idx%nr(1:2, 1:dim))
131 safe_allocate(idx%ll(1:dim))
132 safe_allocate(idx%enlarge(1:dim))
133 safe_allocate(idx%offset(1:dim))
134 safe_allocate(idx%stride(1:dim+1))
144 type(index_t),
intent(inout) :: idx
148 safe_deallocate_a(idx%nr)
149 safe_deallocate_a(idx%ll)
150 safe_deallocate_a(idx%enlarge)
151 safe_deallocate_a(idx%offset)
152 safe_deallocate_a(idx%stride)
164 integer,
intent(in) :: ix(1:idx%dim)
166 integer(int64) :: ispatial
170 if (ispatial < 0 .or. ispatial > ubound(idx%spatial_to_grid_global, dim=1, kind=int64))
then
173 index = idx%spatial_to_grid_global(ispatial)
180 type(
index_t),
intent(in) :: idx
181 integer,
intent(in) :: npoints
182 integer,
intent(in) :: ix(1:idx%dim, 1:npoints)
183 integer(int64),
intent(out) :: index(1:npoints)
186 integer(int64) :: ispatial
191 if (ispatial < 0 .or. ispatial > ubound(idx%spatial_to_grid_global, dim=1, kind=int64))
then
194 index(ip) = idx%spatial_to_grid_global(ispatial)
204 type(
index_t),
intent(in) :: idx
205 integer(int64),
intent(in) :: ip
206 integer,
intent(out) :: ix(:)
215 subroutine index_dump(idx, np, dir, mpi_grp, namespace, ierr)
216 type(
index_t),
intent(in) :: idx
217 integer(int64),
intent(in) :: np
218 character(len=*),
intent(in) :: dir
221 integer,
intent(out) :: ierr
231 assert(
associated(idx%grid_to_spatial_global))
233 idx%grid_to_spatial_global, err)
236 message(1) =
"Unable to write index function to '"//trim(dir)//
"/indices.obf'."
241 call mpi_grp%bcast(ierr, 1, mpi_integer, 0)
249 subroutine index_load(idx, np, dir, mpi_grp, namespace, ierr)
250 type(
index_t),
intent(inout) :: idx
251 integer(int64),
intent(in) :: np
252 character(len=*),
intent(in) :: dir
255 integer,
intent(out) :: ierr
258 integer(int64) :: ip, global_size
265 assert(
associated(idx%grid_to_spatial_global))
269 inquire(file=trim(trim(
io_workpath(dir, namespace))//
"/lxyz.obf"), exist=exists)
271 message(1) =
"Found lxyz.obf file. This means you created the restart files with an old version of the code."
272 message(2) =
"Please generate the restart files again with the current version of the code"
273 message(3) =
"because the internal format has changed."
278 idx%grid_to_spatial_global, err)
281 message(1) =
"Unable to read index function from '"//trim(dir)//
"/indices.obf'."
287 call mpi_grp%bcast(ierr, 1, mpi_integer, 0)
289 call mpi_grp%bcast(idx%grid_to_spatial_global(1), np, mpi_integer8, 0)
293 global_size = product(idx%nr(2, :) - idx%nr(1, :) + 1)
294 safe_allocate(idx%spatial_to_grid_global(0:global_size))
296 assert(np <= huge(0_int32))
298 idx%spatial_to_grid_global(idx%grid_to_spatial_global(ip)) =
i8_to_i4(ip)
305 type(
index_t),
intent(in) :: idx
306 integer,
intent(in) :: dim
307 integer(int64),
intent(in) :: ispatial
308 integer,
intent(out) :: point(1:dim)
311 select case (idx%type)
317 message(1) =
"Unknown index type."
323 type(
index_t),
intent(in) :: idx
324 integer,
intent(in) :: dim
325 integer(int64),
intent(out) :: ispatial
326 integer,
intent(in) :: point(1:dim)
329 select case (idx%type)
335 message(1) =
"Unknown index type."
341 type(
index_t),
intent(in) :: idx
342 integer,
intent(in) :: dim
343 integer(int64),
intent(in) :: icubic
344 integer,
intent(out) :: point(1:dim)
347 integer(int64) :: tmp
352 point(ii) = int(tmp/idx%stride(ii) - idx%offset(ii), int32)
353 tmp = mod(tmp, idx%stride(ii))
355 point(1) = int(tmp - idx%offset(1), int32)
359 type(
index_t),
intent(in) :: idx
360 integer,
intent(in) :: dim
361 integer(int64),
intent(out) :: icubic
362 integer,
intent(in) :: point(1:dim)
369 if (point(ii) < idx%nr(1, ii) .or. point(ii) > idx%nr(2, ii))
then
373 icubic = icubic + int(point(ii)+idx%offset(ii), int64) * idx%stride(ii)
378 type(
index_t),
intent(in) :: idx
379 integer,
intent(in) :: dim
380 integer(int64),
intent(in) :: ihilbert
381 integer,
intent(out) :: point(:)
385 point(1:dim) = point(1:dim) - idx%offset(1:dim)
389 type(
index_t),
intent(in) :: idx
390 integer,
intent(in) :: dim
391 integer(int64),
intent(out) :: ihilbert
392 integer,
intent(in) :: point(1:dim)
394 integer :: point_copy(1:dim)
397 point_copy(1:dim) = point(1:dim) + idx%offset(1:dim)
403 integer(int64) function get_blocked_index(dim, point, bsize, number_of_blocks, increase_with_dimensions)
404 integer,
intent(in) :: dim
405 integer,
intent(in) :: point(1:dim)
406 integer,
intent(in) :: bsize(1:dim)
407 integer,
intent(in) :: number_of_blocks(1:dim)
408 logical,
optional,
intent(in) :: increase_with_dimensions
409 integer(int64) :: idim, j_local, j_block, stride_local, stride_block
410 integer :: start, stop, step
431 do idim = start, stop, step
432 j_local = j_local + mod(point(idim), bsize(idim)) * stride_local
433 stride_local = stride_local * bsize(idim)
434 j_block = j_block + point(idim) / bsize(idim) * stride_block
435 stride_block = stride_block * number_of_blocks(idim)
This module implements a simple hash table for non-negative integer keys and integer values.
This module implements the index, used for the mesh points.
subroutine, public index_load(idx, np, dir, mpi_grp, namespace, ierr)
Load the index arrays from a file.
subroutine index_hilbert_to_point(idx, dim, ihilbert, point)
subroutine, public index_end(idx)
This subroutine deallocates all memory.
pure subroutine index_cubic_to_point(idx, dim, icubic, point)
subroutine, public index_from_coords_vec(idx, npoints, ix, index)
subroutine, public index_init(idx, dim)
This subroutine allocates memory and initializes some components.
integer(int64) function, public get_blocked_index(dim, point, bsize, number_of_blocks, increase_with_dimensions)
subroutine, public index_spatial_to_point(idx, dim, ispatial, point)
subroutine, public index_to_coords(idx, ip, ix)
Given a global point index, this function returns the set of integer coordinates of the point.
integer, parameter, public idx_hilbert
subroutine, public index_dump(idx, np, dir, mpi_grp, namespace, ierr)
subroutine, public index_point_to_spatial(idx, dim, ispatial, point)
subroutine index_point_to_hilbert(idx, dim, ihilbert, point)
integer(int64) function, public index_from_coords(idx, ix)
This function takes care of the boundary conditions for a given vector of integer coordinates it retu...
pure subroutine index_point_to_cubic(idx, dim, icubic, point)
character(len=max_path_len) function, public io_workpath(path, namespace)
subroutine, public messages_warning(no_lines, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
This is defined even when running serial.