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: 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(PETSC_SUCCESS);
17: }
19: /*@C
20: MatCreateFFT - Creates a matrix object that provides FFT via an external package
22: Collective
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., `MATFFTW` or `MATSEQCUFFT`
30: Output Parameter:
31: . A - the matrix
33: Options Database Key:
34: . -mat_fft_type - set FFT type fft or seqcufft
36: Note: this serves as a base class for all FFT marix classes, currently `MATFFTW` or `MATSEQCUFFT`
38: Level: intermediate
40: .seealso: [](chapter_matrices), `Mat`, `MATFFTW`, `MATSEQCUFFT`, `MatCreateVecsFFTW()`
41: @*/
42: PetscErrorCode MatCreateFFT(MPI_Comm comm, PetscInt ndim, const PetscInt dim[], MatType mattype, Mat *A)
43: {
44: PetscMPIInt size;
45: Mat FFT;
46: PetscInt N, i;
47: Mat_FFT *fft;
49: PetscFunctionBegin;
52: PetscCheck(ndim >= 1, comm, PETSC_ERR_USER, "ndim %" PetscInt_FMT " must be > 0", ndim);
53: PetscCallMPI(MPI_Comm_size(comm, &size));
55: PetscCall(MatCreate(comm, &FFT));
56: PetscCall(PetscNew(&fft));
57: FFT->data = (void *)fft;
58: N = 1;
59: for (i = 0; i < ndim; i++) {
60: PetscCheck(dim[i] >= 1, PETSC_COMM_SELF, PETSC_ERR_USER, "dim[%" PetscInt_FMT "]=%" PetscInt_FMT " must be > 0", i, dim[i]);
61: N *= dim[i];
62: }
64: PetscCall(PetscMalloc1(ndim, &fft->dim));
65: PetscCall(PetscArraycpy(fft->dim, dim, ndim));
67: fft->ndim = ndim;
68: fft->n = PETSC_DECIDE;
69: fft->N = N;
70: fft->data = NULL;
72: PetscCall(MatSetType(FFT, mattype));
74: FFT->ops->destroy = MatDestroy_FFT;
76: /* get runtime options... what options? */
77: PetscObjectOptionsBegin((PetscObject)FFT);
78: PetscOptionsEnd();
80: *A = FFT;
81: PetscFunctionReturn(PETSC_SUCCESS);
82: }