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., `MATFFTW` 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: `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; 48 49 PetscFunctionBegin; 50 PetscValidIntPointer(dim, 3); 51 PetscValidPointer(A, 5); 52 PetscCheck(ndim >= 1, comm, PETSC_ERR_USER, "ndim %" PetscInt_FMT " must be > 0", ndim); 53 PetscCallMPI(MPI_Comm_size(comm, &size)); 54 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 } 63 64 PetscCall(PetscMalloc1(ndim, &fft->dim)); 65 PetscCall(PetscArraycpy(fft->dim, dim, ndim)); 66 67 fft->ndim = ndim; 68 fft->n = PETSC_DECIDE; 69 fft->N = N; 70 fft->data = NULL; 71 72 PetscCall(MatSetType(FFT, mattype)); 73 74 FFT->ops->destroy = MatDestroy_FFT; 75 76 /* get runtime options... what options? */ 77 PetscObjectOptionsBegin((PetscObject)FFT); 78 PetscOptionsEnd(); 79 80 *A = FFT; 81 PetscFunctionReturn(0); 82 } 83