void Scene::refine_bisection(const FT max_sqlen) { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } std::cout << "Refine through recursive longest edge bisection..."; Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron); refiner(max_sqlen); std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; clear_internal_data(); }
// bench memory against number of facets in the tree // the tree is reconstructed each timer in the mesh // refinement loop void Scene::bench_memory() { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } std::cout << std::endl << "Benchmark memory" << std::endl; std::cout << "#Facets, Bytes, Mbytes, Bytes/primitive" << std::endl; while(m_pPolyhedron->size_of_facets() < 2000000) { // refines mesh at increasing speed Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron); std::size_t digits = nb_digits(m_pPolyhedron->size_of_facets()); unsigned int nb_splits = static_cast<unsigned int>(0.2 * std::pow(10.0,(double)digits - 1.0)); refiner.run_nb_splits(nb_splits); // constructs tree and measure memory before then after typedef CGAL::Memory_sizer::size_type size_type; size_type before = CGAL::Memory_sizer().virtual_size(); Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); // tree.accelerate_distance_queries(); // 150 vs 61 bytes per primitive! size_type after = CGAL::Memory_sizer().virtual_size(); size_type bytes = after - before; // in Bytes double mbytes = (double)bytes / (double)1048576; // in MBytes double bpp = (double)bytes / (double)m_pPolyhedron->size_of_facets(); std::cout << m_pPolyhedron->size_of_facets() << ", " << bytes << ", " << mbytes << ", " << bpp << std::endl; } }
void Scene::bench_distances_vs_nbt() { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } std::cout << std::endl << "Benchmark distances against #triangles" << std::endl; std::cout << std::endl << "for random point queries and closest_point()" << std::endl; std::cout << "#Facets, #queries/s" << std::endl; // generates 10K random point queries const int nb_queries = 10000; std::vector<Point> queries; srand(0); for(int i=0;i<nb_queries;i++) queries.push_back(random_point(m_bbox)); while(m_pPolyhedron->size_of_facets() < 1000000) { // refines mesh at increasing speed Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron); std::size_t digits = nb_digits(m_pPolyhedron->size_of_facets()); unsigned int nb_splits = static_cast<unsigned int>(0.2 * std::pow(10.0,(double)digits - 1.0)); refiner.run_nb_splits(nb_splits); // constructs tree (out of timing) Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); tree.accelerate_distance_queries(); // calls queries CGAL::Timer timer; timer.start(); for(int i=0;i<nb_queries;i++) tree.closest_point(queries[i]); double duration = timer.time(); int speed = (int)((double)nb_queries / (double)duration); std::cout << m_pPolyhedron->size_of_facets() << ", " << speed << std::endl; } }
void RefineLB::work(LDStats* stats) { int obj; int n_pes = stats->nprocs(); // CkPrintf("[%d] RefineLB strategy\n",CkMyPe()); // RemoveNonMigratable(stats, n_pes); // get original object mapping int* from_procs = Refiner::AllocProcs(n_pes, stats); for(obj=0;obj<stats->n_objs;obj++) { int pe = stats->from_proc[obj]; from_procs[obj] = pe; } // Get a new buffer to refine into int* to_procs = Refiner::AllocProcs(n_pes, stats); Refiner refiner(1.003); // overload tolerance=1.05 refiner.Refine(n_pes, stats, from_procs, to_procs); // Save output for(obj=0;obj<stats->n_objs;obj++) { int pe = stats->from_proc[obj]; if (to_procs[obj] != pe) { if (_lb_args.debug()>=2) { CkPrintf("[%d] Obj %d migrating from %d to %d\n", CkMyPe(),obj,pe,to_procs[obj]); } stats->to_proc[obj] = to_procs[obj]; } } // Free the refine buffers Refiner::FreeProcs(from_procs); Refiner::FreeProcs(to_procs); }
void Scene::bench_construction() { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } std::cout << std::endl << "Benchmark construction" << std::endl; std::cout << "#Facets alone (s) with KD-tree (s)" << std::endl; while(m_pPolyhedron->size_of_facets() < 1000000) { // refines mesh at increasing speed Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron); std::size_t digits = nb_digits(m_pPolyhedron->size_of_facets()); unsigned int nb_splits = static_cast<unsigned int>(0.2 * std::pow(10.0,(double)digits - 1.0)); refiner.run_nb_splits(nb_splits); // constructs tree CGAL::Timer time1; time1.start(); Facet_tree tree1(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); double duration_construction_alone = time1.time(); CGAL::Timer time2; time2.start(); Facet_tree tree2(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); tree2.accelerate_distance_queries(); double duration_construction_and_kdtree = time2.time(); std::cout << m_pPolyhedron->size_of_facets() << "\t" << duration_construction_alone << "\t" << duration_construction_and_kdtree << std::endl; } }
bool termination_baset::cegar( concrete_modelt &model, goto_tracet &goto_trace, fine_timet &modelchecker_time, fine_timet &unsafe_time, fine_timet &safe_time) { goto_trace.clear(); #if 0 std::ofstream out("model"); model.goto_functions.output(ns, out); out.close(); #endif null_message_handlert nmh; message_handlert &mh = (verbosity >= 8) ? get_message_handler() : nmh; loop_componentt::argst args(mh, model); std::auto_ptr<refinert> refiner(select_refiner(options, args)); std::auto_ptr<abstractort> abstractor(select_abstractor(options, args)); std::auto_ptr<modelcheckert> modelchecker(select_modelchecker(options, args)); std::auto_ptr<simulatort> simulator(select_simulator(options, args, shadow_context)); unsigned this_verb=get_verbosity()-2; // set their verbosity -- all the same for now refiner->set_verbosity(this_verb); abstractor->set_verbosity(this_verb); modelchecker->set_verbosity(this_verb); simulator->set_verbosity(this_verb); try { satabs_safety_checker_baset safety_checker(ns, *abstractor, *refiner, *modelchecker, *simulator); safety_checker.set_message_handler(mh); safety_checker.set_verbosity(this_verb); fine_timet before=current_time(); safety_checkert::resultt result=safety_checker(model.goto_functions); fine_timet diff=current_time()-before; modelchecker_time+=diff; switch(result) { case safety_checkert::ERROR: unsafe_time+=diff; throw "CEGAR Error"; case safety_checkert::UNSAFE: goto_trace.clear(); goto_trace.swap(safety_checker.error_trace); unsafe_time+=diff; return false; // not safe case safety_checkert::SAFE: safe_time+=diff; return true; // safe default: unsafe_time+=diff; throw std::string("CEGAR Result: ") + i2string(result); } } catch(const std::bad_alloc &s) { status(std::string("CEGAR Loop Exception: Memory exhausted")); } catch(const std::string &s) { status(std::string("CEGAR Loop Exception: ") + s); } catch(const char *s) { status(std::string("CEGAR Loop Exception: ") + s); if(std::string(s)=="refinement failure") { status("Dumping failure.o"); write_goto_binary("failure.o", ns.get_context(), model.goto_functions, mh); } } catch(unsigned u) { status(std::string("CEGAR Loop Exception: ") + i2string(u)); } catch(...) { status("UNKNOWN EXCEPTION CAUGHT"); } return false; }
void RefineKLB::work(LDStats* stats) { int obj; int n_pes = stats->nprocs(); // CkPrintf("[%d] RefineKLB strategy\n",CkMyPe()); // RemoveNonMigratable(stats, n_pes); // get original object mapping int* from_procs = RefinerApprox::AllocProcs(n_pes, stats); for(obj=0;obj<stats->n_objs;obj++) { int pe = stats->from_proc[obj]; from_procs[obj] = pe; } // Get a new buffer to refine into int* to_procs = RefinerApprox::AllocProcs(n_pes, stats); RefinerApprox refiner(1.003); // overload tolerance=1.003 if(_lb_args.percentMovesAllowed()>0 && _USE_APPROX_ALGO_) { refiner.Refine(n_pes, stats, from_procs, to_procs, _lb_args.percentMovesAllowed()); } else { for(obj=0;obj<stats->n_objs;obj++) { to_procs[obj] = stats->from_proc[obj]; } } // Save output int numMoves=0; for(obj=0;obj<stats->n_objs;obj++) { int pe = stats->from_proc[obj]; if (to_procs[obj] != pe) { // CkPrintf("[%d] Obj %d migrating from %d to %d\n", // CkMyPe(),obj,pe,to_procs[obj]); stats->to_proc[obj] = to_procs[obj]; numMoves++; } } int maxMoves=0.01*(stats->n_objs)*(_lb_args.percentMovesAllowed()); int availableMoves=maxMoves-numMoves; //Perform Additional Moves in Greedy Fashion if(availableMoves>0 && _USE_RESIDUAL_MOVES_) { int *to_procs2=new int[stats->n_objs]; performGreedyMoves(n_pes, stats, to_procs, to_procs2, availableMoves); int nmoves2=0; for(obj=0;obj<stats->n_objs;obj++) { if(to_procs2[obj]!=to_procs[obj]) { stats->to_proc[obj]=to_procs2[obj]; nmoves2++; } } delete[] to_procs2; } // Free the refine buffers RefinerApprox::FreeProcs(from_procs); RefinerApprox::FreeProcs(to_procs); }
void getsseq( float *sseq, /* (o) the pitch-synchronous sequence */ float *idata, /* (i) original data */ int idatal, /* (i) dimension of data */ int centerStartPos, /* (i) where current block starts */ float *period, /* (i) rough-pitch-period array */ float *plocs, /* (i) where periods of period array are taken */ int periodl, /* (i) dimension period array */ int hl /* (i) 2*hl+1 is the number of sequences */ ){ int i,centerEndPos,q; float blockStartPos[2*ENH_HL+1]; int lagBlock[2*ENH_HL+1]; float plocs2[ENH_PLOCSL]; float *psseq; centerEndPos=centerStartPos+ENH_BLOCKL-1; /* present */ NearestNeighbor(lagBlock+hl,plocs, (float)0.5*(centerStartPos+centerEndPos),periodl); blockStartPos[hl]=(float)centerStartPos; psseq=sseq+ENH_BLOCKL*hl; memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float)); /* past */ for (q=hl-1; q>=0; q--) { blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]]; NearestNeighbor(lagBlock+q,plocs, blockStartPos[q]+ ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl); if (blockStartPos[q]-ENH_OVERHANG>=0) { refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata, idatal, centerStartPos, blockStartPos[q], period[lagBlock[q+1]]); } else { psseq=sseq+q*ENH_BLOCKL; memset(psseq, 0, ENH_BLOCKL*sizeof(float)); } } /* future */ for (i=0; i<periodl; i++) { plocs2[i]=plocs[i]-period[i]; } for (q=hl+1; q<=2*hl; q++) { NearestNeighbor(lagBlock+q,plocs2, blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl); blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]]; if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) { refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata, idatal, centerStartPos, blockStartPos[q], period[lagBlock[q]]); } else { psseq=sseq+q*ENH_BLOCKL; memset(psseq, 0, ENH_BLOCKL*sizeof(float)); } } }
void TempAwareRefineLB::work(LDStats* stats) { #ifdef TEMP_LDB //////////////////////////////////////////////////// numProcs=stats->nprocs(); numChips=numProcs/logicalCoresPerChip; avgChipTemp=new float[numChips]; if(procFreq!=NULL) delete [] procFreq; if(procFreqEffect!=NULL) delete [] procFreqEffect; // if(procFreqPtr!=NULL) delete [] procFreqPtr; if(procTemp!=NULL) delete [] procTemp; if(procFreqNew!=NULL) delete [] procFreqNew; if(procFreqNewEffect!=NULL) delete [] procFreqNewEffect; if(avgChipTemp!=NULL) delete [] avgChipTemp; procFreq = new int[numProcs]; procFreqEffect = new int[numProcs]; // procFreqPtr = new int[numProcs]; procTemp = new float[numProcs]; procFreqNew = new int[numProcs]; procFreqNewEffect = new int[numProcs]; avgChipTemp = new float[numChips]; for(int i=0;i<numChips;i++) avgChipTemp[i]=0; for(int i=0;i<numProcs;i++) { procFreq[i] = stats->procs[i].pe_speed; procTemp[i] = stats->procs[i].pe_temp; // procFreqPtr[i] = getProcFreqPtr(freqs,numAvailFreqs,procFreq[i]); avgChipTemp[i/logicalCoresPerChip] += procTemp[i]; } for(int i=0;i<numChips;i++) { avgChipTemp[i]/=logicalCoresPerChip; //CkPrintf("---- CHIP#%d has temp=%f ----------\n",i,avgChipTemp[i]); } for(int i=0;i<numChips;i++) { int over=0,under=0; if(avgChipTemp[i] > MAX_TEMP) { over=1; if(procFreqPtr[i*logicalCoresPerChip]==numAvailFreqs-1) { for(int j=i*logicalCoresPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) procFreqNew[j] = freqs[procFreqPtr[j]]; CkPrintf("CHIP#%d RUNNING HOT EVEN WITH MIN FREQUENCY!!\n",i); } else { for(int j=i*logicalCoresPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) { if(procFreqPtr[j]<numAvailFreqs-1) procFreqPtr[j]++; #ifdef MAX_MIN /// PLEASE COMMENT OUT .. TESTING ONLY if(i==0) {procFreqPtr[j] = numAvailFreqs-1;/*CkPrintf("C for i:%d\n",j);*/} //if(i<numChips-1) procFreqPtr[j]=0; else procFreqPtr[j]=0; ///////////////////////// #endif procFreqNew[j] = freqs[procFreqPtr[j]]; } #ifndef ORG_VERSION CkPrintf("!!!!! Chip#%d running HOT shifting from %d to %d temp=%f\n",i,procFreq[i*logicalCoresPerChip],procFreqNew[i*logicalCoresPerChip],avgChipTemp[i]); #endif } } else // if(avgChipTemp[i] < MAX_TEMP-1) { under=1; if(procFreqPtr[i*logicalCoresPerChip]>0) { for(int j=i*logicalCoresPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) { if(procFreqPtr[j]>0) procFreqPtr[j]--; #ifdef MAX_MIN /// PLEASE COMMENT OUT .. TESTING ONLY if(i==0) procFreqPtr[j] = numAvailFreqs-1; //if(i<numChips-1) procFreqPtr[j]=0; else procFreqPtr[j]=0; ///////////////////////// #endif procFreqNew[j] = freqs[procFreqPtr[j]]; } #ifndef ORG_VERSION CkPrintf("!!!!! Chip#%d running COLD shifting from %d to %d temp=%f\n",i,procFreq[i*logicalCoresPerChip],procFreqNew[i*logicalCoresPerChip],avgChipTemp[i]); #endif } else { for(int j=i*logicalCoresPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) procFreqNew[j] = freqs[procFreqPtr[j]]; } } /* if(under==0 && over==0) { for(int j=i*logicalCoresPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) procFreqNew[j] = freqs[procFreqPtr[j]]; } */ //if(i==5) for(int j=i*c(resPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) procFreqNew[j] = freqs[numAvailFreqs-1]; //else #ifdef ORG_VERSION for(int j=i*logicalCoresPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) procFreqNew[j] = freqs[0]; #endif //for(int j=i*logicalCoresPerChip;j<i*logicalCoresPerChip+logicalCoresPerChip;j++) procFreqNew[j] = freqs[0]; } //for(int x=0;x<numProcs;x+=logicalCoresPerChip) if(procFreq[x]!=procFreqNew[x]) thisProxy[x].changeFreq(procFreqNew[x]); //for(int x=0;x<numProcs;x++) CkPrintf("Procs#%d freq %d\n",x,procFreqNew[x]); //////////////////////////////////////////////////// #ifndef NO_TEMP_LB int obj; int n_pes = stats->nprocs(); // CkPrintf("[%d] RefineLB strategy\n",CkMyPe()); // RemoveNonMigratable(stats, n_pes); // get original object mapping int* from_procs = RefinerTemp::AllocProcs(n_pes, stats); for(obj=0;obj<stats->n_objs;obj++) { int pe = stats->from_proc[obj]; from_procs[obj] = pe; } // Get a new buffer to refine into populateEffectiveFreq(numProcs); int* to_procs = RefinerTemp::AllocProcs(n_pes, stats); // RefinerTemp refiner(1.03,procFreqEffect,procFreqNewEffect,n_pes); // overload tolerance=1.05 RefinerTemp refiner(1.03,procFreq,procFreqNew,n_pes); refiner.Refine(n_pes, stats, from_procs, to_procs); // Save output int migs=0; int *numMigs = new int[numProcs]; int totE = 0; for(int mm=0;mm<numProcs;mm++) numMigs[mm] = 0; for(obj=0;obj<stats->n_objs;obj++) { int pe = stats->from_proc[obj]; numMigs[to_procs[obj]]++; //stats->objData[obj].objID(); LDObjData &odata = stats->objData[obj]; computeInfo *c1 = new computeInfo(); c1->id = odata.objID(); //if(to_procs[obj]==3) CkPrintf("[%d,%d] going to 3 totE:%d\n",c1->id.getID()[0],c1->id.getID()[1],totE++);//,(stats->objData[obj].objID().getID())[1],totE++); if (to_procs[obj] != pe) { migs++; //if (_lb_args.debug()>=2) { // CkPrintf("[%d,%d] Obj %d migrating from %d to %d\n", // c1->id.getID()[0],c1->id.getID()[1],obj,pe,to_procs[obj]); } stats->to_proc[obj] = to_procs[obj]; } } for(int mm=0;mm<numProcs;mm++) { //CkPrintf("PROC#%d freq:%d objs:%d ----------\n",mm,procFreqNew[mm],numMigs[mm]); } CkPrintf("TEMPLB INFO: Total Objs:%d migrations:%d time:%f \n",stats->n_objs,migs,CmiWallTimer()-starting); fprintf(migFile,"%f %d\n",CmiWallTimer()-starting,migs); // Free the refine buffers RefinerTemp::FreeProcs(from_procs); RefinerTemp::FreeProcs(to_procs); #endif //for(int x=0;x<numProcs;x++) CkPrintf("Procs#%d ------- freq %d\n",x,procFreqNew[x]); /* for(int x=0;x<numProcs;x+=logicalCoresPerChip) { if(procFreq[x]!=procFreqNew[x]) { CkPrintf("Chaning the freq for PROC#%d\n",x); thisProxy[x].changeFreq(procFreqNew[x]); } } */ for(int x=0;x<numProcs;x++) { //CkPrintf("--------- Proc#%d %d numProcs=%d\n",x,procFreqNew[x],numProcs); if(procFreq[x]!=procFreqNew[x]) thisProxy[x].changeFreq(procFreqNew[x]); } #endif // TEMP_LDB endif }