Octopus
cube.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2011 M. Marques, A. Castro, A. Rubio,
2!! G. Bertsch, M. Oliveira, J. Alberdi-Rodriguez
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
22module cube_oct_m
23 use accel_oct_m
26 use debug_oct_m
27 use fft_oct_m
28 use global_oct_m
29 use io_oct_m
30 use, intrinsic :: iso_fortran_env
33 use mesh_oct_m
35 use mpi_oct_m
37 use parser_oct_m
38 use pfft_oct_m
40 use space_oct_m
41
42 implicit none
43 private
44 public :: &
45 cube_t, &
47 cube_init, &
54
55 type cube_t
56 ! Components are public by default
57 logical :: parallel_in_domains
58 type(mpi_grp_t) :: mpi_grp
59
60 integer :: rs_n_global(1:3)
61 integer :: fs_n_global(1:3)
62 integer :: rs_n(1:3)
63 integer :: fs_n(1:3)
64 integer :: rs_istart(1:3)
65 integer :: fs_istart(1:3)
66 integer :: center(1:3)
67
68 integer, allocatable :: fs_ifx(:)
69 integer, allocatable :: fs_ify(:)
70 integer, allocatable :: fs_ifz(:)
71
72 real(real64), allocatable :: Lrs(:,:)
73 real(real64), allocatable :: Lfs(:,:)
74
75 integer, allocatable :: np_local(:)
76 integer, allocatable :: xlocal(:)
77 integer, allocatable :: local(:,:)
78 integer, allocatable :: np_local_fs(:)
79 integer, allocatable :: xlocal_fs(:)
80 integer, allocatable :: local_fs(:,:)
81
82
83 type(fft_t), allocatable :: fft
84 logical, private :: has_cube_mapping = .false.
86
87 real(real64) :: spacing(3)
88 ! latt is declared as allocatable as a work-around for a bug in gfortran when invoking the finalizer of latt.
89 type(lattice_vectors_t), allocatable :: latt
90
91 type(mesh_cube_map_t) :: cube_map
92 logical :: cube_map_present = .false.
93 integer :: batch_capacity
94 end type cube_t
95
101 type dimensions_t
102 integer :: start_xyz(1:3)
103 integer :: end_xyz(1:3)
104 end type dimensions_t
105
106contains
107
108 ! ---------------------------------------------------------
109 subroutine cube_init(cube, nn, namespace, space, spacing, coord_system, fft_type, fft_library, dont_optimize, nn_out, &
110 mpi_grp, need_partition, tp_enlarge, blocksize, batch_size)
111 type(cube_t), intent(out) :: cube
112 integer, intent(in) :: nn(:)
113 type(namespace_t), intent(in) :: namespace
114 class(space_t), intent(in) :: space
115 real(real64), intent(in) :: spacing(:)
116 class(coordinate_system_t), intent(in) :: coord_system
117 integer, optional, intent(in) :: fft_type
118 integer, optional, intent(in) :: fft_library
119 logical, optional, intent(in) :: dont_optimize
120 integer, optional, intent(out) :: nn_out(3)
122 type(mpi_grp_t), optional, intent(in) :: mpi_grp
123 logical, optional, intent(in) :: need_partition
124 real(real64), optional, intent(in) :: tp_enlarge(3)
127 integer, optional, intent(in) :: blocksize
129 integer, optional, intent(in) :: batch_size
130 ! the batch size for the FFTW and cuFFT solvers
131
132 type(MPI_Comm) :: comm
133 integer :: tmp_n(3), fft_type_, optimize_parity(3), fft_library_, nn3d(3)
134 integer :: effdim_fft, my_n(3), idir, idir2
135 logical :: optimize(3)
136 type(mpi_grp_t) :: mpi_grp_
137 real(real64) :: tp_enlarge_(3), lattice_vectors(3, 3)
138 type(space_t) :: cube_space
139
140 push_sub(cube_init)
141
142 assert(all(nn > 0))
143 assert(space%dim <= 3)
144
145 nn3d(1:space%dim) = nn(1:space%dim)
146 nn3d(space%dim+1:3) = 1
147
148 cube%spacing(1:space%dim) = spacing(1:space%dim)
149 cube%spacing(space%dim+1:3) = -m_one
150 cube%batch_capacity = optional_default(batch_size, 1)
151
152 fft_type_ = optional_default(fft_type, fft_none)
153 tp_enlarge_(:) = (/m_one, m_one, m_one/)
154 if (present(tp_enlarge)) tp_enlarge_(:)=tp_enlarge(:)
156 effdim_fft = min(3, space%dim)
158 mpi_grp_ = mpi_world
159 if (present(mpi_grp)) mpi_grp_ = mpi_grp
161 if (fft_type_ /= fft_none) then
162
163 if (present(fft_library)) then
164 fft_library_ = fft_library
165 else
166 fft_library_ = fft_default_lib
167 end if
169#ifndef HAVE_PFFT
170 if (fft_library_ == fftlib_pfft) then
171 write(message(1),'(a)')'You have selected the PFFT for FFT, but it was not linked.'
172 call messages_fatal(1, namespace=namespace)
173 end if
174#endif
176 else
177 fft_library_ = fftlib_none
178 end if
180 ! Only FFTW and cuFFT can batch the FFT (howmany > 1); PFFT/NFFT/PNFFT run one transform at a
181 ! time, so a batched cube on those backends is not possible. Callers that requested a batch
182 ! (batch_size > 1) fall back to a per-function loop (see X(poisson_solve_batch)).
183 if (fft_library_ /= fftlib_fftw .and. fft_library_ /= fftlib_accel) then
184 cube%batch_capacity = 1
185 end if
187 ! Note: later we set parallel_in_domains if blocksize is given, too
188 cube%parallel_in_domains = (fft_library_ == fftlib_pfft .or. fft_library_ == fftlib_pnfft)
189 if (present(blocksize)) then
190 assert(present(need_partition).and.need_partition)
191 assert(fft_library_ == fftlib_none)
192 ! For all the different FFT libraries there are strange (?)
193 ! rules about how the decomposition is chosen. What we want
194 ! (for libvdwxc) is a cube parallelized according to the simple
195 ! but contrary rule "just do what I say". Hence the blocksize
196 ! parameter. (Later to be expanded to allow 2D distributions.)
197 cube%rs_n_global = nn3d
198 cube%fs_n_global = nn3d ! not to be used
199 cube%fs_n = cube%fs_n_global ! not to be used
200 cube%fs_istart = 1 ! not to be used
201
202 comm = mpi_grp_%comm
203 cube%parallel_in_domains = (mpi_grp_%size > 1) ! XXX whether comm size > 1
204 call cube_set_blocksize(cube%rs_n_global, blocksize, mpi_grp_%rank, cube%rs_n, cube%rs_istart)
205 else if (fft_library_ == fftlib_none) then
206 cube%rs_n_global = nn3d
207 cube%fs_n_global = nn3d
208 cube%rs_n = cube%rs_n_global
209 cube%fs_n = cube%fs_n_global
210 cube%rs_istart = 1
211 cube%fs_istart = 1
212 comm = mpi_comm_undefined
213 if (present(nn_out)) nn_out(1:3) = nn3d(1:3)
214 else
215 safe_allocate(cube%fft)
216 tmp_n = nn3d
217
218 optimize(1:3) = .false.
219 optimize_parity(1:3) = 0
220 optimize(space%periodic_dim + 1:effdim_fft) = .true.
221 optimize_parity(space%periodic_dim + 1:effdim_fft) = 1
222
223 if (present(dont_optimize)) then
224 if (dont_optimize) optimize = .false.
225 end if
226
227 if (present(tp_enlarge)) call cube_tp_fft_defaults(cube, fft_library_)
228
229 call fft_init(cube%fft, tmp_n, space%dim, fft_type_, fft_library_, optimize, optimize_parity, &
230 comm=comm, mpi_grp = mpi_grp_, use_aligned=.true., howmany=cube%batch_capacity)
231 if (present(nn_out)) nn_out(1:3) = tmp_n(1:3)
232
233 call fft_get_dims(cube%fft, cube%rs_n_global, cube%fs_n_global, cube%rs_n, cube%fs_n, &
234 cube%rs_istart, cube%fs_istart)
235
236 if (present(tp_enlarge)) then
237 call cube_init_coords(cube, tp_enlarge_, cube%spacing, fft_library_)
238 end if
239
240 if (fft_library_ == fftlib_nfft .or. fft_library_ == fftlib_pnfft) then
241 call fft_init_stage1(cube%fft, namespace, cube%Lrs, cube%rs_n_global)
242 !set local dimensions after stage1 - needed for PNFFT
243 call fft_get_dims(cube%fft, cube%rs_n_global, cube%fs_n_global, cube%rs_n, cube%fs_n, &
244 cube%rs_istart, cube%fs_istart)
245 end if
246
247 end if
248
249 if (.not. allocated(cube%Lrs)) then
250 call cube_init_coords(cube, tp_enlarge_, cube%spacing, fft_library_)
251 end if
252
253 cube%center(1:3) = cube%rs_n_global(1:3)/2 + 1
254
256
257 call mpi_grp_init(cube%mpi_grp, comm)
258
259 ! Initialize mapping only if needed
260 if (present(need_partition) .and. cube%parallel_in_domains) then
261 cube%has_cube_mapping = need_partition
262 else
263 cube%has_cube_mapping = .false.
264 end if
265 if (cube%has_cube_mapping) then
266 call cube_do_mapping(cube, fs = fft_library_ == fftlib_pnfft)
267 end if
268
269 if (cube%parallel_in_domains) call cube_partition_messages_debug(cube, namespace)
270
271 select type (coord_system)
272 class is (affine_coordinates_t)
273 ! We are constructing a lattice vector for the cube
274 ! This differs from the actual lattice vectors if it is not an integer multiple of the spacing
275 ! mesh%idx%ll is "general" in aperiodic directions,
276 ! but "periodic" in periodic directions.
277 my_n(1:space%periodic_dim) = cube%rs_n_global(1:space%periodic_dim) + 1
278 my_n(space%periodic_dim + 1:space%dim) = cube%rs_n_global(space%periodic_dim + 1:space%dim)
279
280 lattice_vectors = m_zero
281 do idir = 1, space%dim
282 do idir2 = 1, space%dim
283 lattice_vectors(idir2, idir) = cube%spacing(idir) * (my_n(idir) - 1) * coord_system%basis%vectors(idir2, idir)
284 end do
285 end do
286 do idir = space%dim + 1, 3
287 lattice_vectors(idir, idir) = m_one
288 end do
289
290 cube_space%dim = 3
291 cube_space%periodic_dim = space%periodic_dim
292 safe_allocate(cube%latt)
293 cube%latt = lattice_vectors_t(namespace, cube_space, lattice_vectors)
294 class default
295 message(1) = "The cube only support affine coordinate systems."
296 call messages_fatal(1, namespace=namespace)
297 end select
298
299 pop_sub(cube_init)
300 end subroutine cube_init
301
302 ! ---------------------------------------------------------
303 subroutine cube_end(cube)
304 type(cube_t), intent(inout) :: cube
305
306 push_sub(cube_end)
307
308 if (allocated(cube%fft)) then
309 call fft_end(cube%fft)
310 safe_deallocate_a(cube%fft)
311 end if
312
313 if (cube%has_cube_mapping) then
314 safe_deallocate_a(cube%np_local)
315 safe_deallocate_a(cube%xlocal)
316 safe_deallocate_a(cube%local)
317
318 safe_deallocate_a(cube%np_local_fs)
319 safe_deallocate_a(cube%xlocal_fs)
320 safe_deallocate_a(cube%local_fs)
321 end if
322
323 if (cube%cube_map_present) then
324 call mesh_cube_map_end(cube%cube_map)
325 end if
326
327 safe_deallocate_a(cube%Lrs)
328 safe_deallocate_a(cube%Lfs)
329
330 safe_deallocate_a(cube%latt)
331 safe_deallocate_a(cube%fs_ifx)
332 safe_deallocate_a(cube%fs_ify)
333 safe_deallocate_a(cube%fs_ifz)
334
335 pop_sub(cube_end)
336 end subroutine cube_end
337
338
352 class(cube_t), intent(inout) :: cube
353
354 integer :: lx, ly, lz
355
357
358 safe_allocate(cube%fs_ifx(1:max(1, cube%fs_n(1))))
359 safe_allocate(cube%fs_ify(1:max(1, cube%fs_n(2))))
360 safe_allocate(cube%fs_ifz(1:max(1, cube%fs_n(3))))
361
362 do lx = 1, cube%fs_n(1)
363 cube%fs_ifx(lx) = pad_feq(cube%fs_istart(1) + lx - 1, cube%rs_n_global(1), .true.)
364 end do
365 do ly = 1, cube%fs_n(2)
366 cube%fs_ify(ly) = pad_feq(cube%fs_istart(2) + ly - 1, cube%rs_n_global(2), .true.)
367 end do
368 do lz = 1, cube%fs_n(3)
369 cube%fs_ifz(lz) = pad_feq(cube%fs_istart(3) + lz - 1, cube%rs_n_global(3), .true.)
370 end do
371
373
375
376
377 ! ---------------------------------------------------------
378 subroutine cube_tp_fft_defaults(cube, fft_library)
379 type(cube_t), intent(inout) :: cube
380 integer, intent(in) :: fft_library
381
382 push_sub(cube_tp_fft_defaults)
383 select case (fft_library)
384 case (fftlib_pnfft)
385 cube%fft%pnfft%set_defaults = .true.
386 cube%fft%pnfft%m = 2
387 cube%fft%pnfft%sigma = 1.1_real64
388
389 case default
390 !do nothing
391 end select
392
393 pop_sub(cube_tp_fft_defaults)
394 end subroutine cube_tp_fft_defaults
395
396
397 ! ---------------------------------------------------------
398 subroutine cube_init_coords(cube, tp_enlarge, spacing, fft_library)
399 type(cube_t), intent(inout) :: cube
400 real(real64), intent(in) :: tp_enlarge(3)
401 real(real64), intent(in) :: spacing(3)
402 integer, intent(in) :: fft_library
403
404 real(real64) :: temp
405 integer :: ii, nn(3), maxn, idim
406
407 push_sub(cube_init_coords)
408
409
410 nn(1:3) = cube%fs_n_global(1:3)
411
412 maxn = maxval(nn)
413 safe_allocate(cube%Lrs(1:maxn, 1:3))
414 cube%Lrs(:,:) = m_zero
415
416 !! Real space coordinates
417 do idim = 1,3
418 if (tp_enlarge(idim) > m_one) then
419 do ii = 2, nn(idim) - 1
420 cube%Lrs(ii, idim) = (ii - int(nn(idim)/2) -1) * spacing(idim)
421 end do
422 cube%Lrs(1, idim) = (-int(nn(idim)/2)) * spacing(idim) * tp_enlarge(idim)
423 cube%Lrs(nn(idim), idim) = (int(nn(idim)/2)) * spacing(idim) * tp_enlarge(idim)
424 else
425 do ii = 1, nn(idim)
426 cube%Lrs(ii, idim) = (ii - int(nn(idim)/2) -1) * spacing(idim)
427 end do
428 end if
429 end do
430
431
432 !! Fourier space coordinates
433 if (fft_library /= fftlib_none) then
434
435 safe_allocate(cube%Lfs(1:maxn, 1:3))
436 cube%Lfs(:,:) = m_zero
437
438 do idim = 1,3
439 temp = m_two * m_pi / (nn(idim) * spacing(idim))
440!temp = M_PI / (nn * spacing(1))
441 do ii = 1, nn(idim)
442 if (fft_library == fftlib_nfft .or. fft_library == fftlib_pnfft) then
443 !The Fourier space is shrunk by the tp_enlarge factor
444 !cube%Lfs(ii, 1:3) = (ii - nn/2 - 1)*temp/tp_enlarge
445!HH NOTE:
446!not sure this is the right general factor
447 cube%Lfs(ii, idim) = (ii - nn(idim)/2 - 1)*temp/tp_enlarge(idim)
448 else
449 cube%Lfs(ii, idim) = pad_feq(ii,nn(idim), .true.) * temp
450 end if
451 end do
452 end do
453 end if
454
455 pop_sub(cube_init_coords)
456 end subroutine cube_init_coords
457
458
459 ! ---------------------------------------------------------
462 logical function cube_global2local(cube, ixyz, lxyz) result(is_here)
463 type(cube_t), intent(in) :: cube
464 integer, intent(in) :: ixyz(3)
465 integer, intent(out) :: lxyz(3)
466
467 lxyz(1) = ixyz(1) - cube%rs_istart(1) + 1
468 lxyz(2) = ixyz(2) - cube%rs_istart(2) + 1
469 lxyz(3) = ixyz(3) - cube%rs_istart(3) + 1
470 is_here = lxyz(1) >= 1 .and. lxyz(1) <= cube%rs_n(1) .and. &
471 lxyz(2) >= 1 .and. lxyz(2) <= cube%rs_n(2) .and. &
472 lxyz(3) >= 1 .and. lxyz(3) <= cube%rs_n(3)
474 end function cube_global2local
475
476
477 ! ---------------------------------------------------------
482 integer function cube_getfftlibrary(cube) result(fft_library)
483 type(cube_t), intent(in) :: cube
484
485 if (allocated(cube%fft)) then
486 fft_library = cube%fft%library
487 else
488 fft_library = fftlib_none
489 end if
490 end function cube_getfftlibrary
491
492 ! ---------------------------------------------------------
494 subroutine cube_do_mapping(cube, fs)
495 type(cube_t), intent(inout) :: cube
496 logical, intent(in) :: fs
497
498 integer :: tmp_local(6), position, process, ix, iy, iz, index
499 integer, allocatable :: local_sizes(:)
500 integer(int64) :: number_points
501
502 push_sub(cube_do_mapping)
503
504 !!BEGIN:gather the local information into a unique vector.
505 !!do a gather in 3d of all the box, into a loop
506 tmp_local(1) = cube%rs_istart(1)
507 tmp_local(2) = cube%rs_istart(2)
508 tmp_local(3) = cube%rs_istart(3)
509 tmp_local(4) = cube%rs_n(1)
510 tmp_local(5) = cube%rs_n(2)
511 tmp_local(6) = cube%rs_n(3)
512
513 if (cube%parallel_in_domains) then
514 safe_allocate(local_sizes(1:6*cube%mpi_grp%size))
515 call profiling_in("CUBE_GAT")
516 call cube%mpi_grp%allgather(tmp_local, 6, mpi_integer, local_sizes, 6, mpi_integer)
517 call profiling_out("CUBE_GAT")
518 else
519 safe_allocate(local_sizes(1:6))
520 local_sizes = tmp_local
521 end if
522
523 call profiling_in("CUBE_MAP")
524
525 safe_allocate(cube%xlocal(1:cube%mpi_grp%size))
526 safe_allocate(cube%np_local(1:cube%mpi_grp%size))
527 ! make sure we do not run into integer overflow here
528 number_points = cube%rs_n_global(1) * cube%rs_n_global(2)
529 number_points = number_points * cube%rs_n_global(3)
530 if (number_points >= huge(0)) then
531 message(1) = "Error: too many points for the normal cube. Please try to use a distributed FFT."
532 call messages_fatal(1)
533 end if
534 safe_allocate(cube%local(1:cube%rs_n_global(1)*cube%rs_n_global(2)*cube%rs_n_global(3), 1:3))
535
536 index = 1
537 do process = 1, cube%mpi_grp%size
538 position = ((process-1)*6)+1
539 if (position == 1) then
540 cube%xlocal(1) = 1
541 cube%np_local(1) = local_sizes(4)*local_sizes(5)*local_sizes(6)
542 else
543 ! calculate the begin index and size of each process
544 cube%xlocal(process) = cube%xlocal(process-1) + cube%np_local(process-1)
545 cube%np_local(process) = local_sizes(position+3)*local_sizes(position+4)*local_sizes(position+5)
546 end if
547
548 ! save the mapping between the global x,y,z and the global index
549 ! and determine which partition the point belongs to
550 do iz = local_sizes(position+2), local_sizes(position+2)+local_sizes(position+5)-1
551 do iy = local_sizes(position+1), local_sizes(position+1)+local_sizes(position+4)-1
552 do ix = local_sizes(position), local_sizes(position)+local_sizes(position+3)-1
553 cube%local(index, 1) = ix
554 cube%local(index, 2) = iy
555 cube%local(index, 3) = iz
556 index = index + 1
557 end do
558 end do
559 end do
560 end do
561
562 call profiling_out("CUBE_MAP")
563
564 if (optional_default(fs,.false.)) then
565
566 tmp_local(1) = cube%fs_istart(1)
567 tmp_local(2) = cube%fs_istart(2)
568 tmp_local(3) = cube%fs_istart(3)
569 tmp_local(4) = cube%fs_n(1)
570 tmp_local(5) = cube%fs_n(2)
571 tmp_local(6) = cube%fs_n(3)
572
573 local_sizes = 0
574 if (cube%parallel_in_domains) then
575 call profiling_in("CUBE_GAT_FS")
576 call cube%mpi_grp%allgather(tmp_local, 6, mpi_integer, local_sizes, 6, mpi_integer)
577 call profiling_out("CUBE_GAT_FS")
578 else
579 local_sizes = tmp_local
580 end if
581
582 call profiling_in("CUBE_MAP_FS")
583
584 safe_allocate(cube%xlocal_fs(1:cube%mpi_grp%size))
585 safe_allocate(cube%np_local_fs(1:cube%mpi_grp%size))
586 ! make sure we do not run into integer overflow here
587 number_points = cube%fs_n_global(1) * cube%fs_n_global(2)
588 number_points = number_points * cube%fs_n_global(3)
589 if (number_points >= huge(0)) then
590 message(1) = "Error: too many points for the normal cube. Please try to use a distributed FFT."
591 call messages_fatal(1)
592 end if
593 safe_allocate(cube%local_fs(1:cube%fs_n_global(1)*cube%fs_n_global(2)*cube%fs_n_global(3), 1:3))
594
595 index = 1
596 do process = 1, cube%mpi_grp%size
597 position = ((process-1)*6)+1
598 if (position == 1) then
599 cube%xlocal_fs(1) = 1
600 cube%np_local_fs(1) = local_sizes(4)*local_sizes(5)*local_sizes(6)
601 else
602 ! calculate the begin index and size of each process
603 cube%xlocal_fs(process) = cube%xlocal_fs(process-1) + cube%np_local_fs(process-1)
604 cube%np_local_fs(process) = local_sizes(position+3)*local_sizes(position+4)*local_sizes(position+5)
605 end if
606
607 ! save the mapping between the global x,y,z and the global index
608 ! and determine which partition the point belongs to
609 do iz = local_sizes(position+2), local_sizes(position+2)+local_sizes(position+5)-1
610 do iy = local_sizes(position+1), local_sizes(position+1)+local_sizes(position+4)-1
611 do ix = local_sizes(position), local_sizes(position)+local_sizes(position+3)-1
612 cube%local_fs(index, 1) = ix
613 cube%local_fs(index, 2) = iy
614 cube%local_fs(index, 3) = iz
615 index = index + 1
616 end do
617 end do
618 end do
619 end do
620
621 call profiling_out("CUBE_MAP_FS")
622
623 end if
624
625
626
627 safe_deallocate_a(local_sizes)
628
629 pop_sub(cube_do_mapping)
630 end subroutine cube_do_mapping
631
632 !!> Given a x, y, z point of the cube, it returns the corresponding process
633 !!
634 !! last_found is used to speed-up the search
635 integer pure function cube_point_to_process(mpi_grp, xyz, part) result(process)
636 type(mpi_grp_t), intent(in) :: mpi_grp
637 integer, intent(in) :: xyz(1:3)
638 type(dimensions_t), intent(in) :: part(:)
639
640 integer :: proc
641 logical :: found
642
643 ! No PUSH/POP because it is a PURE function
644
645 found = .false.
646 do proc = 1, mpi_grp%size
647 !Compare XYZ index
648 if (all(xyz >= part(proc)%start_xyz) .and. all(xyz <= part(proc)%end_xyz)) then
649 process = proc
650 found = .true.
651 exit
652 end if
653 end do
654
655 ! An error message should be raised, if this point is reached
656 if (.not. found) then
657 process = -1
658 end if
659
660 end function cube_point_to_process
661
662 ! Sets a 1D decomposition with fixed-size blocks over the last (least-contiguous) axis.
663 ! Each core will have <blocksize> slices except the last one which will typically have
664 ! less. (In some cases, there can be multiple trailing cores without any slices.)
665 subroutine cube_set_blocksize(rs_n_global, blocksize, rank, rs_n, rs_istart)
666 integer, intent(in) :: rs_n_global(1:3)
667 integer, intent(in) :: blocksize
668 integer, intent(in) :: rank
669 integer, intent(out) :: rs_n(1:3)
670 integer, intent(out) :: rs_istart(1:3)
671
672 integer :: imin, imax
673
674 rs_n = rs_n_global
675 rs_istart = 1
676
677 imin = min(blocksize * rank, rs_n_global(3))
678 imax = min(imin + blocksize, rs_n_global(3))
679 rs_istart(3) = 1 + imin
680 rs_n(3) = imax - imin
681 end subroutine cube_set_blocksize
682
683 ! ---------------------------------------------------------
684 subroutine cube_partition(cube, part)
685 type(cube_t), intent(in) :: cube
686 type(dimensions_t), intent(out) :: part(:)
687
688 integer :: tmp_local(6), position, process
689 integer, allocatable :: local_sizes(:)
690
691 push_sub(cube_partition)
692
693 !!gather the local information into a unique vector.
694 tmp_local(1) = cube%rs_istart(1)
695 tmp_local(2) = cube%rs_istart(2)
696 tmp_local(3) = cube%rs_istart(3)
697 tmp_local(4) = cube%rs_n(1)
698 tmp_local(5) = cube%rs_n(2)
699 tmp_local(6) = cube%rs_n(3)
700
701 if (cube%parallel_in_domains) then
702 safe_allocate(local_sizes(1:6*cube%mpi_grp%size))
703 call cube%mpi_grp%allgather(tmp_local, 6, mpi_integer, local_sizes, 6, mpi_integer)
704 else
705 safe_allocate(local_sizes(1:6))
706 local_sizes(:) = tmp_local(:)
707 end if
708
709 do process = 1, cube%mpi_grp%size
710 position = ((process-1)*6)+1
711
712 part(process)%start_xyz(1) = local_sizes(position)
713 part(process)%start_xyz(2) = local_sizes(position+1)
714 part(process)%start_xyz(3) = local_sizes(position+2)
715 part(process)%end_xyz(1) = local_sizes(position)+local_sizes(position+3)-1
716 part(process)%end_xyz(2) = local_sizes(position+1)+local_sizes(position+4)-1
717 part(process)%end_xyz(3) = local_sizes(position+2)+local_sizes(position+5)-1
718
719 end do
720
721 pop_sub(cube_partition)
722 end subroutine cube_partition
723
724 ! ---------------------------------------------------------
725 subroutine cube_partition_messages_debug(cube, namespace)
726 type(cube_t), intent(in) :: cube
727 type(namespace_t), intent(in) :: namespace
728
729 integer :: nn, ii, jj, kk ! Counters.
730 integer :: ixyz(3) ! Current value of xyz
731 integer :: npart
732 integer :: iunit ! For debug output to files.
733 character(len=3) :: filenum
734 type(dimensions_t), allocatable :: part(:)
735
737
738 if (debug%info) then
739 safe_allocate(part(1:cube%mpi_grp%size))
740 call cube_partition(cube, part)
741
742 if (mpi_world%is_root()) then
743 call io_mkdir('debug/cube_partition', namespace)
744 npart = cube%mpi_grp%size
745
746 ! Debug output. Write points of each partition in a different file.
747 do nn = 1, npart
748
749 write(filenum, '(i3.3)') nn
750
751 iunit = io_open('debug/cube_partition/cube_partition.'//filenum, &
752 namespace, action='write')
753 do kk = 1, cube%rs_n_global(3)
754 do jj = 1, cube%rs_n_global(2)
755 do ii = 1, cube%rs_n_global(1)
756 ixyz(1) = ii
757 ixyz(2) = jj
758 ixyz(3) = kk
759 if (cube_point_to_process(cube%mpi_grp, ixyz, part) == nn) then
760 write(iunit, '(3i8)') ii, jj, kk
761 end if
762 end do
763 end do
764 end do
765 call io_close(iunit)
766 end do
767
768
769 end if
770
771 safe_deallocate_a(part)
772 end if
773
774 call cube%mpi_grp%barrier()
775
777 end subroutine cube_partition_messages_debug
778
779 ! ---------------------------------------------------------
780 subroutine cube_init_cube_map(cube, mesh)
781 type(cube_t), intent(inout) :: cube
782 class(mesh_t), intent(in) :: mesh
783
784 push_sub(cube_init_cube_map)
785
786 call mesh_cube_map_init(cube%cube_map, mesh, mesh%np)
787 cube%cube_map_present = .true.
788
789 pop_sub(cube_init_cube_map)
790 end subroutine cube_init_cube_map
791end module cube_oct_m
792
793
794!! Local Variables:
795!! mode: f90
796!! coding: utf-8
797!! End:
subroutine cube_set_blocksize(rs_n_global, blocksize, rank, rs_n, rs_istart)
Definition: cube.F90:761
subroutine cube_init_fourier_mode_numbers_mapping(cube)
Initialises the mapping between local cube index in Fourier space and global FFT integer frequencies....
Definition: cube.F90:447
subroutine cube_do_mapping(cube, fs)
do the mapping between global and local points of the cube
Definition: cube.F90:590
subroutine, public cube_end(cube)
Definition: cube.F90:399
logical function, public cube_global2local(cube, ixyz, lxyz)
True if global coordinates belong to this process. On output lxyz contains the local coordinates.
Definition: cube.F90:558
subroutine, public cube_init(cube, nn, namespace, space, spacing, coord_system, fft_type, fft_library, dont_optimize, nn_out, mpi_grp, need_partition, tp_enlarge, blocksize, batch_size)
Definition: cube.F90:206
subroutine cube_tp_fft_defaults(cube, fft_library)
Definition: cube.F90:474
integer pure function, public cube_point_to_process(mpi_grp, xyz, part)
Definition: cube.F90:731
integer function, public cube_getfftlibrary(cube)
Returns the FFT library of the cube. Possible values are FFTLIB_NONE, FFTLIB_FFTW,...
Definition: cube.F90:578
subroutine cube_init_coords(cube, tp_enlarge, spacing, fft_library)
Definition: cube.F90:494
subroutine, public cube_partition(cube, part)
Definition: cube.F90:780
subroutine, public cube_init_cube_map(cube, mesh)
Definition: cube.F90:876
subroutine cube_partition_messages_debug(cube, namespace)
Definition: cube.F90:821
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:120
subroutine, public fft_init(this, nn, dim, type, library, optimize, optimize_parity, comm, mpi_grp, use_aligned, howmany)
Definition: fft.F90:412
integer, parameter, public fft_none
global constants
Definition: fft.F90:174
subroutine, public fft_end(this)
Definition: fft.F90:799
integer, public fft_default_lib
Definition: fft.F90:257
pure integer function, public pad_feq(ii, nn, mode)
convert between array index and G-vector
Definition: fft.F90:913
integer, parameter, public fftlib_accel
Definition: fft.F90:179
subroutine, public fft_get_dims(fft, rs_n_global, fs_n_global, rs_n, fs_n, rs_istart, fs_istart)
Definition: fft.F90:887
integer, parameter, public fftlib_nfft
Definition: fft.F90:179
integer, parameter, public fftlib_none
Definition: fft.F90:179
integer, parameter, public fftlib_pnfft
Definition: fft.F90:179
integer, parameter, public fftlib_pfft
Definition: fft.F90:179
integer, parameter, public fftlib_fftw
Definition: fft.F90:179
subroutine, public fft_init_stage1(this, namespace, XX, nn)
Some fft-libraries (only NFFT for the moment) need an additional precomputation stage that depends on...
Definition: fft.F90:757
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:198
real(real64), parameter, public m_one
Definition: global.F90:201
Definition: io.F90:116
subroutine, public mesh_cube_map_end(this)
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:138
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:276
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:345
The low level module to work with the PFFT library. http:
Definition: pfft.F90:128
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
It is intended to be used within a vector.
Definition: cube.F90:196
This is defined even when running serial.
Definition: mpi.F90:144
int true(void)