Actual source code: ex154.c

  1: static char help[]="This program illustrates the use of PETSc-fftw interface for Complex parallel DFT\n";
  2: #include <petscmat.h>
  3: #include <fftw3-mpi.h>
  8: PetscInt main(PetscInt argc,char **args)
  9: {
 10:   PetscErrorCode  ierr;
 11:   PetscMPIInt     rank,size;
 12:   PetscInt        N0=500,N1=5,N2=5,N3=10,N4=10,N=N0;
 13:   PetscRandom     rdm;
 14:   PetscReal       enorm;
 15:   Vec             x,y,z,input,output;
 16:   Mat             A;
 17:   PetscInt        DIM, dim[5],vsize;
 18:   PetscReal       fac;

 20:   PetscInitialize(&argc,&args,(char *)0,help);
 21:   MPI_Comm_size(PETSC_COMM_WORLD, &size);
 22:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
 23: #if !defined(PETSC_USE_COMPLEX)
 24:   SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "This example requires complex numbers");
 25: #endif
 26:   PetscRandomCreate(PETSC_COMM_WORLD, &rdm);
 27:   PetscRandomSetFromOptions(rdm);
 28:   VecCreate(PETSC_COMM_WORLD,&input);
 29:   VecSetSizes(input,PETSC_DECIDE,N);
 30:   VecSetFromOptions(input);
 31:   VecSetRandom(input,rdm);
 32:   VecAssemblyBegin(input);
 33:   VecAssemblyEnd(input);
 34: //  VecView(input,PETSC_VIEWER_STDOUT_WORLD);
 35:   VecDuplicate(input,&output);
 36: 
 37:   DIM = 1; dim[0] = N0; dim[1] = N1; dim[2] = N2; dim[3] = N3; dim[4] = N4;
 38:   MatCreateFFT(PETSC_COMM_WORLD,DIM,dim,MATFFTW,&A);
 39: //  MatGetVecs(A,&x,&y,&z);
 40:   MatGetVecs(A,&x,&y);
 41:   MatGetVecs(A,&z,PETSC_NULL);

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

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

 49:   InputTransformFFT(A,input,x);
 50: //  VecAssemblyBegin(x);
 51: //  VecAssemblyEnd(x);
 52: //  VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 54:   MatMult(A,x,y);
 55:   MatMultTranspose(A,y,z);

 57:   OutputTransformFFT(A,z,output);
 58:   fac = 1.0/(PetscReal)N;
 59:   VecScale(output,fac);
 60: 
 61: //  VecAssemblyBegin(input);
 62: //  VecAssemblyEnd(input);
 63: //  VecAssemblyBegin(output);
 64: //  VecAssemblyEnd(output);

 66: //  VecView(input,PETSC_VIEWER_STDOUT_WORLD);
 67: //  VecView(output,PETSC_VIEWER_STDOUT_WORLD);

 69:   VecAXPY(output,-1.0,input);
 70:   VecNorm(output,NORM_1,&enorm);
 71: //  if (enorm > 1.e-14){
 72:       PetscPrintf(PETSC_COMM_SELF,"  Error norm of |x - z| %e\n",enorm);
 73: //      }
 74:   VecDestroy(&output);
 75:   VecDestroy(&input);
 76:   VecDestroy(&x);
 77:   VecDestroy(&y);
 78:   VecDestroy(&z);
 79:   MatDestroy(&A);
 80:   PetscRandomDestroy(&rdm);
 81:   PetscFinalize();
 82:   return 0;
 83: }