00001
00002 #include "mpi.h"
00003 #include "petsc.h"
00004 #include "sys.h"
00005 #include "parUtils.h"
00006 #include "octUtils.h"
00007 #include "TreeNode.h"
00008 #include <cstdlib>
00009 #include <cstring>
00010 #include "externVars.h"
00011 #include "dendro.h"
00012
00013
00014 #ifdef MPI_WTIME_IS_GLOBAL
00015 #undef MPI_WTIME_IS_GLOBAL
00016 #endif
00017
00018 int main(int argc, char ** argv ) {
00019 int size, rank;
00020 bool incCorner = 1;
00021 unsigned int writeBOut = 0;
00022 char Kstr[20];
00023 char inpFileName[50],n2oOut[50],balOut[50];
00024
00025 PetscInitialize(&argc,&argv,"options",NULL);
00026 ot::RegisterEvents();
00027
00028 #ifdef PETSC_USE_LOG
00029 int stages[1];
00030 PetscLogStageRegister(&stages[0],"Bal");
00031 #endif
00032
00033 MPI_Comm_size(MPI_COMM_WORLD,&size);
00034 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00035 if(argc < 2) {
00036 std::cerr << "Usage: " << argv[0] << " inpfile writeBOut[0]"<<
00037 " incCorner[1] " << std::endl;
00038 return -1;
00039 }
00040 if(argc > 2) {
00041 writeBOut = atoi(argv[2]);
00042 }
00043 if(argc > 3) { incCorner = (bool)(atoi(argv[3]));}
00044
00045 strcpy(inpFileName, argv[1]);
00046 strcpy(balOut,inpFileName);
00047 ot::int2str(rank,Kstr);
00048 strcat(balOut,Kstr);
00049 strcat(balOut,"_\0");
00050 ot::int2str(size,Kstr);
00051 strcat(balOut,Kstr);
00052 strcpy(n2oOut,balOut);
00053 strcat(balOut,"_Bal.ot\0");
00054 strcat(n2oOut,".ot\0");
00055 std::vector<ot::TreeNode> nodes;
00056 std::vector<ot::TreeNode> linOct;
00057 std::vector<ot::TreeNode> balOct;
00058
00059 ot::readNodesFromFile(n2oOut,nodes);
00060 unsigned int dim = nodes[0].getDim();
00061 unsigned int maxDepth = nodes[0].getMaxDepth();
00062 MPI_Barrier(MPI_COMM_WORLD);
00063 #ifdef PETSC_USE_LOG
00064 PetscLogStagePush(stages[0]);
00065 #endif
00066 ot::completeOctree(nodes, linOct, dim, maxDepth, false, false, false, MPI_COMM_WORLD);
00067 ot::balanceOctree (linOct, balOct, dim, maxDepth, incCorner, MPI_COMM_WORLD, NULL, NULL);
00068
00069 DendroIntL locOutSize = balOct.size();
00070 DendroIntL globOutSize;
00071
00072 par::Mpi_Reduce<DendroIntL>(&locOutSize, &globOutSize, 1, MPI_SUM, 0, MPI_COMM_WORLD);
00073
00074 if(!rank) {
00075 std::cout<<"Final Balanced Octree Size: "<<globOutSize<<std::endl;
00076 }
00077
00078
00079 #ifdef PETSC_USE_LOG
00080 PetscLogStagePop();
00081 #endif
00082 if(writeBOut) {
00083 ot::writeNodesToFile(balOut,balOct);
00084 }
00085
00086 PetscFinalize();
00087
00088 }
00089