Actual source code: ex155.c

petsc-3.10.5 2019-03-28
Report Typos and Errors
  1: static char help[]="This program illustrates the use of PETSc-fftw interface for parallel real DFT\n";
  2:  #include <petscmat.h>
  3: #include <fftw3-mpi.h>
  4: /*extern PetscErrorCode MatCreateVecsFFT(Mat,Vec *,Vec *,Vec *);*/
  5: PetscInt main(PetscInt argc,char **args)
  6: {
  8:   PetscMPIInt    rank,size;
  9:   PetscInt       N0=4096,N1=4096,N2=256,N3=10,N4=10,N=N0*N1;
 10:   PetscRandom    rdm;
 11:   PetscReal      enorm;
 12:   Vec            x,y,z,input,output;
 13:   Mat            A;
 14:   PetscInt       DIM, dim[5],vsize,row,col;
 15:   PetscReal      fac;

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

 21: #if defined(PETSC_USE_COMPLEX)
 22:   SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "Example for Real DFT. Your current data type is complex!");
 23: #endif
 24:   PetscRandomCreate(PETSC_COMM_WORLD, &rdm);
 25:   PetscRandomSetFromOptions(rdm);
 26:   VecCreate(PETSC_COMM_WORLD,&input);
 27:   VecSetSizes(input,PETSC_DECIDE,N);
 28:   VecSetFromOptions(input);
 29:   VecSetRandom(input,rdm);
 30:   VecDuplicate(input,&output);

 32:   DIM  = 2; dim[0] = N0; dim[1] = N1; dim[2] = N2; dim[3] = N3; dim[4] = N4;
 33:   MatCreateFFT(PETSC_COMM_WORLD,DIM,dim,MATFFTW,&A);
 34:   MatGetLocalSize(A,&row,&col);
 35:   printf("The Matrix size  is %d and %d from process %d\n",row,col,rank);
 36:   MatCreateVecsFFTW(A,&x,&y,&z);

 38:   VecGetSize(x,&vsize);

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

 43:   VecScatterPetscToFFTW(A,input,x);
 44:   /*VecDestroy(&input);*/
 45:   MatMult(A,x,y);
 46:   MatMultTranspose(A,y,z);
 47:   VecScatterFFTWToPetsc(A,z,output);
 48:   /*VecDestroy(&z);*/
 49:   fac  = 1.0/(PetscReal)N;
 50:   VecScale(output,fac);

 52:   VecAssemblyBegin(input);
 53:   VecAssemblyEnd(input);
 54:   VecAssemblyBegin(output);
 55:   VecAssemblyEnd(output);

 57: /*  VecView(input,PETSC_VIEWER_STDOUT_WORLD);*/
 58: /*  VecView(output,PETSC_VIEWER_STDOUT_WORLD);*/

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

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

 76: }