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 Mat_FFT *fft = (Mat_FFT *)A->data; 9 10 PetscFunctionBegin; 11 if (fft->matdestroy) PetscCall((fft->matdestroy)(A)); 12 PetscCall(PetscFree(fft->dim)); 13 PetscCall(PetscFree(A->data)); 14 PetscCall(PetscObjectChangeTypeName((PetscObject)A, NULL)); 15 PetscFunctionReturn(0); 16 } 17 18 /*@C 19 MatCreateFFT - Creates a matrix object that provides FFT via an external package 20 21 Collective 22 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 28 29 Output Parameter: 30 . A - the matrix 31 32 Options Database Keys: 33 . -mat_fft_type - set FFT type fft or seqcufft 34 35 Note: this serves as a base class for all FFT marix classes, currently MATFFTW or MATSEQCUFFT 36 37 Level: intermediate 38 39 .seealso: `MatCreateVecsFFTW()` 40 @*/ 41 PetscErrorCode MatCreateFFT(MPI_Comm comm, PetscInt ndim, const PetscInt dim[], MatType mattype, Mat *A) { 42 PetscMPIInt size; 43 Mat FFT; 44 PetscInt N, i; 45 Mat_FFT *fft; 46 47 PetscFunctionBegin; 48 PetscValidIntPointer(dim, 3); 49 PetscValidPointer(A, 5); 50 PetscCheck(ndim >= 1, comm, PETSC_ERR_USER, "ndim %" PetscInt_FMT " must be > 0", ndim); 51 PetscCallMPI(MPI_Comm_size(comm, &size)); 52 53 PetscCall(MatCreate(comm, &FFT)); 54 PetscCall(PetscNewLog(FFT, &fft)); 55 FFT->data = (void *)fft; 56 N = 1; 57 for (i = 0; i < ndim; i++) { 58 PetscCheck(dim[i] >= 1, PETSC_COMM_SELF, PETSC_ERR_USER, "dim[%" PetscInt_FMT "]=%" PetscInt_FMT " must be > 0", i, dim[i]); 59 N *= dim[i]; 60 } 61 62 PetscCall(PetscMalloc1(ndim, &fft->dim)); 63 PetscCall(PetscArraycpy(fft->dim, dim, ndim)); 64 65 fft->ndim = ndim; 66 fft->n = PETSC_DECIDE; 67 fft->N = N; 68 fft->data = NULL; 69 70 PetscCall(MatSetType(FFT, mattype)); 71 72 FFT->ops->destroy = MatDestroy_FFT; 73 74 /* get runtime options... what options? */ 75 PetscObjectOptionsBegin((PetscObject)FFT); 76 PetscOptionsEnd(); 77 78 *A = FFT; 79 PetscFunctionReturn(0); 80 } 81