Octopus
par_vec.F90
Go to the documentation of this file.
1!! Copyright (C) 2005-2006 Florian Lorenzen, Heiko Appel, J. Alberdi-Rodriguez
2!! Copyright (C) 2021 Sebastian Ohlmann
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
78module par_vec_oct_m
79 use accel_oct_m
80 use debug_oct_m
81 use global_oct_m
82 use iihash_oct_m
83 use index_oct_m
84 use io_oct_m
86 use mpi_oct_m
89 use parser_oct_m
92 use sort_oct_m
93 use space_oct_m
95 use types_oct_m
96 use utils_oct_m
97
98 implicit none
99
100 private
101
102 public :: &
103 par_vec_t, &
104 par_vec_init, &
105 par_vec_end, &
111
116 !
117 type par_vec_t
118 ! Components are public by default
119
120 ! The content of these members is process-dependent.
121 integer :: rank
122 integer :: partno
123 integer, allocatable :: ghost_sendpos(:)
124
125 integer, allocatable :: ghost_rdispls(:)
126 integer, allocatable :: ghost_sdispls(:)
127 integer, allocatable :: ghost_rcounts(:)
128 integer, allocatable :: ghost_scounts(:)
129 integer :: ghost_scount
130 integer, allocatable :: ghost_sendmap(:)
131 integer, allocatable :: ghost_recvmap(:)
132 type(accel_mem_t) :: buff_sendmap
133 type(accel_mem_t) :: buff_recvmap
134
135 ! The following members are set independent of the processs.
136 type(mpi_grp_t) :: mpi_grp
137 integer :: npart
138 integer(int64) :: np_global
139
140 integer, allocatable :: np_local_vec(:)
142 integer :: np_local
144 integer(int64), allocatable, private :: xlocal_vec(:)
148 integer(int64) :: xlocal
151 integer(int64), allocatable, private :: local(:)
153 integer, allocatable :: recv_count(:)
154 integer, allocatable :: send_count(:)
156 integer, allocatable :: recv_disp(:)
157 integer, allocatable :: send_disp(:)
158 integer(int64), allocatable:: sendmap(:)
159 integer(int64), allocatable:: recvmap(:)
161 integer :: np_bndry
162
163 integer(int64), allocatable, private :: bndry(:)
164
165 type(lihash_t), private :: global
166
167 integer :: np_ghost
168 integer(int64), allocatable, private :: ghost(:)
169 end type par_vec_t
170
171 interface par_vec_scatter
172 module procedure dpar_vec_scatter
173 module procedure zpar_vec_scatter
174 module procedure ipar_vec_scatter
175 module procedure spar_vec_scatter
176 module procedure cpar_vec_scatter
177 end interface par_vec_scatter
178
179 interface par_vec_gather
180 module procedure dpar_vec_gather
181 module procedure zpar_vec_gather
182 module procedure ipar_vec_gather
183 module procedure spar_vec_gather
184 module procedure cpar_vec_gather
185 end interface par_vec_gather
186
187 interface par_vec_allgather
188 module procedure dpar_vec_allgather
189 module procedure zpar_vec_allgather
190 module procedure ipar_vec_allgather
191 module procedure spar_vec_allgather
192 module procedure cpar_vec_allgather
193 end interface par_vec_allgather
195contains
196
206 subroutine par_vec_init(mpi_grp, np_global, idx, stencil, space, partition, pv, namespace)
207 type(mpi_grp_t), intent(in) :: mpi_grp
208 ! The next seven entries come from the mesh.
209 integer(int64), intent(in) :: np_global
210 type(index_t), intent(in) :: idx
211 type(stencil_t), intent(in) :: stencil
212 class(space_t), intent(in) :: space
213 type(partition_t), intent(in) :: partition
214 type(par_vec_t), intent(inout) :: pv
215 type(namespace_t), intent(in) :: namespace
217 ! Careful: MPI counts process ranks from 0 to numproc-1.
218 ! Partition numbers from METIS range from 1 to numproc.
219 ! For this reason, all ranks are incremented by one.
220 integer :: npart
221 integer(int64) :: gip, index
222 integer :: ip, jp, jj, inode
223 integer :: p1(space%dim)
224 type(lihash_t) :: boundary
225 type(lihash_t) :: ghost
226 integer(int64), allocatable :: boundary_inv(:), ghost_inv(:)
227 integer :: iunit
228 character(len=6) :: filenum
229 logical :: found
231 integer :: idir, ipart, itmp
232 integer(int64) :: tmp
233 integer, allocatable :: points(:), part_ghost(:), part_ghost_tmp(:)
234 integer(int64), allocatable :: indices(:), ghost_tmp(:)
236 push_sub(par_vec_init)
238 ! Shortcuts.
239 npart = mpi_grp%size
241 ! Store partition number and rank for later reference.
242 ! Having both variables is a bit redundant but makes the code readable.
243 pv%rank = mpi_grp%rank
244 pv%partno = pv%rank + 1
245
246 call mpi_grp_copy(pv%mpi_grp, mpi_grp)
247 pv%np_global = np_global
248 pv%npart = npart
249
250
251 safe_allocate(pv%np_local_vec(1:npart))
252 safe_allocate(pv%xlocal_vec(1:npart))
253 safe_allocate(pv%ghost_rcounts(1:npart))
254 safe_allocate(pv%ghost_scounts(1:npart))
255
256 ! Count number of points for each process.
257 ! Local points.
258 call partition_get_np_local(partition, pv%np_local_vec)
259 pv%np_local = pv%np_local_vec(pv%partno)
260
261
262 ! Set up local-to-global index table for local points (xlocal_vec, local)
263 pv%xlocal_vec(1) = 1
264 ! Set the starting point of local and boundary points
265 do inode = 2, npart
266 pv%xlocal_vec(inode) = pv%xlocal_vec(inode - 1) + pv%np_local_vec(inode - 1)
267 end do
268 pv%xlocal = pv%xlocal_vec(pv%partno)
269
270 safe_allocate(pv%local(pv%xlocal:pv%xlocal + pv%np_local - 1))
271 ! Calculate the local vector in parallel
272 call partition_get_local(partition, pv%local(pv%xlocal:), itmp)
273
274 ! Create hash table.
275 call lihash_init(pv%global)
276 ! Insert local points.
277 do ip = 1, pv%np_local
278 call lihash_insert(pv%global, pv%local(pv%xlocal + ip - 1), ip)
279 end do
280
281 ! reorder points if needed
282 call reorder_points()
283
284 call lihash_init(boundary)
285 call lihash_init(ghost)
286 safe_allocate(boundary_inv(1:pv%np_local))
287 safe_allocate(ghost_inv(1:pv%np_local))
288 pv%np_ghost = 0
289 pv%np_bndry = 0
290 do gip = pv%xlocal, pv%xlocal + pv%np_local - 1
291 ! Get coordinates of current point.
292 call index_to_coords(idx, pv%local(gip), p1)
293 ! For all points in stencil.
294 do jj = 1, stencil%size
295 ! Get point number of possible ghost point.
296 index = index_from_coords(idx, p1(:) + stencil%points(:, jj))
297 if (index == 0) then
298 message(1) = "Internal error: a stencil neighbour of a local mesh point is not a mesh point."
299 message(2) = "The mesh has holes. The most likely cause is grid points on a box face being"
300 message(3) = "rejected by the box membership tolerance."
301 call messages_fatal(3, namespace=namespace)
302 end if
303 ! check if this point is a local point
304 tmp = lihash_lookup(pv%global, index, found)
305 if (found) cycle
306 ! now check if the point is a potential ghost or boundary point
307 if (index > np_global) then
308 tmp = lihash_lookup(boundary, index, found)
309 if (found) cycle
310 pv%np_bndry = pv%np_bndry + 1
311 call lihash_insert(boundary, index, pv%np_bndry)
312 if (pv%np_bndry >= ubound(boundary_inv, 1)) call make_array_larger(boundary_inv, pv%np_bndry*2)
313 boundary_inv(pv%np_bndry) = index
314 else
315 tmp = lihash_lookup(ghost, index, found)
316 if (found) cycle
317 pv%np_ghost = pv%np_ghost + 1
318 call lihash_insert(ghost, index, pv%np_ghost)
319 if (pv%np_ghost >= ubound(ghost_inv, 1)) call make_array_larger(ghost_inv, pv%np_ghost*2)
320 ghost_inv(pv%np_ghost) = index
321 end if
322 end do
323 end do
324
325 safe_allocate(pv%bndry(1:pv%np_bndry))
326 do ip = 1, pv%np_bndry
327 pv%bndry(ip) = boundary_inv(ip)
328 end do
329
330 ! first get the temporary array of ghost points, will be later reorder by partition
331 safe_allocate(ghost_tmp(1:pv%np_ghost))
332 do ip = 1, pv%np_ghost
333 ghost_tmp(ip) = ghost_inv(ip)
334 end do
335 call lihash_end(ghost)
336 call lihash_end(boundary)
337 safe_deallocate_a(ghost_inv)
338 safe_deallocate_a(boundary_inv)
339
340 safe_allocate(part_ghost_tmp(1:pv%np_ghost))
341 call partition_get_partition_number(partition, pv%np_ghost, &
342 ghost_tmp, part_ghost_tmp)
343
344 ! determine parallel distribution (counts, displacements)
345 pv%ghost_rcounts(:) = 0
346 do ip = 1, pv%np_ghost
347 ipart = part_ghost_tmp(ip)
348 pv%ghost_rcounts(ipart) = pv%ghost_rcounts(ipart)+1
349 end do
350 assert(sum(pv%ghost_rcounts) == pv%np_ghost)
351
352 safe_allocate(pv%ghost_rdispls(1:pv%npart))
353 pv%ghost_rdispls(1) = 0
354 do ipart = 2, pv%npart
355 pv%ghost_rdispls(ipart) = pv%ghost_rdispls(ipart - 1) + pv%ghost_rcounts(ipart - 1)
356 end do
357
358 ! reorder points by partition
359 safe_allocate(pv%ghost(1:pv%np_ghost))
360 safe_allocate(part_ghost(1:pv%np_ghost))
361 safe_allocate(points(1:pv%npart))
362 points = 0
363 do ip = 1, pv%np_ghost
364 ipart = part_ghost_tmp(ip)
365 points(ipart) = points(ipart)+1
366 ! jp is the new index, sorted according to partitions
367 jp = pv%ghost_rdispls(ipart) + points(ipart)
368 pv%ghost(jp) = ghost_tmp(ip)
369 part_ghost(jp) = part_ghost_tmp(ip)
370 end do
371 safe_deallocate_a(points)
372 safe_deallocate_a(ghost_tmp)
373 safe_deallocate_a(part_ghost_tmp)
374
375 call pv%mpi_grp%alltoall(pv%ghost_rcounts, 1, mpi_integer, &
376 pv%ghost_scounts, 1, mpi_integer)
377
378 safe_allocate(pv%ghost_sdispls(1:pv%npart))
379
380 pv%ghost_sdispls(1) = 0
381 do ipart = 2, pv%npart
382 pv%ghost_sdispls(ipart) = pv%ghost_sdispls(ipart - 1) + pv%ghost_scounts(ipart - 1)
383 end do
384 pv%ghost_scount = sum(pv%ghost_scounts)
385
386 safe_allocate(pv%ghost_recvmap(1:pv%np_ghost))
387 safe_allocate(points(1:pv%npart))
388 points = 0
389 do ip = 1, pv%np_ghost
390 ipart = part_ghost(ip)
391 points(ipart) = points(ipart) + 1
392 pv%ghost_recvmap(ip) = pv%ghost_rdispls(ipart) + points(ipart)
393 end do
394 safe_deallocate_a(points)
395
396 safe_allocate(indices(1:pv%np_ghost))
397 do ip = 1, pv%np_ghost
398 indices(pv%ghost_recvmap(ip)) = pv%ghost(ip)
399 end do
400 safe_allocate(pv%ghost_sendmap(1:pv%ghost_scount))
401 safe_allocate(ghost_tmp(1:pv%ghost_scount))
402 call pv%mpi_grp%alltoallv(indices, pv%ghost_rcounts, pv%ghost_rdispls, mpi_integer8, &
403 ghost_tmp, pv%ghost_scounts, pv%ghost_sdispls, mpi_integer8)
404 do ip = 1, pv%ghost_scount
405 ! get local index
406 jp = lihash_lookup(pv%global, ghost_tmp(ip), found)
407 assert(found)
408 pv%ghost_sendmap(ip) = jp
409 end do
410 safe_deallocate_a(indices)
411 safe_deallocate_a(ghost_tmp)
412
413 if (accel_is_enabled()) then
414 ! copy maps to GPU
415 call accel_create_buffer(pv%buff_sendmap, accel_mem_read_only, type_integer, pv%ghost_scount)
416 call accel_write_buffer(pv%buff_sendmap, pv%ghost_scount, pv%ghost_sendmap)
417
418 call accel_create_buffer(pv%buff_recvmap, accel_mem_read_only, type_integer, pv%np_ghost)
419 call accel_write_buffer(pv%buff_recvmap, pv%np_ghost, pv%ghost_recvmap)
420 end if
421
422 if (debug%info) then
423 ! Write numbers and coordinates of each process` ghost points
424 ! to a single file (like in mesh_partition_init) called
425 ! debug/mesh_partition/ghost_points.###.
426 call io_mkdir('debug/mesh_partition', namespace, parents=.true.)
427
428 write(filenum, '(i6.6)') pv%partno
429 iunit = io_open('debug/mesh_partition/ghost_points.'//filenum, namespace, action='write')
430 do ip = 1, pv%np_ghost
431 call index_to_coords(idx, pv%ghost(ip), p1)
432 write(iunit, '(99i8)') pv%ghost(ip), (p1(idir), idir = 1, space%dim)
433 end do
434
435 call io_close(iunit)
436 end if
437
438 call init_mpi_alltoall()
439
440 ! Insert ghost points.
441 do ip = 1, pv%np_ghost
442 call lihash_insert(pv%global, pv%ghost(ip), ip + pv%np_local)
443 end do
444 ! Insert boundary points.
445 do ip = 1, pv%np_bndry
446 call lihash_insert(pv%global, pv%bndry(ip), ip + pv%np_local + pv%np_ghost)
447 end do
448
449 safe_deallocate_a(part_ghost)
450
451 pop_sub(par_vec_init)
452
453 contains
454 subroutine reorder_points()
455 integer :: ip, nn, direction
456 integer(int64) :: ipg
457 integer :: bsize(space%dim), order, point(space%dim), number_of_blocks(space%dim)
458 integer(int64), allocatable :: reorder_indices(:)
459 integer(int64), allocatable :: reordered(:)
460 integer, allocatable :: global_indices(:)
461 type(block_t) :: blk
462 logical :: increase_with_dimension
463 integer, parameter :: &
464 order_blocks = 1, &
465 order_cube = 3, &
466 order_global = 4
467
469
470 !%Variable MeshLocalOrder
471 !%Default blocks
472 !%Type integer
473 !%Section Execution::Optimization
474 !%Description
475 !% This variable controls how the grid points are mapped to a
476 !% linear array. This influences the performance of the code.
477 !%Option order_blocks 1
478 !% The grid is mapped using small parallelepipedic grids. The size
479 !% of the blocks is controlled by <tt>MeshBlockSize</tt>.
480 !%Option order_cube 3
481 !% The grid is mapped using a full cube, i.e. without blocking.
482 !%Option order_global 4
483 !% Use the ordering from the global mesh
484 !%End
485 call parse_variable(namespace, 'MeshLocalOrder', order_blocks, order)
486 ! no reordering in 1D necessary
487 if (space%dim == 1) then
488 order = order_global
489 end if
490
491 !%Variable MeshLocalBlockDirection
492 !%Type integer
493 !%Section Execution::Optimization
494 !%Description
495 !% Determines the direction in which the dimensions are chosen to compute
496 !% the blocked index for sorting the mesh points (see MeshLocalBlockSize).
497 !% The default is increase_with_dimensions, corresponding to xyz ordering
498 !% in 3D.
499 !%Option increase_with_dimension 1
500 !% The fastest changing index is in the first dimension, i.e., in 3D this
501 !% corresponds to ordering in xyz directions.
502 !%Option decrease_with_dimension 2
503 !% The fastest changing index is in the last dimension, i.e., in 3D this
504 !% corresponds to ordering in zyx directions.
505 !%End
506 call parse_variable(namespace, 'MeshLocalBlockDirection', 1, direction)
507 increase_with_dimension = direction == 1
508 if (direction /= 1 .and. direction /= 2) then
509 call messages_input_error(namespace, 'MeshLocalBlockDirection')
510 end if
511
512 select case (order)
513 case (order_global)
514 ! nothing to do, points are ordered along the global distribution by default
515 case (order_blocks, order_cube)
516 if (order == order_cube) then
517 bsize(1:space%dim) = idx%nr(2, 1:space%dim) - idx%nr(1, 1:space%dim) + 1
518 else
519 !%Variable MeshLocalBlockSize
520 !%Type block
521 !%Section Execution::Optimization
522 !%Description
523 !% To improve memory-access locality when calculating derivatives,
524 !% <tt>Octopus</tt> arranges mesh points in blocks. This variable
525 !% controls the size of this blocks in the different
526 !% directions. The default is selected according to the value of
527 !% the <tt>StatesBlockSize</tt> variable. (This variable only affects the
528 !% performance of <tt>Octopus</tt> and not the results.)
529 !%End
530 if (conf%target_states_block_size < 16) then
531 bsize(1) = 80 * 4 / abs(conf%target_states_block_size)
532 if (space%dim > 1) bsize(2) = 4
533 if (space%dim > 2) bsize(3:) = 10
534 else
535 bsize(1) = max(4 * 16 / abs(conf%target_states_block_size), 1)
536 if (space%dim > 1) bsize(2) = 15
537 if (space%dim > 2) bsize(3:) = 15
538 end if
539
540 if (parse_block(namespace, 'MeshLocalBlockSize', blk) == 0) then
541 nn = parse_block_cols(blk, 0)
542 if (nn /= space%dim) then
543 message(1) = "Error: number of entries in MeshLocalBlockSize must match the umber of dimensions."
544 call messages_fatal(1, namespace=namespace)
545 end if
546 do idir = 1, nn
547 call parse_block_integer(blk, 0, idir - 1, bsize(idir))
548 end do
549 end if
550 end if
551
552 number_of_blocks(1:space%dim) = idx%ll(1:space%dim)/bsize(1:space%dim) + 1
553
554 ! compute new indices locally
555 safe_allocate(reorder_indices(1:pv%np_local))
556 safe_allocate(global_indices(1:pv%np_local))
557 do ip = 1, pv%np_local
558 ipg = pv%local(ip + pv%xlocal - 1)
559 call index_spatial_to_point(idx, space%dim, idx%grid_to_spatial_global(ipg), point)
560 point = point + idx%offset + idx%enlarge
561 reorder_indices(ip) = get_blocked_index(space%dim, point, bsize, number_of_blocks, increase_with_dimension)
562 end do
563 ! sort the local array
564 call sort(reorder_indices, global_indices)
565 safe_deallocate_a(reorder_indices)
566
567 ! reorder according to new order
568 safe_allocate(reordered(1:pv%np_local))
569 do ip = 1, pv%np_local
570 reordered(ip) = pv%local(global_indices(ip) + pv%xlocal - 1)
571 end do
572 safe_deallocate_a(global_indices)
573
574 ! assign the reordered points
575 do ip = 1, pv%np_local
576 pv%local(ip + pv%xlocal - 1) = reordered(ip)
577 end do
578 safe_deallocate_a(reordered)
579
580 ! Recreate hash table.
581 call lihash_end(pv%global)
582 call lihash_init(pv%global)
583 ! Insert local points.
584 do ip = 1, pv%np_local
585 call lihash_insert(pv%global, pv%local(pv%xlocal + ip - 1), ip)
586 end do
587 end select
588
590 end subroutine reorder_points
591
592 subroutine init_mpi_alltoall()
593 integer, allocatable :: part_local(:)
594
596
597 safe_allocate(part_local(1:pv%np_local))
598 safe_allocate(indices(1:pv%np_local))
599 do ip = 1, pv%np_local
600 indices(ip) = pv%xlocal + ip - 1
601 end do
602 call partition_get_partition_number(partition, pv%np_local, &
603 indices, part_local)
604 safe_deallocate_a(indices)
605
606 safe_allocate(pv%send_count(1:npart))
607 safe_allocate(pv%recv_count(1:npart))
608 safe_allocate(pv%send_disp(1:npart))
609 safe_allocate(pv%recv_disp(1:npart))
610
611 pv%send_count = 0
612 do ip = 1, pv%np_local
613 ipart = part_local(ip)
614 pv%send_count(ipart) = pv%send_count(ipart) + 1
615 end do
616 pv%send_disp(1) = 0
617 do ipart = 2, npart
618 pv%send_disp(ipart) = pv%send_disp(ipart - 1) + pv%send_count(ipart - 1)
619 end do
620
621 call pv%mpi_grp%alltoall(pv%send_count, 1, mpi_integer, &
622 pv%recv_count, 1, mpi_integer)
623
624 pv%recv_disp(1) = 0
625 do ipart = 2, npart
626 pv%recv_disp(ipart) = pv%recv_disp(ipart - 1) + pv%recv_count(ipart - 1)
627 end do
628
629 ! create maps
630 safe_allocate(pv%sendmap(1:pv%np_local))
631 safe_allocate(points(1:pv%npart))
632 points = 0
633 do ip = 1, pv%np_local
634 ipart = part_local(ip)
635 points(ipart) = points(ipart) + 1
636 pv%sendmap(ip) = pv%send_disp(ipart) + points(ipart)
637 end do
638 safe_deallocate_a(points)
639
640 safe_allocate(indices(1:pv%np_local))
641 do ip = 1, pv%np_local
642 indices(pv%sendmap(ip)) = pv%xlocal + ip - 1
643 end do
644 safe_allocate(pv%recvmap(1:sum(pv%recv_count)))
645 call pv%mpi_grp%alltoallv(indices, pv%send_count, pv%send_disp, mpi_integer8, &
646 pv%recvmap, pv%recv_count, pv%recv_disp, mpi_integer8)
647 do ip = 1, sum(pv%recv_count)
648 ! get local index
649 index = lihash_lookup(pv%global, pv%recvmap(ip), found)
650 assert(found)
651 pv%recvmap(ip) = index
652 end do
653 safe_deallocate_a(indices)
654
656 end subroutine init_mpi_alltoall
657 end subroutine par_vec_init
658
659 ! ---------------------------------------------------------
661 subroutine par_vec_end(pv)
662 type(par_vec_t), intent(inout) :: pv
663
664 push_sub(par_vec_end)
665
666 safe_deallocate_a(pv%ghost_rdispls)
667 safe_deallocate_a(pv%ghost_sdispls)
668 safe_deallocate_a(pv%ghost_rcounts)
669 safe_deallocate_a(pv%ghost_scounts)
670 safe_deallocate_a(pv%ghost_sendpos)
671 safe_deallocate_a(pv%ghost_recvmap)
672 safe_deallocate_a(pv%ghost_sendmap)
673 safe_deallocate_a(pv%send_disp)
674 safe_deallocate_a(pv%recv_disp)
675 safe_deallocate_a(pv%np_local_vec)
676 safe_deallocate_a(pv%xlocal_vec)
677 safe_deallocate_a(pv%local)
678 safe_deallocate_a(pv%send_count)
679 safe_deallocate_a(pv%recv_count)
680 safe_deallocate_a(pv%sendmap)
681 safe_deallocate_a(pv%recvmap)
682 safe_deallocate_a(pv%bndry)
683 safe_deallocate_a(pv%ghost)
684
685 call lihash_end(pv%global)
686
687 if (accel_is_enabled()) then
688 call accel_free_buffer(pv%buff_recvmap)
689 call accel_free_buffer(pv%buff_sendmap)
690 end if
691
692 pop_sub(par_vec_end)
693 end subroutine par_vec_end
694
695
696 ! ---------------------------------------------------------
699 integer function par_vec_global2local(pv, ipg) result(ip)
700 type(par_vec_t), intent(in) :: pv
701 integer(int64), intent(in) :: ipg
702
703 integer :: nn
704 logical :: found
705
706! no push_sub because called too frequently
707
708 if (pv%npart > 1) then
709 ip = 0
710 nn = lihash_lookup(pv%global, ipg, found)
711 if (found) ip = nn
712 else
713 assert(ipg < huge(ip))
714 ip = int(ipg, int32)
715 end if
716 end function par_vec_global2local
717
718 ! ---------------------------------------------------------
720 integer(int64) function par_vec_local2global(pv, ip) result(ipg)
721 type(par_vec_t), intent(in) :: pv
722 integer, intent(in) :: ip
723
724! no push_sub because called too frequently
725
726 if (pv%npart == 1) then
727 ipg = ip
728 else
729 if (ip <= pv%np_local) then
730 ipg = pv%local(pv%xlocal + ip - 1)
731 else if (ip <= pv%np_local + pv%np_ghost) then
732 ipg = pv%ghost(ip - pv%np_local)
733 else if (ip <= pv%np_local + pv%np_ghost + pv%np_bndry) then
734 ipg = pv%bndry(ip - pv%np_local - pv%np_ghost)
735 else
736 ipg = 0_int64
737 end if
738 end if
739 end function par_vec_local2global
740
741 ! gather all local arrays into a global one on rank root
742 ! this gives the global mapping of the index in the partition to the global index
743 subroutine gather_local_vec(pv, root, local_vec)
744 type(par_vec_t), intent(in) :: pv
745 integer, intent(in) :: root
746 integer(int64), allocatable, intent(inout) :: local_vec(:)
747
748 integer(int64), allocatable :: xlocal_tmp(:)
749
750 push_sub(gather_local_vec)
751
752 safe_allocate(xlocal_tmp(1:pv%npart))
753 xlocal_tmp(:) = pv%xlocal_vec(:) - 1
754 ! Gather all the local vectors in a unique big one
755 call pv%mpi_grp%gatherv(pv%local(pv%xlocal:), pv%np_local, mpi_integer8, &
756 local_vec, pv%np_local_vec, xlocal_tmp, mpi_integer8, root)
757 safe_deallocate_a(xlocal_tmp)
758
759 pop_sub(gather_local_vec)
760 end subroutine gather_local_vec
761
762#include "undef.F90"
763#include "complex.F90"
764#include "par_vec_inc.F90"
765
766#include "undef.F90"
767#include "real.F90"
768#include "par_vec_inc.F90"
769
770#include "undef.F90"
771#include "integer.F90"
772#include "par_vec_inc.F90"
773
774#include "undef.F90"
775#include "real32.F90"
776#include "par_vec_inc.F90"
777
778#include "undef.F90"
779#include "complex32.F90"
780#include "par_vec_inc.F90"
781
782end module par_vec_oct_m
783
784!! Local Variables:
785!! mode: f90
786!! coding: utf-8
787!! End:
This is the common interface to a sorting routine. It performs the shell algorithm,...
Definition: sort.F90:133
subroutine, public accel_free_buffer(this, async)
Definition: accel.F90:967
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
integer, parameter, public accel_mem_read_only
Definition: accel.F90:162
type(debug_t), save, public debug
Definition: debug.F90:133
type(conf_t), public conf
Global instance of Octopus configuration.
Definition: global.F90:163
This module implements a simple hash table for non-negative integer keys and integer values.
Definition: iihash.F90:104
integer function, public lihash_lookup(h, key, found)
Look up a value in the hash table h. If found is present, it indicates if key could be found in the t...
Definition: iihash.F90:313
subroutine, public lihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: iihash.F90:287
subroutine, public lihash_end(h)
Free a hash table.
Definition: iihash.F90:265
subroutine, public lihash_init(h)
Initialize a hash table h.
Definition: iihash.F90:242
This module implements the index, used for the mesh points.
Definition: index.F90:101
integer(int64) function, public get_blocked_index(dim, point, bsize, number_of_blocks, increase_with_dimensions)
Definition: index.F90:476
subroutine, public index_spatial_to_point(idx, dim, ispatial, point)
Definition: index.F90:377
subroutine, public index_to_coords(idx, ip, ix)
Given a global point index, this function returns the set of integer coordinates of the point.
Definition: index.F90:276
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...
Definition: index.F90:235
Definition: io.F90:93
subroutine, public io_close(iunit, grp)
Definition: io.F90:444
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:338
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:379
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine mpi_grp_copy(mpi_grp_out, mpi_grp_in)
MPI_THREAD_FUNNELED allows for calls to MPI from an OMP region if the thread is the team master.
Definition: mpi.F90:428
Some general things and nomenclature:
Definition: par_vec.F90:150
subroutine cpar_vec_scatter(pv, root, v_local, v)
Generally: Xpar_vec_gather and Xpar_vec_scatter only consider inner points. Xpar_vec_scatter_bndry ta...
Definition: par_vec.F90:1837
subroutine, public par_vec_end(pv)
Deallocate memory used by pv.
Definition: par_vec.F90:734
integer function, public par_vec_global2local(pv, ipg)
Returns local number of global point ip on the local node If the result is zero, the point is not ava...
Definition: par_vec.F90:772
subroutine ipar_vec_scatter(pv, root, v_local, v)
Generally: Xpar_vec_gather and Xpar_vec_scatter only consider inner points. Xpar_vec_scatter_bndry ta...
Definition: par_vec.F90:1371
subroutine dpar_vec_allgather(pv, v, v_local)
Like Xpar_vec_gather but the result is gathered on all nodes, i. e. v has to be a properly allocated ...
Definition: par_vec.F90:1268
subroutine zpar_vec_scatter(pv, root, v_local, v)
Generally: Xpar_vec_gather and Xpar_vec_scatter only consider inner points. Xpar_vec_scatter_bndry ta...
Definition: par_vec.F90:913
subroutine dpar_vec_scatter(pv, root, v_local, v)
Generally: Xpar_vec_gather and Xpar_vec_scatter only consider inner points. Xpar_vec_scatter_bndry ta...
Definition: par_vec.F90:1142
integer(int64) function, public par_vec_local2global(pv, ip)
Returns global index of local point ip.
Definition: par_vec.F90:793
subroutine, public par_vec_init(mpi_grp, np_global, idx, stencil, space, partition, pv, namespace)
Initializes a par_vec_type object (parallel vector).
Definition: par_vec.F90:279
subroutine spar_vec_gather(pv, root, v_local, v)
Reverse operation of Xpar_vec_scatter. All v_locals from the nodes are packed together into v on node...
Definition: par_vec.F90:1667
subroutine ipar_vec_gather(pv, root, v_local, v)
Reverse operation of Xpar_vec_scatter. All v_locals from the nodes are packed together into v on node...
Definition: par_vec.F90:1434
subroutine zpar_vec_gather(pv, root, v_local, v)
Reverse operation of Xpar_vec_scatter. All v_locals from the nodes are packed together into v on node...
Definition: par_vec.F90:976
subroutine spar_vec_allgather(pv, v, v_local)
Like Xpar_vec_gather but the result is gathered on all nodes, i. e. v has to be a properly allocated ...
Definition: par_vec.F90:1730
subroutine gather_local_vec(pv, root, local_vec)
Definition: par_vec.F90:816
subroutine cpar_vec_gather(pv, root, v_local, v)
Reverse operation of Xpar_vec_scatter. All v_locals from the nodes are packed together into v on node...
Definition: par_vec.F90:1900
subroutine dpar_vec_gather(pv, root, v_local, v)
Reverse operation of Xpar_vec_scatter. All v_locals from the nodes are packed together into v on node...
Definition: par_vec.F90:1205
subroutine cpar_vec_allgather(pv, v, v_local)
Like Xpar_vec_gather but the result is gathered on all nodes, i. e. v has to be a properly allocated ...
Definition: par_vec.F90:1963
subroutine zpar_vec_allgather(pv, v, v_local)
Like Xpar_vec_gather but the result is gathered on all nodes, i. e. v has to be a properly allocated ...
Definition: par_vec.F90:1039
subroutine spar_vec_scatter(pv, root, v_local, v)
Generally: Xpar_vec_gather and Xpar_vec_scatter only consider inner points. Xpar_vec_scatter_bndry ta...
Definition: par_vec.F90:1604
subroutine ipar_vec_allgather(pv, v, v_local)
Like Xpar_vec_gather but the result is gathered on all nodes, i. e. v has to be a properly allocated ...
Definition: par_vec.F90:1497
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:600
subroutine, public partition_get_np_local(partition, np_local_vec)
Given the partition, returns the corresponding number of local points that each partition has.
Definition: partition.F90:541
subroutine, public partition_get_local(partition, rbuffer, np_local)
Calculates the local vector of all partitions in parallel. Local vector stores the global point indic...
Definition: partition.F90:601
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
This module is intended to contain "only mathematical" functions and procedures.
Definition: sort.F90:96
This module defines stencils used in Octopus.
Definition: stencil.F90:114
type(type_t), parameter, public type_integer
Definition: types.F90:115
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:99
subroutine, public make_array_larger(array, new_size)
Definition: utils.F90:658
subroutine init_mpi_alltoall()
Definition: par_vec.F90:665
subroutine reorder_points()
Definition: par_vec.F90:527
This is defined even when running serial.
Definition: mpi.F90:121
Parallel information.
Definition: par_vec.F90:189
The partition is an array that contains the mapping between some global index and a process,...
Definition: partition.F90:144
The class representing the stencil, which is used for non-local mesh operations.
Definition: stencil.F90:142
int true(void)