/* This program illustrates use of parallel real FFT */ static char help[]="This program illustrates the use of parallel real 2D fft using fftw without PETSc interface"; #include #include #include int main(int argc,char **args) { const ptrdiff_t N0=2056,N1=2056; fftw_plan bplan,fplan; fftw_complex *out; double *in1,*in2; ptrdiff_t alloc_local,local_n0,local_0_start; ptrdiff_t local_n1,local_1_start; PetscInt i,j; PetscMPIInt size,rank; int n,N,N_factor,NM; PetscScalar one=2.0,zero=0.5; PetscScalar two=4.0,three=8.0,four=16.0; PetscScalar a,*x_arr,*y_arr,*z_arr; PetscReal enorm; Vec fin,fout,fout1; Vec ini,final; PetscRandom rnd; PetscInt *indx3,tempindx,low,*indx4,tempindx1; PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size)); PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank)); PetscCall(PetscRandomCreate(PETSC_COMM_WORLD,&rnd)); alloc_local = fftw_mpi_local_size_2d_transposed(N0,N1/2+1,PETSC_COMM_WORLD,&local_n0,&local_0_start,&local_n1,&local_1_start); #if defined(DEBUGGING) printf("The value alloc_local is %ld from process %d\n",alloc_local,rank); printf("The value local_n0 is %ld from process %d\n",local_n0,rank); printf("The value local_0_start is %ld from process %d\n",local_0_start,rank); /* printf("The value local_n1 is %ld from process %d\n",local_n1,rank); */ /* printf("The value local_1_start is %ld from process %d\n",local_1_start,rank); */ /* printf("The value local_n0 is %ld from process %d\n",local_n0,rank); */ #endif /* Allocate space for input and output arrays */ in1=(double*)fftw_malloc(sizeof(double)*alloc_local*2); in2=(double*)fftw_malloc(sizeof(double)*alloc_local*2); out=(fftw_complex*)fftw_malloc(sizeof(fftw_complex)*alloc_local); N = 2*N0*(N1/2+1); N_factor = N0*N1; n = 2*local_n0*(N1/2+1); /* printf("The value N is %d from process %d\n",N,rank); */ /* printf("The value n is %d from process %d\n",n,rank); */ /* printf("The value n1 is %d from process %d\n",n1,rank);*/ /* Creating data vector and accompanying array with VeccreateMPIWithArray */ PetscCall(VecCreateMPIWithArray(PETSC_COMM_WORLD,1,n,N,(PetscScalar*)in1,&fin)); PetscCall(VecCreateMPIWithArray(PETSC_COMM_WORLD,1,n,N,(PetscScalar*)out,&fout)); PetscCall(VecCreateMPIWithArray(PETSC_COMM_WORLD,1,n,N,(PetscScalar*)in2,&fout1)); /* Set the vector with random data */ PetscCall(VecSet(fin,zero)); /* for (i=0;i 1.e-10) { PetscCall(PetscPrintf(PETSC_COMM_WORLD," Error norm of |x - z| = %e\n",enorm)); } /* Execute fftw with function fftw_execute and destroy it after execution */ fftw_destroy_plan(fplan); fftw_destroy_plan(bplan); fftw_free(in1); PetscCall(VecDestroy(&fin)); fftw_free(out); PetscCall(VecDestroy(&fout)); fftw_free(in2); PetscCall(VecDestroy(&fout1)); PetscCall(VecDestroy(&ini)); PetscCall(VecDestroy(&final)); PetscCall(PetscRandomDestroy(&rnd)); PetscCall(PetscFree(indx3)); PetscCall(PetscFree(indx4)); PetscCall(PetscFinalize()); return 0; } /*TEST build: requires: !mpiuni fftw !complex test: output_file: output/ex144.out test: suffix: 2 nsize: 3 output_file: output/ex144.out TEST*/