Actual source code: ex155.c
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: int main(int argc,char **args)
6: {
7: PetscMPIInt rank,size;
8: PetscInt N0=4096,N1=4096,N2=256,N3=10,N4=10,N=N0*N1;
9: PetscRandom rdm;
10: PetscReal enorm;
11: Vec x,y,z,input,output;
12: Mat A;
13: PetscInt DIM, dim[5],vsize,row,col;
14: PetscReal fac;
16: PetscInitialize(&argc,&args,(char*)0,help);
17: MPI_Comm_size(PETSC_COMM_WORLD, &size);
18: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
20: #if defined(PETSC_USE_COMPLEX)
21: SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "Example for Real DFT. Your current data type is complex!");
22: #endif
23: PetscRandomCreate(PETSC_COMM_WORLD, &rdm);
24: PetscRandomSetFromOptions(rdm);
25: VecCreate(PETSC_COMM_WORLD,&input);
26: VecSetSizes(input,PETSC_DECIDE,N);
27: VecSetFromOptions(input);
28: VecSetRandom(input,rdm);
29: VecDuplicate(input,&output);
31: DIM = 2; dim[0] = N0; dim[1] = N1; dim[2] = N2; dim[3] = N3; dim[4] = N4;
32: MatCreateFFT(PETSC_COMM_WORLD,DIM,dim,MATFFTW,&A);
33: MatGetLocalSize(A,&row,&col);
34: printf("The Matrix size is %d and %d from process %d\n",row,col,rank);
35: MatCreateVecsFFTW(A,&x,&y,&z);
37: VecGetSize(x,&vsize);
39: VecGetSize(z,&vsize);
40: printf("The vector size of output from the main routine is %d\n",vsize);
42: VecScatterPetscToFFTW(A,input,x);
43: /*VecDestroy(&input);*/
44: MatMult(A,x,y);
45: MatMultTranspose(A,y,z);
46: VecScatterFFTWToPetsc(A,z,output);
47: /*VecDestroy(&z);*/
48: fac = 1.0/(PetscReal)N;
49: VecScale(output,fac);
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);*/
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(&x);
66: VecDestroy(&y);
67: VecDestroy(&z);
68: VecDestroy(&output);
69: VecDestroy(&input);
70: MatDestroy(&A);
71: PetscRandomDestroy(&rdm);
72: PetscFinalize();
73: return 0;
75: }