Actual source code: fft.c
1: /*
2: Provides an interface to the FFT packages.
3: */
5: #include <../src/mat/impls/fft/fft.h>
7: PetscErrorCode MatDestroy_FFT(Mat A)
8: {
9: Mat_FFT *fft = (Mat_FFT *)A->data;
11: if (fft->matdestroy) (fft->matdestroy)(A);
12: PetscFree(fft->dim);
13: PetscFree(A->data);
14: PetscObjectChangeTypeName((PetscObject)A, NULL);
15: return 0;
16: }
18: /*@C
19: MatCreateFFT - Creates a matrix object that provides FFT via an external package
21: Collective
23: Input Parameters:
24: + comm - MPI communicator
25: . ndim - the ndim-dimensional transform
26: . dim - array of size ndim, dim[i] contains the vector length in the i-dimension
27: - type - package type, e.g., `MATFFTW` or `MATSEQCUFFT`
29: Output Parameter:
30: . A - the matrix
32: Options Database Keys:
33: . -mat_fft_type - set FFT type fft or seqcufft
35: Note: this serves as a base class for all FFT marix classes, currently `MATFFTW` or `MATSEQCUFFT`
37: Level: intermediate
39: .seealso: `MATFFTW`, `MATSEQCUFFT`, `MatCreateVecsFFTW()`
40: @*/
41: PetscErrorCode MatCreateFFT(MPI_Comm comm, PetscInt ndim, const PetscInt dim[], MatType mattype, Mat *A)
42: {
43: PetscMPIInt size;
44: Mat FFT;
45: PetscInt N, i;
46: Mat_FFT *fft;
51: MPI_Comm_size(comm, &size);
53: MatCreate(comm, &FFT);
54: PetscNew(&fft);
55: FFT->data = (void *)fft;
56: N = 1;
57: for (i = 0; i < ndim; i++) {
59: N *= dim[i];
60: }
62: PetscMalloc1(ndim, &fft->dim);
63: PetscArraycpy(fft->dim, dim, ndim);
65: fft->ndim = ndim;
66: fft->n = PETSC_DECIDE;
67: fft->N = N;
68: fft->data = NULL;
70: MatSetType(FFT, mattype);
72: FFT->ops->destroy = MatDestroy_FFT;
74: /* get runtime options... what options? */
75: PetscObjectOptionsBegin((PetscObject)FFT);
76: PetscOptionsEnd();
78: *A = FFT;
79: return 0;
80: }