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