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