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., FFTW 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: MatCreateVecsFFTW()
40: @*/
41: PetscErrorCode MatCreateFFT(MPI_Comm comm,PetscInt ndim,const PetscInt dim[],MatType mattype,Mat *A)
42: {
44: PetscMPIInt size;
45: Mat FFT;
46: PetscInt N,i;
47: Mat_FFT *fft;
52: MPI_Comm_size(comm, &size);
54: MatCreate(comm,&FFT);
55: PetscNewLog(FFT,&fft);
56: FFT->data = (void*)fft;
57: N = 1;
58: for (i=0; i<ndim; i++) {
60: N *= dim[i];
61: }
63: PetscMalloc1(ndim,&fft->dim);
64: PetscArraycpy(fft->dim,dim,ndim);
66: fft->ndim = ndim;
67: fft->n = PETSC_DECIDE;
68: fft->N = N;
69: fft->data = NULL;
71: MatSetType(FFT,mattype);
73: FFT->ops->destroy = MatDestroy_FFT;
75: /* get runtime options... what options? */
76: PetscObjectOptionsBegin((PetscObject)FFT);
77: PetscOptionsEnd();
79: *A = FFT;
80: return 0;
81: }