Actual source code: ex149.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  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>

  7: extern PetscErrorCode InputTransformFFT(Mat,Vec,Vec);
  8: extern PetscErrorCode OutputTransformFFT(Mat,Vec,Vec);
  9: PetscInt main(PetscInt argc,char **args)
 10: {
 12:   PetscMPIInt    rank,size;
 13:   PetscInt       N0=3,N1=3,N2=3,N=N0*N1*N2;
 14:   PetscRandom    rdm;
 15:   PetscScalar    a;
 16:   PetscReal      enorm;
 17:   Vec            x,y,z,input,output;
 18:   PetscBool      view=PETSC_FALSE,use_interface=PETSC_TRUE;
 19:   Mat            A;
 20:   PetscInt       DIM, dim[3],vsize;
 21:   PetscReal      fac;

 23:   PetscInitialize(&argc,&args,(char*)0,help);
 24: #if defined(PETSC_USE_COMPLEX)
 25:   SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "This example requires real numbers");
 26: #endif

 28:   MPI_Comm_size(PETSC_COMM_WORLD, &size);
 29:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);


 32:   PetscRandomCreate(PETSC_COMM_WORLD, &rdm);
 33:   PetscRandomSetFromOptions(rdm);

 35:   VecCreate(PETSC_COMM_WORLD,&input);
 36:   VecSetSizes(input,PETSC_DECIDE,N);
 37:   VecSetFromOptions(input);
 38:   VecSetRandom(input,rdm);
 39:   VecDuplicate(input,&output);
 40: /*  VecGetSize(input,&vsize); */
 41: /*  printf("Size of the input Vector is %d\n",vsize); */

 43:   DIM    = 3;
 44:   dim[0] = N0; dim[1] = N1; dim[2] = N2;

 46:   MatCreateFFT(PETSC_COMM_WORLD,DIM,dim,MATFFTW,&A);
 47:   MatCreateVecs(A,&x,&y);
 48:   MatCreateVecs(A,&z,NULL);
 49:   VecGetSize(y,&vsize);
 50:   printf("The vector size from the main routine is %d\n",vsize);

 52:   InputTransformFFT(A,input,x);
 53:   MatMult(A,x,y);
 54:   MatMultTranspose(A,y,z);
 55:   OutputTransformFFT(A,z,output);

 57:   fac  = 1.0/(PetscReal)N;
 58:   VecScale(output,fac);

 60:   VecAssemblyBegin(input);
 61:   VecAssemblyEnd(input);
 62:   VecAssemblyBegin(output);
 63:   VecAssemblyEnd(output);

 65:   VecView(input,PETSC_VIEWER_STDOUT_WORLD);
 66:   VecView(output,PETSC_VIEWER_STDOUT_WORLD);

 68:   VecAXPY(output,-1.0,input);
 69:   VecNorm(output,NORM_1,&enorm);
 70: /*  if (enorm > 1.e-14) { */
 71:   if (!rank) {
 72:     PetscPrintf(PETSC_COMM_SELF,"  Error norm of |x - z| %e\n",enorm);
 73:   }
 74: /*      } */




 79: /* MatCreateVecs(A,&z,NULL); */
 80: /*  printf("Vector size from ex148 %d\n",vsize); */
 81: /*  PetscObjectSetName((PetscObject) x, "Real space vector"); */
 82: /*      PetscObjectSetName((PetscObject) y, "Frequency space vector"); */
 83: /*      PetscObjectSetName((PetscObject) z, "Reconstructed vector"); */

 85:   PetscFinalize();
 86:   return 0;

 88: }