1 #define PETSCMAT_DLL 2 3 /* 4 Provides an interface to the FFT packages. 5 */ 6 7 #include "../src/mat/impls/fft/fft.h" /*I "petscmat.h" I*/ 8 9 #undef __FUNCT__ 10 #define __FUNCT__ "MatDestroy_FFT" 11 PetscErrorCode MatDestroy_FFT(Mat A) 12 { 13 PetscErrorCode ierr; 14 Mat_FFT *fft = (Mat_FFT*)A->data; 15 16 PetscFunctionBegin; 17 if (fft->matdestroy){ 18 ierr = (fft->matdestroy)(A);CHKERRQ(ierr); 19 } 20 ierr = PetscFree(fft->dim);CHKERRQ(ierr); 21 ierr = PetscFree(fft);CHKERRQ(ierr); 22 ierr = PetscObjectChangeTypeName((PetscObject)A,0);CHKERRQ(ierr); 23 PetscFunctionReturn(0); 24 } 25 26 #undef __FUNCT__ 27 #define __FUNCT__ "MatCreateFFT" 28 /*@ 29 MatCreateFFT - Creates a matrix object that provides FFT via an external package 30 31 Collective on MPI_Comm 32 33 Input Parameter: 34 + comm - MPI communicator 35 . ndim - the ndim-dimensional transform 36 . dim - array of size ndim, dim[i] contains the vector length in the i-dimension 37 - type - package type, e.g., FFTW or FFTCU 38 39 Output Parameter: 40 . A - the matrix 41 42 Options Database Keys: 43 + -mat_fft_type - set FFT type 44 45 Level: intermediate 46 47 @*/ 48 PetscErrorCode MatCreateFFT(MPI_Comm comm,PetscInt ndim,const PetscInt dim[],const MatType mattype,Mat* A) 49 { 50 PetscErrorCode ierr; 51 PetscMPIInt size; 52 Mat FFT; 53 PetscInt N,i; 54 Mat_FFT *fft; 55 56 PetscFunctionBegin; 57 if (ndim < 1) SETERRQ1(comm,PETSC_ERR_USER,"ndim %d must be > 0",ndim); 58 ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 59 60 ierr = MatCreate(comm,&FFT);CHKERRQ(ierr); 61 ierr = PetscNewLog(FFT,Mat_FFT,&fft);CHKERRQ(ierr); 62 FFT->data = (void*)fft; 63 N = 1; 64 for (i=0; i<ndim; i++){ 65 if (dim[i] < 1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"dim[%d]=%d must be > 0",i,dim[i]); 66 N *= dim[i]; 67 } 68 69 ierr = PetscMalloc(ndim*sizeof(PetscInt),&fft->dim);CHKERRQ(ierr); 70 ierr = PetscMemcpy(fft->dim,dim,ndim*sizeof(PetscInt));CHKERRQ(ierr); 71 72 fft->ndim = ndim; 73 fft->n = PETSC_DECIDE; 74 fft->N = N; 75 fft->data = PETSC_NULL; 76 77 ierr = MatSetType(FFT,mattype);CHKERRQ(ierr); 78 FFT->ops->destroy = MatDestroy_FFT; 79 80 /* get runtime options */ 81 ierr = PetscOptionsBegin(((PetscObject)FFT)->comm,((PetscObject)FFT)->prefix,"FFT Options","Mat");CHKERRQ(ierr); 82 PetscOptionsEnd(); 83 84 *A = FFT; 85 PetscFunctionReturn(0); 86 } 87