00001
00002 #include "mpi.h"
00003 #include "petsc.h"
00004 #include "sys.h"
00005 #include "octUtils.h"
00006 #include "TreeNode.h"
00007 #include <cstdlib>
00008 #include <cstring>
00009 #include "externVars.h"
00010
00011
00012 #ifdef MPI_WTIME_IS_GLOBAL
00013 #undef MPI_WTIME_IS_GLOBAL
00014 #endif
00015
00016 int main(int argc, char ** argv ) {
00017 int size, rank;
00018 unsigned int writeCOut = 1;
00019 char Kstr[20];
00020 char inpFileName[50],n2oOut[50],linOut[50];
00021
00022 PetscInitialize(&argc,&argv,"options",NULL);
00023 ot::RegisterEvents();
00024
00025 #ifdef PETSC_USE_LOG
00026 int stages[1];
00027 PetscLogStageRegister(&stages[0],"Coarsen");
00028 #else
00029 MPI_Init(&argc,&argv);
00030 #endif
00031 MPI_Comm_size(MPI_COMM_WORLD,&size);
00032 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00033 if(argc < 2) {
00034 std::cerr << "Usage: " << argv[0] << " inpfile writeCOut[1]"<< std::endl;
00035 return -1;
00036 }
00037 if(argc > 2) {
00038 writeCOut = atoi(argv[2]);
00039 }
00040
00041 strcpy(inpFileName, argv[1]);
00042 strcpy(linOut,inpFileName);
00043 ot::int2str(rank,Kstr);
00044 strcat(linOut,Kstr);
00045 strcat(linOut,"_\0");
00046 ot::int2str(size,Kstr);
00047 strcat(linOut,Kstr);
00048 strcpy(n2oOut,linOut);
00049 strcat(linOut,"_C.ot\0");
00050 strcat(n2oOut,".ot\0");
00051 std::vector<ot::TreeNode> nodes;
00052 std::vector<ot::TreeNode> linOct;
00053
00054 ot::readNodesFromFile(n2oOut,nodes);
00055 unsigned int dim = nodes[0].getDim();
00056 unsigned int maxDepth = nodes[0].getMaxDepth();
00057 MPI_Barrier(MPI_COMM_WORLD);
00058 #ifdef PETSC_USE_LOG
00059 PetscLogStagePush(stages[0]);
00060 #endif
00061 ot::coarsenOctree(nodes, linOct, dim, maxDepth, MPI_COMM_WORLD, false, NULL, NULL);
00062 #ifdef PETSC_USE_LOG
00063 PetscLogStagePop();
00064 #endif
00065 if(writeCOut) {
00066 ot::writeNodesToFile(linOut,linOct);
00067 }
00068
00069 PetscFinalize();
00070
00071 }
00072