Actual source code: ex149.c

petsc-3.8.4 2018-03-24
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>

  5: extern PetscErrorCode InputTransformFFT(Mat,Vec,Vec);
  6: extern PetscErrorCode OutputTransformFFT(Mat,Vec,Vec);
  7: PetscInt main(PetscInt 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);


 30:   PetscRandomCreate(PETSC_COMM_WORLD, &rdm);
 31:   PetscRandomSetFromOptions(rdm);

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

 41:   DIM    = 3;
 42:   dim[0] = N0; dim[1] = N1; dim[2] = N2;

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

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

 55:   fac  = 1.0/(PetscReal)N;
 56:   VecScale(output,fac);

 58:   VecAssemblyBegin(input);
 59:   VecAssemblyEnd(input);
 60:   VecAssemblyBegin(output);
 61:   VecAssemblyEnd(output);

 63:   VecView(input,PETSC_VIEWER_STDOUT_WORLD);
 64:   VecView(output,PETSC_VIEWER_STDOUT_WORLD);

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




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

 83:   PetscFinalize();
 84:   return ierr;

 86: }