1 static char help[]="This program illustrates the use of PETSc-fftw interface for real DFT\n"; 2 #include <petscmat.h> 3 #include <fftw3-mpi.h> 4 5 extern PetscErrorCode InputTransformFFT(Mat,Vec,Vec); 6 extern PetscErrorCode OutputTransformFFT(Mat,Vec,Vec); 7 int main(int argc,char **args) 8 { 9 PetscMPIInt rank,size; 10 PetscInt N0=3,N1=3,N2=3,N=N0*N1*N2; 11 PetscRandom rdm; 12 PetscScalar a; 13 PetscReal enorm; 14 Vec x,y,z,input,output; 15 PetscBool view=PETSC_FALSE,use_interface=PETSC_TRUE; 16 Mat A; 17 PetscInt DIM, dim[3],vsize; 18 PetscReal fac; 19 20 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 21 #if defined(PETSC_USE_COMPLEX) 22 SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "This example requires real numbers"); 23 #endif 24 25 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size)); 26 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank)); 27 28 PetscCall(PetscRandomCreate(PETSC_COMM_WORLD, &rdm)); 29 PetscCall(PetscRandomSetFromOptions(rdm)); 30 31 PetscCall(VecCreate(PETSC_COMM_WORLD,&input)); 32 PetscCall(VecSetSizes(input,PETSC_DECIDE,N)); 33 PetscCall(VecSetFromOptions(input)); 34 PetscCall(VecSetRandom(input,rdm)); 35 PetscCall(VecDuplicate(input,&output)); 36 /* PetscCall(VecGetSize(input,&vsize)); */ 37 /* printf("Size of the input Vector is %d\n",vsize); */ 38 39 DIM = 3; 40 dim[0] = N0; dim[1] = N1; dim[2] = N2; 41 42 PetscCall(MatCreateFFT(PETSC_COMM_WORLD,DIM,dim,MATFFTW,&A)); 43 PetscCall(MatCreateVecs(A,&x,&y)); 44 PetscCall(MatCreateVecs(A,&z,NULL)); 45 PetscCall(VecGetSize(y,&vsize)); 46 printf("The vector size from the main routine is %d\n",vsize); 47 48 PetscCall(InputTransformFFT(A,input,x)); 49 PetscCall(MatMult(A,x,y)); 50 PetscCall(MatMultTranspose(A,y,z)); 51 PetscCall(OutputTransformFFT(A,z,output)); 52 53 fac = 1.0/(PetscReal)N; 54 PetscCall(VecScale(output,fac)); 55 56 PetscCall(VecAssemblyBegin(input)); 57 PetscCall(VecAssemblyEnd(input)); 58 PetscCall(VecAssemblyBegin(output)); 59 PetscCall(VecAssemblyEnd(output)); 60 61 PetscCall(VecView(input,PETSC_VIEWER_STDOUT_WORLD)); 62 PetscCall(VecView(output,PETSC_VIEWER_STDOUT_WORLD)); 63 64 PetscCall(VecAXPY(output,-1.0,input)); 65 PetscCall(VecNorm(output,NORM_1,&enorm)); 66 /* if (enorm > 1.e-14) { */ 67 if (rank == 0) { 68 PetscCall(PetscPrintf(PETSC_COMM_SELF," Error norm of |x - z| %e\n",enorm)); 69 } 70 /* } */ 71 72 /* PetscCall(MatCreateVecs(A,&z,NULL)); */ 73 /* printf("Vector size from ex148 %d\n",vsize); */ 74 /* PetscCall(PetscObjectSetName((PetscObject) x, "Real space vector")); */ 75 /* PetscCall(PetscObjectSetName((PetscObject) y, "Frequency space vector")); */ 76 /* PetscCall(PetscObjectSetName((PetscObject) z, "Reconstructed vector")); */ 77 78 PetscCall(PetscFinalize()); 79 return 0; 80 81 } 82