(git:3d5d2e5)
Loading...
Searching...
No Matches
fft_tools.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \par History
10!> JGH (30-Nov-2000): ESSL FFT Library added
11!> JGH (05-Jan-2001): Added SGI library FFT
12!> JGH (14-Jan-2001): Added parallel 3d FFT
13!> JGH (10-Feb-2006): New interface type
14!> JGH (31-Mar-2008): Remove local allocates and reshapes (performance)
15!> Possible problems can be related with setting arrays
16!> not to zero
17!> Some interfaces could be further simplified by avoiding
18!> an initial copy. However, this assumes contiguous arrays
19!> IAB (15-Oct-2008): Moved mp_cart_sub calls out of cube_tranpose_* and into
20!> fft_scratch type, reducing number of calls dramatically
21!> IAB (05-Dec-2008): Moved all other non-essential MPI calls into scratch type
22!> IAB (09-Jan-2009): Added fft_plan_type to store FFT data, including cached FFTW plans
23!> IAB (13-Feb-2009): Extended plan caching to serial 3D FFT (fft3d_s)
24!> IAB (09-Oct-2009): Added OpenMP directives to parallel 3D FFT
25!> (c) The Numerical Algorithms Group (NAG) Ltd, 2008-2009 on behalf of the HECToR project
26!> HFP (17-Oct-2024): Thread-safety insurance (CPASSERT), and OMP ATOMIC (tick_fft_pool)
27!> \author JGH
28! **************************************************************************************************
30 USE iso_c_binding, ONLY: c_f_pointer,&
31 c_loc,&
32 c_ptr,&
33 c_size_t
35 USE fft_api, ONLY: &
39 USE kinds, ONLY: dp,&
40 dp_size,&
41 sp
42 USE mathconstants, ONLY: z_zero
43 USE message_passing, ONLY: mp_cart_type,&
50
51!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_in_parallel
52
53#include "../base/base_uses.f90"
54
55 IMPLICIT NONE
56
57 CHARACTER(LEN=*), PARAMETER, PRIVATE :: moduleN = 'fft_tools'
58
60 LOGICAL :: fsign = .true.
61 LOGICAL :: trans_in = .false., trans_out = .false., fft_in_place = .false., &
62 valid = .false., separated_plans = .false.
63 INTEGER :: n = -1, m = -1, ldx_in = -1, ldy_in = -1, ldx_out = -1, ldy_out = -1
64 INTEGER, DIMENSION(3) :: n_3d = -1
65 END TYPE fft_plan_type
66
67 ! Types for the pool of scratch data needed in FFT routines
68 ! keep the subroutine "is_equal" up-to-date
69 ! needs a default initialization
71 INTEGER :: nx = 0, ny = 0, nz = 0
72 INTEGER :: lmax = 0, mmax = 0, nmax = 0
73 INTEGER :: mx1 = 0, mx2 = 0, mx3 = 0
74 INTEGER :: my1 = 0, my2 = 0, my3 = 0
75 INTEGER :: mz1 = 0, mz2 = 0, mz3 = 0
76 INTEGER :: mcz1 = 0, mcz2 = 0, mcy3 = 0, mcx2 = 0
77 INTEGER :: lg = 0, mg = 0
78 INTEGER :: nbx = 0, nbz = 0
79 INTEGER :: nmray = 0, nyzray = 0
80 TYPE(mp_cart_type) :: rs_group = mp_cart_type()
81 INTEGER, DIMENSION(2) :: g_pos = 0, r_pos = 0, r_dim = 0
82 INTEGER :: numtask = 0
83 END TYPE fft_scratch_sizes
84
86 INTEGER :: fft_scratch_id = 0
87 INTEGER :: tf_type = -1
88 LOGICAL :: in_use = .true.
89 TYPE(mp_comm_type) :: group = mp_comm_type()
90 INTEGER, DIMENSION(3) :: nfft = -1
91 ! to be used in cube_transpose_* routines
92 TYPE(mp_cart_type), DIMENSION(2) :: cart_sub_comm = mp_cart_type()
93 INTEGER, DIMENSION(2) :: dim = -1, pos = -1
94 ! to be used in fft3d_s
95 COMPLEX(KIND=dp), DIMENSION(:, :, :), POINTER, CONTIGUOUS &
96 :: ziptr => null(), zoptr => null()
97 ! to be used in fft3d_ps : block distribution
98 COMPLEX(KIND=dp), DIMENSION(:, :), CONTIGUOUS, POINTER &
99 :: p1buf => null(), p2buf => null(), p3buf => null(), p4buf => null(), &
100 p5buf => null(), p6buf => null(), p7buf => null()
101 ! to be used in fft3d_ps : plane distribution
102 COMPLEX(KIND=dp), DIMENSION(:, :), POINTER, CONTIGUOUS &
103 :: r1buf => null(), r2buf => null()
104 COMPLEX(KIND=dp), DIMENSION(:, :, :), POINTER, CONTIGUOUS &
105 :: tbuf => null()
106 ! to be used in fft3d_pb
107 COMPLEX(KIND=dp), DIMENSION(:, :), POINTER, CONTIGUOUS &
108 :: a1buf => null(), a2buf => null(), a3buf => null(), &
109 a4buf => null(), a5buf => null(), a6buf => null()
110 ! to be used in communication routines
111 INTEGER, DIMENSION(:), CONTIGUOUS, POINTER :: scount => null(), rcount => null(), sdispl => null(), rdispl => null()
112 INTEGER, DIMENSION(:, :), CONTIGUOUS, POINTER :: pgcube => null()
113 INTEGER, DIMENSION(:), CONTIGUOUS, POINTER :: xzcount => null(), yzcount => null(), xzdispl => null(), yzdispl => null()
114 INTEGER :: in = 0, mip = -1
115 REAL(kind=dp) :: rsratio = 1.0_dp
116 COMPLEX(KIND=dp), DIMENSION(:), POINTER, CONTIGUOUS &
117 :: xzbuf => null(), yzbuf => null()
118 COMPLEX(KIND=sp), DIMENSION(:), POINTER, CONTIGUOUS &
119 :: xzbuf_sgl => null(), yzbuf_sgl => null()
120 COMPLEX(KIND=dp), DIMENSION(:, :), POINTER, CONTIGUOUS &
121 :: rbuf1 => null(), rbuf2 => null(), rbuf3 => null(), rbuf4 => null(), &
122 rbuf5 => null(), rbuf6 => null(), rr => null()
123 COMPLEX(KIND=sp), DIMENSION(:, :), POINTER, CONTIGUOUS &
124 :: ss => null(), tt => null()
125 INTEGER, DIMENSION(:, :), POINTER, CONTIGUOUS :: pgrid => null()
126 INTEGER, DIMENSION(:), POINTER, CONTIGUOUS :: xcor => null(), zcor => null(), pzcoord => null()
128 TYPE(fft_plan_type), DIMENSION(6) :: fft_plan = fft_plan_type()
129 INTEGER :: last_tick = -1
130 END TYPE fft_scratch_type
131
133 TYPE(fft_scratch_type), POINTER :: fft_scratch => null()
134 TYPE(fft_scratch_pool_type), POINTER :: fft_scratch_next => null()
135 END TYPE fft_scratch_pool_type
136
137 INTEGER, SAVE :: init_fft_pool = 0
138 ! the clock for fft pool. Allows to identify the least recently used scratch
139 INTEGER, SAVE :: tick_fft_pool = 0
140 ! limit the number of scratch pools to fft_pool_scratch_limit.
141 INTEGER, SAVE :: fft_pool_scratch_limit = 15
143 ! END of types for the pool of scratch data needed in FFT routines
144
145 PRIVATE
148 PUBLIC :: init_fft_scratch_pool
149 PUBLIC :: fft_radix_operations
150 PUBLIC :: fwfft, bwfft
152 PUBLIC :: fft_radix_next_odd
154
155 LOGICAL, PARAMETER :: fwfft = .true., bwfft = .false.
156 INTEGER, PARAMETER :: fft_radix_closest = 493, fft_radix_next = 494
157 INTEGER, PARAMETER :: fft_radix_allowed = 495, fft_radix_disallowed = 496
158 INTEGER, PARAMETER :: fft_radix_next_odd = 497
159
160 REAL(kind=dp), PARAMETER :: ratio_sparse_alltoall = 0.5_dp
161
162 ! these saved variables are FFT globals
163 LOGICAL, SAVE :: alltoall_sgl = .false.
164
165 ! these are only needed for fft_gpu (-D__OFFLOAD)
168 PUBLIC :: yz_to_x, x_to_yz, xz_to_yz, yz_to_xz
170
171 INTERFACE fft3d
172 MODULE PROCEDURE fft3d_s, fft3d_ps, fft3d_pb
173 END INTERFACE
174
175! **************************************************************************************************
176
177CONTAINS
178
179! **************************************************************************************************
180!> \brief ...
181!> \param fftlib ...
182!> \param alltoall ...
183!> \param pool_limit ...
184!> \param wisdom_file ...
185!> \param plan_style ...
186!> \param status ...
187!> \param use_guru_interface ...
188!> \author JGH
189! **************************************************************************************************
190 SUBROUTINE init_fft(fftlib, alltoall, pool_limit, wisdom_file, &
191 plan_style, status, use_guru_interface)
192
193 INTEGER, INTENT(IN) :: fftlib
194 LOGICAL, INTENT(IN) :: alltoall
195 INTEGER, INTENT(IN) :: pool_limit
196 CHARACTER(LEN=*), INTENT(IN) :: wisdom_file
197 INTEGER, INTENT(IN) :: plan_style
198 INTEGER, INTENT(OUT) :: status
199 LOGICAL, INTENT(IN), OPTIONAL :: use_guru_interface
200
201 LOGICAL :: use_guru
202
203 use_guru = .true.
204 IF (PRESENT(use_guru_interface)) use_guru = use_guru_interface
205
206 alltoall_sgl = alltoall
207 fft_pool_scratch_limit = pool_limit
208
209 CALL release_fft_scratch_pool()
210
211 CALL fft_library_init(fftlib, plan_style, use_guru, wisdom_file, status)
212
213 ! setup the FFT scratch pool, if one is associated, clear first
215
216 END SUBROUTINE init_fft
217
218! **************************************************************************************************
219!> \brief does whatever is needed to finalize the current fft setup
220!> \param wisdom_file ...
221!> \par History
222!> 10.2007 created [Joost VandeVondele]
223! **************************************************************************************************
224 SUBROUTINE finalize_fft(wisdom_file)
225 CHARACTER(LEN=*), INTENT(IN) :: wisdom_file
226
227! release the FFT scratch pool
228
229 CALL release_fft_scratch_pool()
230
231 ! finalize fft libs
232
233 CALL fft_library_finalize(wisdom_file)
234
235 END SUBROUTINE finalize_fft
236
237! **************************************************************************************************
238!> \brief ...
239!> \param DATA ...
240!> \param max_length ...
241!> \par History
242!> JGH 23-Jan-2006 : initial version
243!> Adapted for new interface
244!> IAB 09-Jan-2009 : Modified to cache plans in fft_plan_type
245!> (c) The Numerical Algorithms Group (NAG) Ltd, 2009 on behalf of the HECToR project
246!> IAB 09-Oct-2009 : Added OpenMP directives to 1D FFT, and planning routines
247!> (c) The Numerical Algorithms Group (NAG) Ltd, 2009 on behalf of the HECToR project
248!> IAB 11-Sep-2012 : OpenMP parallel 3D FFT (Ruyman Reyes, PRACE)
249!> \author JGH
250! **************************************************************************************************
251 SUBROUTINE fft_get_lengths(DATA, max_length)
252
253 INTEGER, DIMENSION(:), INTENT(INOUT) :: data
254 INTEGER, INTENT(INOUT) :: max_length
255
256 INTEGER :: h, i, j, k, m, maxn, maxn_elevens, &
257 maxn_fives, maxn_sevens, &
258 maxn_thirteens, maxn_threes, &
259 maxn_twos, ndata, nmax, number
260 INTEGER, ALLOCATABLE, DIMENSION(:) :: dlocal, idx
261
262!------------------------------------------------------------------------------
263! compute ndata
264!! FFTW can do arbitrary(?) lengths, maybe you want to limit them to some
265!! powers of small prime numbers though...
266
267 maxn_twos = 15
268 maxn_threes = 3
269 maxn_fives = 2
270 maxn_sevens = 1
271 maxn_elevens = 1
272 maxn_thirteens = 0
273 maxn = 37748736
274
275 ndata = 0
276 DO h = 0, maxn_twos
277 nmax = huge(0)/2**h
278 DO i = 0, maxn_threes
279 DO j = 0, maxn_fives
280 DO k = 0, maxn_sevens
281 DO m = 0, maxn_elevens
282 number = (3**i)*(5**j)*(7**k)*(11**m)
283
284 IF (number > nmax) cycle
285
286 number = number*2**h
287 IF (number >= maxn) cycle
288
289 ndata = ndata + 1
290 END DO
291 END DO
292 END DO
293 END DO
294 END DO
295
296 ALLOCATE (dlocal(ndata), idx(ndata))
297
298 ndata = 0
299 dlocal(:) = 0
300 DO h = 0, maxn_twos
301 nmax = huge(0)/2**h
302 DO i = 0, maxn_threes
303 DO j = 0, maxn_fives
304 DO k = 0, maxn_sevens
305 DO m = 0, maxn_elevens
306 number = (3**i)*(5**j)*(7**k)*(11**m)
307
308 IF (number > nmax) cycle
309
310 number = number*2**h
311 IF (number >= maxn) cycle
312
313 ndata = ndata + 1
314 dlocal(ndata) = number
315 END DO
316 END DO
317 END DO
318 END DO
319 END DO
320
321 CALL sortint(dlocal, ndata, idx)
322 ndata = min(ndata, max_length)
323 DATA(1:ndata) = dlocal(1:ndata)
324 max_length = ndata
325
326 DEALLOCATE (dlocal, idx)
327
328 END SUBROUTINE fft_get_lengths
329
330! **************************************************************************************************
331!> \brief ...
332!> \param iarr ...
333!> \param n ...
334!> \param index ...
335! **************************************************************************************************
336 SUBROUTINE sortint(iarr, n, index)
337
338 INTEGER, INTENT(IN) :: n
339 INTEGER, INTENT(INOUT) :: iarr(1:n)
340 INTEGER, INTENT(OUT) :: index(1:n)
341
342 INTEGER, PARAMETER :: m = 7, nstack = 50
343
344 INTEGER :: a, i, ib, ir, istack(1:nstack), itemp, &
345 j, jstack, k, l, temp
346
347!------------------------------------------------------------------------------
348
349 DO i = 1, n
350 index(i) = i
351 END DO
352 jstack = 0
353 l = 1
354 ir = n
355 DO WHILE (.true.)
356 IF (ir - l < m) THEN
357 DO j = l + 1, ir
358 a = iarr(j)
359 ib = index(j)
360 DO i = j - 1, 0, -1
361 IF (i == 0) EXIT
362 IF (iarr(i) <= a) EXIT
363 iarr(i + 1) = iarr(i)
364 index(i + 1) = index(i)
365 END DO
366 iarr(i + 1) = a
367 index(i + 1) = ib
368 END DO
369 IF (jstack == 0) RETURN
370 ir = istack(jstack)
371 l = istack(jstack - 1)
372 jstack = jstack - 2
373 ELSE
374 k = (l + ir)/2
375 temp = iarr(k)
376 iarr(k) = iarr(l + 1)
377 iarr(l + 1) = temp
378 itemp = index(k)
379 index(k) = index(l + 1)
380 index(l + 1) = itemp
381 IF (iarr(l + 1) > iarr(ir)) THEN
382 temp = iarr(l + 1)
383 iarr(l + 1) = iarr(ir)
384 iarr(ir) = temp
385 itemp = index(l + 1)
386 index(l + 1) = index(ir)
387 index(ir) = itemp
388 END IF
389 IF (iarr(l) > iarr(ir)) THEN
390 temp = iarr(l)
391 iarr(l) = iarr(ir)
392 iarr(ir) = temp
393 itemp = index(l)
394 index(l) = index(ir)
395 index(ir) = itemp
396 END IF
397 IF (iarr(l + 1) > iarr(l)) THEN
398 temp = iarr(l + 1)
399 iarr(l + 1) = iarr(l)
400 iarr(l) = temp
401 itemp = index(l + 1)
402 index(l + 1) = index(l)
403 index(l) = itemp
404 END IF
405 i = l + 1
406 j = ir
407 a = iarr(l)
408 ib = index(l)
409 DO WHILE (.true.)
410 i = i + 1
411 DO WHILE (iarr(i) < a)
412 i = i + 1
413 END DO
414 j = j - 1
415 DO WHILE (iarr(j) > a)
416 j = j - 1
417 END DO
418 IF (j < i) EXIT
419 temp = iarr(i)
420 iarr(i) = iarr(j)
421 iarr(j) = temp
422 itemp = index(i)
423 index(i) = index(j)
424 index(j) = itemp
425 END DO
426 iarr(l) = iarr(j)
427 iarr(j) = a
428 index(l) = index(j)
429 index(j) = ib
430 jstack = jstack + 2
431 IF (jstack > nstack) cpabort("Nstack too small in sortint")
432 IF (ir - i + 1 >= j - l) THEN
433 istack(jstack) = ir
434 istack(jstack - 1) = i
435 ir = j - 1
436 ELSE
437 istack(jstack) = j - 1
438 istack(jstack - 1) = l
439 l = i
440 END IF
441 END IF
442
443 END DO
444
445 END SUBROUTINE sortint
446
447! **************************************************************************************************
448!> \brief Determine the allowed lengths of FFT's '''
449!> \param radix_in ...
450!> \param radix_out ...
451!> \param operation ...
452!> \par History
453!> new library structure (JGH)
454!> \author Ari Seitsonen
455! **************************************************************************************************
456 SUBROUTINE fft_radix_operations(radix_in, radix_out, operation)
457
458 INTEGER, INTENT(IN) :: radix_in
459 INTEGER, INTENT(OUT) :: radix_out
460 INTEGER, INTENT(IN) :: operation
461
462 INTEGER, PARAMETER :: number_of_small_radices = 81
463 INTEGER, DIMENSION(number_of_small_radices), PARAMETER :: small_radices = [2, 4, 6, 8, 9, 12,&
464 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40, 45, 48, 54, 60, 64, 72, 75, 80, 81, 90, 96, &
465 100, 108, 120, 125, 128, 135, 144, 150, 160, 162, 180, 192, 200, 216, 225, 240, 243, 256, &
466 270, 288, 300, 320, 324, 360, 375, 384, 400, 405, 432, 450, 480, 486, 500, 512, 540, 576, &
467 600, 625, 640, 648, 675, 720, 729, 750, 768, 800, 810, 864, 900, 960, 972, 1000, 1024]
468
469 INTEGER :: i, iloc, ldata, trial_number
470 INTEGER, ALLOCATABLE, DIMENSION(:) :: data
471
472 ldata = 1024
473 ALLOCATE (DATA(ldata))
474 DATA = -1
475
476 DATA(1:number_of_small_radices) = small_radices(1:number_of_small_radices)
477
478 ! First run: try smaller radices
479 ! Second run: Fetch extended list of radices and try these
480 DO trial_number = 1, 2
481 IF (trial_number == 2) CALL fft_get_lengths(DATA, ldata)
482 iloc = 0
483 DO i = 1, ldata
484 IF (DATA(i) == radix_in) THEN
485 iloc = i
486 EXIT
487 ELSE
488 IF (operation == fft_radix_allowed) THEN
489 cycle
490 ELSE IF (DATA(i) > radix_in) THEN
491 iloc = i
492 EXIT
493 END IF
494 END IF
495 END DO
496
497 IF (iloc == 0) THEN
498 IF (trial_number == 1) THEN
499 ! We haven't found any suitable size in the list of smaller radices
500 ! because the requested radix is too large (large cell or large cutoff)
501 ! So, try again with the larger radices
502 cycle
503 ELSE
504 IF (operation == fft_radix_closest) THEN
505 radix_out = maxval(data)
506 ELSE
507 CALL cp_abort(__location__, &
508 "No suitable FFT lengths found! Either enable FFTW or reduce the grid size!")
509 END IF
510 RETURN
511 END IF
512
513 END IF
514
515 IF (operation == fft_radix_allowed) THEN
516 IF (DATA(iloc) == radix_in) THEN
517 radix_out = fft_radix_allowed
518 ELSE
519 radix_out = fft_radix_disallowed
520 END IF
521
522 ELSE IF (operation == fft_radix_closest) THEN
523 IF (DATA(iloc) == radix_in) THEN
524 radix_out = DATA(iloc)
525 ELSE
526 IF (abs(DATA(iloc - 1) - radix_in) <= &
527 abs(DATA(iloc) - radix_in)) THEN
528 radix_out = DATA(iloc - 1)
529 ELSE
530 radix_out = DATA(iloc)
531 END IF
532 END IF
533
534 ELSE IF (operation == fft_radix_next) THEN
535 radix_out = DATA(iloc)
536
537 ELSE IF (operation == fft_radix_next_odd) THEN
538 DO i = iloc, ldata
539 IF (mod(DATA(i), 2) == 1) THEN
540 radix_out = DATA(i)
541 EXIT
542 END IF
543 END DO
544 IF (mod(radix_out, 2) == 0) THEN
545 ! No larger odd radix found
546 IF (trial_number == 1) THEN
547 cycle
548 ELSE
549 radix_out = radix_in + 1 - mod(radix_in, 2)
550 END IF
551 END IF
552
553 END IF
554 EXIT
555 END DO
556
557 DEALLOCATE (data)
558
559 END SUBROUTINE fft_radix_operations
560
561! **************************************************************************************************
562!> \brief ...
563!> \param plan ...
564!> \param fsign ...
565!> \param trans_in ...
566!> \param trans_out ...
567!> \param ldx_in ...
568!> \param ldx_out ...
569!> \param n ...
570!> \param m ...
571!> \param zin ...
572!> \param zout ...
573! **************************************************************************************************
574 SUBROUTINE fft_create_plan_1d(plan, fsign, trans_in, trans_out, ldx_in, ldx_out, n, m, zin, zout)
575 TYPE(fft_plan_type), INTENT(INOUT) :: plan
576 LOGICAL, INTENT(IN) :: fsign, trans_in, trans_out
577 INTEGER, INTENT(IN) :: ldx_in, ldx_out, n, m
578 COMPLEX(KIND=dp), DIMENSION(*), INTENT(INOUT), &
579 TARGET :: zin, zout
580
581 plan%fsign = fsign
582 plan%trans_in = trans_in
583 plan%trans_out = trans_out
584 IF (plan%trans_in) THEN
585 plan%ldx_in = ldx_in
586 plan%ldy_in = n
587 ELSE
588 plan%ldx_in = ldx_in
589 plan%ldy_in = m
590 END IF
591 IF (plan%trans_out) THEN
592 plan%ldx_out = ldx_out
593 plan%ldy_out = n
594 ELSE
595 plan%ldx_out = ldx_out
596 plan%ldy_out = m
597 END IF
598
599 plan%n = n
600 plan%m = m
601
602 IF (n*m /= 0) THEN
603 CALL fft_register_1d_local(fsign, n, m, trans_in, trans_out, ldx_in, ldx_out, zin, zout)
604 plan%valid = .true.
605 ELSE
606 plan%valid = .false.
607 END IF
608
609 END SUBROUTINE fft_create_plan_1d
610
611! **************************************************************************************************
612!> \brief ...
613!> \param plan ...
614!> \param fsign ...
615!> \param trans_in ...
616!> \param trans_out ...
617!> \param n ...
618!> \param m ...
619!> \param zin ...
620!> \param zout ...
621! **************************************************************************************************
622 SUBROUTINE fft_create_plan_2d(plan, fsign, trans_in, trans_out, n, m, zin, zout)
623 TYPE(fft_plan_type), INTENT(INOUT) :: plan
624 LOGICAL, INTENT(IN) :: fsign, trans_in, trans_out
625 INTEGER, INTENT(IN) :: n(2), m
626 COMPLEX(KIND=dp), DIMENSION(*), INTENT(INOUT), &
627 TARGET :: zin, zout
628
629 plan%fsign = fsign
630 plan%trans_in = trans_in
631 plan%trans_out = trans_out
632 IF (plan%trans_in) THEN
633 plan%ldx_in = m
634 plan%ldy_in = n(1)*n(2)
635 ELSE
636 plan%ldx_in = n(1)*n(2)
637 plan%ldy_in = m
638 END IF
639 IF (plan%trans_out) THEN
640 plan%ldx_out = m
641 plan%ldy_out = n(1)*n(2)
642 ELSE
643 plan%ldx_out = n(1)*n(2)
644 plan%ldy_out = m
645 END IF
646
647 plan%n_3d(1:2) = n
648 plan%n_3d(3) = 0
649 plan%m = m
650
651 IF (n(1) > 0 .AND. n(2) > 0 .AND. m > 0) THEN
652 CALL fft_register_2d_local(fsign, n, m, trans_in, trans_out, zin, zout)
653 plan%valid = .true.
654 ELSE
655 plan%valid = .false.
656 END IF
657
658 END SUBROUTINE fft_create_plan_2d
659
660! **************************************************************************************************
661!> \brief ...
662!> \param plan ...
663!> \param fsign ...
664!> \param n ...
665!> \param zin ...
666!> \param zout ...
667! **************************************************************************************************
668 SUBROUTINE fft_create_plan_3d(plan, fsign, n, zin, zout)
669
670 TYPE(fft_plan_type), INTENT(INOUT) :: plan
671 LOGICAL, INTENT(IN) :: fsign
672 INTEGER, DIMENSION(3), INTENT(IN) :: n
673 COMPLEX(KIND=dp), DIMENSION(PRODUCT(n)), &
674 INTENT(INOUT), TARGET :: zin, zout
675
676 plan%fsign = fsign
677 plan%fft_in_place = .false.
678 plan%n_3d = n
679
680 CALL fft_register_3d_local(fsign, n, 1, .false., .false., zin, zout)
681 plan%valid = .true.
682
683 END SUBROUTINE fft_create_plan_3d
684
685! **************************************************************************************************
686!> \brief ...
687!> \param plan ...
688!> \param fsign ...
689!> \param n ...
690!> \param zinout ...
691! **************************************************************************************************
692 SUBROUTINE fft_create_plan_3d_inplace(plan, fsign, n, zinout)
693
694 TYPE(fft_plan_type), INTENT(INOUT) :: plan
695 LOGICAL, INTENT(IN) :: fsign
696 INTEGER, DIMENSION(3), INTENT(IN) :: n
697 COMPLEX(KIND=dp), DIMENSION(PRODUCT(n)), &
698 INTENT(INOUT), TARGET :: zinout
699
700 plan%fsign = fsign
701 plan%fft_in_place = .true.
702 plan%n_3d = n
703
704 CALL fft_register_3d_local_inplace(fsign, n, 1, .false., zinout)
705 plan%valid = .true.
706
707 END SUBROUTINE fft_create_plan_3d_inplace
708
709! **************************************************************************************************
710!> \brief ...
711!> \param plan ...
712!> \param scale ...
713!> \param zin ...
714!> \param zout ...
715! **************************************************************************************************
716 SUBROUTINE fft_3d(plan, scale, zin, zout)
717 TYPE(fft_plan_type), INTENT(IN) :: plan
718 REAL(kind=dp), INTENT(IN) :: scale
719 COMPLEX(KIND=dp), DIMENSION(*), INTENT(INOUT), &
720 TARGET :: zin, zout
721
722 cpassert(.NOT. plan%fft_in_place)
723
724 IF (all(plan%n_3d > 0)) THEN
725 CALL fft_3d_local(plan%fsign, plan%n_3d, 1, .false., .false., zin, zout)
726 END IF
727 zout(1:product(plan%n_3d)) = zout(1:product(plan%n_3d))*scale
728
729 END SUBROUTINE fft_3d
730
731! **************************************************************************************************
732!> \brief ...
733!> \param plan ...
734!> \param scale ...
735!> \param zinout ...
736! **************************************************************************************************
737 SUBROUTINE fft_3d_inplace(plan, scale, zinout)
738 TYPE(fft_plan_type), INTENT(IN) :: plan
739 REAL(kind=dp), INTENT(IN) :: scale
740 COMPLEX(KIND=dp), DIMENSION(*), INTENT(INOUT), &
741 TARGET :: zinout
742
743 cpassert(plan%fft_in_place)
744
745 IF (all(plan%n_3d > 0)) THEN
746 CALL fft_3d_local_inplace(plan%fsign, plan%n_3d, 1, .false., zinout)
747 END IF
748 zinout(1:product(plan%n_3d)) = zinout(1:product(plan%n_3d))*scale
749
750 END SUBROUTINE fft_3d_inplace
751
752! **************************************************************************************************
753!> \brief ...
754!> \param plan ...
755! **************************************************************************************************
756 SUBROUTINE fft_destroy_plan(plan)
757 TYPE(fft_plan_type), INTENT(INOUT) :: plan
758
759 plan%valid = .false.
760
761 END SUBROUTINE fft_destroy_plan
762
763! **************************************************************************************************
764!> \brief ...
765!> \param plan ...
766!> \param zin ...
767!> \param zout ...
768!> \param scale ...
769! **************************************************************************************************
770 SUBROUTINE fft_1d(plan, zin, zout, scale)
771 TYPE(fft_plan_type), INTENT(IN) :: plan
772 COMPLEX(KIND=dp), DIMENSION(*), INTENT(INOUT), &
773 TARGET :: zin, zout
774 REAL(kind=dp), INTENT(IN) :: scale
775
776 IF (plan%n*plan%m > 0) THEN
777 CALL fft_1d_local(plan%fsign, plan%n, plan%m, plan%trans_in, plan%trans_out, plan%ldx_in, plan%ldx_out, zin, zout)
778 IF (scale /= 1.0_dp) zout(1:plan%n*plan%m) = zout(1:plan%n*plan%m)*scale
779 END IF
780
781 END SUBROUTINE fft_1d
782
783! **************************************************************************************************
784!> \brief ...
785!> \param plan ...
786!> \param zin ...
787!> \param zout ...
788!> \param scale ...
789! **************************************************************************************************
790 SUBROUTINE fft_2d(plan, zin, zout, scale)
791 TYPE(fft_plan_type), INTENT(IN) :: plan
792 COMPLEX(KIND=dp), DIMENSION(*), INTENT(INOUT), &
793 TARGET :: zin, zout
794 REAL(kind=dp), INTENT(IN) :: scale
795
796 IF (plan%n_3d(1) > 0 .AND. plan%n_3d(2) > 0 .AND. plan%m > 0) THEN
797 CALL fft_2d_local(plan%fsign, plan%n_3d(1:2), plan%m, plan%trans_in, plan%trans_out, zin, zout)
798 IF (scale /= 1.0_dp) zout(1:plan%n_3d(1)*plan%n_3d(2)*plan%m) = &
799 zout(1:plan%n_3d(1)*plan%n_3d(2)*plan%m)*scale
800 END IF
801
802 END SUBROUTINE fft_2d
803
804! **************************************************************************************************
805!> \brief Calls the 3D-FFT function from the initialized library
806!> \param fsign ...
807!> \param n ...
808!> \param zin ...
809!> \param zout ...
810!> \param debug ...
811!> \par History
812!> none
813!> \author JGH
814! **************************************************************************************************
815 SUBROUTINE fft3d_s(fsign, n, zin, zout, debug)
816
817 LOGICAL, INTENT(IN) :: fsign
818 INTEGER, DIMENSION(:), INTENT(INOUT) :: n
819 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
820 INTENT(INOUT), TARGET :: zin
821 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
822 INTENT(INOUT), OPTIONAL, TARGET :: zout
823 LOGICAL, INTENT(IN), OPTIONAL :: debug
824
825 CHARACTER(LEN=*), PARAMETER :: routinen = 'fft3d_s'
826
827 INTEGER :: handle, ld(3), lo(3), output_unit
828 LOGICAL :: fft_in_place, test
829 REAL(KIND=dp) :: in_sum, norm, out_sum
830 TYPE(fft_scratch_type), POINTER :: fft_scratch
831
832 CALL timeset(routinen, handle)
833 output_unit = cp_logger_get_default_io_unit()
834
835 IF (fsign) THEN
836 norm = 1.0_dp/real(product(n), kind=dp)
837 ELSE
838 norm = 1.0_dp
839 END IF
840
841 IF (PRESENT(debug)) THEN
842 test = debug
843 ELSE
844 test = .false.
845 END IF
846
847 IF (PRESENT(zout)) THEN
848 fft_in_place = .false.
849 ELSE
850 fft_in_place = .true.
851 END IF
852
853 IF (test) THEN
854 in_sum = sum(abs(zin))
855 END IF
856
857 ld(1) = SIZE(zin, 1)
858 ld(2) = SIZE(zin, 2)
859 ld(3) = SIZE(zin, 3)
860
861 IF (n(1) /= ld(1) .OR. n(2) /= ld(2) .OR. n(3) /= ld(3)) THEN
862 cpabort("Size and dimension (zin) have to be the same.")
863 END IF
864
865 CALL get_fft_scratch(fft_scratch, tf_type=400, n=n)
866
867 IF (fft_in_place) THEN
868 IF (fsign) THEN
869 CALL fft_3d_inplace(fft_scratch%fft_plan(1), norm, zin)
870 ELSE
871 CALL fft_3d_inplace(fft_scratch%fft_plan(2), norm, zin)
872 END IF
873 ELSE
874 IF (fsign) THEN
875 CALL fft_3d(fft_scratch%fft_plan(3), norm, zin, zout)
876 ELSE
877 CALL fft_3d(fft_scratch%fft_plan(4), norm, zin, zout)
878 END IF
879 END IF
880
881 CALL release_fft_scratch(fft_scratch)
882
883 IF (PRESENT(zout)) THEN
884 lo(1) = SIZE(zout, 1)
885 lo(2) = SIZE(zout, 2)
886 lo(3) = SIZE(zout, 3)
887 IF (n(1) /= lo(1) .OR. n(2) /= lo(2) .OR. n(3) /= lo(3)) THEN
888 cpabort("Size and dimension (zout) have to be the same.")
889 END IF
890 END IF
891
892 IF (test .AND. output_unit > 0) THEN
893 IF (PRESENT(zout)) THEN
894 out_sum = sum(abs(zout))
895 WRITE (output_unit, '(A)') " Out of place 3D FFT (local) : fft3d_s"
896 WRITE (output_unit, '(A,T60,3I7)') " Transform lengths ", n
897 WRITE (output_unit, '(A,T60,3I7)') " Input array dimensions ", ld
898 WRITE (output_unit, '(A,T60,3I7)') " Output array dimensions ", lo
899 WRITE (output_unit, '(A,T61,E20.14)') " Sum of input data ", in_sum
900 WRITE (output_unit, '(A,T61,E20.14)') " Sum of output data ", out_sum
901 ELSE
902 out_sum = sum(abs(zin))
903 WRITE (output_unit, '(A)') " In place 3D FFT (local) : fft3d_s"
904 WRITE (output_unit, '(A,T60,3I7)') " Transform lengths ", n
905 WRITE (output_unit, '(A,T60,3I7)') " Input/output array dimensions ", ld
906 WRITE (output_unit, '(A,T61,E20.14)') " Sum of input data ", in_sum
907 WRITE (output_unit, '(A,T61,E20.14)') " Sum of output data ", out_sum
908 END IF
909 END IF
910
911 CALL timestop(handle)
912
913 END SUBROUTINE fft3d_s
914
915! **************************************************************************************************
916!> \brief ...
917!> \param fsign ...
918!> \param n ...
919!> \param cin ...
920!> \param gin ...
921!> \param rs_group ...
922!> \param yzp ...
923!> \param nyzray ...
924!> \param bo ...
925!> \param debug ...
926! **************************************************************************************************
927 SUBROUTINE fft3d_ps(fsign, n, cin, gin, rs_group, yzp, nyzray, &
928 bo, debug)
929
930 LOGICAL, INTENT(IN) :: fsign
931 INTEGER, DIMENSION(:), INTENT(IN) :: n
932 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
933 INTENT(INOUT) :: cin
934 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
935 INTENT(INOUT) :: gin
936 TYPE(mp_cart_type), INTENT(IN) :: rs_group
937 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
938 INTENT(IN) :: yzp
939 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: nyzray
940 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:, :), &
941 INTENT(IN) :: bo
942 LOGICAL, INTENT(IN), OPTIONAL :: debug
943
944 CHARACTER(LEN=*), PARAMETER :: routineN = 'fft3d_ps'
945
946 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
947 POINTER :: pbuf, qbuf, rbuf, sbuf
948 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
949 POINTER :: tbuf
950 INTEGER :: g_pos, handle, lg, lmax, mcx2, mcz1, mcz2, mg, mmax, mx1, mx2, my1, mz2, n1, n2, &
951 nmax, numtask, nx, ny, nz, output_unit, r_dim(2), r_pos(2), rp
952 INTEGER, ALLOCATABLE, DIMENSION(:) :: p2p
953 LOGICAL :: test
954 REAL(KIND=dp) :: norm, sum_data
955 TYPE(fft_scratch_sizes) :: fft_scratch_size
956 TYPE(fft_scratch_type), POINTER :: fft_scratch
957
958 CALL timeset(routinen, handle)
959 output_unit = cp_logger_get_default_io_unit()
960
961 IF (PRESENT(debug)) THEN
962 test = debug
963 ELSE
964 test = .false.
965 END IF
966
967 g_pos = rs_group%mepos
968 numtask = rs_group%num_pe
969 r_dim = rs_group%num_pe_cart
970 r_pos = rs_group%mepos_cart
971
972 IF (fsign) THEN
973 norm = 1.0_dp/real(product(n), kind=dp)
974 ELSE
975 norm = 1.0_dp
976 END IF
977
978 lg = SIZE(gin, 1)
979 mg = SIZE(gin, 2)
980
981 nx = SIZE(cin, 1)
982 ny = SIZE(cin, 2)
983 nz = SIZE(cin, 3)
984
985 IF (mg == 0) THEN
986 mmax = 1
987 ELSE
988 mmax = mg
989 END IF
990 lmax = max(lg, (nx*ny*nz)/mmax + 1)
991
992 ALLOCATE (p2p(0:numtask - 1))
993
994 CALL rs_group%rank_compare(rs_group, p2p)
995
996 rp = p2p(g_pos)
997 mx1 = bo(2, 1, rp, 1) - bo(1, 1, rp, 1) + 1
998 my1 = bo(2, 2, rp, 1) - bo(1, 2, rp, 1) + 1
999 mx2 = bo(2, 1, rp, 2) - bo(1, 1, rp, 2) + 1
1000 mz2 = bo(2, 3, rp, 2) - bo(1, 3, rp, 2) + 1
1001
1002 n1 = maxval(bo(2, 1, :, 1) - bo(1, 1, :, 1) + 1)
1003 n2 = maxval(bo(2, 2, :, 1) - bo(1, 2, :, 1) + 1)
1004 nmax = max((2*n2)/numtask, 2)*mx2*mz2
1005 nmax = max(nmax, n1*maxval(nyzray))
1006 n1 = maxval(bo(2, 1, :, 2))
1007 n2 = maxval(bo(2, 3, :, 2))
1008
1009 fft_scratch_size%nx = nx
1010 fft_scratch_size%ny = ny
1011 fft_scratch_size%nz = nz
1012 fft_scratch_size%lmax = lmax
1013 fft_scratch_size%mmax = mmax
1014 fft_scratch_size%mx1 = mx1
1015 fft_scratch_size%mx2 = mx2
1016 fft_scratch_size%my1 = my1
1017 fft_scratch_size%mz2 = mz2
1018 fft_scratch_size%lg = lg
1019 fft_scratch_size%mg = mg
1020 fft_scratch_size%nbx = n1
1021 fft_scratch_size%nbz = n2
1022 mcz1 = maxval(bo(2, 3, :, 1) - bo(1, 3, :, 1) + 1)
1023 mcx2 = maxval(bo(2, 1, :, 2) - bo(1, 1, :, 2) + 1)
1024 mcz2 = maxval(bo(2, 3, :, 2) - bo(1, 3, :, 2) + 1)
1025 fft_scratch_size%mcz1 = mcz1
1026 fft_scratch_size%mcx2 = mcx2
1027 fft_scratch_size%mcz2 = mcz2
1028 fft_scratch_size%nmax = nmax
1029 fft_scratch_size%nmray = maxval(nyzray)
1030 fft_scratch_size%nyzray = nyzray(g_pos)
1031 fft_scratch_size%rs_group = rs_group
1032 fft_scratch_size%g_pos = g_pos
1033 fft_scratch_size%r_pos = r_pos
1034 fft_scratch_size%r_dim = r_dim
1035 fft_scratch_size%numtask = numtask
1036
1037 IF (test) THEN
1038 IF (g_pos == 0 .AND. output_unit > 0) THEN
1039 WRITE (output_unit, '(A)') " Parallel 3D FFT : fft3d_ps"
1040 WRITE (output_unit, '(A,T60,3I7)') " Transform lengths ", n
1041 WRITE (output_unit, '(A,T67,2I7)') " Array dimensions (gin) ", lg, mg
1042 WRITE (output_unit, '(A,T60,3I7)') " Array dimensions (cin) ", nx, ny, nz
1043 END IF
1044 END IF
1045
1046 IF (r_dim(2) > 1) THEN
1047
1048 !
1049 ! real space is distributed over x and y coordinate
1050 ! we have two stages of communication
1051 !
1052
1053 IF (r_dim(1) == 1) THEN
1054 cpabort("This processor distribution is not supported.")
1055 END IF
1056 CALL get_fft_scratch(fft_scratch, tf_type=300, n=n, fft_sizes=fft_scratch_size)
1057
1058 IF (fsign) THEN
1059 ! cin -> gin
1060
1061 IF (test) THEN
1062 sum_data = abs(sum(cin))
1063 CALL rs_group%sum(sum_data)
1064 IF (g_pos == 0 .AND. output_unit > 0) THEN
1065 WRITE (output_unit, '(A)') " Two step communication algorithm "
1066 WRITE (output_unit, '(A,T60,3I7)') " Transform Z ", n(3), mx1*my1
1067 WRITE (output_unit, '(A,T60,3I7)') " Transform Y ", n(2), mx2*mz2
1068 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), nyzray(g_pos)
1069 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1070 END IF
1071 END IF
1072
1073 pbuf => fft_scratch%p1buf
1074 qbuf => fft_scratch%p2buf
1075
1076 ! FFT along z
1077 CALL fft_1d(fft_scratch%fft_plan(1), cin, qbuf, norm)
1078
1079 rbuf => fft_scratch%p3buf
1080
1081 IF (test) THEN
1082 sum_data = abs(sum(qbuf))
1083 CALL rs_group%sum(sum_data)
1084 IF (g_pos == 0 .AND. output_unit > 0) THEN
1085 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) T", sum_data
1086 END IF
1087 END IF
1088
1089 ! Exchange data ( transpose of matrix )
1090 CALL cube_transpose_2(qbuf, bo(:, :, :, 1), bo(:, :, :, 2), rbuf, fft_scratch)
1091
1092 IF (test) THEN
1093 sum_data = abs(sum(rbuf))
1094 CALL rs_group%sum(sum_data)
1095 IF (g_pos == 0 .AND. output_unit > 0) THEN
1096 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) T", sum_data
1097 END IF
1098 END IF
1099
1100 pbuf => fft_scratch%p4buf
1101
1102 ! FFT along y
1103 CALL fft_1d(fft_scratch%fft_plan(2), rbuf, pbuf, 1.0_dp)
1104
1105 qbuf => fft_scratch%p5buf
1106
1107 IF (test) THEN
1108 sum_data = abs(sum(pbuf))
1109 CALL rs_group%sum(sum_data)
1110 IF (g_pos == 0 .AND. output_unit > 0) THEN
1111 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) TS", sum_data
1112 END IF
1113 END IF
1114
1115 ! Exchange data ( transpose of matrix ) and sort
1116 CALL xz_to_yz(pbuf, rs_group, r_dim, g_pos, p2p, yzp, nyzray, &
1117 bo(:, :, :, 2), qbuf, fft_scratch)
1118
1119 IF (test) THEN
1120 sum_data = abs(sum(qbuf))
1121 CALL rs_group%sum(sum_data)
1122 IF (g_pos == 0 .AND. output_unit > 0) THEN
1123 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(5) TS", sum_data
1124 END IF
1125 END IF
1126
1127 ! FFT along x
1128 CALL fft_1d(fft_scratch%fft_plan(3), qbuf, gin, 1.0_dp)
1129
1130 IF (test) THEN
1131 sum_data = abs(sum(gin))
1132 CALL rs_group%sum(sum_data)
1133 IF (g_pos == 0 .AND. output_unit > 0) THEN
1134 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(6) ", sum_data
1135 END IF
1136 END IF
1137
1138 ELSE
1139 ! gin -> cin
1140
1141 IF (test) THEN
1142 sum_data = abs(sum(gin))
1143 CALL rs_group%sum(sum_data)
1144 IF (g_pos == 0 .AND. output_unit > 0) THEN
1145 WRITE (output_unit, '(A)') " Two step communication algorithm "
1146 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), nyzray(g_pos)
1147 WRITE (output_unit, '(A,T60,3I7)') " Transform Y ", n(2), mx2*mz2
1148 WRITE (output_unit, '(A,T60,3I7)') " Transform Z ", n(3), mx1*my1
1149 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1150 END IF
1151 END IF
1152
1153 pbuf => fft_scratch%p7buf
1154
1155 ! FFT along x
1156 CALL fft_1d(fft_scratch%fft_plan(4), gin, pbuf, norm)
1157
1158 qbuf => fft_scratch%p4buf
1159
1160 IF (test) THEN
1161 sum_data = abs(sum(pbuf))
1162 CALL rs_group%sum(sum_data)
1163 IF (g_pos == 0 .AND. output_unit > 0) THEN
1164 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) TS", sum_data
1165 END IF
1166 END IF
1167
1168 ! Exchange data ( transpose of matrix ) and sort
1169 CALL yz_to_xz(pbuf, rs_group, r_dim, g_pos, p2p, yzp, nyzray, &
1170 bo(:, :, :, 2), qbuf, fft_scratch)
1171
1172 IF (test) THEN
1173 sum_data = abs(sum(qbuf))
1174 CALL rs_group%sum(sum_data)
1175 IF (g_pos == 0 .AND. output_unit > 0) THEN
1176 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) TS", sum_data
1177 END IF
1178 END IF
1179
1180 rbuf => fft_scratch%p3buf
1181
1182 ! FFT along y
1183 CALL fft_1d(fft_scratch%fft_plan(5), qbuf, rbuf, 1.0_dp)
1184
1185 pbuf => fft_scratch%p2buf
1186
1187 IF (test) THEN
1188 sum_data = abs(sum(rbuf))
1189 CALL rs_group%sum(sum_data)
1190 IF (g_pos == 0 .AND. output_unit > 0) THEN
1191 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) T", sum_data
1192 END IF
1193 END IF
1194
1195 ! Exchange data ( transpose of matrix )
1196 CALL cube_transpose_1(rbuf, bo(:, :, :, 2), bo(:, :, :, 1), pbuf, fft_scratch)
1197
1198 IF (test) THEN
1199 sum_data = abs(sum(pbuf))
1200 CALL rs_group%sum(sum_data)
1201 IF (g_pos == 0 .AND. output_unit > 0) THEN
1202 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(5) T", sum_data
1203 END IF
1204 END IF
1205
1206 qbuf => fft_scratch%p1buf
1207
1208 ! FFT along z
1209 CALL fft_1d(fft_scratch%fft_plan(6), pbuf, cin, 1.0_dp)
1210
1211 IF (test) THEN
1212 sum_data = abs(sum(cin))
1213 CALL rs_group%sum(sum_data)
1214 IF (g_pos == 0 .AND. output_unit > 0) THEN
1215 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(6) ", sum_data
1216 END IF
1217 END IF
1218 END IF
1219
1220 CALL release_fft_scratch(fft_scratch)
1221
1222 ELSE
1223
1224 !
1225 ! real space is only distributed over x coordinate
1226 ! we have one stage of communication, after the transform of
1227 ! direction x
1228 !
1229
1230 CALL get_fft_scratch(fft_scratch, tf_type=200, n=n, fft_sizes=fft_scratch_size)
1231
1232 sbuf => fft_scratch%r1buf
1233 tbuf => fft_scratch%tbuf
1234
1235 sbuf = z_zero
1236 tbuf = z_zero
1237
1238 IF (fsign) THEN
1239 ! cin -> gin
1240
1241 IF (test) THEN
1242 sum_data = abs(sum(cin))
1243 CALL rs_group%sum(sum_data)
1244 IF (g_pos == 0 .AND. output_unit > 0) THEN
1245 WRITE (output_unit, '(A)') " One step communication algorithm "
1246 WRITE (output_unit, '(A,T60,3I7)') " Transform YZ ", n(2), n(3), nx
1247 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), nyzray(g_pos)
1248 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1249 END IF
1250 END IF
1251
1252 ! FFT along y and z
1253 CALL fft_2d(fft_scratch%fft_plan(1), cin, tbuf, 1._dp)
1254
1255 IF (test) THEN
1256 sum_data = abs(sum(tbuf))
1257 CALL rs_group%sum(sum_data)
1258 IF (g_pos == 0 .AND. output_unit > 0) THEN
1259 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) TS", sum_data
1260 END IF
1261 END IF
1262
1263 ! Exchange data ( transpose of matrix ) and sort
1264 CALL yz_to_x(tbuf, rs_group, g_pos, p2p, yzp, nyzray, &
1265 bo(:, :, :, 2), sbuf, fft_scratch)
1266
1267 IF (test) THEN
1268 sum_data = abs(sum(sbuf))
1269 CALL rs_group%sum(sum_data)
1270 IF (g_pos == 0 .AND. output_unit > 0) THEN
1271 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) TS", sum_data
1272 END IF
1273 END IF
1274 ! FFT along x
1275 CALL fft_1d(fft_scratch%fft_plan(3), sbuf, gin, norm)
1276
1277 IF (test) THEN
1278 sum_data = abs(sum(gin))
1279 CALL rs_group%sum(sum_data)
1280 IF (g_pos == 0 .AND. output_unit > 0) THEN
1281 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) ", sum_data
1282 END IF
1283 END IF
1284
1285 ELSE
1286 ! gin -> cin
1287
1288 IF (test) THEN
1289 sum_data = abs(sum(gin))
1290 CALL rs_group%sum(sum_data)
1291 IF (g_pos == 0 .AND. output_unit > 0) THEN
1292 WRITE (output_unit, '(A)') " One step communication algorithm "
1293 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), nyzray(g_pos)
1294 WRITE (output_unit, '(A,T60,3I7)') " Transform YZ ", n(2), n(3), nx
1295 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1296 END IF
1297 END IF
1298
1299 ! FFT along x
1300 CALL fft_1d(fft_scratch%fft_plan(4), gin, sbuf, norm)
1301
1302 IF (test) THEN
1303 sum_data = abs(sum(sbuf))
1304 CALL rs_group%sum(sum_data)
1305 IF (g_pos == 0 .AND. output_unit > 0) THEN
1306 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) TS", sum_data
1307 END IF
1308 END IF
1309
1310 ! Exchange data ( transpose of matrix ) and sort
1311 CALL x_to_yz(sbuf, rs_group, g_pos, p2p, yzp, nyzray, &
1312 bo(:, :, :, 2), tbuf, fft_scratch)
1313
1314 IF (test) THEN
1315 sum_data = abs(sum(tbuf))
1316 CALL rs_group%sum(sum_data)
1317 IF (g_pos == 0 .AND. output_unit > 0) THEN
1318 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) TS", sum_data
1319 END IF
1320 END IF
1321
1322 ! FFT along y and z
1323 CALL fft_2d(fft_scratch%fft_plan(5), tbuf, cin, 1._dp)
1324
1325 IF (test) THEN
1326 sum_data = abs(sum(cin))
1327 CALL rs_group%sum(sum_data)
1328 IF (g_pos == 0 .AND. output_unit > 0) THEN
1329 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) ", sum_data
1330 END IF
1331 END IF
1332 END IF
1333
1334 CALL release_fft_scratch(fft_scratch)
1335
1336 END IF
1337
1338 DEALLOCATE (p2p)
1339
1340 CALL timestop(handle)
1341
1342 END SUBROUTINE fft3d_ps
1343
1344! **************************************************************************************************
1345!> \brief ...
1346!> \param fsign ...
1347!> \param n ...
1348!> \param zin ...
1349!> \param gin ...
1350!> \param group ...
1351!> \param bo ...
1352!> \param debug ...
1353! **************************************************************************************************
1354 SUBROUTINE fft3d_pb(fsign, n, zin, gin, group, bo, debug)
1355
1356 LOGICAL, INTENT(IN) :: fsign
1357 INTEGER, DIMENSION(3), INTENT(IN) :: n
1358 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
1359 INTENT(INOUT) :: zin
1360 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1361 INTENT(INOUT) :: gin
1362 TYPE(mp_cart_type), INTENT(IN) :: group
1363 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:, :), &
1364 INTENT(IN) :: bo
1365 LOGICAL, INTENT(IN), OPTIONAL :: debug
1366
1367 CHARACTER(LEN=*), PARAMETER :: routineN = 'fft3d_pb'
1368
1369 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1370 POINTER :: abuf, bbuf
1371 INTEGER :: handle, lg(2), lz(3), mcx2, mcy3, mcz1, &
1372 mcz2, mx1, mx2, mx3, my1, my2, my3, &
1373 my_pos, mz1, mz2, mz3, output_unit
1374 INTEGER, DIMENSION(2) :: dim
1375 LOGICAL :: test
1376 REAL(KIND=dp) :: norm, sum_data
1377 TYPE(fft_scratch_sizes) :: fft_scratch_size
1378 TYPE(fft_scratch_type), POINTER :: fft_scratch
1379
1380!------------------------------------------------------------------------------
1381! "Real Space" 1) xyZ or 1) xYZ
1382! 2) xYz or not used
1383! "G Space" 3) Xyz or 3) XYz
1384!
1385! There is one communicator (2-dimensional) for all distributions
1386! np = n1 * n2, where np is the total number of processors
1387! If n2 = 1, we have the second case and only one transpose step is needed
1388!
1389! Assignment of dimensions to axis for different steps
1390! First case: 1) n1=x; n2=y
1391! 2) n1=x; n2=z
1392! 3) n1=y; n2=z
1393! Second case 1) n1=x
1394! 3) n1=z
1395!
1396! The more general case with two communicators for the initial and final
1397! distribution is not covered.
1398!------------------------------------------------------------------------------
1399
1400 CALL timeset(routinen, handle)
1401 output_unit = cp_logger_get_default_io_unit()
1402
1403 dim = group%num_pe_cart
1404 my_pos = group%mepos
1405
1406 IF (PRESENT(debug)) THEN
1407 test = debug
1408 ELSE
1409 test = .false.
1410 END IF
1411
1412 IF (fsign) THEN
1413 norm = 1.0_dp/real(product(n), kind=dp)
1414 ELSE
1415 norm = 1.0_dp
1416 END IF
1417
1418 IF (test) THEN
1419 lg(1) = SIZE(gin, 1)
1420 lg(2) = SIZE(gin, 2)
1421 lz(1) = SIZE(zin, 1)
1422 lz(2) = SIZE(zin, 2)
1423 lz(3) = SIZE(zin, 3)
1424 IF (my_pos == 0 .AND. output_unit > 0) THEN
1425 WRITE (output_unit, '(A)') " Parallel 3D FFT : fft3d_pb"
1426 WRITE (output_unit, '(A,T60,3I7)') " Transform lengths ", n
1427 WRITE (output_unit, '(A,T67,2I7)') " Array dimensions (gin) ", lg
1428 WRITE (output_unit, '(A,T60,3I7)') " Array dimensions (cin) ", lz
1429 END IF
1430 END IF
1431
1432 mx1 = bo(2, 1, my_pos, 1) - bo(1, 1, my_pos, 1) + 1
1433 my1 = bo(2, 2, my_pos, 1) - bo(1, 2, my_pos, 1) + 1
1434 mz1 = bo(2, 3, my_pos, 1) - bo(1, 3, my_pos, 1) + 1
1435 mx2 = bo(2, 1, my_pos, 2) - bo(1, 1, my_pos, 2) + 1
1436 my2 = bo(2, 2, my_pos, 2) - bo(1, 2, my_pos, 2) + 1
1437 mz2 = bo(2, 3, my_pos, 2) - bo(1, 3, my_pos, 2) + 1
1438 mx3 = bo(2, 1, my_pos, 3) - bo(1, 1, my_pos, 3) + 1
1439 my3 = bo(2, 2, my_pos, 3) - bo(1, 2, my_pos, 3) + 1
1440 mz3 = bo(2, 3, my_pos, 3) - bo(1, 3, my_pos, 3) + 1
1441 fft_scratch_size%mx1 = mx1
1442 fft_scratch_size%mx2 = mx2
1443 fft_scratch_size%mx3 = mx3
1444 fft_scratch_size%my1 = my1
1445 fft_scratch_size%my2 = my2
1446 fft_scratch_size%my3 = my3
1447 fft_scratch_size%mz1 = mz1
1448 fft_scratch_size%mz2 = mz2
1449 fft_scratch_size%mz3 = mz3
1450 mcz1 = maxval(bo(2, 3, :, 1) - bo(1, 3, :, 1) + 1)
1451 mcx2 = maxval(bo(2, 1, :, 2) - bo(1, 1, :, 2) + 1)
1452 mcz2 = maxval(bo(2, 3, :, 2) - bo(1, 3, :, 2) + 1)
1453 mcy3 = maxval(bo(2, 2, :, 3) - bo(1, 2, :, 3) + 1)
1454 fft_scratch_size%mcz1 = mcz1
1455 fft_scratch_size%mcx2 = mcx2
1456 fft_scratch_size%mcz2 = mcz2
1457 fft_scratch_size%mcy3 = mcy3
1458 fft_scratch_size%rs_group = group
1459 fft_scratch_size%g_pos = my_pos
1460 fft_scratch_size%numtask = dim(1)*dim(2)
1461
1462 IF (dim(1) > 1 .AND. dim(2) > 1) THEN
1463
1464 !
1465 ! First case; two stages of communication
1466 !
1467
1468 CALL get_fft_scratch(fft_scratch, tf_type=100, n=n, fft_sizes=fft_scratch_size)
1469
1470 IF (fsign) THEN
1471 ! Stage 1 -> 3
1472
1473 bbuf => fft_scratch%a2buf
1474
1475 IF (test) THEN
1476 sum_data = abs(sum(zin))
1477 CALL group%sum(sum_data)
1478 IF (my_pos == 0 .AND. output_unit > 0) THEN
1479 WRITE (output_unit, '(A)') " Two step communication algorithm "
1480 WRITE (output_unit, '(A,T67,2I7)') " Transform Z ", n(3), mx1*my1
1481 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1482 END IF
1483 END IF
1484
1485 ! FFT along z
1486 CALL fft_1d(fft_scratch%fft_plan(1), zin, bbuf, norm)
1487
1488 abuf => fft_scratch%a3buf
1489
1490 IF (test) THEN
1491 sum_data = abs(sum(bbuf))
1492 CALL group%sum(sum_data)
1493 IF (my_pos == 0 .AND. output_unit > 0) THEN
1494 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) T", sum_data
1495 END IF
1496 END IF
1497
1498 CALL cube_transpose_2(bbuf, bo(:, :, :, 1), bo(:, :, :, 2), abuf, fft_scratch)
1499
1500 bbuf => fft_scratch%a4buf
1501
1502 IF (test) THEN
1503 sum_data = abs(sum(abuf))
1504 CALL group%sum(sum_data)
1505 IF (my_pos == 0 .AND. output_unit > 0) THEN
1506 WRITE (output_unit, '(A,T67,2I7)') " Transform Y ", n(2), mx2*mz2
1507 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) ", sum_data
1508 END IF
1509 END IF
1510
1511 ! FFT along y
1512 CALL fft_1d(fft_scratch%fft_plan(2), abuf, bbuf, 1.0_dp)
1513
1514 abuf => fft_scratch%a5buf
1515
1516 IF (test) THEN
1517 sum_data = abs(sum(bbuf))
1518 CALL group%sum(sum_data)
1519 IF (my_pos == 0 .AND. output_unit > 0) THEN
1520 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) T", sum_data
1521 END IF
1522 END IF
1523
1524 CALL cube_transpose_4(bbuf, bo(:, :, :, 2), bo(:, :, :, 3), abuf, fft_scratch)
1525
1526 IF (test) THEN
1527 sum_data = abs(sum(abuf))
1528 CALL group%sum(sum_data)
1529 IF (my_pos == 0 .AND. output_unit > 0) THEN
1530 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), my3*mz3
1531 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(5) ", sum_data
1532 END IF
1533 END IF
1534
1535 ! FFT along x
1536 CALL fft_1d(fft_scratch%fft_plan(3), abuf, gin, 1.0_dp)
1537
1538 IF (test) THEN
1539 sum_data = abs(sum(gin))
1540 CALL group%sum(sum_data)
1541 IF (my_pos == 0 .AND. output_unit > 0) THEN
1542 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(6) ", sum_data
1543 END IF
1544 END IF
1545
1546 ELSE
1547 ! Stage 3 -> 1
1548
1549 bbuf => fft_scratch%a5buf
1550
1551 IF (test) THEN
1552 sum_data = abs(sum(gin))
1553 CALL group%sum(sum_data)
1554 IF (my_pos == 0 .AND. output_unit > 0) THEN
1555 WRITE (output_unit, '(A)') " Two step communication algorithm "
1556 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), my3*mz3
1557 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1558 END IF
1559 END IF
1560
1561 ! FFT along x
1562 CALL fft_1d(fft_scratch%fft_plan(4), gin, bbuf, 1.0_dp)
1563
1564 abuf => fft_scratch%a4buf
1565
1566 IF (test) THEN
1567 sum_data = abs(sum(bbuf))
1568 CALL group%sum(sum_data)
1569 IF (my_pos == 0 .AND. output_unit > 0) THEN
1570 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) T", sum_data
1571 END IF
1572 END IF
1573
1574 CALL cube_transpose_3(bbuf, bo(:, :, :, 3), bo(:, :, :, 2), abuf, fft_scratch)
1575
1576 bbuf => fft_scratch%a3buf
1577
1578 IF (test) THEN
1579 sum_data = abs(sum(abuf))
1580 CALL group%sum(sum_data)
1581 IF (my_pos == 0 .AND. output_unit > 0) THEN
1582 WRITE (output_unit, '(A,T67,2I7)') " Transform Y ", n(2), mx2*mz2
1583 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) ", sum_data
1584 END IF
1585 END IF
1586
1587 ! FFT along y
1588 CALL fft_1d(fft_scratch%fft_plan(5), abuf, bbuf, 1.0_dp)
1589
1590 abuf => fft_scratch%a2buf
1591
1592 IF (test) THEN
1593 sum_data = abs(sum(bbuf))
1594 CALL group%sum(sum_data)
1595 IF (my_pos == 0 .AND. output_unit > 0) THEN
1596 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) T", sum_data
1597 END IF
1598 END IF
1599
1600 CALL cube_transpose_1(bbuf, bo(:, :, :, 2), bo(:, :, :, 1), abuf, fft_scratch)
1601
1602 IF (test) THEN
1603 sum_data = abs(sum(abuf))
1604 CALL group%sum(sum_data)
1605 IF (my_pos == 0 .AND. output_unit > 0) THEN
1606 WRITE (output_unit, '(A,T67,2I7)') " Transform Z ", n(3), mx1*my1
1607 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(5) ", sum_data
1608 END IF
1609 END IF
1610
1611 ! FFT along z
1612 CALL fft_1d(fft_scratch%fft_plan(6), abuf, zin, norm)
1613
1614 IF (test) THEN
1615 sum_data = abs(sum(zin))
1616 CALL group%sum(sum_data)
1617 IF (my_pos == 0 .AND. output_unit > 0) THEN
1618 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(6) ", sum_data
1619 END IF
1620 END IF
1621 END IF
1622
1623 CALL release_fft_scratch(fft_scratch)
1624
1625 ELSE IF (dim(2) == 1) THEN
1626
1627 !
1628 ! Second case; one stage of communication
1629 !
1630
1631 CALL get_fft_scratch(fft_scratch, tf_type=101, n=n, fft_sizes=fft_scratch_size)
1632
1633 IF (fsign) THEN
1634 ! Stage 1 -> 3
1635
1636 IF (test) THEN
1637 sum_data = abs(sum(zin))
1638 CALL group%sum(sum_data)
1639 IF (my_pos == 0 .AND. output_unit > 0) THEN
1640 WRITE (output_unit, '(A)') " one step communication algorithm "
1641 WRITE (output_unit, '(A,T67,2I7)') " Transform Z ", n(3), mx1*my1
1642 WRITE (output_unit, '(A,T67,2I7)') " Transform Y ", n(2), mx1*mz1
1643 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1644 END IF
1645 END IF
1646
1647 bbuf => fft_scratch%a4buf
1648 ! FFT along z and y
1649 CALL fft_2d(fft_scratch%fft_plan(1), zin, bbuf, norm)
1650
1651 abuf => fft_scratch%a5buf
1652
1653 IF (test) THEN
1654 sum_data = abs(sum(bbuf))
1655 CALL group%sum(sum_data)
1656 IF (my_pos == 0 .AND. output_unit > 0) THEN
1657 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) T", sum_data
1658 END IF
1659 END IF
1660
1661 CALL cube_transpose_6(bbuf, group, bo(:, :, :, 1), bo(:, :, :, 3), abuf, fft_scratch)
1662
1663 IF (test) THEN
1664 sum_data = abs(sum(abuf))
1665 CALL group%sum(sum_data)
1666 IF (my_pos == 0 .AND. output_unit > 0) THEN
1667 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), my3*mz3
1668 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) ", sum_data
1669 END IF
1670 END IF
1671
1672 ! FFT along x
1673 CALL fft_1d(fft_scratch%fft_plan(3), abuf, gin, 1.0_dp)
1674
1675 IF (test) THEN
1676 sum_data = abs(sum(gin))
1677 CALL group%sum(sum_data)
1678 IF (my_pos == 0 .AND. output_unit > 0) THEN
1679 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) ", sum_data
1680 END IF
1681 END IF
1682
1683 ELSE
1684 ! Stage 3 -> 1
1685
1686 IF (test) THEN
1687 sum_data = abs(sum(gin))
1688 CALL group%sum(sum_data)
1689 IF (my_pos == 0 .AND. output_unit > 0) THEN
1690 WRITE (output_unit, '(A)') " one step communication algorithm "
1691 WRITE (output_unit, '(A,T67,2I7)') " Transform X ", n(1), my3*mz3
1692 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(1) ", sum_data
1693 END IF
1694 END IF
1695
1696 bbuf => fft_scratch%a5buf
1697
1698 ! FFT along x
1699 CALL fft_1d(fft_scratch%fft_plan(4), gin, bbuf, 1.0_dp)
1700
1701 abuf => fft_scratch%a4buf
1702
1703 IF (test) THEN
1704 sum_data = abs(sum(bbuf))
1705 CALL group%sum(sum_data)
1706 IF (my_pos == 0 .AND. output_unit > 0) THEN
1707 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(2) T", sum_data
1708 END IF
1709 END IF
1710
1711 CALL cube_transpose_5(bbuf, group, bo(:, :, :, 3), bo(:, :, :, 1), abuf, fft_scratch)
1712
1713 IF (test) THEN
1714 sum_data = abs(sum(abuf))
1715 CALL group%sum(sum_data)
1716 IF (my_pos == 0 .AND. output_unit > 0) THEN
1717 WRITE (output_unit, '(A,T67,2I7)') " Transform Y ", n(2), mx1*mz1
1718 WRITE (output_unit, '(A,T67,2I7)') " Transform Z ", n(3), mx1*my1
1719 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(3) ", sum_data
1720 END IF
1721 END IF
1722
1723 ! FFT along y and z
1724 CALL fft_2d(fft_scratch%fft_plan(5), abuf, zin, norm)
1725
1726 IF (test) THEN
1727 sum_data = abs(sum(zin))
1728 CALL group%sum(sum_data)
1729 IF (my_pos == 0 .AND. output_unit > 0) THEN
1730 WRITE (output_unit, '(A,T61,E20.14)') " Sum of data(4) ", sum_data
1731 END IF
1732 END IF
1733 END IF
1734
1735 CALL release_fft_scratch(fft_scratch)
1736
1737 ELSE
1738
1739 cpabort("Partition not implemented.")
1740
1741 END IF
1742
1743 CALL timestop(handle)
1744
1745 END SUBROUTINE fft3d_pb
1746
1747! **************************************************************************************************
1748!> \brief ...
1749!> \param sb ...
1750!> \param group ...
1751!> \param my_pos ...
1752!> \param p2p ...
1753!> \param yzp ...
1754!> \param nray ...
1755!> \param bo ...
1756!> \param tb ...
1757!> \param fft_scratch ...
1758!> \par History
1759!> 15. Feb. 2006 : single precision all_to_all
1760!> \author JGH (14-Jan-2001)
1761! **************************************************************************************************
1762 SUBROUTINE x_to_yz(sb, group, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
1763
1764 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1765 INTENT(IN) :: sb
1766 CLASS(mp_comm_type), INTENT(IN) :: group
1767 INTEGER, INTENT(IN) :: my_pos
1768 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: p2p
1769 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
1770 INTENT(IN) :: yzp
1771 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: nray
1772 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
1773 INTENT(IN) :: bo
1774 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
1775 INTENT(INOUT) :: tb
1776 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
1777
1778 CHARACTER(LEN=*), PARAMETER :: routinen = 'x_to_yz'
1779
1780 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1781 POINTER :: rr
1782 COMPLEX(KIND=sp), CONTIGUOUS, DIMENSION(:, :), &
1783 POINTER :: ss, tt
1784 INTEGER :: handle, ip, ir, ix, ixx, iy, iz, mpr, &
1785 nm, np, nr, nx
1786 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
1787
1788 CALL timeset(routinen, handle)
1789
1790 np = SIZE(p2p)
1791 scount => fft_scratch%scount
1792 rcount => fft_scratch%rcount
1793 sdispl => fft_scratch%sdispl
1794 rdispl => fft_scratch%rdispl
1795
1796 IF (alltoall_sgl) THEN
1797 ss => fft_scratch%ss
1798 tt => fft_scratch%tt
1799 ss(:, :) = cmplx(sb(:, :), kind=sp)
1800 tt(:, :) = 0._sp
1801 ELSE
1802 rr => fft_scratch%rr
1803 END IF
1804
1805 mpr = p2p(my_pos)
1806 nm = maxval(nray(0:np - 1))
1807 nr = nray(my_pos)
1808!$OMP PARALLEL DO DEFAULT(NONE), &
1809!$OMP PRIVATE(ix,nx), &
1810!$OMP SHARED(np,p2p,bo,nr,scount,sdispl)
1811 DO ip = 0, np - 1
1812 ix = p2p(ip)
1813 nx = bo(2, 1, ix) - bo(1, 1, ix) + 1
1814 scount(ip) = nr*nx
1815 sdispl(ip) = nr*(bo(1, 1, ix) - 1)
1816 END DO
1817!$OMP END PARALLEL DO
1818 nx = bo(2, 1, mpr) - bo(1, 1, mpr) + 1
1819!$OMP PARALLEL DO DEFAULT(NONE), &
1820!$OMP PRIVATE(nr), &
1821!$OMP SHARED(np,nray,nx,rcount,rdispl,nm)
1822 DO ip = 0, np - 1
1823 nr = nray(ip)
1824 rcount(ip) = nr*nx
1825 rdispl(ip) = nm*nx*ip
1826 END DO
1827!$OMP END PARALLEL DO
1828 IF (alltoall_sgl) THEN
1829 CALL group%alltoall(ss, scount, sdispl, tt, rcount, rdispl)
1830 ELSE
1831 CALL group%alltoall(sb, scount, sdispl, rr, rcount, rdispl)
1832 END IF
1833
1834 nx = bo(2, 1, mpr) - bo(1, 1, mpr) + 1
1835!$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) &
1836!$OMP PRIVATE(ixx,ir,iy,iz,ix) &
1837!$OMP SHARED(np,nray,nx,alltoall_sgl,yzp,tt,rr,tb)
1838 DO ip = 0, np - 1
1839 DO ix = 1, nx
1840 ixx = nray(ip)*(ix - 1)
1841 IF (alltoall_sgl) THEN
1842 DO ir = 1, nray(ip)
1843 iy = yzp(1, ir, ip)
1844 iz = yzp(2, ir, ip)
1845 tb(iy, iz, ix) = tt(ir + ixx, ip)
1846 END DO
1847 ELSE
1848 DO ir = 1, nray(ip)
1849 iy = yzp(1, ir, ip)
1850 iz = yzp(2, ir, ip)
1851 tb(iy, iz, ix) = rr(ir + ixx, ip)
1852 END DO
1853 END IF
1854 END DO
1855 END DO
1856!$OMP END PARALLEL DO
1857
1858 CALL timestop(handle)
1859
1860 END SUBROUTINE x_to_yz
1861
1862! **************************************************************************************************
1863!> \brief ...
1864!> \param tb ...
1865!> \param group ...
1866!> \param my_pos ...
1867!> \param p2p ...
1868!> \param yzp ...
1869!> \param nray ...
1870!> \param bo ...
1871!> \param sb ...
1872!> \param fft_scratch ...
1873!> \par History
1874!> 15. Feb. 2006 : single precision all_to_all
1875!> \author JGH (14-Jan-2001)
1876! **************************************************************************************************
1877 SUBROUTINE yz_to_x(tb, group, my_pos, p2p, yzp, nray, bo, sb, fft_scratch)
1878
1879 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
1880 INTENT(IN) :: tb
1881 CLASS(mp_comm_type), INTENT(IN) :: group
1882 INTEGER, INTENT(IN) :: my_pos
1883 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: p2p
1884 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
1885 INTENT(IN) :: yzp
1886 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: nray
1887 INTEGER, DIMENSION(:, :, 0:), INTENT(IN) :: bo
1888 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1889 INTENT(INOUT) :: sb
1890 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
1891
1892 CHARACTER(LEN=*), PARAMETER :: routinen = 'yz_to_x'
1893
1894 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1895 POINTER :: rr
1896 COMPLEX(KIND=sp), CONTIGUOUS, DIMENSION(:, :), &
1897 POINTER :: ss, tt
1898 INTEGER :: handle, ip, ir, ix, ixx, iy, iz, mpr, &
1899 nm, np, nr, nx
1900 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
1901
1902 CALL timeset(routinen, handle)
1903
1904 np = SIZE(p2p)
1905 mpr = p2p(my_pos)
1906 scount => fft_scratch%scount
1907 rcount => fft_scratch%rcount
1908 sdispl => fft_scratch%sdispl
1909 rdispl => fft_scratch%rdispl
1910
1911 IF (alltoall_sgl) THEN
1912 ss => fft_scratch%ss
1913 tt => fft_scratch%tt
1914 ss = 0._sp
1915 tt = 0._sp
1916 ELSE
1917 rr => fft_scratch%rr
1918 END IF
1919
1920 nx = bo(2, 1, mpr) - bo(1, 1, mpr) + 1
1921!$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) &
1922!$OMP PRIVATE(ip, ixx, ir, iy, iz, ix) &
1923!$OMP SHARED(np,nray,nx,alltoall_sgl,yzp,tb,tt,rr)
1924 DO ip = 0, np - 1
1925 DO ix = 1, nx
1926 ixx = nray(ip)*(ix - 1)
1927 IF (alltoall_sgl) THEN
1928 DO ir = 1, nray(ip)
1929 iy = yzp(1, ir, ip)
1930 iz = yzp(2, ir, ip)
1931 tt(ir + ixx, ip) = cmplx(tb(iy, iz, ix), kind=sp)
1932 END DO
1933 ELSE
1934 DO ir = 1, nray(ip)
1935 iy = yzp(1, ir, ip)
1936 iz = yzp(2, ir, ip)
1937 rr(ir + ixx, ip) = tb(iy, iz, ix)
1938 END DO
1939 END IF
1940 END DO
1941 END DO
1942!$OMP END PARALLEL DO
1943 nm = maxval(nray(0:np - 1))
1944 nr = nray(my_pos)
1945!$OMP PARALLEL DO DEFAULT(NONE), &
1946!$OMP PRIVATE(ix,nx), &
1947!$OMP SHARED(np,p2p,bo,rcount,rdispl,nr)
1948 DO ip = 0, np - 1
1949 ix = p2p(ip)
1950 nx = bo(2, 1, ix) - bo(1, 1, ix) + 1
1951 rcount(ip) = nr*nx
1952 rdispl(ip) = nr*(bo(1, 1, ix) - 1)
1953 END DO
1954!$OMP END PARALLEL DO
1955 nx = bo(2, 1, mpr) - bo(1, 1, mpr) + 1
1956!$OMP PARALLEL DO DEFAULT(NONE), &
1957!$OMP PRIVATE(nr), &
1958!$OMP SHARED(np,nray,scount,sdispl,nx,nm)
1959 DO ip = 0, np - 1
1960 nr = nray(ip)
1961 scount(ip) = nr*nx
1962 sdispl(ip) = nm*nx*ip
1963 END DO
1964!$OMP END PARALLEL DO
1965
1966 IF (alltoall_sgl) THEN
1967 CALL group%alltoall(tt, scount, sdispl, ss, rcount, rdispl)
1968 sb = ss
1969 ELSE
1970 CALL group%alltoall(rr, scount, sdispl, sb, rcount, rdispl)
1971 END IF
1972
1973 CALL timestop(handle)
1974
1975 END SUBROUTINE yz_to_x
1976
1977! **************************************************************************************************
1978!> \brief ...
1979!> \param sb ...
1980!> \param group ...
1981!> \param dims ...
1982!> \param my_pos ...
1983!> \param p2p ...
1984!> \param yzp ...
1985!> \param nray ...
1986!> \param bo ...
1987!> \param tb ...
1988!> \param fft_scratch ...
1989!> \par History
1990!> 15. Feb. 2006 : single precision all_to_all
1991!> \author JGH (18-Jan-2001)
1992! **************************************************************************************************
1993 SUBROUTINE yz_to_xz(sb, group, dims, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
1994
1995 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1996 INTENT(IN) :: sb
1997 CLASS(mp_comm_type), INTENT(IN) :: group
1998 INTEGER, DIMENSION(2), INTENT(IN) :: dims
1999 INTEGER, INTENT(IN) :: my_pos
2000 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: p2p
2001 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2002 INTENT(IN) :: yzp
2003 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: nray
2004 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2005 INTENT(IN) :: bo
2006 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2007 INTENT(INOUT) :: tb
2008 TYPE(fft_scratch_type), INTENT(INOUT) :: fft_scratch
2009
2010 CHARACTER(LEN=*), PARAMETER :: routinen = 'yz_to_xz'
2011
2012 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:), &
2013 POINTER :: xzbuf, yzbuf
2014 COMPLEX(KIND=sp), CONTIGUOUS, DIMENSION(:), &
2015 POINTER :: xzbuf_sgl, yzbuf_sgl
2016 INTEGER :: handle, icrs, ip, ipl, ipr, ir, ix, iz, &
2017 jj, jx, jy, jz, myx, myz, np, npx, &
2018 npz, nx, nz, rs_pos
2019 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: pzcoord, rcount, rdispl, scount, sdispl, &
2020 xcor, zcor
2021 INTEGER, CONTIGUOUS, DIMENSION(:, :), POINTER :: pgrid
2022
2023 CALL timeset(routinen, handle)
2024
2025 np = SIZE(p2p)
2026
2027 rs_pos = p2p(my_pos)
2028
2029 IF (alltoall_sgl) THEN
2030 yzbuf_sgl => fft_scratch%yzbuf_sgl
2031 xzbuf_sgl => fft_scratch%xzbuf_sgl
2032 ELSE
2033 yzbuf => fft_scratch%yzbuf
2034 xzbuf => fft_scratch%xzbuf
2035 END IF
2036 npx = dims(1)
2037 npz = dims(2)
2038 pgrid => fft_scratch%pgrid
2039 xcor => fft_scratch%xcor
2040 zcor => fft_scratch%zcor
2041 pzcoord => fft_scratch%pzcoord
2042 scount => fft_scratch%scount
2043 rcount => fft_scratch%rcount
2044 sdispl => fft_scratch%sdispl
2045 rdispl => fft_scratch%rdispl
2046
2047 nx = SIZE(sb, 2)
2048
2049! If the send and recv counts are not already cached, then
2050! calculate and store them
2051 IF (fft_scratch%in == 0) THEN
2052
2053 scount = 0
2054
2055 DO ix = 0, npx - 1
2056 ip = pgrid(ix, 0)
2057 xcor(bo(1, 1, ip):bo(2, 1, ip)) = ix
2058 END DO
2059 DO iz = 0, npz - 1
2060 ip = pgrid(0, iz)
2061 zcor(bo(1, 3, ip):bo(2, 3, ip)) = iz
2062 END DO
2063 DO jx = 1, nx
2064 IF (alltoall_sgl) THEN
2065 DO ir = 1, nray(my_pos)
2066 jy = yzp(1, ir, my_pos)
2067 jz = yzp(2, ir, my_pos)
2068 ip = pgrid(xcor(jx), zcor(jz))
2069 scount(ip) = scount(ip) + 1
2070 END DO
2071 ELSE
2072 DO ir = 1, nray(my_pos)
2073 jy = yzp(1, ir, my_pos)
2074 jz = yzp(2, ir, my_pos)
2075 ip = pgrid(xcor(jx), zcor(jz))
2076 scount(ip) = scount(ip) + 1
2077 END DO
2078 END IF
2079 END DO
2080
2081 CALL group%alltoall(scount, rcount, 1)
2082 fft_scratch%yzcount = scount
2083 fft_scratch%xzcount = rcount
2084
2085 ! Work out the correct displacements in the buffers
2086 sdispl(0) = 0
2087 rdispl(0) = 0
2088 DO ip = 1, np - 1
2089 sdispl(ip) = sdispl(ip - 1) + scount(ip - 1)
2090 rdispl(ip) = rdispl(ip - 1) + rcount(ip - 1)
2091 END DO
2092
2093 fft_scratch%yzdispl = sdispl
2094 fft_scratch%xzdispl = rdispl
2095
2096 icrs = 0
2097 DO ip = 0, np - 1
2098 IF (scount(ip) /= 0) icrs = icrs + 1
2099 IF (rcount(ip) /= 0) icrs = icrs + 1
2100 END DO
2101 CALL group%sum(icrs)
2102 fft_scratch%rsratio = real(icrs, kind=dp)/(real(2*np, kind=dp)*real(np, kind=dp))
2103
2104 fft_scratch%in = 1
2105 ELSE
2106 scount = fft_scratch%yzcount
2107 rcount = fft_scratch%xzcount
2108 sdispl = fft_scratch%yzdispl
2109 rdispl = fft_scratch%xzdispl
2110 END IF
2111
2112! Do the actual packing
2113!$OMP PARALLEL DO DEFAULT(NONE), &
2114!$OMP PRIVATE(ipl,jj,nx,ir,jx,jy,jz),&
2115!$OMP SHARED(np,p2p,pzcoord,bo,nray,yzp,zcor),&
2116!$OMP SHARED(yzbuf,sb,scount,sdispl,my_pos),&
2117!$OMP SHARED(yzbuf_sgl,alltoall_sgl)
2118 DO ip = 0, np - 1
2119 IF (scount(ip) == 0) cycle
2120 ipl = p2p(ip)
2121 jj = 0
2122 nx = bo(2, 1, ipl) - bo(1, 1, ipl) + 1
2123 DO ir = 1, nray(my_pos)
2124 jz = yzp(2, ir, my_pos)
2125 IF (zcor(jz) == pzcoord(ipl)) THEN
2126 jj = jj + 1
2127 jy = yzp(1, ir, my_pos)
2128 IF (alltoall_sgl) THEN
2129 DO jx = 0, nx - 1
2130 yzbuf_sgl(sdispl(ip) + jj + jx*scount(ip)/nx) = cmplx(sb(ir, jx + bo(1, 1, ipl)), kind=sp)
2131 END DO
2132 ELSE
2133 DO jx = 0, nx - 1
2134 yzbuf(sdispl(ip) + jj + jx*scount(ip)/nx) = sb(ir, jx + bo(1, 1, ipl))
2135 END DO
2136 END IF
2137 END IF
2138 END DO
2139 END DO
2140!$OMP END PARALLEL DO
2141
2142 IF (alltoall_sgl) THEN
2143 CALL group%alltoall(yzbuf_sgl, scount, sdispl, xzbuf_sgl, rcount, rdispl)
2144 ELSE
2145 IF (fft_scratch%rsratio < ratio_sparse_alltoall) THEN
2146 CALL sparse_alltoall(yzbuf, scount, sdispl, xzbuf, rcount, rdispl, group)
2147 ELSE
2148 CALL group%alltoall(yzbuf, scount, sdispl, xzbuf, rcount, rdispl)
2149 END IF
2150 END IF
2151
2152 myx = fft_scratch%sizes%r_pos(1)
2153 myz = fft_scratch%sizes%r_pos(2)
2154 nz = bo(2, 3, rs_pos) - bo(1, 3, rs_pos) + 1
2155
2156!$OMP PARALLEL DO DEFAULT(NONE), &
2157!$OMP PRIVATE(ipr,jj,ir,jx,jy,jz),&
2158!$OMP SHARED(tb,np,p2p,bo,rs_pos,nray),&
2159!$OMP SHARED(yzp,alltoall_sgl,zcor,myz),&
2160!$OMP SHARED(xzbuf,xzbuf_sgl,nz,rdispl)
2161 DO ip = 0, np - 1
2162 ipr = p2p(ip)
2163 jj = 0
2164 DO jx = 0, bo(2, 1, rs_pos) - bo(1, 1, rs_pos)
2165 DO ir = 1, nray(ip)
2166 jz = yzp(2, ir, ip)
2167 IF (alltoall_sgl) THEN
2168 IF (zcor(jz) == myz) THEN
2169 jj = jj + 1
2170 jy = yzp(1, ir, ip)
2171 jz = jz - bo(1, 3, rs_pos) + 1
2172 tb(jy, jz + jx*nz) = xzbuf_sgl(jj + rdispl(ipr))
2173 END IF
2174 ELSE
2175 IF (zcor(jz) == myz) THEN
2176 jj = jj + 1
2177 jy = yzp(1, ir, ip)
2178 jz = jz - bo(1, 3, rs_pos) + 1
2179 tb(jy, jz + jx*nz) = xzbuf(jj + rdispl(ipr))
2180 END IF
2181 END IF
2182 END DO
2183 END DO
2184 END DO
2185!$OMP END PARALLEL DO
2186
2187 CALL timestop(handle)
2188
2189 END SUBROUTINE yz_to_xz
2190
2191! **************************************************************************************************
2192!> \brief ...
2193!> \param sb ...
2194!> \param group ...
2195!> \param dims ...
2196!> \param my_pos ...
2197!> \param p2p ...
2198!> \param yzp ...
2199!> \param nray ...
2200!> \param bo ...
2201!> \param tb ...
2202!> \param fft_scratch ...
2203!> \par History
2204!> 15. Feb. 2006 : single precision all_to_all
2205!> \author JGH (19-Jan-2001)
2206! **************************************************************************************************
2207 SUBROUTINE xz_to_yz(sb, group, dims, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
2208
2209 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2210 INTENT(IN) :: sb
2211 CLASS(mp_comm_type), INTENT(IN) :: group
2212 INTEGER, DIMENSION(2), INTENT(IN) :: dims
2213 INTEGER, INTENT(IN) :: my_pos
2214 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: p2p
2215 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2216 INTENT(IN) :: yzp
2217 INTEGER, CONTIGUOUS, DIMENSION(0:), INTENT(IN) :: nray
2218 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2219 INTENT(IN) :: bo
2220 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2221 INTENT(INOUT) :: tb
2222 TYPE(fft_scratch_type), INTENT(INOUT) :: fft_scratch
2223
2224 CHARACTER(LEN=*), PARAMETER :: routinen = 'xz_to_yz'
2225
2226 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:), &
2227 POINTER :: xzbuf, yzbuf
2228 COMPLEX(KIND=sp), CONTIGUOUS, DIMENSION(:), &
2229 POINTER :: xzbuf_sgl, yzbuf_sgl
2230 INTEGER :: handle, icrs, ip, ipl, ir, ix, ixx, iz, &
2231 jj, jx, jy, jz, mp, myx, myz, np, npx, &
2232 npz, nx, nz
2233 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: pzcoord, rcount, rdispl, scount, sdispl, &
2234 xcor, zcor
2235 INTEGER, CONTIGUOUS, DIMENSION(:, :), POINTER :: pgrid
2236
2237 CALL timeset(routinen, handle)
2238
2239 np = SIZE(p2p)
2240
2241 IF (alltoall_sgl) THEN
2242 yzbuf_sgl => fft_scratch%yzbuf_sgl
2243 xzbuf_sgl => fft_scratch%xzbuf_sgl
2244 ELSE
2245 yzbuf => fft_scratch%yzbuf
2246 xzbuf => fft_scratch%xzbuf
2247 END IF
2248 npx = dims(1)
2249 npz = dims(2)
2250 pgrid => fft_scratch%pgrid
2251 xcor => fft_scratch%xcor
2252 zcor => fft_scratch%zcor
2253 pzcoord => fft_scratch%pzcoord
2254 scount => fft_scratch%scount
2255 rcount => fft_scratch%rcount
2256 sdispl => fft_scratch%sdispl
2257 rdispl => fft_scratch%rdispl
2258
2259! If the send and recv counts are not already cached, then
2260! calculate and store them
2261 IF (fft_scratch%in == 0) THEN
2262
2263 rcount = 0
2264 nx = maxval(bo(2, 1, :))
2265
2266 DO ix = 0, npx - 1
2267 ip = pgrid(ix, 0)
2268 xcor(bo(1, 1, ip):bo(2, 1, ip)) = ix
2269 END DO
2270 DO iz = 0, npz - 1
2271 ip = pgrid(0, iz)
2272 zcor(bo(1, 3, ip):bo(2, 3, ip)) = iz
2273 END DO
2274 DO jx = 1, nx
2275 DO ir = 1, nray(my_pos)
2276 jy = yzp(1, ir, my_pos)
2277 jz = yzp(2, ir, my_pos)
2278 ip = pgrid(xcor(jx), zcor(jz))
2279 rcount(ip) = rcount(ip) + 1
2280 END DO
2281 END DO
2282
2283 CALL group%alltoall(rcount, scount, 1)
2284 fft_scratch%xzcount = scount
2285 fft_scratch%yzcount = rcount
2286
2287 ! Work out the correct displacements in the buffers
2288 sdispl(0) = 0
2289 rdispl(0) = 0
2290 DO ip = 1, np - 1
2291 sdispl(ip) = sdispl(ip - 1) + scount(ip - 1)
2292 rdispl(ip) = rdispl(ip - 1) + rcount(ip - 1)
2293 END DO
2294
2295 fft_scratch%xzdispl = sdispl
2296 fft_scratch%yzdispl = rdispl
2297
2298 icrs = 0
2299 DO ip = 0, np - 1
2300 IF (scount(ip) /= 0) icrs = icrs + 1
2301 IF (rcount(ip) /= 0) icrs = icrs + 1
2302 END DO
2303 CALL group%sum(icrs)
2304 fft_scratch%rsratio = real(icrs, kind=dp)/(real(2*np, kind=dp)*real(np, kind=dp))
2305
2306 fft_scratch%in = 1
2307 ELSE
2308 scount = fft_scratch%xzcount
2309 rcount = fft_scratch%yzcount
2310 sdispl = fft_scratch%xzdispl
2311 rdispl = fft_scratch%yzdispl
2312 END IF
2313
2314! Now do the actual packing
2315 myx = fft_scratch%sizes%r_pos(1)
2316 myz = fft_scratch%sizes%r_pos(2)
2317 mp = p2p(my_pos)
2318 nz = bo(2, 3, mp) - bo(1, 3, mp) + 1
2319 nx = bo(2, 1, mp) - bo(1, 1, mp) + 1
2320
2321!$OMP PARALLEL DO DEFAULT(NONE), &
2322!$OMP PRIVATE(jj,ipl,ir,jx,jy,jz,ixx),&
2323!$OMP SHARED(np,p2p,nray,yzp,zcor,myz,bo,mp),&
2324!$OMP SHARED(alltoall_sgl,nx,scount,sdispl),&
2325!$OMP SHARED(xzbuf,xzbuf_sgl,sb,nz)
2326 DO ip = 0, np - 1
2327 jj = 0
2328 ipl = p2p(ip)
2329 DO ir = 1, nray(ip)
2330 jz = yzp(2, ir, ip)
2331 IF (zcor(jz) == myz) THEN
2332 jj = jj + 1
2333 jy = yzp(1, ir, ip)
2334 jz = yzp(2, ir, ip) - bo(1, 3, mp) + 1
2335 IF (alltoall_sgl) THEN
2336 DO jx = 0, nx - 1
2337 ixx = jj + jx*scount(ipl)/nx
2338 xzbuf_sgl(ixx + sdispl(ipl)) = cmplx(sb(jy, jz + jx*nz), kind=sp)
2339 END DO
2340 ELSE
2341 DO jx = 0, nx - 1
2342 ixx = jj + jx*scount(ipl)/nx
2343 xzbuf(ixx + sdispl(ipl)) = sb(jy, jz + jx*nz)
2344 END DO
2345 END IF
2346 END IF
2347 END DO
2348 END DO
2349!$OMP END PARALLEL DO
2350
2351 IF (alltoall_sgl) THEN
2352 CALL group%alltoall(xzbuf_sgl, scount, sdispl, yzbuf_sgl, rcount, rdispl)
2353 ELSE
2354 IF (fft_scratch%rsratio < ratio_sparse_alltoall) THEN
2355 CALL sparse_alltoall(xzbuf, scount, sdispl, yzbuf, rcount, rdispl, group)
2356 ELSE
2357 CALL group%alltoall(xzbuf, scount, sdispl, yzbuf, rcount, rdispl)
2358 END IF
2359 END IF
2360
2361!$OMP PARALLEL DO DEFAULT(NONE), &
2362!$OMP PRIVATE(ipl,jj,nx,ir,jx,jy,jz),&
2363!$OMP SHARED(p2p,pzcoord,bo,nray,my_pos,yzp),&
2364!$OMP SHARED(rcount,rdispl,tb,yzbuf,zcor),&
2365!$OMP SHARED(yzbuf_sgl,alltoall_sgl,np)
2366 DO ip = 0, np - 1
2367 IF (rcount(ip) == 0) cycle
2368 ipl = p2p(ip)
2369 jj = 0
2370 nx = bo(2, 1, ipl) - bo(1, 1, ipl) + 1
2371 DO ir = 1, nray(my_pos)
2372 jz = yzp(2, ir, my_pos)
2373 IF (zcor(jz) == pzcoord(ipl)) THEN
2374 jj = jj + 1
2375 jy = yzp(1, ir, my_pos)
2376 IF (alltoall_sgl) THEN
2377 DO jx = 0, nx - 1
2378 tb(ir, jx + bo(1, 1, ipl)) = yzbuf_sgl(rdispl(ip) + jj + jx*rcount(ip)/nx)
2379 END DO
2380 ELSE
2381 DO jx = 0, nx - 1
2382 tb(ir, jx + bo(1, 1, ipl)) = yzbuf(rdispl(ip) + jj + jx*rcount(ip)/nx)
2383 END DO
2384 END IF
2385 END IF
2386 END DO
2387 END DO
2388!$OMP END PARALLEL DO
2389
2390 CALL timestop(handle)
2391
2392 END SUBROUTINE xz_to_yz
2393
2394! **************************************************************************************************
2395!> \brief ...
2396!> \param cin ...
2397!> \param boin ...
2398!> \param boout ...
2399!> \param sout ...
2400!> \param fft_scratch ...
2401!> \par History
2402!> none
2403!> \author JGH (20-Jan-2001)
2404! **************************************************************************************************
2405 SUBROUTINE cube_transpose_1(cin, boin, boout, sout, fft_scratch)
2406
2407 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2408 INTENT(IN) :: cin
2409 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2410 INTENT(IN) :: boin, boout
2411 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2412 INTENT(OUT) :: sout
2413 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
2414
2415 CHARACTER(LEN=*), PARAMETER :: routinen = 'cube_transpose_1'
2416
2417 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2418 POINTER :: rbuf
2419 INTEGER :: handle, ip, ipl, ir, is, ixy, iz, mip, &
2420 mz, np, nx, ny, nz
2421 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
2422 INTEGER, CONTIGUOUS, DIMENSION(:, :), POINTER :: pgrid
2423 INTEGER, DIMENSION(2) :: dim, pos
2424
2425 CALL timeset(routinen, handle)
2426
2427 mip = fft_scratch%mip
2428 dim = fft_scratch%dim
2429 pos = fft_scratch%pos
2430 scount => fft_scratch%scount
2431 rcount => fft_scratch%rcount
2432 sdispl => fft_scratch%sdispl
2433 rdispl => fft_scratch%rdispl
2434 pgrid => fft_scratch%pgcube
2435 np = dim(2)
2436
2437 nx = boin(2, 1, mip) - boin(1, 1, mip) + 1
2438 nz = boin(2, 3, mip) - boin(1, 3, mip) + 1
2439
2440!$OMP PARALLEL DO DEFAULT(NONE), &
2441!$OMP PRIVATE(ipl,ny), &
2442!$OMP SHARED(np,pgrid,boout,scount,sdispl,nx,nz)
2443 DO ip = 0, np - 1
2444 ipl = pgrid(ip, 2)
2445 ny = boout(2, 2, ipl) - boout(1, 2, ipl) + 1
2446 scount(ip) = nx*nz*ny
2447 sdispl(ip) = nx*nz*(boout(1, 2, ipl) - 1)
2448 END DO
2449!$OMP END PARALLEL DO
2450 ny = boout(2, 2, mip) - boout(1, 2, mip) + 1
2451 mz = maxval(boin(2, 3, :) - boin(1, 3, :) + 1)
2452!$OMP PARALLEL DO DEFAULT(NONE), &
2453!$OMP PRIVATE(ipl,nz), &
2454!$OMP SHARED(np,pgrid,boin,nx,ny,rcount,rdispl,mz)
2455 DO ip = 0, np - 1
2456 ipl = pgrid(ip, 2)
2457 nz = boin(2, 3, ipl) - boin(1, 3, ipl) + 1
2458 rcount(ip) = nx*nz*ny
2459 rdispl(ip) = nx*ny*mz*ip
2460 END DO
2461!$OMP END PARALLEL DO
2462
2463 rbuf => fft_scratch%rbuf1
2464
2465 CALL fft_scratch%cart_sub_comm(2)%alltoall(cin, scount, sdispl, rbuf, rcount, rdispl)
2466
2467!$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) &
2468!$OMP PRIVATE(ip,ipl,nz,iz,is,ir) &
2469!$OMP SHARED(nx,ny,np,pgrid,boin,sout,rbuf)
2470 DO ixy = 1, nx*ny
2471 DO ip = 0, np - 1
2472 ipl = pgrid(ip, 2)
2473 nz = boin(2, 3, ipl) - boin(1, 3, ipl) + 1
2474 DO iz = 1, nz
2475 is = boin(1, 3, ipl) + iz - 1
2476 ir = iz + nz*(ixy - 1)
2477 sout(is, ixy) = rbuf(ir, ip)
2478 END DO
2479 END DO
2480 END DO
2481!$OMP END PARALLEL DO
2482
2483 CALL timestop(handle)
2484
2485 END SUBROUTINE cube_transpose_1
2486
2487! **************************************************************************************************
2488!> \brief ...
2489!> \param cin ...
2490!> \param boin ...
2491!> \param boout ...
2492!> \param sout ...
2493!> \param fft_scratch ...
2494! **************************************************************************************************
2495 SUBROUTINE cube_transpose_2(cin, boin, boout, sout, fft_scratch)
2496
2497 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2498 INTENT(IN) :: cin
2499 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2500 INTENT(IN) :: boin, boout
2501 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2502 INTENT(OUT) :: sout
2503 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
2504
2505 CHARACTER(LEN=*), PARAMETER :: routinen = 'cube_transpose_2'
2506
2507 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2508 POINTER :: rbuf
2509 INTEGER :: handle, ip, ipl, ir, ixy, iz, mip, mz, &
2510 np, nx, ny, nz
2511 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
2512 INTEGER, CONTIGUOUS, DIMENSION(:, :), POINTER :: pgrid
2513 INTEGER, DIMENSION(2) :: dim, pos
2514 TYPE(mp_comm_type) :: sub_group
2515
2516 CALL timeset(routinen, handle)
2517
2518 sub_group = fft_scratch%cart_sub_comm(2)
2519 mip = fft_scratch%mip
2520 dim = fft_scratch%dim
2521 pos = fft_scratch%pos
2522 scount => fft_scratch%scount
2523 rcount => fft_scratch%rcount
2524 sdispl => fft_scratch%sdispl
2525 rdispl => fft_scratch%rdispl
2526 pgrid => fft_scratch%pgcube
2527 np = dim(2)
2528
2529 nx = boin(2, 1, mip) - boin(1, 1, mip) + 1
2530 ny = boin(2, 2, mip) - boin(1, 2, mip) + 1
2531 mz = maxval(boout(2, 3, :) - boout(1, 3, :) + 1)
2532
2533 rbuf => fft_scratch%rbuf2
2534
2535!$OMP PARALLEL DEFAULT(NONE), &
2536!$OMP PRIVATE(ip,ipl,nz,iz,ir), &
2537!$OMP SHARED(nx,ny,np,pgrid,boout,rbuf,cin,scount,sdispl,mz)
2538!$OMP DO COLLAPSE(2)
2539 DO ixy = 1, nx*ny
2540 DO ip = 0, np - 1
2541 ipl = pgrid(ip, 2)
2542 nz = boout(2, 3, ipl) - boout(1, 3, ipl) + 1
2543 DO iz = boout(1, 3, ipl), boout(2, 3, ipl)
2544 ir = iz - boout(1, 3, ipl) + 1 + (ixy - 1)*nz
2545 rbuf(ir, ip) = cin(iz, ixy)
2546 END DO
2547 END DO
2548 END DO
2549!$OMP END DO
2550!$OMP DO
2551 DO ip = 0, np - 1
2552 ipl = pgrid(ip, 2)
2553 nz = boout(2, 3, ipl) - boout(1, 3, ipl) + 1
2554 scount(ip) = nx*ny*nz
2555 sdispl(ip) = nx*ny*mz*ip
2556 END DO
2557!$OMP END DO
2558!$OMP END PARALLEL
2559 nz = boout(2, 3, mip) - boout(1, 3, mip) + 1
2560!$OMP PARALLEL DO DEFAULT(NONE), &
2561!$OMP PRIVATE(ipl,ny), &
2562!$OMP SHARED(np,pgrid,boin,nx,nz,rcount,rdispl)
2563 DO ip = 0, np - 1
2564 ipl = pgrid(ip, 2)
2565 ny = boin(2, 2, ipl) - boin(1, 2, ipl) + 1
2566 rcount(ip) = nx*ny*nz
2567 rdispl(ip) = nx*nz*(boin(1, 2, ipl) - 1)
2568 END DO
2569!$OMP END PARALLEL DO
2570
2571 CALL sub_group%alltoall(rbuf, scount, sdispl, sout, rcount, rdispl)
2572
2573 CALL timestop(handle)
2574
2575 END SUBROUTINE cube_transpose_2
2576
2577! **************************************************************************************************
2578!> \brief ...
2579!> \param cin ...
2580!> \param boin ...
2581!> \param boout ...
2582!> \param sout ...
2583!> \param fft_scratch ...
2584! **************************************************************************************************
2585 SUBROUTINE cube_transpose_3(cin, boin, boout, sout, fft_scratch)
2586
2587 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2588 INTENT(IN) :: cin
2589 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2590 INTENT(IN) :: boin, boout
2591 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2592 INTENT(OUT) :: sout
2593 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
2594
2595 CHARACTER(LEN=*), PARAMETER :: routinen = 'cube_transpose_3'
2596
2597 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2598 POINTER :: rbuf
2599 INTEGER :: handle, ip, ipl, ir, is, ixz, iy, lb, &
2600 mip, my, my_id, np, num_threads, nx, &
2601 ny, nz, ub
2602 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
2603 INTEGER, CONTIGUOUS, DIMENSION(:, :), POINTER :: pgrid
2604 INTEGER, DIMENSION(2) :: dim, pos
2605 TYPE(mp_comm_type) :: sub_group
2606
2607 CALL timeset(routinen, handle)
2608
2609 sub_group = fft_scratch%cart_sub_comm(1)
2610 mip = fft_scratch%mip
2611 dim = fft_scratch%dim
2612 pos = fft_scratch%pos
2613 np = dim(1)
2614 scount => fft_scratch%scount
2615 rcount => fft_scratch%rcount
2616 sdispl => fft_scratch%sdispl
2617 rdispl => fft_scratch%rdispl
2618 pgrid => fft_scratch%pgcube
2619
2620 ny = boin(2, 2, mip) - boin(1, 2, mip) + 1
2621 nz = boin(2, 3, mip) - boin(1, 3, mip) + 1
2622!$OMP PARALLEL DO DEFAULT(NONE), &
2623!$OMP PRIVATE(ipl, nx), &
2624!$OMP SHARED(np,pgrid,boout,ny,nz,scount,sdispl)
2625 DO ip = 0, np - 1
2626 ipl = pgrid(ip, 1)
2627 nx = boout(2, 1, ipl) - boout(1, 1, ipl) + 1
2628 scount(ip) = nx*nz*ny
2629 sdispl(ip) = ny*nz*(boout(1, 1, ipl) - 1)
2630 END DO
2631!$OMP END PARALLEL DO
2632 nx = boout(2, 1, mip) - boout(1, 1, mip) + 1
2633 my = maxval(boin(2, 2, :) - boin(1, 2, :) + 1)
2634!$OMP PARALLEL DO DEFAULT(NONE), &
2635!$OMP PRIVATE(ipl, ny), &
2636!$OMP SHARED(np,pgrid,boin,nx,nz,my,rcount,rdispl)
2637 DO ip = 0, np - 1
2638 ipl = pgrid(ip, 1)
2639 ny = boin(2, 2, ipl) - boin(1, 2, ipl) + 1
2640 rcount(ip) = nx*nz*ny
2641 rdispl(ip) = nx*my*nz*ip
2642 END DO
2643!$OMP END PARALLEL DO
2644
2645 rbuf => fft_scratch%rbuf3
2646 num_threads = 1
2647 my_id = 0
2648!$OMP PARALLEL DEFAULT(NONE), &
2649!$OMP PRIVATE(NUM_THREADS, my_id, lb, ub) &
2650!$OMP SHARED(rbuf)
2651!$ num_threads = MIN(omp_get_max_threads(), SIZE(rbuf, 2))
2652!$ my_id = omp_get_thread_num()
2653 IF (my_id < num_threads) THEN
2654 lb = (SIZE(rbuf, 2)*my_id)/num_threads
2655 ub = (SIZE(rbuf, 2)*(my_id + 1))/num_threads - 1
2656 rbuf(:, lb:ub) = 0.0_dp
2657 END IF
2658!$OMP END PARALLEL
2659
2660 CALL sub_group%alltoall(cin, scount, sdispl, rbuf, rcount, rdispl)
2661
2662!$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) &
2663!$OMP PRIVATE(ip,ipl,ny,iy,is,ir) &
2664!$OMP SHARED(nx,nz,np,pgrid,boin,rbuf,sout)
2665 DO ixz = 1, nx*nz
2666 DO ip = 0, np - 1
2667 ipl = pgrid(ip, 1)
2668 ny = boin(2, 2, ipl) - boin(1, 2, ipl) + 1
2669 DO iy = 1, ny
2670 is = boin(1, 2, ipl) + iy - 1
2671 ir = iy + ny*(ixz - 1)
2672 sout(is, ixz) = rbuf(ir, ip)
2673 END DO
2674 END DO
2675 END DO
2676!$OMP END PARALLEL DO
2677
2678 CALL timestop(handle)
2679
2680 END SUBROUTINE cube_transpose_3
2681
2682! **************************************************************************************************
2683!> \brief ...
2684!> \param cin ...
2685!> \param boin ...
2686!> \param boout ...
2687!> \param sout ...
2688!> \param fft_scratch ...
2689! **************************************************************************************************
2690 SUBROUTINE cube_transpose_4(cin, boin, boout, sout, fft_scratch)
2691
2692 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2693 INTENT(IN) :: cin
2694 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2695 INTENT(IN) :: boin, boout
2696 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2697 INTENT(OUT) :: sout
2698 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
2699
2700 CHARACTER(LEN=*), PARAMETER :: routinen = 'cube_transpose_4'
2701
2702 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2703 POINTER :: rbuf
2704 INTEGER :: handle, ip, ipl, ir, iy, izx, lb, mip, &
2705 my, my_id, np, num_threads, nx, ny, &
2706 nz, ub
2707 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
2708 INTEGER, CONTIGUOUS, DIMENSION(:, :), POINTER :: pgrid
2709 INTEGER, DIMENSION(2) :: dim, pos
2710 TYPE(mp_comm_type) :: sub_group
2711
2712 CALL timeset(routinen, handle)
2713
2714 sub_group = fft_scratch%cart_sub_comm(1)
2715 mip = fft_scratch%mip
2716 dim = fft_scratch%dim
2717 pos = fft_scratch%pos
2718 np = dim(1)
2719 scount => fft_scratch%scount
2720 rcount => fft_scratch%rcount
2721 sdispl => fft_scratch%sdispl
2722 rdispl => fft_scratch%rdispl
2723 pgrid => fft_scratch%pgcube
2724
2725 nx = boin(2, 1, mip) - boin(1, 1, mip) + 1
2726 nz = boin(2, 3, mip) - boin(1, 3, mip) + 1
2727 my = maxval(boout(2, 2, :) - boout(1, 2, :) + 1)
2728
2729 rbuf => fft_scratch%rbuf4
2730 num_threads = 1
2731 my_id = 0
2732!$OMP PARALLEL DEFAULT(NONE), &
2733!$OMP PRIVATE(NUM_THREADS,my_id,lb,ub,ip,ipl,ny,iy,ir), &
2734!$OMP SHARED(rbuf,nz,nx,np,pgrid,boout,cin,my,scount,sdispl)
2735!$ num_threads = MIN(omp_get_max_threads(), SIZE(rbuf, 2))
2736!$ my_id = omp_get_thread_num()
2737 IF (my_id < num_threads) THEN
2738 lb = (SIZE(rbuf, 2)*my_id)/num_threads
2739 ub = (SIZE(rbuf, 2)*(my_id + 1))/num_threads - 1
2740 rbuf(:, lb:ub) = 0.0_dp
2741 END IF
2742!$OMP BARRIER
2743
2744!$OMP DO COLLAPSE(2)
2745 DO izx = 1, nz*nx
2746 DO ip = 0, np - 1
2747 ipl = pgrid(ip, 1)
2748 ny = boout(2, 2, ipl) - boout(1, 2, ipl) + 1
2749 DO iy = boout(1, 2, ipl), boout(2, 2, ipl)
2750 ir = iy - boout(1, 2, ipl) + 1 + (izx - 1)*ny
2751 rbuf(ir, ip) = cin(iy, izx)
2752 END DO
2753 END DO
2754 END DO
2755!$OMP END DO
2756!$OMP DO
2757 DO ip = 0, np - 1
2758 ipl = pgrid(ip, 1)
2759 ny = boout(2, 2, ipl) - boout(1, 2, ipl) + 1
2760 scount(ip) = nx*ny*nz
2761 sdispl(ip) = nx*nz*my*ip
2762 END DO
2763!$OMP END DO
2764!$OMP END PARALLEL
2765 ny = boout(2, 2, mip) - boout(1, 2, mip) + 1
2766!$OMP PARALLEL DO DEFAULT(NONE), &
2767!$OMP PRIVATE(ipl,nx), &
2768!$OMP SHARED(np,pgrid,boin,rcount,rdispl,ny,nz)
2769 DO ip = 0, np - 1
2770 ipl = pgrid(ip, 1)
2771 nx = boin(2, 1, ipl) - boin(1, 1, ipl) + 1
2772 rcount(ip) = nx*ny*nz
2773 rdispl(ip) = ny*nz*(boin(1, 1, ipl) - 1)
2774 END DO
2775!$OMP END PARALLEL DO
2776
2777 CALL sub_group%alltoall(rbuf, scount, sdispl, sout, rcount, rdispl)
2778
2779 CALL timestop(handle)
2780
2781 END SUBROUTINE cube_transpose_4
2782
2783! **************************************************************************************************
2784!> \brief ...
2785!> \param cin ...
2786!> \param group ...
2787!> \param boin ...
2788!> \param boout ...
2789!> \param sout ...
2790!> \param fft_scratch ...
2791! **************************************************************************************************
2792 SUBROUTINE cube_transpose_5(cin, group, boin, boout, sout, fft_scratch)
2793
2794 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2795 INTENT(IN) :: cin
2796 CLASS(mp_comm_type), INTENT(IN) :: group
2797 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2798 INTENT(IN) :: boin, boout
2799 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2800 INTENT(OUT) :: sout
2801 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
2802
2803 CHARACTER(LEN=*), PARAMETER :: routinen = 'cube_transpose_5'
2804
2805 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2806 POINTER :: rbuf
2807 INTEGER :: handle, ip, ir, is, ixz, iy, lb, mip, &
2808 my, my_id, np, num_threads, nx, ny, &
2809 nz, ub
2810 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
2811
2812 CALL timeset(routinen, handle)
2813
2814 np = fft_scratch%sizes%numtask
2815 mip = fft_scratch%mip
2816 scount => fft_scratch%scount
2817 rcount => fft_scratch%rcount
2818 sdispl => fft_scratch%sdispl
2819 rdispl => fft_scratch%rdispl
2820
2821 ny = boin(2, 2, mip) - boin(1, 2, mip) + 1
2822 nz = boin(2, 3, mip) - boin(1, 3, mip) + 1
2823!$OMP PARALLEL DO DEFAULT(NONE), &
2824!$OMP PRIVATE(nx), &
2825!$OMP SHARED(np,boout,ny,nz,scount,sdispl)
2826 DO ip = 0, np - 1
2827 nx = boout(2, 1, ip) - boout(1, 1, ip) + 1
2828 scount(ip) = nx*nz*ny
2829 sdispl(ip) = ny*nz*(boout(1, 1, ip) - 1)
2830 END DO
2831!$OMP END PARALLEL DO
2832 nx = boout(2, 1, mip) - boout(1, 1, mip) + 1
2833 my = maxval(boin(2, 2, :) - boin(1, 2, :) + 1)
2834!$OMP PARALLEL DO DEFAULT(NONE), &
2835!$OMP PRIVATE(ny), &
2836!$OMP SHARED(np,boin,nx,nz,rcount,rdispl,my)
2837 DO ip = 0, np - 1
2838 ny = boin(2, 2, ip) - boin(1, 2, ip) + 1
2839 rcount(ip) = nx*nz*ny
2840 rdispl(ip) = nx*my*nz*ip
2841 END DO
2842!$OMP END PARALLEL DO
2843
2844 rbuf => fft_scratch%rbuf5
2845 num_threads = 1
2846 my_id = 0
2847!$OMP PARALLEL DEFAULT(NONE), &
2848!$OMP PRIVATE(NUM_THREADS, my_id, lb, ub), &
2849!$OMP SHARED(rbuf)
2850!$ num_threads = MIN(omp_get_max_threads(), SIZE(rbuf, 2))
2851!$ my_id = omp_get_thread_num()
2852 IF (my_id < num_threads) THEN
2853 lb = (SIZE(rbuf, 2)*my_id)/num_threads
2854 ub = (SIZE(rbuf, 2)*(my_id + 1))/num_threads - 1
2855 rbuf(:, lb:ub) = 0.0_dp
2856 END IF
2857!$OMP END PARALLEL
2858
2859 CALL group%alltoall(cin, scount, sdispl, rbuf, rcount, rdispl)
2860
2861!$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) &
2862!$OMP PRIVATE(ip,ny,iy,is,ir) &
2863!$OMP SHARED(nx,nz,np,boin,sout,rbuf)
2864 DO ixz = 1, nx*nz
2865 DO ip = 0, np - 1
2866 ny = boin(2, 2, ip) - boin(1, 2, ip) + 1
2867 DO iy = 1, ny
2868 is = boin(1, 2, ip) + iy - 1
2869 ir = iy + ny*(ixz - 1)
2870 sout(is, ixz) = rbuf(ir, ip)
2871 END DO
2872 END DO
2873 END DO
2874!$OMP END PARALLEL DO
2875
2876 CALL timestop(handle)
2877
2878 END SUBROUTINE cube_transpose_5
2879
2880! **************************************************************************************************
2881!> \brief ...
2882!> \param cin ...
2883!> \param group ...
2884!> \param boin ...
2885!> \param boout ...
2886!> \param sout ...
2887!> \param fft_scratch ...
2888! **************************************************************************************************
2889 SUBROUTINE cube_transpose_6(cin, group, boin, boout, sout, fft_scratch)
2890
2891 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2892 INTENT(IN) :: cin
2893 CLASS(mp_comm_type), INTENT(IN) :: group
2894 INTEGER, CONTIGUOUS, DIMENSION(:, :, 0:), &
2895 INTENT(IN) :: boin, boout
2896 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2897 INTENT(OUT) :: sout
2898 TYPE(fft_scratch_type), INTENT(IN) :: fft_scratch
2899
2900 CHARACTER(LEN=*), PARAMETER :: routinen = 'cube_transpose_6'
2901
2902 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
2903 POINTER :: rbuf
2904 INTEGER :: handle, ip, ir, iy, izx, lb, mip, my, &
2905 my_id, np, num_threads, nx, ny, nz, ub
2906 INTEGER, CONTIGUOUS, DIMENSION(:), POINTER :: rcount, rdispl, scount, sdispl
2907
2908 CALL timeset(routinen, handle)
2909
2910 np = fft_scratch%sizes%numtask
2911 mip = fft_scratch%mip
2912 scount => fft_scratch%scount
2913 rcount => fft_scratch%rcount
2914 sdispl => fft_scratch%sdispl
2915 rdispl => fft_scratch%rdispl
2916
2917 nx = boin(2, 1, mip) - boin(1, 1, mip) + 1
2918 nz = boin(2, 3, mip) - boin(1, 3, mip) + 1
2919 my = maxval(boout(2, 2, :) - boout(1, 2, :) + 1)
2920
2921 rbuf => fft_scratch%rbuf5
2922 num_threads = 1
2923 my_id = 0
2924!$OMP PARALLEL DEFAULT(NONE), &
2925!$OMP PRIVATE(NUM_THREADS,my_id,lb,ub,ip,ny,iy,ir), &
2926!$OMP SHARED(rbuf,nx,nz,np,boout,cin,my,scount,sdispl)
2927!$ num_threads = MIN(omp_get_max_threads(), SIZE(rbuf, 2))
2928!$ my_id = omp_get_thread_num()
2929 IF (my_id < num_threads) THEN
2930 lb = (SIZE(rbuf, 2)*my_id)/num_threads
2931 ub = (SIZE(rbuf, 2)*(my_id + 1))/num_threads - 1
2932 rbuf(:, lb:ub) = 0.0_dp
2933 END IF
2934!$OMP BARRIER
2935
2936!$OMP DO COLLAPSE(2)
2937 DO izx = 1, nz*nx
2938 DO ip = 0, np - 1
2939 ny = boout(2, 2, ip) - boout(1, 2, ip) + 1
2940 DO iy = boout(1, 2, ip), boout(2, 2, ip)
2941 ir = iy - boout(1, 2, ip) + 1 + (izx - 1)*ny
2942 rbuf(ir, ip) = cin(iy, izx)
2943 END DO
2944 END DO
2945 END DO
2946!$OMP END DO
2947!$OMP DO
2948 DO ip = 0, np - 1
2949 ny = boout(2, 2, ip) - boout(1, 2, ip) + 1
2950 scount(ip) = nx*ny*nz
2951 sdispl(ip) = nx*nz*my*ip
2952 END DO
2953!$OMP END DO
2954!$OMP END PARALLEL
2955 ny = boout(2, 2, mip) - boout(1, 2, mip) + 1
2956!$OMP PARALLEL DO DEFAULT(NONE), &
2957!$OMP PRIVATE(nx), &
2958!$OMP SHARED(np,boin,rcount,rdispl,nz,ny)
2959 DO ip = 0, np - 1
2960 nx = boin(2, 1, ip) - boin(1, 1, ip) + 1
2961 rcount(ip) = nx*ny*nz
2962 rdispl(ip) = ny*nz*(boin(1, 1, ip) - 1)
2963 END DO
2964!$OMP END PARALLEL DO
2965
2966 CALL group%alltoall(rbuf, scount, sdispl, sout, rcount, rdispl)
2967
2968 CALL timestop(handle)
2969
2970 END SUBROUTINE cube_transpose_6
2971
2972! **************************************************************************************************
2973!> \brief ...
2974! **************************************************************************************************
2976
2977 CALL release_fft_scratch_pool()
2978
2979 ! Allocate first scratch and mark it as used
2980 ALLOCATE (fft_scratch_first)
2981 ALLOCATE (fft_scratch_first%fft_scratch)
2982 ! this is a very special scratch, it seems, we always keep it 'most - recent' so we will never delete it
2983 fft_scratch_first%fft_scratch%last_tick = huge(fft_scratch_first%fft_scratch%last_tick)
2984
2986
2987 END SUBROUTINE init_fft_scratch_pool
2988
2989! **************************************************************************************************
2990!> \brief ...
2991!> \param fft_scratch ...
2992! **************************************************************************************************
2993 SUBROUTINE deallocate_fft_scratch_type(fft_scratch)
2994 TYPE(fft_scratch_type), INTENT(INOUT) :: fft_scratch
2995
2996#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
2997 INTEGER :: ierr
2998 COMPLEX(KIND=dp), POINTER :: dummy_ptr_z
2999#endif
3000
3001 ! deallocate structures
3002 IF (ASSOCIATED(fft_scratch%ziptr)) THEN
3003 CALL fft_deallocate(fft_scratch%ziptr)
3004 END IF
3005 IF (ASSOCIATED(fft_scratch%zoptr)) THEN
3006 CALL fft_deallocate(fft_scratch%zoptr)
3007 END IF
3008 IF (ASSOCIATED(fft_scratch%p1buf)) THEN
3009 CALL fft_deallocate(fft_scratch%p1buf)
3010 END IF
3011 IF (ASSOCIATED(fft_scratch%p2buf)) THEN
3012#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3013 dummy_ptr_z => fft_scratch%p2buf(1, 1)
3014 ierr = offload_free_pinned_mem(c_loc(dummy_ptr_z))
3015#else
3016 CALL fft_deallocate(fft_scratch%p2buf)
3017#endif
3018 END IF
3019 IF (ASSOCIATED(fft_scratch%p3buf)) THEN
3020#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3021 dummy_ptr_z => fft_scratch%p3buf(1, 1)
3022 ierr = offload_free_pinned_mem(c_loc(dummy_ptr_z))
3023#else
3024 CALL fft_deallocate(fft_scratch%p3buf)
3025#endif
3026 END IF
3027 IF (ASSOCIATED(fft_scratch%p4buf)) THEN
3028#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3029 dummy_ptr_z => fft_scratch%p4buf(1, 1)
3030 ierr = offload_free_pinned_mem(c_loc(dummy_ptr_z))
3031#else
3032 CALL fft_deallocate(fft_scratch%p4buf)
3033#endif
3034 END IF
3035 IF (ASSOCIATED(fft_scratch%p5buf)) THEN
3036#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3037 dummy_ptr_z => fft_scratch%p5buf(1, 1)
3038 ierr = offload_free_pinned_mem(c_loc(dummy_ptr_z))
3039#else
3040 CALL fft_deallocate(fft_scratch%p5buf)
3041#endif
3042 END IF
3043 IF (ASSOCIATED(fft_scratch%p6buf)) THEN
3044 CALL fft_deallocate(fft_scratch%p6buf)
3045 END IF
3046 IF (ASSOCIATED(fft_scratch%p7buf)) THEN
3047#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3048 dummy_ptr_z => fft_scratch%p7buf(1, 1)
3049 ierr = offload_free_pinned_mem(c_loc(dummy_ptr_z))
3050#else
3051 CALL fft_deallocate(fft_scratch%p7buf)
3052#endif
3053 END IF
3054 IF (ASSOCIATED(fft_scratch%r1buf)) THEN
3055#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3056 dummy_ptr_z => fft_scratch%r1buf(1, 1)
3057 ierr = offload_free_pinned_mem(c_loc(dummy_ptr_z))
3058#else
3059 CALL fft_deallocate(fft_scratch%r1buf)
3060#endif
3061 END IF
3062 IF (ASSOCIATED(fft_scratch%r2buf)) THEN
3063 CALL fft_deallocate(fft_scratch%r2buf)
3064 END IF
3065 IF (ASSOCIATED(fft_scratch%tbuf)) THEN
3066#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3067 dummy_ptr_z => fft_scratch%tbuf(1, 1, 1)
3068 ierr = offload_free_pinned_mem(c_loc(dummy_ptr_z))
3069#else
3070 CALL fft_deallocate(fft_scratch%tbuf)
3071#endif
3072 END IF
3073 IF (ASSOCIATED(fft_scratch%a1buf)) THEN
3074 CALL fft_deallocate(fft_scratch%a1buf)
3075 END IF
3076 IF (ASSOCIATED(fft_scratch%a2buf)) THEN
3077 CALL fft_deallocate(fft_scratch%a2buf)
3078 END IF
3079 IF (ASSOCIATED(fft_scratch%a3buf)) THEN
3080 CALL fft_deallocate(fft_scratch%a3buf)
3081 END IF
3082 IF (ASSOCIATED(fft_scratch%a4buf)) THEN
3083 CALL fft_deallocate(fft_scratch%a4buf)
3084 END IF
3085 IF (ASSOCIATED(fft_scratch%a5buf)) THEN
3086 CALL fft_deallocate(fft_scratch%a5buf)
3087 END IF
3088 IF (ASSOCIATED(fft_scratch%a6buf)) THEN
3089 CALL fft_deallocate(fft_scratch%a6buf)
3090 END IF
3091 IF (ASSOCIATED(fft_scratch%scount)) THEN
3092 DEALLOCATE (fft_scratch%scount, fft_scratch%rcount, &
3093 fft_scratch%sdispl, fft_scratch%rdispl)
3094 END IF
3095 IF (ASSOCIATED(fft_scratch%rr)) THEN
3096 DEALLOCATE (fft_scratch%rr)
3097 END IF
3098 IF (ASSOCIATED(fft_scratch%xzbuf)) THEN
3099 DEALLOCATE (fft_scratch%xzbuf)
3100 END IF
3101 IF (ASSOCIATED(fft_scratch%yzbuf)) THEN
3102 DEALLOCATE (fft_scratch%yzbuf)
3103 END IF
3104 IF (ASSOCIATED(fft_scratch%xzbuf_sgl)) THEN
3105 DEALLOCATE (fft_scratch%xzbuf_sgl)
3106 END IF
3107 IF (ASSOCIATED(fft_scratch%yzbuf_sgl)) THEN
3108 DEALLOCATE (fft_scratch%yzbuf_sgl)
3109 END IF
3110 IF (ASSOCIATED(fft_scratch%ss)) THEN
3111 DEALLOCATE (fft_scratch%ss)
3112 END IF
3113 IF (ASSOCIATED(fft_scratch%tt)) THEN
3114 DEALLOCATE (fft_scratch%tt)
3115 END IF
3116 IF (ASSOCIATED(fft_scratch%pgrid)) THEN
3117 DEALLOCATE (fft_scratch%pgrid)
3118 END IF
3119 IF (ASSOCIATED(fft_scratch%pgcube)) THEN
3120 DEALLOCATE (fft_scratch%pgcube)
3121 END IF
3122 IF (ASSOCIATED(fft_scratch%xcor)) THEN
3123 DEALLOCATE (fft_scratch%xcor, fft_scratch%zcor)
3124 END IF
3125 IF (ASSOCIATED(fft_scratch%pzcoord)) THEN
3126 DEALLOCATE (fft_scratch%pzcoord)
3127 END IF
3128 IF (ASSOCIATED(fft_scratch%xzcount)) THEN
3129 DEALLOCATE (fft_scratch%xzcount, fft_scratch%yzcount)
3130 DEALLOCATE (fft_scratch%xzdispl, fft_scratch%yzdispl)
3131 fft_scratch%in = 0
3132 fft_scratch%rsratio = 1._dp
3133 END IF
3134 IF (ASSOCIATED(fft_scratch%rbuf1)) THEN
3135 DEALLOCATE (fft_scratch%rbuf1)
3136 END IF
3137 IF (ASSOCIATED(fft_scratch%rbuf2)) THEN
3138 DEALLOCATE (fft_scratch%rbuf2)
3139 END IF
3140 IF (ASSOCIATED(fft_scratch%rbuf3)) THEN
3141 DEALLOCATE (fft_scratch%rbuf3)
3142 END IF
3143 IF (ASSOCIATED(fft_scratch%rbuf4)) THEN
3144 DEALLOCATE (fft_scratch%rbuf4)
3145 END IF
3146 IF (ASSOCIATED(fft_scratch%rbuf5)) THEN
3147 DEALLOCATE (fft_scratch%rbuf5)
3148 END IF
3149 IF (ASSOCIATED(fft_scratch%rbuf6)) THEN
3150 DEALLOCATE (fft_scratch%rbuf6)
3151 END IF
3152
3153 IF (fft_scratch%cart_sub_comm(1) /= mp_comm_null) THEN
3154 CALL fft_scratch%cart_sub_comm(1)%free()
3155 END IF
3156 IF (fft_scratch%cart_sub_comm(2) /= mp_comm_null) THEN
3157 CALL fft_scratch%cart_sub_comm(2)%free()
3158 END IF
3159
3160 CALL fft_destroy_plan(fft_scratch%fft_plan(1))
3161 CALL fft_destroy_plan(fft_scratch%fft_plan(2))
3162 CALL fft_destroy_plan(fft_scratch%fft_plan(3))
3163 CALL fft_destroy_plan(fft_scratch%fft_plan(4))
3164 CALL fft_destroy_plan(fft_scratch%fft_plan(5))
3165 CALL fft_destroy_plan(fft_scratch%fft_plan(6))
3166
3167 END SUBROUTINE deallocate_fft_scratch_type
3168
3169! **************************************************************************************************
3170!> \brief ...
3171! **************************************************************************************************
3172 SUBROUTINE release_fft_scratch_pool()
3173 TYPE(fft_scratch_pool_type), POINTER :: fft_scratch, fft_scratch_current
3174
3175!$ CPASSERT(.NOT. omp_in_parallel() .OR. 0 == omp_get_thread_num())
3176
3177 IF (init_fft_pool == 0) NULLIFY (fft_scratch_first)
3178
3179 fft_scratch => fft_scratch_first
3180 DO
3181 IF (ASSOCIATED(fft_scratch)) THEN
3182 fft_scratch_current => fft_scratch
3183 fft_scratch => fft_scratch_current%fft_scratch_next
3184 NULLIFY (fft_scratch_current%fft_scratch_next)
3185
3186 CALL deallocate_fft_scratch_type(fft_scratch_current%fft_scratch)
3187
3188 DEALLOCATE (fft_scratch_current%fft_scratch)
3189 DEALLOCATE (fft_scratch_current)
3190 ELSE
3191 EXIT
3192 END IF
3193 END DO
3194
3195 init_fft_pool = 0
3196
3197 END SUBROUTINE release_fft_scratch_pool
3198
3199! **************************************************************************************************
3200!> \brief ...
3201! **************************************************************************************************
3202 SUBROUTINE resize_fft_scratch_pool()
3203
3204 INTEGER :: last_tick, nscratch
3205 TYPE(fft_scratch_pool_type), POINTER :: fft_scratch_current, fft_scratch_old
3206
3207 nscratch = 0
3208
3209 last_tick = huge(last_tick)
3210 NULLIFY (fft_scratch_old)
3211
3212 ! start at the global pool, count, and find a deletion candidate
3213 fft_scratch_current => fft_scratch_first
3214 DO
3215 IF (ASSOCIATED(fft_scratch_current)) THEN
3216 nscratch = nscratch + 1
3217 ! is this a candidate for deletion (i.e. least recently used, and not in use)
3218 IF (.NOT. fft_scratch_current%fft_scratch%in_use) THEN
3219 IF (fft_scratch_current%fft_scratch%last_tick < last_tick) THEN
3220 last_tick = fft_scratch_current%fft_scratch%last_tick
3221 fft_scratch_old => fft_scratch_current
3222 END IF
3223 END IF
3224 fft_scratch_current => fft_scratch_current%fft_scratch_next
3225 ELSE
3226 EXIT
3227 END IF
3228 END DO
3229
3230 ! we should delete a scratch
3231 IF (nscratch > fft_pool_scratch_limit) THEN
3232 ! note that we never deallocate the first (special) element of the list
3233 IF (ASSOCIATED(fft_scratch_old)) THEN
3234 fft_scratch_current => fft_scratch_first
3235 DO
3236 IF (ASSOCIATED(fft_scratch_current)) THEN
3237 ! should we delete the next in the list?
3238 IF (ASSOCIATED(fft_scratch_current%fft_scratch_next, fft_scratch_old)) THEN
3239 ! fix the linked list
3240 fft_scratch_current%fft_scratch_next => fft_scratch_old%fft_scratch_next
3241
3242 ! deallocate the element
3243 CALL deallocate_fft_scratch_type(fft_scratch_old%fft_scratch)
3244 DEALLOCATE (fft_scratch_old%fft_scratch)
3245 DEALLOCATE (fft_scratch_old)
3246
3247 ELSE
3248 fft_scratch_current => fft_scratch_current%fft_scratch_next
3249 END IF
3250 ELSE
3251 EXIT
3252 END IF
3253 END DO
3254
3255 ELSE
3256 cpwarn("The number of the scratches exceeded the limit, but none could be deallocated")
3257 END IF
3258 END IF
3259
3260 END SUBROUTINE resize_fft_scratch_pool
3261
3262! **************************************************************************************************
3263!> \brief ...
3264!> \param fft_scratch ...
3265!> \param tf_type ...
3266!> \param n ...
3267!> \param fft_sizes ...
3268! **************************************************************************************************
3269 SUBROUTINE get_fft_scratch(fft_scratch, tf_type, n, fft_sizes)
3270 TYPE(fft_scratch_type), POINTER :: fft_scratch
3271 INTEGER, INTENT(IN) :: tf_type
3272 INTEGER, DIMENSION(:), INTENT(IN) :: n
3273 TYPE(fft_scratch_sizes), INTENT(IN), &
3274 OPTIONAL :: fft_sizes
3275
3276 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_fft_scratch'
3277
3278 INTEGER :: coord(2), dim(2), handle, i, ix, iz, lg, lmax, m1, m2, &
3279 mcx2, mcy3, mcz1, mcz2, mg, mmax, mx1, mx2, my1, my3, mz1, mz2, mz3, &
3280 nbx, nbz, nm, nmax, nmray, np, nx, ny, nyzray, nz, pos(2)
3281 INTEGER, DIMENSION(3) :: pcoord
3282 LOGICAL :: equal
3283 LOGICAL, DIMENSION(2) :: dims
3284 TYPE(fft_scratch_pool_type), POINTER :: fft_scratch_current, &
3285 fft_scratch_last, &
3286 fft_scratch_new
3287#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3288 INTEGER :: ierr
3289 INTEGER(KIND=C_SIZE_T) :: length
3290 TYPE(c_ptr) :: cptr_r1buf, cptr_tbuf, &
3291 cptr_p2buf, cptr_p3buf, cptr_p4buf, cptr_p5buf, cptr_p7buf
3292#endif
3293 CALL timeset(routinen, handle)
3294
3295 ! this is the place to check that the scratch_pool does not grow without limits
3296 ! before we add a new scratch check the size of the pool and release some of the list if needed
3297 CALL resize_fft_scratch_pool()
3298
3299 ! get the required scratch
3300!$OMP ATOMIC
3302 fft_scratch_current => fft_scratch_first
3303 DO
3304 IF (ASSOCIATED(fft_scratch_current)) THEN
3305 IF (fft_scratch_current%fft_scratch%in_use) THEN
3306 fft_scratch_last => fft_scratch_current
3307 fft_scratch_current => fft_scratch_current%fft_scratch_next
3308 cycle
3309 END IF
3310 IF (tf_type /= fft_scratch_current%fft_scratch%tf_type) THEN
3311 fft_scratch_last => fft_scratch_current
3312 fft_scratch_current => fft_scratch_current%fft_scratch_next
3313 cycle
3314 END IF
3315 IF (.NOT. all(n == fft_scratch_current%fft_scratch%nfft)) THEN
3316 fft_scratch_last => fft_scratch_current
3317 fft_scratch_current => fft_scratch_current%fft_scratch_next
3318 cycle
3319 END IF
3320 IF (PRESENT(fft_sizes)) THEN
3321 IF (fft_sizes%rs_group /= fft_scratch_current%fft_scratch%group) THEN
3322 fft_scratch_last => fft_scratch_current
3323 fft_scratch_current => fft_scratch_current%fft_scratch_next
3324 cycle
3325 END IF
3326 CALL is_equal(fft_sizes, fft_scratch_current%fft_scratch%sizes, equal)
3327 IF (.NOT. equal) THEN
3328 fft_scratch_last => fft_scratch_current
3329 fft_scratch_current => fft_scratch_current%fft_scratch_next
3330 cycle
3331 END IF
3332 END IF
3333 ! Success
3334 fft_scratch => fft_scratch_current%fft_scratch
3335 fft_scratch_current%fft_scratch%in_use = .true.
3336 EXIT
3337 ELSE
3338 ! We cannot find the scratch type in this pool
3339 ! Generate a new scratch set
3340 ALLOCATE (fft_scratch_new)
3341 ALLOCATE (fft_scratch_new%fft_scratch)
3342
3343 IF (tf_type /= 400) THEN
3344 fft_scratch_new%fft_scratch%sizes = fft_sizes
3345 np = fft_sizes%numtask
3346 ALLOCATE (fft_scratch_new%fft_scratch%scount(0:np - 1), fft_scratch_new%fft_scratch%rcount(0:np - 1), &
3347 fft_scratch_new%fft_scratch%sdispl(0:np - 1), fft_scratch_new%fft_scratch%rdispl(0:np - 1), &
3348 fft_scratch_new%fft_scratch%pgcube(0:np - 1, 2))
3349 END IF
3350
3351 SELECT CASE (tf_type)
3352 CASE DEFAULT
3353 cpabort("Invalid scratch type.")
3354 CASE (100) ! fft3d_pb: full cube distribution
3355 cpassert(PRESENT(fft_sizes))
3356 mx1 = fft_sizes%mx1
3357 my1 = fft_sizes%my1
3358 mx2 = fft_sizes%mx2
3359 mz2 = fft_sizes%mz2
3360 my3 = fft_sizes%my3
3361 mz3 = fft_sizes%mz3
3362 CALL fft_allocate(fft_scratch_new%fft_scratch%a1buf, [mx1*my1, n(3)])
3363 CALL fft_allocate(fft_scratch_new%fft_scratch%a2buf, [n(3), mx1*my1])
3364 CALL fft_allocate(fft_scratch_new%fft_scratch%a3buf, [mx2*mz2, n(2)])
3365 CALL fft_allocate(fft_scratch_new%fft_scratch%a4buf, [n(2), mx2*mz2])
3366 CALL fft_allocate(fft_scratch_new%fft_scratch%a5buf, [my3*mz3, n(1)])
3367 CALL fft_allocate(fft_scratch_new%fft_scratch%a6buf, [n(1), my3*mz3])
3368 fft_scratch_new%fft_scratch%group = fft_sizes%rs_group
3369
3370 dim = fft_sizes%rs_group%num_pe_cart
3371 pos = fft_sizes%rs_group%mepos_cart
3372 fft_scratch_new%fft_scratch%mip = fft_sizes%rs_group%mepos
3373 fft_scratch_new%fft_scratch%dim = dim
3374 fft_scratch_new%fft_scratch%pos = pos
3375 mcz1 = fft_sizes%mcz1
3376 mcx2 = fft_sizes%mcx2
3377 mcz2 = fft_sizes%mcz2
3378 mcy3 = fft_sizes%mcy3
3379 ALLOCATE (fft_scratch_new%fft_scratch%rbuf1(mx2*my1*mcz2, 0:dim(2) - 1))
3380 ALLOCATE (fft_scratch_new%fft_scratch%rbuf2(mx1*my1*mcz2, 0:dim(2) - 1))
3381 ALLOCATE (fft_scratch_new%fft_scratch%rbuf3(mx2*mz3*mcy3, 0:dim(1) - 1))
3382 ALLOCATE (fft_scratch_new%fft_scratch%rbuf4(mx2*mz2*mcy3, 0:dim(1) - 1))
3383
3384 dims = [.true., .false.]
3385 CALL fft_scratch_new%fft_scratch%cart_sub_comm(1)%from_sub(fft_sizes%rs_group, dims)
3386 dims = [.false., .true.]
3387 CALL fft_scratch_new%fft_scratch%cart_sub_comm(2)%from_sub(fft_sizes%rs_group, dims)
3388
3389 !initialise pgcube
3390 DO i = 0, dim(1) - 1
3391 coord = [i, pos(2)]
3392 CALL fft_sizes%rs_group%rank_cart(coord, fft_scratch_new%fft_scratch%pgcube(i, 1))
3393 END DO
3394 DO i = 0, dim(2) - 1
3395 coord = [pos(1), i]
3396 CALL fft_sizes%rs_group%rank_cart(coord, fft_scratch_new%fft_scratch%pgcube(i, 2))
3397 END DO
3398
3399 !set up fft plans
3400 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(1), fwfft, .true., .false., &
3401 mx1*my1, n(3), n(3), mx1*my1, &
3402 fft_scratch_new%fft_scratch%a1buf, fft_scratch_new%fft_scratch%a2buf)
3403 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(2), fwfft, .true., .false., &
3404 mx2*mz2, n(2), n(2), mx2*mz2, &
3405 fft_scratch_new%fft_scratch%a3buf, fft_scratch_new%fft_scratch%a4buf)
3406 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(3), fwfft, .true., .false., &
3407 my3*mz3, n(1), n(1), my3*mz3, &
3408 fft_scratch_new%fft_scratch%a5buf, fft_scratch_new%fft_scratch%a6buf)
3409 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(4), bwfft, .false., .true., &
3410 n(1), my3*mz3, n(1), my3*mz3, &
3411 fft_scratch_new%fft_scratch%a6buf, fft_scratch_new%fft_scratch%a5buf)
3412 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(5), bwfft, .false., .true., &
3413 n(2), mx2*mz2, n(2), mx2*mz2, &
3414 fft_scratch_new%fft_scratch%a4buf, fft_scratch_new%fft_scratch%a3buf)
3415 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(6), bwfft, .false., .true., &
3416 n(3), mx1*my1, n(3), mx1*my1, &
3417 fft_scratch_new%fft_scratch%a2buf, fft_scratch_new%fft_scratch%a1buf)
3418
3419 CASE (101) ! fft3d_pb: full cube distribution (dim 1)
3420 cpassert(PRESENT(fft_sizes))
3421 mx1 = fft_sizes%mx1
3422 my1 = fft_sizes%my1
3423 mz1 = fft_sizes%mz1
3424 my3 = fft_sizes%my3
3425 mz3 = fft_sizes%mz3
3426 CALL fft_allocate(fft_scratch_new%fft_scratch%a1buf, [mx1*my1, n(3)])
3427 CALL fft_allocate(fft_scratch_new%fft_scratch%a2buf, [n(3), mx1*my1])
3428 fft_scratch_new%fft_scratch%group = fft_sizes%rs_group
3429 CALL fft_allocate(fft_scratch_new%fft_scratch%a4buf, [n(2), mx1*mz1])
3430 CALL fft_allocate(fft_scratch_new%fft_scratch%a5buf, [my3*mz3, n(1)])
3431 CALL fft_allocate(fft_scratch_new%fft_scratch%a6buf, [n(1), my3*mz3])
3432
3433 dim = fft_sizes%rs_group%num_pe_cart
3434 pos = fft_sizes%rs_group%mepos_cart
3435 fft_scratch_new%fft_scratch%mip = fft_sizes%rs_group%mepos
3436 fft_scratch_new%fft_scratch%dim = dim
3437 fft_scratch_new%fft_scratch%pos = pos
3438 mcy3 = fft_sizes%mcy3
3439 ALLOCATE (fft_scratch_new%fft_scratch%rbuf5(mx1*mz3*mcy3, 0:dim(1) - 1))
3440 ALLOCATE (fft_scratch_new%fft_scratch%rbuf6(mx1*mz1*mcy3, 0:dim(1) - 1))
3441
3442 !set up fft plans
3443 CALL fft_create_plan_2d(fft_scratch_new%fft_scratch%fft_plan(1), fwfft, .true., .false., &
3444 [n(2), n(3)], mx1, &
3445 fft_scratch_new%fft_scratch%a1buf, fft_scratch_new%fft_scratch%a4buf)
3446 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(3), fwfft, .true., .false., &
3447 my3*mz3, n(1), n(1), my3*mz3, &
3448 fft_scratch_new%fft_scratch%a5buf, fft_scratch_new%fft_scratch%a6buf)
3449 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(4), bwfft, .false., .true., &
3450 n(1), my3*mz3, n(1), my3*mz3, &
3451 fft_scratch_new%fft_scratch%a6buf, fft_scratch_new%fft_scratch%a5buf)
3452 CALL fft_create_plan_2d(fft_scratch_new%fft_scratch%fft_plan(5), bwfft, .false., .true., &
3453 [n(2), n(3)], mx1, fft_scratch_new%fft_scratch%a4buf, fft_scratch_new%fft_scratch%a1buf)
3454
3455 CASE (200) ! fft3d_ps: plane distribution
3456 cpassert(PRESENT(fft_sizes))
3457 nx = fft_sizes%nx
3458 ny = fft_sizes%ny
3459 nz = fft_sizes%nz
3460 mx2 = fft_sizes%mx2
3461 lmax = fft_sizes%lmax
3462 mmax = fft_sizes%mmax
3463 lg = fft_sizes%lg
3464 mg = fft_sizes%mg
3465 np = fft_sizes%numtask
3466 nmray = fft_sizes%nmray
3467 nyzray = fft_sizes%nyzray
3468#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3469 length = int(2*dp_size*max(mmax, 1)*max(lmax, 1), kind=c_size_t)
3470 ierr = offload_malloc_pinned_mem(cptr_r1buf, length)
3471 cpassert(ierr == 0)
3472 CALL c_f_pointer(cptr_r1buf, fft_scratch_new%fft_scratch%r1buf, [max(mmax, 1), max(lmax, 1)])
3473 length = int(2*dp_size*max(ny, 1)*max(nz, 1)*max(nx, 1), kind=c_size_t)
3474 ierr = offload_malloc_pinned_mem(cptr_tbuf, length)
3475 cpassert(ierr == 0)
3476 CALL c_f_pointer(cptr_tbuf, fft_scratch_new%fft_scratch%tbuf, [max(ny, 1), max(nz, 1), max(nx, 1)])
3477#else
3478 CALL fft_allocate(fft_scratch_new%fft_scratch%r1buf, [mmax, lmax])
3479 CALL fft_allocate(fft_scratch_new%fft_scratch%tbuf, [ny, nz, nx])
3480#endif
3481 fft_scratch_new%fft_scratch%group = fft_sizes%rs_group
3482 CALL fft_allocate(fft_scratch_new%fft_scratch%r2buf, [lg, mg])
3483 nm = nmray*mx2
3484 IF (alltoall_sgl) THEN
3485 ALLOCATE (fft_scratch_new%fft_scratch%ss(mmax, lmax))
3486 ALLOCATE (fft_scratch_new%fft_scratch%tt(nm, 0:np - 1))
3487 ELSE
3488 ALLOCATE (fft_scratch_new%fft_scratch%rr(nm, 0:np - 1))
3489 END IF
3490
3491 !set up fft plans
3492 CALL fft_create_plan_2d(fft_scratch_new%fft_scratch%fft_plan(1), fwfft, .true., .false., &
3493 [ny, nz], nx, fft_scratch_new%fft_scratch%r1buf, fft_scratch_new%fft_scratch%tbuf)
3494 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(3), fwfft, .true., .false., &
3495 nyzray, n(1), n(1), nyzray, &
3496 fft_scratch_new%fft_scratch%r1buf, fft_scratch_new%fft_scratch%r2buf)
3497 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(4), bwfft, .false., .true., &
3498 n(1), nyzray, n(1), nyzray, &
3499 fft_scratch_new%fft_scratch%r2buf, fft_scratch_new%fft_scratch%r1buf)
3500 CALL fft_create_plan_2d(fft_scratch_new%fft_scratch%fft_plan(5), bwfft, .false., .true., &
3501 [ny, nz], nx, &
3502 fft_scratch_new%fft_scratch%tbuf, fft_scratch_new%fft_scratch%r1buf)
3503
3504 CASE (300) ! fft3d_ps: block distribution
3505 cpassert(PRESENT(fft_sizes))
3506 mx1 = fft_sizes%mx1
3507 mx2 = fft_sizes%mx2
3508 my1 = fft_sizes%my1
3509 mz2 = fft_sizes%mz2
3510 mcx2 = fft_sizes%mcx2
3511 lg = fft_sizes%lg
3512 mg = fft_sizes%mg
3513 nmax = fft_sizes%nmax
3514 nmray = fft_sizes%nmray
3515 nyzray = fft_sizes%nyzray
3516 m1 = fft_sizes%r_dim(1)
3517 m2 = fft_sizes%r_dim(2)
3518 nbx = fft_sizes%nbx
3519 nbz = fft_sizes%nbz
3520 CALL fft_allocate(fft_scratch_new%fft_scratch%p1buf, [mx1*my1, n(3)])
3521 CALL fft_allocate(fft_scratch_new%fft_scratch%p6buf, [lg, mg])
3522#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
3523 length = int(2*dp_size*max(n(3), 1)*max(mx1*my1, 1), kind=c_size_t)
3524 ierr = offload_malloc_pinned_mem(cptr_p2buf, length)
3525 cpassert(ierr == 0)
3526 CALL c_f_pointer(cptr_p2buf, fft_scratch_new%fft_scratch%p2buf, [max(n(3), 1), max(mx1*my1, 1)])
3527 length = int(2*dp_size*max(mx2*mz2, 1)*max(n(2), 1), kind=c_size_t)
3528 ierr = offload_malloc_pinned_mem(cptr_p3buf, length)
3529 cpassert(ierr == 0)
3530 CALL c_f_pointer(cptr_p3buf, fft_scratch_new%fft_scratch%p3buf, [max(mx2*mz2, 1), max(n(2), 1)])
3531 length = int(2*dp_size*max(n(2), 1)*max(mx2*mz2, 1), kind=c_size_t)
3532 ierr = offload_malloc_pinned_mem(cptr_p4buf, length)
3533 cpassert(ierr == 0)
3534 CALL c_f_pointer(cptr_p4buf, fft_scratch_new%fft_scratch%p4buf, [max(n(2), 1), max(mx2*mz2, 1)])
3535 length = int(2*dp_size*max(nyzray, 1)*max(n(1), 1), kind=c_size_t)
3536 ierr = offload_malloc_pinned_mem(cptr_p5buf, length)
3537 cpassert(ierr == 0)
3538 CALL c_f_pointer(cptr_p5buf, fft_scratch_new%fft_scratch%p5buf, [max(nyzray, 1), max(n(1), 1)])
3539 length = int(2*dp_size*max(mg, 1)*max(lg, 1), kind=c_size_t)
3540 ierr = offload_malloc_pinned_mem(cptr_p7buf, length)
3541 cpassert(ierr == 0)
3542 CALL c_f_pointer(cptr_p7buf, fft_scratch_new%fft_scratch%p7buf, [max(mg, 1), max(lg, 1)])
3543#else
3544 CALL fft_allocate(fft_scratch_new%fft_scratch%p2buf, [n(3), mx1*my1])
3545 CALL fft_allocate(fft_scratch_new%fft_scratch%p3buf, [mx2*mz2, n(2)])
3546 CALL fft_allocate(fft_scratch_new%fft_scratch%p4buf, [n(2), mx2*mz2])
3547 CALL fft_allocate(fft_scratch_new%fft_scratch%p5buf, [nyzray, n(1)])
3548 CALL fft_allocate(fft_scratch_new%fft_scratch%p7buf, [mg, lg])
3549#endif
3550 IF (alltoall_sgl) THEN
3551 ALLOCATE (fft_scratch_new%fft_scratch%yzbuf_sgl(mg*lg))
3552 ALLOCATE (fft_scratch_new%fft_scratch%xzbuf_sgl(n(2)*mx2*mz2))
3553 ELSE
3554 ALLOCATE (fft_scratch_new%fft_scratch%yzbuf(mg*lg))
3555 ALLOCATE (fft_scratch_new%fft_scratch%xzbuf(n(2)*mx2*mz2))
3556 END IF
3557 ALLOCATE (fft_scratch_new%fft_scratch%pgrid(0:m1 - 1, 0:m2 - 1))
3558 ALLOCATE (fft_scratch_new%fft_scratch%xcor(nbx))
3559 ALLOCATE (fft_scratch_new%fft_scratch%zcor(nbz))
3560 ALLOCATE (fft_scratch_new%fft_scratch%pzcoord(0:np - 1))
3561 ALLOCATE (fft_scratch_new%fft_scratch%xzcount(0:np - 1), &
3562 fft_scratch_new%fft_scratch%yzcount(0:np - 1))
3563 ALLOCATE (fft_scratch_new%fft_scratch%xzdispl(0:np - 1), &
3564 fft_scratch_new%fft_scratch%yzdispl(0:np - 1))
3565 fft_scratch_new%fft_scratch%group = fft_sizes%rs_group
3566
3567 dim = fft_sizes%rs_group%num_pe_cart
3568 pos = fft_sizes%rs_group%mepos_cart
3569 fft_scratch_new%fft_scratch%mip = fft_sizes%rs_group%mepos
3570 fft_scratch_new%fft_scratch%dim = dim
3571 fft_scratch_new%fft_scratch%pos = pos
3572 mcz1 = fft_sizes%mcz1
3573 mcz2 = fft_sizes%mcz2
3574 ALLOCATE (fft_scratch_new%fft_scratch%rbuf1(mx2*my1*mcz2, 0:dim(2) - 1))
3575 ALLOCATE (fft_scratch_new%fft_scratch%rbuf2(mx1*my1*mcz2, 0:dim(2) - 1))
3576
3577 dims = [.false., .true.]
3578 CALL fft_scratch_new%fft_scratch%cart_sub_comm(2)%from_sub(fft_sizes%rs_group, dims)
3579
3580 !initialise pgcube
3581 DO i = 0, dim(2) - 1
3582 coord = [pos(1), i]
3583 CALL fft_sizes%rs_group%rank_cart(coord, fft_scratch_new%fft_scratch%pgcube(i, 2))
3584 END DO
3585
3586 !initialise pgrid
3587 DO ix = 0, m1 - 1
3588 DO iz = 0, m2 - 1
3589 coord = [ix, iz]
3590 CALL fft_sizes%rs_group%rank_cart(coord, fft_scratch_new%fft_scratch%pgrid(ix, iz))
3591 END DO
3592 END DO
3593
3594 !initialise pzcoord
3595 DO i = 0, np - 1
3596 CALL fft_sizes%rs_group%coords(i, pcoord)
3597 fft_scratch_new%fft_scratch%pzcoord(i) = pcoord(2)
3598 END DO
3599
3600 !set up fft plans
3601 ! The scratch buffers must cover the geometry declared in each call
3602 ! below, because the FFTW planner may write the buffers during
3603 ! planning. The plans pair the buffers such that each of p1-p6 is
3604 ! checked once; p7 shares the size of p6.
3605 cpassert(SIZE(fft_scratch_new%fft_scratch%p1buf) >= mx1*my1*n(3))
3606 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(1), fwfft, .true., .false., &
3607 mx1*my1, n(3), n(3), mx1*my1, &
3608 fft_scratch_new%fft_scratch%p1buf, fft_scratch_new%fft_scratch%p2buf)
3609 cpassert(SIZE(fft_scratch_new%fft_scratch%p3buf) >= mx2*mz2*n(2))
3610 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(2), fwfft, .true., .false., &
3611 mx2*mz2, n(2), n(2), mx2*mz2, &
3612 fft_scratch_new%fft_scratch%p3buf, fft_scratch_new%fft_scratch%p4buf)
3613 cpassert(SIZE(fft_scratch_new%fft_scratch%p5buf) >= nyzray*n(1))
3614 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(3), fwfft, .true., .false., &
3615 nyzray, n(1), n(1), nyzray, &
3616 fft_scratch_new%fft_scratch%p5buf, fft_scratch_new%fft_scratch%p6buf)
3617 cpassert(SIZE(fft_scratch_new%fft_scratch%p6buf) >= n(1)*nyzray)
3618 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(4), bwfft, .false., .true., &
3619 n(1), nyzray, n(1), nyzray, &
3620 fft_scratch_new%fft_scratch%p6buf, fft_scratch_new%fft_scratch%p7buf)
3621 cpassert(SIZE(fft_scratch_new%fft_scratch%p4buf) >= n(2)*mx2*mz2)
3622 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(5), bwfft, .false., .true., &
3623 n(2), mx2*mz2, n(2), mx2*mz2, &
3624 fft_scratch_new%fft_scratch%p4buf, fft_scratch_new%fft_scratch%p3buf)
3625 cpassert(SIZE(fft_scratch_new%fft_scratch%p2buf) >= n(3)*mx1*my1)
3626 CALL fft_create_plan_1d(fft_scratch_new%fft_scratch%fft_plan(6), bwfft, .false., .true., &
3627 n(3), mx1*my1, n(3), mx1*my1, &
3628 fft_scratch_new%fft_scratch%p2buf, fft_scratch_new%fft_scratch%p1buf)
3629
3630 CASE (400) ! serial FFT
3631 np = 0
3632 CALL fft_allocate(fft_scratch_new%fft_scratch%ziptr, n)
3633 CALL fft_allocate(fft_scratch_new%fft_scratch%zoptr, n)
3634
3635 !in place plans
3636 CALL fft_create_plan_3d_inplace(fft_scratch_new%fft_scratch%fft_plan(1), fwfft, n, &
3637 fft_scratch_new%fft_scratch%ziptr)
3638 CALL fft_create_plan_3d_inplace(fft_scratch_new%fft_scratch%fft_plan(2), bwfft, n, &
3639 fft_scratch_new%fft_scratch%ziptr)
3640 ! out of place plans
3641 CALL fft_create_plan_3d(fft_scratch_new%fft_scratch%fft_plan(3), fwfft, n, &
3642 fft_scratch_new%fft_scratch%ziptr, fft_scratch_new%fft_scratch%zoptr)
3643 CALL fft_create_plan_3d(fft_scratch_new%fft_scratch%fft_plan(4), bwfft, n, &
3644 fft_scratch_new%fft_scratch%ziptr, fft_scratch_new%fft_scratch%zoptr)
3645
3646 END SELECT
3647
3648 NULLIFY (fft_scratch_new%fft_scratch_next)
3649 fft_scratch_new%fft_scratch%fft_scratch_id = &
3650 fft_scratch_last%fft_scratch%fft_scratch_id + 1
3651 fft_scratch_new%fft_scratch%in_use = .true.
3652 fft_scratch_new%fft_scratch%nfft = n
3653 fft_scratch_last%fft_scratch_next => fft_scratch_new
3654 fft_scratch_new%fft_scratch%tf_type = tf_type
3655 fft_scratch => fft_scratch_new%fft_scratch
3656 EXIT
3657
3658 END IF
3659 END DO
3660
3661!$OMP ATOMIC READ
3662 fft_scratch%last_tick = tick_fft_pool
3663
3664 CALL timestop(handle)
3665
3666 END SUBROUTINE get_fft_scratch
3667
3668! **************************************************************************************************
3669!> \brief ...
3670!> \param fft_scratch ...
3671! **************************************************************************************************
3672 SUBROUTINE release_fft_scratch(fft_scratch)
3673
3674 TYPE(fft_scratch_type), POINTER :: fft_scratch
3675
3676 INTEGER :: scratch_id
3677 TYPE(fft_scratch_pool_type), POINTER :: fft_scratch_current
3678
3679 scratch_id = fft_scratch%fft_scratch_id
3680
3681 fft_scratch_current => fft_scratch_first
3682 DO
3683 IF (ASSOCIATED(fft_scratch_current)) THEN
3684 IF (scratch_id == fft_scratch_current%fft_scratch%fft_scratch_id) THEN
3685 fft_scratch%in_use = .false.
3686 NULLIFY (fft_scratch)
3687 EXIT
3688 END IF
3689 fft_scratch_current => fft_scratch_current%fft_scratch_next
3690 ELSE
3691 ! We cannot find the scratch type in this pool
3692 cpabort("Invalid scratch type.")
3693 EXIT
3694 END IF
3695 END DO
3696
3697 END SUBROUTINE release_fft_scratch
3698
3699! **************************************************************************************************
3700!> \brief ...
3701!> \param rs ...
3702!> \param scount ...
3703!> \param sdispl ...
3704!> \param rq ...
3705!> \param rcount ...
3706!> \param rdispl ...
3707!> \param group ...
3708! **************************************************************************************************
3709 SUBROUTINE sparse_alltoall(rs, scount, sdispl, rq, rcount, rdispl, group)
3710 COMPLEX(KIND=dp), DIMENSION(:), POINTER :: rs
3711 INTEGER, DIMENSION(:), POINTER :: scount, sdispl
3712 COMPLEX(KIND=dp), DIMENSION(:), POINTER :: rq
3713 INTEGER, DIMENSION(:), POINTER :: rcount, rdispl
3714 CLASS(mp_comm_type), INTENT(IN) :: group
3715
3716 COMPLEX(KIND=dp), DIMENSION(:), POINTER :: msgin, msgout
3717 INTEGER :: ip, n, nr, ns, pos
3718 TYPE(mp_request_type), ALLOCATABLE, DIMENSION(:) :: rreq, sreq
3719
3720 CALL group%sync()
3721 n = group%num_pe
3722 pos = group%mepos
3723 ALLOCATE (sreq(0:n - 1))
3724 ALLOCATE (rreq(0:n - 1))
3725 nr = 0
3726 DO ip = 0, n - 1
3727 IF (rcount(ip) == 0) cycle
3728 IF (ip == pos) cycle
3729 msgout => rq(rdispl(ip) + 1:rdispl(ip) + rcount(ip))
3730 CALL group%irecv(msgout, ip, rreq(nr))
3731 nr = nr + 1
3732 END DO
3733 ns = 0
3734 DO ip = 0, n - 1
3735 IF (scount(ip) == 0) cycle
3736 IF (ip == pos) cycle
3737 msgin => rs(sdispl(ip) + 1:sdispl(ip) + scount(ip))
3738 CALL group%isend(msgin, ip, sreq(ns))
3739 ns = ns + 1
3740 END DO
3741 IF (rcount(pos) /= 0) THEN
3742 IF (rcount(pos) /= scount(pos)) cpabort("Invalid count.")
3743 rq(rdispl(pos) + 1:rdispl(pos) + rcount(pos)) = rs(sdispl(pos) + 1:sdispl(pos) + scount(pos))
3744 END IF
3745 CALL mp_waitall(sreq(0:ns - 1))
3746 CALL mp_waitall(rreq(0:nr - 1))
3747 DEALLOCATE (sreq)
3748 DEALLOCATE (rreq)
3749 CALL group%sync()
3750
3751 END SUBROUTINE sparse_alltoall
3752
3753! **************************************************************************************************
3754!> \brief test data structures for equality. It is assumed that if they are
3755!> different for one mpi task they are different for all (??)
3756!> \param fft_size_1 ...
3757!> \param fft_size_2 ...
3758!> \param equal ...
3759! **************************************************************************************************
3760 SUBROUTINE is_equal(fft_size_1, fft_size_2, equal)
3761 TYPE(fft_scratch_sizes) :: fft_size_1, fft_size_2
3762 LOGICAL :: equal
3763
3764 equal = .true.
3765
3766 equal = equal .AND. fft_size_1%nx == fft_size_2%nx
3767 equal = equal .AND. fft_size_1%ny == fft_size_2%ny
3768 equal = equal .AND. fft_size_1%nz == fft_size_2%nz
3769
3770 equal = equal .AND. fft_size_1%lmax == fft_size_2%lmax
3771 equal = equal .AND. fft_size_1%mmax == fft_size_2%mmax
3772 equal = equal .AND. fft_size_1%nmax == fft_size_2%nmax
3773
3774 equal = equal .AND. fft_size_1%mx1 == fft_size_2%mx1
3775 equal = equal .AND. fft_size_1%mx2 == fft_size_2%mx2
3776 equal = equal .AND. fft_size_1%mx3 == fft_size_2%mx3
3777
3778 equal = equal .AND. fft_size_1%my1 == fft_size_2%my1
3779 equal = equal .AND. fft_size_1%my2 == fft_size_2%my2
3780 equal = equal .AND. fft_size_1%my3 == fft_size_2%my3
3781
3782 equal = equal .AND. fft_size_1%mcz1 == fft_size_2%mcz1
3783 equal = equal .AND. fft_size_1%mcx2 == fft_size_2%mcx2
3784 equal = equal .AND. fft_size_1%mcz2 == fft_size_2%mcz2
3785 equal = equal .AND. fft_size_1%mcy3 == fft_size_2%mcy3
3786
3787 equal = equal .AND. fft_size_1%lg == fft_size_2%lg
3788 equal = equal .AND. fft_size_1%mg == fft_size_2%mg
3789
3790 equal = equal .AND. fft_size_1%nbx == fft_size_2%nbx
3791 equal = equal .AND. fft_size_1%nbz == fft_size_2%nbz
3792
3793 equal = equal .AND. fft_size_1%nmray == fft_size_2%nmray
3794 equal = equal .AND. fft_size_1%nyzray == fft_size_2%nyzray
3795
3796 equal = equal .AND. fft_size_1%rs_group == fft_size_2%rs_group
3797
3798 equal = equal .AND. all(fft_size_1%g_pos == fft_size_2%g_pos)
3799 equal = equal .AND. all(fft_size_1%r_pos == fft_size_2%r_pos)
3800 equal = equal .AND. all(fft_size_1%r_dim == fft_size_2%r_dim)
3801
3802 equal = equal .AND. fft_size_1%numtask == fft_size_2%numtask
3803
3804 END SUBROUTINE is_equal
3805
3806END MODULE fft_tools
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Fortran API for the FFT package, which is written in C.
Definition fft_api.F:12
subroutine, public fft_register_3d_local_inplace(direction, fft_size, number_of_ffts, transpose, grid)
Registers a complex-to-complex 3D FFT.
Definition fft_api.F:672
subroutine, public fft_2d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Performs a complex-to-complex 2D FFT.
Definition fft_api.F:757
subroutine, public fft_register_3d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Registers a complex-to-complex 3D FFT.
Definition fft_api.F:559
subroutine, public fft_register_2d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Registers a complex-to-complex 2D FFT.
Definition fft_api.F:519
subroutine, public fft_3d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, grid_in, grid_out)
Performs a complex-to-complex 3D FFT.
Definition fft_api.F:796
subroutine, public fft_1d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, leading_dimension_in, leading_dimension_out, grid_in, grid_out)
Performs a complex-to-complex 1D FFT.
Definition fft_api.F:713
subroutine, public fft_library_init(backend, planning_mode, use_guru_interface, wisdom_file, status)
Initialize FFT library.
Definition fft_api.F:114
subroutine, public fft_3d_local_inplace(direction, fft_size, number_of_ffts, transpose, grid)
Performs a complex-to-complex 3D FFT.
Definition fft_api.F:906
subroutine, public fft_library_finalize(wisdom_file)
Finalize FFT library.
Definition fft_api.F:152
subroutine, public fft_register_1d_local(direction, fft_size, number_of_ffts, transpose_in, transpose_out, leading_dimension_in, leading_dimension_out, grid_in, grid_out)
Registers a complex-to-complex 1D FFT.
Definition fft_api.F:474
subroutine, public fft_radix_operations(radix_in, radix_out, operation)
Determine the allowed lengths of FFT's '''.
Definition fft_tools.F:457
logical, parameter, public fwfft
Definition fft_tools.F:155
subroutine, public finalize_fft(wisdom_file)
does whatever is needed to finalize the current fft setup
Definition fft_tools.F:225
subroutine, public init_fft(fftlib, alltoall, pool_limit, wisdom_file, plan_style, status, use_guru_interface)
...
Definition fft_tools.F:192
integer, save init_fft_pool
Definition fft_tools.F:137
subroutine, public yz_to_x(tb, group, my_pos, p2p, yzp, nray, bo, sb, fft_scratch)
...
Definition fft_tools.F:1878
subroutine, public fft_create_plan_3d(plan, fsign, n, zin, zout)
...
Definition fft_tools.F:669
subroutine, public fft_destroy_plan(plan)
...
Definition fft_tools.F:757
subroutine, public yz_to_xz(sb, group, dims, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
...
Definition fft_tools.F:1994
subroutine, public init_fft_scratch_pool()
...
Definition fft_tools.F:2976
subroutine, public fft_1d(plan, zin, zout, scale)
...
Definition fft_tools.F:771
subroutine, public fft_create_plan_1d(plan, fsign, trans_in, trans_out, ldx_in, ldx_out, n, m, zin, zout)
...
Definition fft_tools.F:575
subroutine, public cube_transpose_1(cin, boin, boout, sout, fft_scratch)
...
Definition fft_tools.F:2406
logical, parameter, public bwfft
Definition fft_tools.F:155
integer, parameter, public fft_radix_closest
Definition fft_tools.F:156
subroutine, public release_fft_scratch(fft_scratch)
...
Definition fft_tools.F:3673
subroutine, public x_to_yz(sb, group, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
...
Definition fft_tools.F:1763
integer, save tick_fft_pool
Definition fft_tools.F:139
subroutine, public get_fft_scratch(fft_scratch, tf_type, n, fft_sizes)
...
Definition fft_tools.F:3270
integer, parameter, public fft_radix_next_odd
Definition fft_tools.F:158
subroutine, public fft_3d(plan, scale, zin, zout)
...
Definition fft_tools.F:717
subroutine, public xz_to_yz(sb, group, dims, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
...
Definition fft_tools.F:2208
subroutine, public cube_transpose_2(cin, boin, boout, sout, fft_scratch)
...
Definition fft_tools.F:2496
type(fft_scratch_pool_type), pointer, save fft_scratch_first
Definition fft_tools.F:142
integer, save fft_pool_scratch_limit
Definition fft_tools.F:141
integer, parameter, public fft_radix_next
Definition fft_tools.F:156
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp_size
Definition kinds.F:36
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public sp
Definition kinds.F:33
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
type(mp_comm_type), parameter, public mp_comm_null
Fortran API for the offload package, which is written in C.
Definition offload_api.F:12
integer function, public offload_free_pinned_mem(buffer)
free pinned memory
Definition offload_api.F:75
integer function, public offload_malloc_pinned_mem(buffer, length)
allocate pinned memory.
Definition offload_api.F:52