xref: /petsc/src/mat/impls/fft/fft.c (revision 6a5217c03994f2d95bb2e6dbd8bed42381aeb015)
1 /*
2     Provides an interface to the FFT packages.
3 */
4 
5 #include <../src/mat/impls/fft/fft.h>   /*I "petscmat.h" I*/
6 
7 PetscErrorCode MatDestroy_FFT(Mat A)
8 {
9   Mat_FFT *fft = (Mat_FFT*)A->data;
10 
11   PetscFunctionBegin;
12   if (fft->matdestroy) PetscCall((fft->matdestroy)(A));
13   PetscCall(PetscFree(fft->dim));
14   PetscCall(PetscFree(A->data));
15   PetscCall(PetscObjectChangeTypeName((PetscObject)A,NULL));
16   PetscFunctionReturn(0);
17 }
18 
19 /*@C
20       MatCreateFFT - Creates a matrix object that provides FFT via an external package
21 
22    Collective
23 
24    Input Parameters:
25 +   comm - MPI communicator
26 .   ndim - the ndim-dimensional transform
27 .   dim - array of size ndim, dim[i] contains the vector length in the i-dimension
28 -   type - package type, e.g., FFTW or MATSEQCUFFT
29 
30    Output Parameter:
31 .   A  - the matrix
32 
33    Options Database Keys:
34 .   -mat_fft_type - set FFT type fft or seqcufft
35 
36    Note: this serves as a base class for all FFT marix classes, currently MATFFTW or MATSEQCUFFT
37 
38    Level: intermediate
39 
40 .seealso: MatCreateVecsFFTW()
41 @*/
42 PetscErrorCode MatCreateFFT(MPI_Comm comm,PetscInt ndim,const PetscInt dim[],MatType mattype,Mat *A)
43 {
44   PetscErrorCode ierr;
45   PetscMPIInt    size;
46   Mat            FFT;
47   PetscInt       N,i;
48   Mat_FFT        *fft;
49 
50   PetscFunctionBegin;
51   PetscValidIntPointer(dim,3);
52   PetscValidPointer(A,5);
53   PetscCheck(ndim >= 1,comm,PETSC_ERR_USER,"ndim %" PetscInt_FMT " must be > 0",ndim);
54   PetscCallMPI(MPI_Comm_size(comm, &size));
55 
56   PetscCall(MatCreate(comm,&FFT));
57   PetscCall(PetscNewLog(FFT,&fft));
58   FFT->data = (void*)fft;
59   N         = 1;
60   for (i=0; i<ndim; i++) {
61     PetscCheck(dim[i] >= 1,PETSC_COMM_SELF,PETSC_ERR_USER,"dim[%" PetscInt_FMT "]=%" PetscInt_FMT " must be > 0",i,dim[i]);
62     N *= dim[i];
63   }
64 
65   PetscCall(PetscMalloc1(ndim,&fft->dim));
66   PetscCall(PetscArraycpy(fft->dim,dim,ndim));
67 
68   fft->ndim = ndim;
69   fft->n    = PETSC_DECIDE;
70   fft->N    = N;
71   fft->data = NULL;
72 
73   PetscCall(MatSetType(FFT,mattype));
74 
75   FFT->ops->destroy = MatDestroy_FFT;
76 
77   /* get runtime options... what options? */
78   ierr = PetscObjectOptionsBegin((PetscObject)FFT);PetscCall(ierr);
79   ierr = PetscOptionsEnd();PetscCall(ierr);
80 
81   *A = FFT;
82   PetscFunctionReturn(0);
83 }
84