-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfft_essl.f90
729 lines (604 loc) · 20.4 KB
/
fft_essl.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
!=======================================================================
! This is part of the 2DECOMP&FFT library
!
! 2DECOMP&FFT is a software framework for general-purpose 2D (pencil)
! decomposition. It also implements a highly scalable distributed
! three-dimensional Fast Fourier Transform (FFT).
!
! Copyright (C) 2009-2012 Ning Li, the Numerical Algorithms Group (NAG)
!
!=======================================================================
! This is the ESSL implementation of the FFT library
module decomp_2d_fft
use decomp_2d ! 2D decomposition module
use glassman
implicit none
private ! Make everything private unless declared public
! engine-specific global variables
! always perform unscaled FFTs
real(mytype), parameter :: scale=1.0_mytype
! number of supported transform lengths
integer, parameter :: MAGIC=451
! work space
integer, save :: naux1, naux2, naux3
double precision, allocatable, dimension(:) :: aux1, aux2, aux3
complex(mytype), allocatable, dimension(:) :: buf, scratch
! ESSL has a list of acceptable lengths for transforms
! - if winthin this list, use ESSL calls directly
! - if not, use the less efficient generic implementation
logical, save :: x_goodsize, y_goodsize, z_goodsize
! common code used for all engines, including global variables,
! generic interface definitions and several subroutines
#include "fft_common.f90"
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! This routine performs one-time initialisations for the FFT engine
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine init_fft_engine
implicit none
integer, dimension(MAGIC) :: lengths
integer :: bufsize, tmp1, tmp2
if (nrank==0) then
write(*,*) ' '
write(*,*) '***** Using the ESSL engine *****'
write(*,*) ' '
end if
! Most ESSL FFT routines work on a limited set of sample size
call get_acceptable_length(lengths)
if (binarySearch(lengths, nx_fft)==0) then
x_goodsize = .false.
else
x_goodsize = .true.
end if
if (binarySearch(lengths, ny_fft)==0) then
y_goodsize = .false.
else
y_goodsize = .true.
end if
if (binarySearch(lengths, nz_fft)==0) then
z_goodsize = .false.
else
z_goodsize = .true.
end if
if (nrank==0) then
if ( (.not.x_goodsize) .or. (.not.y_goodsize) &
.or. (.not.z_goodsize) ) then
write(*,*) '***WARNING***: sample size not supported by ESSL.'
write(*,*) 'Please consult the ESSL documentation for detail.'
write(*,*) '2DECOMP&FFT will use alternative FFT algorithms.'
write(*,*) 'You will still get the correct results.'
write(*,*) 'But performance of your application may suffer.'
end if
end if
! allocate ESSL work space
call cftd_wk(naux1, naux2)
call cft_wk(tmp1, tmp2)
naux1 = max(naux1, tmp1)
naux2 = max(naux2, tmp2)
call rcft_wk(tmp1, tmp2)
naux1 = max(naux1, tmp1)
naux2 = max(naux2, tmp2)
naux3 = 1 ! not in use by ESSL but exists for migration purpose
!if (nrank==0) then
! write(*,*) '3D problem size:', ph%xsz(1), ph%ysz(2), ph%zsz(3)
! write(*,*) 'Work array size:', naux1, naux2
!end if
allocate(aux1(naux1))
allocate(aux2(naux2))
allocate(aux3(naux3))
! work space by generic algorithm for FFT sizes unsupported by ESSL
bufsize = max(ph%xsz(1),ph%zsz(3))
allocate(buf(bufsize))
allocate(scratch(bufsize))
return
end subroutine init_fft_engine
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! This routine performs one-time finalisations for the FFT engine
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine finalize_fft_engine
implicit none
deallocate(aux1, aux2, aux3)
deallocate(buf, scratch)
return
end subroutine finalize_fft_engine
! Following routines calculate multiple one-dimensional FFTs to form
! the basis of three-dimensional FFTs.
! *** NOTE, in ESSL forward transforms have isign>0 and backward ones
! have isign<0. This is different from other FFT libraries.
! c2c transform, multiple 1D FFTs in x direction
subroutine c2c_1m_x(inout, isign, decomp)
implicit none
complex(mytype), dimension(:,:,:), intent(INOUT) :: inout
integer, intent(IN) :: isign
TYPE(DECOMP_INFO), intent(IN) :: decomp
if (x_goodsize) then
#ifdef DOUBLE_PREC
call dcft(1,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
call dcft(0,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
#else
call scft(1,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
call scft(0,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
#endif
else
#ifdef DOUBLE_PREC
call dcftd(1,1,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
call dcftd(0,1,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
#else
call scftd(1,1,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
call scftd(0,1,inout,1,decomp%xsz(1),inout,1,decomp%xsz(1), &
decomp%xsz(1),decomp%xsz(2)*decomp%xsz(3) &
,-isign,scale,aux1,naux1,aux2,naux2)
#endif
end if
return
end subroutine c2c_1m_x
! c2c transform, multiple 1D FFTs in y direction
subroutine c2c_1m_y(inout, isign, decomp)
implicit none
complex(mytype), dimension(:,:,:), intent(INOUT) :: inout
integer, intent(IN) :: isign
TYPE(DECOMP_INFO), intent(IN) :: decomp
integer :: k
if (y_goodsize) then
#ifdef DOUBLE_PREC
call dcft(1,inout,decomp%ysz(1),1,inout,decomp%ysz(1),1, &
decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
do k=1,decomp%ysz(3)
call dcft(0,inout(:,:,k),decomp%ysz(1),1,inout(:,:,k), &
decomp%ysz(1),1,decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
end do
#else
call scft(1,inout,decomp%ysz(1),1,inout,decomp%ysz(1),1, &
decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
do k=1,decomp%ysz(3)
call scft(0,inout(:,:,k),decomp%ysz(1),1,inout(:,:,k), &
decomp%ysz(1),1,decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
end do
#endif
else
#ifdef DOUBLE_PREC
call dcftd(1,1,inout,decomp%ysz(1),1,inout,decomp%ysz(1),1, &
decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
do k=1,decomp%ysz(3)
call dcftd(0,1,inout(:,:,k),decomp%ysz(1),1,inout(:,:,k), &
decomp%ysz(1),1,decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
enddo
#else
call scftd(1,1,inout,decomp%ysz(1),1,inout,decomp%ysz(1),1, &
decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
do k=1,decomp%ysz(3)
call scftd(0,1,inout(:,:,k),decomp%ysz(1),1,inout(:,:,k), &
decomp%ysz(1),1,decomp%ysz(2),decomp%ysz(1), &
-isign,scale,aux1,naux1,aux2,naux2)
enddo
#endif
end if
return
end subroutine c2c_1m_y
! c2c transform, multiple 1D FFTs in z direction
subroutine c2c_1m_z(inout, isign, decomp)
implicit none
complex(mytype), dimension(:,:,:), intent(INOUT) :: inout
integer, intent(IN) :: isign
TYPE(DECOMP_INFO), intent(IN) :: decomp
if (z_goodsize) then
#ifdef DOUBLE_PREC
call dcft(1,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
call dcft(0,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
#else
call scft(1,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
call scft(0,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
#endif
else
#ifdef DOUBLE_PREC
call dcftd(1,1,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
call dcftd(0,1,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
#else
call scftd(1,1,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
call scftd(0,1,inout,decomp%zsz(1)*decomp%zsz(2),1,inout, &
decomp%zsz(1)*decomp%zsz(2),1,decomp%zsz(3), &
decomp%zsz(1)*decomp%zsz(2), &
-isign,scale,aux1,naux1,aux2,naux2)
#endif
end if
return
end subroutine c2c_1m_z
! r2c transform, multiple 1D FFTs in x direction
subroutine r2c_1m_x(input, output)
implicit none
real(mytype), dimension(:,:,:), intent(IN) :: input
complex(mytype), dimension(:,:,:), intent(OUT) :: output
integer :: i,j,k
if (x_goodsize) then
#ifdef DOUBLE_PREC
call drcft(1,input,ph%xsz(1),output,sp%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
call drcft(0,input,ph%xsz(1),output,sp%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
#else
call srcft(1,input,ph%xsz(1),output,sp%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
call srcft(0,input,ph%xsz(1),output,sp%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
#endif
else
! For tranfer lengths not supported by ESSL, using generic
do k=1,ph%xsz(3)
do j=1,ph%xsz(2)
do i=1,ph%xsz(1)
buf(i) = cmplx(input(i,j,k),0._mytype, kind=mytype)
end do
call spcfft(buf,ph%xsz(1),-1,scratch)
do i=1,sp%xsz(1)
output(i,j,k) = buf(i)
end do
end do
end do
end if
return
end subroutine r2c_1m_x
! r2c transform, multiple 1D FFTs in z direction
subroutine r2c_1m_z(input, output)
implicit none
real(mytype), dimension(:,:,:), intent(IN) :: input
complex(mytype), dimension(:,:,:), intent(OUT) :: output
integer :: i,j,k
! ESSL doesn't support non-stride-1 r2c transform
! use the 'generic' implementation here
do j=1,ph%zsz(2)
do i=1,ph%zsz(1)
do k=1,ph%zsz(3)
buf(k) = cmplx(input(i,j,k),0._mytype, kind=mytype)
end do
call spcfft(buf,ph%zsz(3),-1,scratch)
do k=1,sp%zsz(3)
output(i,j,k) = buf(k)
end do
end do
end do
return
end subroutine r2c_1m_z
! c2r transform, multiple 1D FFTs in x direction
subroutine c2r_1m_x(input, output)
implicit none
complex(mytype), dimension(:,:,:), intent(IN) :: input
real(mytype), dimension(:,:,:), intent(OUT) :: output
integer :: i,j,k
if (x_goodsize) then
#ifdef DOUBLE_PREC
call dcrft(1,input,sp%xsz(1),output,ph%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),-1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
call dcrft(0,input,sp%xsz(1),output,ph%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),-1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
#else
call scrft(1,input,sp%xsz(1),output,ph%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),-1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
call scrft(0,input,sp%xsz(1),output,ph%xsz(1), &
ph%xsz(1),ph%xsz(2)*ph%xsz(3),-1,scale, &
aux1,naux1,aux2,naux2,aux3,naux3)
#endif
else
! For tranfer lengths not supported by ESSL, using generic
do k=1,ph%xsz(3)
do j=1,ph%xsz(2)
do i=1,ph%xsz(1)/2+1
buf(i) = input(i,j,k)
end do
do i=ph%xsz(1)/2+2,ph%xsz(1)
buf(i) = conjg(buf(ph%xsz(1)+2-i))
end do
call spcfft(buf,ph%xsz(1),1,scratch)
do i=1,ph%xsz(1)
output(i,j,k) = real(buf(i), kind=mytype)
end do
end do
end do
end if
return
end subroutine c2r_1m_x
! c2r transform, multiple 1D FFTs in z direction
subroutine c2r_1m_z(input, output)
implicit none
complex(mytype), dimension(:,:,:), intent(IN) :: input
real(mytype), dimension(:,:,:), intent(OUT) :: output
integer :: i,j,k
! ESSL doesn't support non-stride-1 c2r transform
! use the 'generic' implementation here
do j=1,ph%zsz(2)
do i=1,ph%zsz(1)
do k=1,ph%zsz(3)/2+1
buf(k) = input(i,j,k)
end do
do k=ph%zsz(3)/2+2,ph%zsz(3)
buf(k) = conjg(buf(ph%zsz(3)+2-k))
end do
call spcfft(buf,ph%zsz(3),1,scratch)
do k=1,ph%zsz(3)
output(i,j,k) = real(buf(k), kind=mytype)
end do
end do
end do
return
end subroutine c2r_1m_z
#include "fft_common_3d.f90"
! Acceptable length for transforms - read ESSL document for details
subroutine get_acceptable_length(values)
implicit none
integer, dimension(MAGIC), intent(OUT) :: values
integer, parameter :: nh=25,ni=2,nj=1,nk=1,nm=1
integer, parameter :: nmax=37748736
integer, parameter :: dbl=kind(0.0D0)
integer :: h,i,j,k,m, counter
double precision :: tmp
counter = 1
do h=1,nh
do i=0,ni
do j=0,nj
do k=0,nk
do m=0,nm
! use a double precision number to avoid overflow
tmp = real(2**h, kind=dbl)*3**i*5**j*7**k*11**m
if (tmp>real(nmax+1, kind=dbl)) then
exit
else
values(counter) = 2**h*3**i*5**j*7**k*11**m
counter = counter + 1
end if
end do
end do
end do
end do
end do
call hpsort(counter-1,values) ! sort acceptable lengths
return
end subroutine get_acceptable_length
! Sorts an array in ascending order by the Heapsort method
! The Heapsort method is a N Log2 N algorithm
subroutine hpsort(N,A)
implicit none
integer, intent(IN) :: N
integer, dimension(N), intent(INOUT) :: A
integer :: L,IR,RA,I,J
L=N/2+1
IR=N
do
if (L>1) then
L=L-1
RA=A(L)
else
RA=A(IR)
A(IR)=A(1)
IR=IR-1
if (IR==1) then
A(1)=RA
exit
end if
end if
I=L
J=L+L
do
if (J>IR) exit
if (J<IR) then
if (A(J)<A(J+1)) J=J+1
end if
if (RA<A(J)) then
A(I)=A(J)
I=J
J=J+J
else
J=IR+1
end if
end do
A(I)=RA
end do
return
end subroutine hpsort
! binary serach
function binarySearch(a, value)
integer :: binarySearch
integer, intent(in), target :: a(:)
integer, intent(in) :: value
integer, pointer :: p(:)
integer :: mid, offset
p => a
binarySearch = 0
offset = 0
do while (size(p) > 0)
mid = size(p)/2 + 1
if (p(mid) > value) then
p => p(:mid-1)
else if (p(mid) < value) then
offset = offset + mid
p => p(mid+1:)
else
binarySearch = offset + mid ! SUCCESS!!
return
end if
end do
end function binarySearch
! work array sizes for SCFTD/DCFTD
subroutine cftd_wk(naux_1, naux_2)
implicit none
integer, intent(OUT) :: naux_1, naux_2
integer :: maxdim, mindim
! enough work space for the largest dimension
maxdim = max(ph%xsz(1), ph%ysz(2))
maxdim = max(maxdim, ph%zsz(3))
mindim = min(ph%xsz(1), ph%ysz(2))
mindim = min(mindim, ph%zsz(3))
#ifdef DOUBLE_PREC
if (maxdim>1024) then
naux_1 = 60000 + int(28.24*maxdim)
else
naux_1 = 30000
end if
if (maxdim<252) then
naux_2 = 20000
else
naux_2 = 20000 + (2*maxdim+256)*int(min(64,mindim)+17.12)
end if
#else
if (maxdim>2048) then
naux_1 = 60000 + int(14.12*maxdim)
else
naux_1 = 30000
end if
if (maxdim<252) then
naux_2 = 20000
else
naux_2 = 20000 + (maxdim+256)*int(min(64,mindim)+8.56)
end if
#endif
return
end subroutine cftd_wk
! work array sizes for SCFT/DCFT
subroutine cft_wk(naux_1, naux_2)
implicit none
integer, intent(OUT) :: naux_1, naux_2
integer :: maxdim, tmp
! enough work space for the largest dimension
maxdim = max(ph%xsz(1), ph%ysz(2))
maxdim = max(maxdim, ph%zsz(3))
#ifdef DOUBLE_PREC
if (maxdim>2048) then
naux_1 = 20000 + int(2.28*maxdim)
else
naux_1 = 20000
end if
! naux2 also dependent on input stride, treat each directions
! X (always stride 1)
if (ph%xsz(1)>2048) then
naux_2 = 20000 + int(2.28*ph%xsz(1))
else
naux_2 = 20000
end if
! Y
if (ph%ysz(2)>2048) then
tmp = 20000 + int(2.28*ph%ysz(2))
else
tmp = 20000
end if
if (ph%ysz(2)>=252) tmp = tmp + (2*ph%ysz(2)+256)*min(64,ph%ysz(1))
naux_2 = max(naux_2, tmp)
! Z
if (ph%zsz(3)>2048) then
tmp = 20000 + int(2.28*ph%zsz(3))
else
tmp = 20000
end if
if (ph%zsz(3)>=252) tmp = tmp &
+ (2*ph%zsz(3)+256)*min(64,ph%zsz(1)*ph%zsz(2))
naux_2 = max(naux_2, tmp)
#else
if (maxdim>8192) then
naux_1 = 20000 + int(1.14*maxdim)
else
naux_1 = 20000
end if
! naux2 also dependent on input stride, treat each directions
! X (always stride 1)
if (ph%xsz(1)>8192) then
naux_2 = 20000 + int(1.14*ph%xsz(1))
else
naux_2 = 20000
end if
! Y
if (ph%ysz(2)>8192) then
tmp = 20000 + int(1.14*ph%ysz(2))
else
tmp = 20000
end if
if (ph%ysz(2)>=252) tmp = tmp + (ph%ysz(2)+256)*min(64,ph%ysz(1))
naux_2 = max(naux_2, tmp)
! Z
if (ph%zsz(3)>8192) then
tmp = 20000 + int(1.14*ph%zsz(3))
else
tmp = 20000
end if
if (ph%zsz(3)>=252) tmp = tmp &
+ (ph%zsz(3)+256)*min(64,ph%zsz(1)*ph%zsz(2))
naux_2 = max(naux_2, tmp)
#endif
! for r2c/c2r the complex arrays are smaller so enough work space
return
end subroutine cft_wk
! work array sizes for SRCFT/DRCFT
subroutine rcft_wk(naux_1, naux_2)
implicit none
integer, intent(OUT) :: naux_1, naux_2
! only do r2c for 1D FFTs in X
#ifdef DOUBLE_PREC
if (ph%xsz(1)>4096) then
naux_1 = 20000 + int(1.64*ph%xsz(1))
else
naux_1 = 22000
end if
if (ph%xsz(1)>4096) then
naux_2 = 20000 + int(1.14*ph%xsz(1))
else
naux_1 = 20000
end if
#else
if (ph%xsz(1)>16384) then
naux_1 = 20000 + int(0.82*ph%xsz(1))
else
naux_1 = 25000
end if
if (ph%xsz(1)>16384) then
naux_2 = 20000 + int(0.57*ph%xsz(1))
else
naux_1 = 20000
end if
#endif
return
end subroutine rcft_wk
end module decomp_2d_fft