File: fft_fwinv.f90

package info (click to toggle)
espresso 6.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 311,068 kB
  • sloc: f90: 447,429; ansic: 52,566; sh: 40,631; xml: 37,561; tcl: 20,077; lisp: 5,923; makefile: 4,503; python: 4,379; perl: 1,219; cpp: 761; fortran: 618; java: 568; awk: 128
file content (555 lines) | stat: -rw-r--r-- 17,648 bytes parent folder | download | duplicates (3)
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
!
! Copyright (C) Quantum ESPRESSO group
!
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!=---------------------------------------------------------------------------=!
SUBROUTINE invfft_y( fft_kind, f, dfft, howmany )
  !! Compute G-space to R-space for a specific grid type
  !! 
  !! **fft_kind = 'Rho'** : 
  !!   inverse fourier transform of potentials and charge density f
  !!   On output, f is overwritten
  !! 
  !! **fft_kind = 'Wave'** :
  !!   inverse fourier transform of  wave functions f
  !!   On output, f is overwritten
  !!
  !! **fft_kind = 'tgWave'** :
  !!   inverse fourier transform of  wave functions f with task group
  !!   On output, f is overwritten
  !!
  !! **dfft = FFT grid descriptor**, IMPORTANT NOTICE: grid is specified only by dfft.
  !!   No check is performed on the correspondence between dfft and fft_kind. 
  !!   from all other cases
  
  USE fft_scalar,    ONLY: cfft3d, cfft3ds
  USE fft_smallbox,  ONLY: cft_b, cft_b_omp
  USE fft_parallel,  ONLY: tg_cft3s, many_cft3s
  USE fft_parallel_2d,  ONLY: tg_cft3s_2d => tg_cft3s
  USE fft_types,     ONLY: fft_type_descriptor
  USE fft_param,     ONLY: DP

  IMPLICIT NONE

  TYPE(fft_type_descriptor), INTENT(INOUT) :: dfft
  CHARACTER(LEN=*), INTENT(IN) :: fft_kind
  COMPLEX(DP) :: f(:)
  INTEGER, OPTIONAL, INTENT(IN) :: howmany
  INTEGER :: howmany_ = 1
  CHARACTER(LEN=12) :: clock_label

  IF(PRESENT(howmany) ) THEN
     howmany_ = howmany
  ELSE
     howmany_ = 1
  END IF
  !
  IF( fft_kind == 'Rho' ) THEN
     clock_label = dfft%rho_clock_label
  ELSE IF( fft_kind == 'Wave' .OR. fft_kind == 'tgWave' ) THEN
     clock_label = dfft%wave_clock_label
  ELSE
     CALL fftx_error__( ' invfft ', ' unknown fft kind : '//fft_kind , 1 )
  END IF
  IF (clock_label == ' ') CALL fftx_error__( ' invfft ', ' uninitialized fft kind : '//fft_kind , 1 )

  CALL start_clock(clock_label)

  IF( dfft%lpara .and. dfft%use_pencil_decomposition ) THEN

     IF( howmany_ == 1 ) THEN
     IF( fft_kind == 'Rho' ) THEN
        CALL tg_cft3s( f, dfft, 1 )
     ELSE IF( fft_kind == 'Wave' ) THEN
        CALL tg_cft3s( f, dfft, 2 )
     ELSE IF( fft_kind == 'tgWave' ) THEN
        CALL tg_cft3s( f, dfft, 3 )
        END IF
     ELSE
        IF( fft_kind == 'Rho' ) THEN
           CALL many_cft3s( f, dfft, 1, howmany )
        ELSE IF( fft_kind == 'Wave' ) THEN
           CALL many_cft3s( f, dfft, 2, howmany )
        ELSE IF( fft_kind == 'tgWave' ) THEN
           CALL fftx_error__( ' invfft ', ' howmany not yet implemented for parallel driver ', 1 )
        END IF
     END IF

  ELSE IF( dfft%lpara ) THEN

     IF( howmany_ /= 1 ) THEN
        CALL fftx_error__( ' invfft ', ' howmany not yet implemented for parallel driver ', 1 )
     END IF

     IF( fft_kind == 'Rho' ) THEN
        CALL tg_cft3s_2d(f,dfft, 1)
     ELSE IF( fft_kind == 'Wave' ) THEN
        CALL tg_cft3s_2d(f,dfft, 2 )
     ELSE IF( fft_kind == 'tgWave' ) THEN
        CALL fftx_error__( ' fwfft ', ' tgWave not implemented  ', 1 )
     END IF

  ELSE

     IF( fft_kind == 'Rho' ) THEN
        CALL cfft3d( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                        dfft%nr1x, dfft%nr2x, dfft%nr3x, howmany_ , 1)
     ELSE 
        CALL cfft3ds( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                        dfft%nr1x,dfft%nr2x,dfft%nr3x, howmany_ , 1, &
                        dfft%isind, dfft%iplw )
     END IF

  END IF

  CALL stop_clock( clock_label )

  RETURN

END SUBROUTINE invfft_y
!
!=---------------------------------------------------------------------------=!
!
SUBROUTINE fwfft_y( fft_kind, f, dfft, howmany )
  !! Compute R-space to G-space for a specific grid type
  !! 
  !! **fft_kind = 'Rho'**
  !!   forward fourier transform of potentials and charge density f
  !!   On output, f is overwritten
  !! 
  !! **fft_kind = 'Wave'**
  !!   forward fourier transform of  wave functions f
  !!   On output, f is overwritten
  !!
  !! **fft_kind = 'tgWave'**
  !!   forward fourier transform of wave functions f with task group
  !!   On output, f is overwritten
  !! 
  
  USE fft_scalar,    ONLY: cfft3d, cfft3ds
  USE fft_parallel,  ONLY: tg_cft3s, many_cft3s
  USE fft_parallel_2d,  ONLY: tg_cft3s_2d => tg_cft3s
  USE fft_types,     ONLY: fft_type_descriptor
  USE fft_param,     ONLY: DP

  IMPLICIT NONE

  TYPE(fft_type_descriptor), INTENT(INOUT) :: dfft
  CHARACTER(LEN=*), INTENT(IN) :: fft_kind
  COMPLEX(DP) :: f(:)
  INTEGER, OPTIONAL, INTENT(IN) :: howmany
  INTEGER :: howmany_ = 1
  CHARACTER(LEN=12) :: clock_label

  IF(PRESENT(howmany) ) THEN
     howmany_ = howmany
  ELSE
     howmany_ = 1
  END IF

  IF( fft_kind == 'Rho' ) THEN
     clock_label = dfft%rho_clock_label
  ELSE IF( fft_kind == 'Wave' .OR. fft_kind == 'tgWave' ) THEN
     clock_label = dfft%wave_clock_label
  ELSE
     CALL fftx_error__( ' fwfft ', ' unknown fft kind: '//fft_kind , 1 )
  END IF
  IF (clock_label == ' ') CALL fftx_error__( ' fwfft ', ' uninitialized fft kind : '//fft_kind , 1 )

  CALL start_clock(clock_label)

  IF( dfft%lpara .and. dfft%use_pencil_decomposition ) THEN
     
     IF( howmany_ == 1 ) THEN
     IF( fft_kind == 'Rho' ) THEN
        CALL tg_cft3s(f,dfft,-1)
     ELSE IF( fft_kind == 'Wave' ) THEN
        CALL tg_cft3s(f,dfft,-2 )
     ELSE IF( fft_kind == 'tgWave' ) THEN
        CALL tg_cft3s(f,dfft,-3 )
        END IF
     ELSE
        IF( fft_kind == 'Rho' ) THEN
           CALL many_cft3s( f, dfft, -1, howmany )
        ELSE IF( fft_kind == 'Wave' ) THEN
           CALL many_cft3s( f, dfft, -2, howmany )
        ELSE IF( fft_kind == 'tgWave' ) THEN
           CALL many_cft3s( f, dfft, -3, howmany )
        END IF
     END IF

  ELSE IF( dfft%lpara ) THEN

     IF( howmany_ /= 1 ) THEN
        CALL fftx_error__( ' fwfft ', ' howmany not yet implemented for parallel driver ', 1 )
     END IF

     IF( fft_kind == 'Rho' ) THEN
        CALL tg_cft3s_2d(f,dfft,-1)
     ELSE IF( fft_kind == 'Wave' ) THEN
        CALL tg_cft3s_2d(f,dfft,-2 )
     ELSE IF( fft_kind == 'tgWave' ) THEN
        CALL fftx_error__( ' fwfft ', ' tgWave not implemented  ', 1 )
     END IF

  ELSE

     IF( fft_kind == 'Rho' ) THEN
        CALL cfft3d( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                        dfft%nr1x,dfft%nr2x,dfft%nr3x, howmany_ , -1)
     ELSE 
        CALL cfft3ds( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                         dfft%nr1x,dfft%nr2x,dfft%nr3x, howmany_ , -1, &
                         dfft%isind, dfft%iplw )
     END IF

  END IF

  CALL stop_clock( clock_label )
  
  RETURN
  !
END SUBROUTINE fwfft_y
!=---------------------------------------------------------------------------=!

!
!=---------------------------------------------------------------------------=!
SUBROUTINE invfft_b( f, dfft, ia )
  !! Not-so-parallel 3d fft for box grid, implemented ONLY for sign=1
  !!
  !! ComputeG-space to R-space, $$ output = \sum_G f(G)exp(+iG*R) $$
  !! The array f (overwritten on output) is NOT distributed:
  !! a copy is present on each processor.
  !! The fft along z  is done on the entire grid.
  !! The fft along y  is done ONLY on planes that have components on the dense 
  !! dense grid for each processor. In addition the fft along x is done ONLY on
  !! the y-sections that have components on the dense grid for each processor. 
  !! Note that the final array will no longer be the same on all processors.
  !! 
  !! **fft_kind** = 'Box' (only allowed value!)
  !! 
  !! **dfft** = fft descriptor for the box grid
  !! 
  !! **ia**   = index of the atom with a box grid. Used to find the number
  !!         of planes on this processors, contained in dfft%np3(ia)
  
  USE fft_scalar,    ONLY: cfft3d, cfft3ds
  USE fft_smallbox,  ONLY: cft_b, cft_b_omp
  USE fft_parallel,  ONLY: tg_cft3s
  USE fft_smallbox_type, ONLY: fft_box_descriptor
  USE fft_param,     ONLY: DP
  
  IMPLICIT NONE

  TYPE(fft_box_descriptor), INTENT(IN) :: dfft
! Removed the 'OPTIONAL' attribute. When present, the specific interfaces
! 'invfft_x' and 'invfft_b' cannot be disambiguated when the generic interface
! call is made. This is a violation the Fortran standard. The Cray compiler
! errors out on this, while the Intel only issues a warning. --rbw
! INTEGER, OPTIONAL, INTENT(IN) :: ia
  INTEGER, INTENT(IN) :: ia
  COMPLEX(DP) :: f(:)
  !
!  INTEGER :: imin2, imax2, np2, imin3, imax2, np2, imax3, np3

  ! clocks called inside a parallel region do not work properly!
  ! in the future we probably need a thread safe version of the clock

!$omp master
  CALL start_clock( 'fftb' )
!$omp end master 

#if defined(__MPI) && !defined(__USE_3D_FFT)
     
  IF( (dfft%np3( ia ) > 0) .AND. (dfft%np2( ia ) > 0) ) THEN

#if defined(_OPENMP)

     CALL cft_b_omp( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                        dfft%nr1x,dfft%nr2x,dfft%nr3x, &
                        dfft%imin2( ia ), dfft%imax2( ia ), &
                        dfft%imin3( ia ), dfft%imax3( ia ), 1 )

#else
     CALL cft_b( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                    dfft%nr1x,dfft%nr2x,dfft%nr3x, &
                    dfft%imin2( ia ), dfft%imax2( ia ), &
                    dfft%imin3( ia ), dfft%imax3( ia ), 1 )
#endif

  END IF

#else

#if defined(_OPENMP)
  CALL cft_b_omp( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                     dfft%nr1x,dfft%nr2x,dfft%nr3x, &
                     dfft%imin2( ia ), dfft%imax2( ia ), &
                     dfft%imin3( ia ), dfft%imax3( ia ), 1 )
#else
  CALL cfft3d( f, dfft%nr1, dfft%nr2, dfft%nr3, &
                  dfft%nr1x,dfft%nr2x,dfft%nr3x, 1, 1)
#endif

#endif

!$omp master
  CALL stop_clock( 'fftb' )
!$omp end master

  RETURN
END SUBROUTINE invfft_b
!=---------------------------------------------------------------------------=!

#if defined(__CUDA)

SUBROUTINE invfft_y_gpu( fft_kind, f_d, dfft, howmany, stream )
  !! Compute G-space to R-space for a specific grid type
  !! 
  !! **fft_kind = 'Rho'** : 
  !!   inverse fourier transform of potentials and charge density f
  !!   On output, f is overwritten
  !! 
  !! **fft_kind = 'Wave'** :
  !!   inverse fourier transform of  wave functions f
  !!   On output, f is overwritten
  !!
  !! **fft_kind = 'tgWave'** :
  !!   inverse fourier transform of  wave functions f with task group
  !!   On output, f is overwritten
  !!
  !! **dfft = FFT grid descriptor**, IMPORTANT NOTICE: grid is specified only by dfft.
  !!   No check is performed on the correspondence between dfft and fft_kind. 
  !!   from all other cases
  USE cudafor
  USE fft_scalar,    ONLY: cfft3d_gpu, cfft3ds_gpu
  USE fft_smallbox,  ONLY: cft_b, cft_b_omp
  USE fft_parallel,  ONLY: tg_cft3s_gpu, many_cft3s_gpu
  USE fft_parallel_2d,  ONLY: tg_cft3s_2d_gpu => tg_cft3s_gpu, &
                            & many_cft3s_2d_gpu => many_cft3s_gpu
  USE fft_types,     ONLY: fft_type_descriptor
  USE fft_param,     ONLY: DP

  IMPLICIT NONE

  TYPE(fft_type_descriptor), INTENT(IN) :: dfft
  CHARACTER(LEN=*), INTENT(IN) :: fft_kind
  COMPLEX(DP), DEVICE :: f_d(:)
  INTEGER, OPTIONAL, INTENT(IN) :: howmany
  INTEGER(kind = cuda_stream_kind), OPTIONAL, INTENT(IN) :: stream
  !
  INTEGER                          :: howmany_ = 1
  INTEGER(kind = cuda_stream_kind) :: stream_  = 0

  CHARACTER(LEN=12) :: clock_label

  IF(PRESENT(howmany) ) THEN
     howmany_ = howmany
  ELSE
     howmany_ = 1
  END IF
  !
  IF( present( stream ) ) THEN
    stream_ = stream
  ELSE
    stream_ = 0
  END IF
  !
  IF( fft_kind == 'Rho' ) THEN
     clock_label = dfft%rho_clock_label
  ELSE IF( fft_kind == 'Wave' .OR. fft_kind == 'tgWave' ) THEN
     clock_label = dfft%wave_clock_label
  ELSE
     CALL fftx_error__( ' invfft ', ' unknown fft kind : '//fft_kind , 1 )
  END IF
  IF (clock_label == ' ') CALL fftx_error__( ' invfft ', ' uninitialized fft kind : '//fft_kind , 1 )

  CALL start_clock_gpu(clock_label)

  IF( dfft%lpara .and. dfft%use_pencil_decomposition ) THEN

     !IF( howmany_ /= 1 .and. fft_kind /= 'Wave' ) THEN
     !   CALL fftx_error__( ' invfft ', ' howmany not yet implemented for parallel driver ', 1 )
     !END IF
     IF( stream_ /= 0 ) THEN
        CALL fftx_error__( ' invfft ', ' stream support not implemented for parallel driver ', 1 )
     END IF
     
     IF( fft_kind == 'Rho' ) THEN
        IF( howmany_ == 1 ) THEN
           CALL tg_cft3s_gpu( f_d, dfft, 1 )
        ELSE
            CALL many_cft3s_gpu( f_d, dfft, 1, howmany_ )
        END IF
     ELSE IF( fft_kind == 'Wave' ) THEN
        IF( howmany_ == 1 ) THEN
            CALL tg_cft3s_gpu( f_d, dfft, 2 )
        ELSE
            CALL many_cft3s_gpu( f_d, dfft, 2, howmany_ )
        END IF
     ELSE IF( fft_kind == 'tgWave' ) THEN
        CALL tg_cft3s_gpu( f_d, dfft, 3 )
     END IF

  ELSE IF( dfft%lpara ) THEN

     IF( howmany_ /= 1 ) THEN
        IF( fft_kind == 'Rho' ) THEN
           CALL many_cft3s_2d_gpu( f_d, dfft, 1,  howmany_)
        ELSE IF( fft_kind == 'Wave' ) THEN
           CALL many_cft3s_2d_gpu( f_d, dfft, 2, howmany_ )
        END IF
     ELSE
        IF( fft_kind == 'Rho' ) THEN
           CALL tg_cft3s_2d_gpu( f_d, dfft, 1 )
        ELSE IF( fft_kind == 'Wave' ) THEN
           CALL tg_cft3s_2d_gpu( f_d, dfft, 2 )
        END IF
     END IF

  ELSE

     IF( fft_kind == 'Rho' ) THEN
        CALL cfft3d_gpu( f_d, dfft%nr1, dfft%nr2, dfft%nr3, &
                        dfft%nr1x, dfft%nr2x, dfft%nr3x, howmany_ , 1, stream_)
     ELSE 
        CALL cfft3ds_gpu( f_d, dfft%nr1, dfft%nr2, dfft%nr3, &
                        dfft%nr1x,dfft%nr2x,dfft%nr3x, howmany_ , 1, &
                        dfft%isind, dfft%iplw, stream_ )
     END IF

  END IF

  CALL stop_clock_gpu( clock_label )

  RETURN

END SUBROUTINE invfft_y_gpu
!
!=---------------------------------------------------------------------------=!
!
SUBROUTINE fwfft_y_gpu( fft_kind, f_d, dfft, howmany, stream )
  !! Compute R-space to G-space for a specific grid type
  !! 
  !! **fft_kind = 'Rho'**
  !!   forward fourier transform of potentials and charge density f
  !!   On output, f is overwritten
  !! 
  !! **fft_kind = 'Wave'**
  !!   forward fourier transform of  wave functions f
  !!   On output, f is overwritten
  !!
  !! **fft_kind = 'tgWave'**
  !!   forward fourier transform of wave functions f with task group
  !!   On output, f is overwritten
  !! 
  USE cudafor
  USE fft_scalar,    ONLY: cfft3d_gpu, cfft3ds_gpu
  USE fft_parallel,  ONLY: tg_cft3s_gpu, many_cft3s_gpu
  USE fft_parallel_2d,  ONLY: tg_cft3s_2d_gpu => tg_cft3s_gpu, &
                              & many_cft3s_2d_gpu => many_cft3s_gpu
  USE fft_types,     ONLY: fft_type_descriptor
  USE fft_param,     ONLY: DP

  IMPLICIT NONE

  TYPE(fft_type_descriptor), INTENT(IN) :: dfft
  CHARACTER(LEN=*), INTENT(IN) :: fft_kind
  COMPLEX(DP), DEVICE :: f_d(:)
  INTEGER, OPTIONAL, INTENT(IN) :: howmany
  INTEGER(kind = cuda_stream_kind), OPTIONAL, INTENT(IN) :: stream

  INTEGER                          :: howmany_ = 1
  INTEGER(kind = cuda_stream_kind) :: stream_  = 0

  CHARACTER(LEN=12) :: clock_label
  !
  IF(PRESENT(howmany) ) THEN
     howmany_ = howmany
  ELSE
     howmany_ = 1
  END IF
  !
  IF( present( stream ) ) THEN
    stream_ = stream
  ELSE
    stream_ = 0
  END IF
  !
  IF( fft_kind == 'Rho' ) THEN
     clock_label = dfft%rho_clock_label
  ELSE IF( fft_kind == 'Wave' .OR. fft_kind == 'tgWave' ) THEN
     clock_label = dfft%wave_clock_label
  ELSE
     CALL fftx_error__( ' fwfft ', ' unknown fft kind: '//fft_kind , 1 )
  END IF
  IF (clock_label == ' ') CALL fftx_error__( ' fwfft ', ' uninitialized fft kind : '//fft_kind , 1 )

  CALL start_clock_gpu(clock_label)

  IF( dfft%lpara .and. dfft%use_pencil_decomposition ) THEN

     !IF( howmany_ /= 1 .and. fft_kind /= 'Wave' ) THEN
     !   CALL fftx_error__( ' fwfft ', ' howmany not yet implemented for parallel driver ', 1 )
     !END IF
     IF( stream_ /= 0 ) THEN
        CALL fftx_error__( ' fwfft ', ' stream support not implemented for parallel driver ', 1 )
     END IF
     
     IF( fft_kind == 'Rho' ) THEN
        IF( howmany_ == 1 ) THEN
           CALL tg_cft3s_gpu(f_d,dfft,-1)
        ELSE
           CALL many_cft3s_gpu(f_d,dfft,-1, howmany_)
        END IF
     ELSE IF( fft_kind == 'Wave' ) THEN
        IF( howmany_ == 1 ) THEN
           CALL tg_cft3s_gpu(f_d,dfft,-2)
        ELSE
           CALL many_cft3s_gpu(f_d,dfft,-2, howmany_)
        END IF
     ELSE IF( fft_kind == 'tgWave' ) THEN
        CALL tg_cft3s_gpu( f_d, dfft, -3 )
     END IF

  ELSE IF( dfft%lpara ) THEN

     IF( howmany_ /= 1 ) THEN
        IF( fft_kind == 'Rho' ) THEN
           CALL many_cft3s_2d_gpu( f_d, dfft, -1, howmany_)
        ELSE IF( fft_kind == 'Wave' ) THEN
           CALL many_cft3s_2d_gpu( f_d, dfft, -2, howmany_ )
        END IF
     ELSE
        IF( fft_kind == 'Rho' ) THEN
           CALL tg_cft3s_2d_gpu( f_d, dfft, -1 )
        ELSE IF( fft_kind == 'Wave' ) THEN
           CALL tg_cft3s_2d_gpu( f_d, dfft, -2 )
        END IF
     END IF

  ELSE

     IF( fft_kind == 'Rho' ) THEN
        CALL cfft3d_gpu( f_d, dfft%nr1, dfft%nr2, dfft%nr3, &
                        dfft%nr1x,dfft%nr2x,dfft%nr3x, howmany_ , -1, stream_ )
     ELSE 
        CALL cfft3ds_gpu( f_d, dfft%nr1, dfft%nr2, dfft%nr3, &
                         dfft%nr1x,dfft%nr2x,dfft%nr3x, howmany_ , -1, &
                         dfft%isind, dfft%iplw, stream_ )
     END IF

  END IF

  CALL stop_clock_gpu( clock_label )
  
  RETURN
  !
END SUBROUTINE fwfft_y_gpu
!=---------------------------------------------------------------------------=!

#endif