Actual source code: ex153.c

petsc-3.4.2 2013-07-02
  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>
  6: PetscInt main(PetscInt argc,char **args)
  7: {
  9:   PetscMPIInt    rank,size;
 10:   PetscInt       N0=10,N1=10,N2=10,N3=10,N4=10,N=N0*N1*N2*N3*N4;
 11:   PetscRandom    rdm;
 12:   PetscReal      enorm;
 13:   Vec            x,y,z,input,output;
 14:   Mat            A;
 15:   PetscInt       DIM, dim[5],vsize;
 16:   PetscReal      fac;

 18:   PetscInitialize(&argc,&args,(char*)0,help);
 19:   MPI_Comm_size(PETSC_COMM_WORLD, &size);
 20:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);

 22:   if (size!=1) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "This is a uni-processor example only");
 23:   PetscRandomCreate(PETSC_COMM_SELF, &rdm);
 24:   PetscRandomSetFromOptions(rdm);
 25:   VecCreate(PETSC_COMM_SELF,&input);
 26:   VecSetSizes(input,N,N);
 27:   VecSetFromOptions(input);
 28:   VecSetRandom(input,rdm);
 29:   VecDuplicate(input,&output);

 31:   DIM  = 5; dim[0] = N0; dim[1] = N1; dim[2] = N2; dim[3] = N3; dim[4] = N4;
 32:   MatCreateFFT(PETSC_COMM_SELF,DIM,dim,MATFFTW,&A);
 33:   MatGetVecs(A,&x,&y);
 34:   MatGetVecs(A,&z,NULL);

 36:   VecGetSize(x,&vsize);
 37:   printf("The vector size  of input from the main routine is %d\n",vsize);

 39:   VecGetSize(z,&vsize);
 40:   printf("The vector size of output from the main routine is %d\n",vsize);

 42:   InputTransformFFT(A,input,x);

 44:   MatMult(A,x,y);
 45:   MatMultTranspose(A,y,z);

 47:   OutputTransformFFT(A,z,output);
 48:   fac  = 1.0/(PetscReal)N;
 49:   VecScale(output,fac);
 50: /*
 51:   VecAssemblyBegin(input);
 52:   VecAssemblyEnd(input);
 53:   VecAssemblyBegin(output);
 54:   VecAssemblyEnd(output);

 56:   VecView(input,PETSC_VIEWER_STDOUT_WORLD);
 57:   VecView(output,PETSC_VIEWER_STDOUT_WORLD);
 58: */
 59:   VecAXPY(output,-1.0,input);
 60:   VecNorm(output,NORM_1,&enorm);
 61: /*  if (enorm > 1.e-14) { */
 62:   PetscPrintf(PETSC_COMM_SELF,"  Error norm of |x - z| %e\n",enorm);
 63: /*      } */

 65:   VecDestroy(&output);
 66:   VecDestroy(&input);
 67:   VecDestroy(&x);
 68:   VecDestroy(&y);
 69:   VecDestroy(&z);
 70:   MatDestroy(&A);
 71:   PetscRandomDestroy(&rdm);
 72:   PetscFinalize();
 73:   return 0;

 75: }