Actual source code: ex155.c
petsc-3.4.5 2014-06-29
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 MatGetVecsFFT(Mat,Vec *,Vec *,Vec *);*/
7: PetscInt main(PetscInt argc,char **args)
8: {
10: PetscMPIInt rank,size;
11: PetscInt N0=4096,N1=4096,N2=256,N3=10,N4=10,N=N0*N1;
12: PetscRandom rdm;
13: PetscReal enorm;
14: Vec x,y,z,input,output;
15: Mat A;
16: PetscInt DIM, dim[5],vsize,row,col;
17: PetscReal fac;
19: PetscInitialize(&argc,&args,(char*)0,help);
20: MPI_Comm_size(PETSC_COMM_WORLD, &size);
21: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
23: /* if (size!=1) */
24: /* SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "This is a uni-processor example only"); */
25: #if defined(PETSC_USE_COMPLEX)
26: SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP, "Example for Real DFT. Your current data type is complex!");
27: #endif
28: PetscRandomCreate(PETSC_COMM_WORLD, &rdm);
29: PetscRandomSetFromOptions(rdm);
30: VecCreate(PETSC_COMM_WORLD,&input);
31: VecSetSizes(input,PETSC_DECIDE,N);
32: VecSetFromOptions(input);
33: VecSetRandom(input,rdm);
34: VecDuplicate(input,&output);
36: DIM = 2; dim[0] = N0; dim[1] = N1; dim[2] = N2; dim[3] = N3; dim[4] = N4;
37: MatCreateFFT(PETSC_COMM_WORLD,DIM,dim,MATFFTW,&A);
38: MatGetLocalSize(A,&row,&col);
39: printf("The Matrix size is %d and %d from process %d\n",row,col,rank);
40: MatGetVecsFFTW(A,&x,&y,&z);
42: VecGetSize(x,&vsize);
44: VecGetSize(z,&vsize);
45: printf("The vector size of output from the main routine is %d\n",vsize);
47: VecScatterPetscToFFTW(A,input,x);
48: /*VecDestroy(&input);*/
49: MatMult(A,x,y);
50: MatMultTranspose(A,y,z);
51: VecScatterFFTWToPetsc(A,z,output);
52: /*VecDestroy(&z);*/
53: fac = 1.0/(PetscReal)N;
54: VecScale(output,fac);
56: VecAssemblyBegin(input);
57: VecAssemblyEnd(input);
58: VecAssemblyBegin(output);
59: VecAssemblyEnd(output);
61: /* VecView(input,PETSC_VIEWER_STDOUT_WORLD);*/
62: /* VecView(output,PETSC_VIEWER_STDOUT_WORLD);*/
64: VecAXPY(output,-1.0,input);
65: VecNorm(output,NORM_1,&enorm);
66: if (enorm > 1.e-14) {
67: PetscPrintf(PETSC_COMM_SELF," Error norm of |x - z| %e\n",enorm);
68: }
70: VecDestroy(&x);
71: VecDestroy(&y);
72: VecDestroy(&z);
73: VecDestroy(&output);
74: VecDestroy(&input);
75: MatDestroy(&A);
76: PetscRandomDestroy(&rdm);
77: PetscFinalize();
78: return 0;
80: }