tt0.cpp

Go to the documentation of this file.
00001 /* Kernel Independent Fast Multipole Method
00002    Copyright (C) 2004 Lexing Ying, New York University
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2, or (at your option)
00007 any later version.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00012 for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; see the file COPYING.  If not, write to the Free
00016 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017 02111-1307, USA.  */
00018 #include "fmm3d_mpi.hpp"
00019 
00020 using namespace std;
00021 
00022 int main(int argc, char** argv)
00023 {
00024   MPI_Init( &argc, &argv );
00025   PetscInitialize(&argc,&argv,"options_0",NULL);  //PetscTruth flg = PETSC_FALSE;
00026   
00027   MPI_Comm comm; comm = PETSC_COMM_WORLD;
00028   int mpirank;  MPI_Comm_rank(MPI_COMM_WORLD, &mpirank);
00029   int mpisize;  MPI_Comm_size(MPI_COMM_WORLD, &mpisize);
00030   int dim = 3;
00031   srand48( (long)( time(NULL)+mpirank ) );
00032   
00033   PetscTruth flg = PETSC_FALSE;
00034   pC( PetscPrintf(MPI_COMM_WORLD, "mpisize %d\n", mpisize) );
00035   printf( "Hello world from process %d of %d\n", mpirank, mpisize );
00036   
00037   //1. allocate random data
00038   int numsrc;  pC( PetscOptionsGetInt(PETSC_NULL, "-numsrc", &numsrc, &flg) ); pA(flg==PETSC_TRUE);
00039   int numtrg;  pC( PetscOptionsGetInt(PETSC_NULL, "-numtrg", &numtrg, &flg) ); pA(flg==PETSC_TRUE);
00040   int kt;  pC( PetscOptionsGetInt(PETSC_NULL, "-kt", &kt, &flg) ); pA(flg==PETSC_TRUE);
00041   
00042   vector<double> tmp(2);         tmp[0] = 1;     tmp[1] = 0.25; //coefs in the kernel, work for all examples
00043   Kernel3d_MPI knl(kt, tmp);
00044   
00045   int lclnumsrc = (numsrc+mpirank)/mpisize;
00046   int lclnumtrg = (numtrg+mpirank)/mpisize;
00047 
00048   printf( "Hello world from process %d of %d\n", mpirank, lclnumsrc );
00049   pC( PetscPrintf(MPI_COMM_WORLD, "luclnumsrc and lclnumtrg %d %d\n", lclnumsrc, lclnumtrg) );
00050   
00051   Vec srcPos;  pC( VecCreateMPI(comm, lclnumsrc*dim, PETSC_DETERMINE, &srcPos) );
00052   double* srcPosarr; pC( VecGetArray(srcPos, &srcPosarr) );
00053   for(int k=0; k<lclnumsrc*dim; k++){
00054          srcPosarr[k] = (2.0*drand48()-1.0);
00055   }
00056   pC( VecRestoreArray(srcPos, &srcPosarr) );
00057   
00058   Vec trgPos;  pC( VecCreateMPI(comm, lclnumtrg*dim, PETSC_DETERMINE, &trgPos) );
00059   double* trgPosarr; pC( VecGetArray(trgPos, &trgPosarr) );
00060   for(int k=0; k<lclnumtrg*dim; k++)
00061          trgPosarr[k] = (2.0*drand48()-1.0);
00062   pC( VecRestoreArray(trgPos, &trgPosarr) );
00063   
00064   int srcDOF = knl.srcDOF();
00065   int trgDOF = knl.trgDOF();
00066   Vec srcDen;  pC( VecCreateMPI(comm, lclnumsrc*srcDOF, PETSC_DETERMINE, &srcDen) );
00067   double* srcDenarr; pC( VecGetArray(srcDen, &srcDenarr) );
00068   for(int k=0; k<lclnumsrc*srcDOF; k++)
00069          srcDenarr[k] = drand48();
00070   pC( VecRestoreArray(srcDen, &srcDenarr) );
00071   
00072   Vec trgVal;  pC( VecCreateMPI(comm, lclnumtrg*trgDOF, PETSC_DETERMINE, &trgVal) );
00073   PetscScalar zero = 0;  pC( VecSet(trgVal, zero) );
00074   
00075   //2. allocate fmm 
00076   clock_t ck0, ck1;
00077   
00078   FMM3d_MPI* fmm = new FMM3d_MPI("fmm3d_");
00079   fmm->srcPos()=srcPos;
00080   fmm->srcNor()=srcPos;
00081   fmm->trgPos()=trgPos;
00082   fmm->ctr() = Point3(0,0,0); // CENTER OF THE TOPLEVEL BOX
00083   fmm->rootLevel() = 0;         // 2^(-rootlvl) is the RADIUS OF THE TOPLEVEL BOX
00084   fmm->knl() = knl;
00085   
00086   ck0 = clock();
00087   pC( fmm->setup() );
00088   ck1 = clock();  
00089   pC( PetscPrintf(MPI_COMM_WORLD, "fmm setup used %e secs\n", double(ck1-ck0)/CLOCKS_PER_SEC) );
00090   
00091   //3. run fmm
00092   for(int i=0; i<3; i++) {
00093          ck0 = clock();
00094          pC( fmm->evaluate(srcDen, trgVal) );
00095          ck1 = clock();
00096          pC( PetscPrintf(MPI_COMM_WORLD, "fmm eval used %e secs\n", double(ck1-ck0)/CLOCKS_PER_SEC) );
00097   }
00098   
00099   //4. check
00100   ck0 = clock();
00101   double rerr;
00102   pC( fmm->check(srcDen, trgVal, 20, rerr) );
00103   pC( PetscPrintf(MPI_COMM_WORLD, "relative %e\n", rerr) );
00104   ck1 = clock();
00105   pC( PetscPrintf(MPI_COMM_WORLD, "fmm check used %e secs\n", double(ck1-ck0)/CLOCKS_PER_SEC) );
00106   
00107   delete fmm;
00108   int tmp2;
00109   pC( VecGetSize(srcDen,&tmp2) );
00110   pC( PetscPrintf(MPI_COMM_WORLD, "%d \n", tmp2 ));
00111   pC( VecGetLocalSize(srcDen,&tmp2) );
00112   pC( PetscPrintf(MPI_COMM_WORLD, "%d \n", tmp2 ));
00113   pC( VecDestroy(srcPos) );
00114   pC( VecDestroy(trgPos) );
00115   pC( VecDestroy(srcDen) );
00116   pC( VecDestroy(trgVal) );
00117   
00118   PetscFinalize();
00119   return 0;
00120 }

Generated on Sun Dec 4 21:12:40 2005 for fmm3d_mpi by  doxygen 1.4.5