bool c4_Column::UsesMap(const t4_byte *ptr_)const { // the most common falsifying case is checked first return _persist != 0 && ptr_ >= Strategy()._mapStart && Strategy()._dataSize != 0 && ptr_ < Strategy()._mapStart + Strategy()._dataSize; }
bool c4_Column::UsesMap(const t4_byte* ptr_) const { // the most common falsifying case is checked first return _persist != 0 && ptr_ >= Strategy()._mapStart && Strategy()._dataSize != 0 && // added 2003-05-08, thx V DeMarco ptr_ - Strategy()._mapStart < Strategy()._dataSize; }
void c4_Column::SetupSegments() { d4_assert(_segments.GetSize() == 0); d4_assert(_gap == 0); d4_assert(_slack == 0); // The last entry in the _segments array is either a partial block // or a null pointer, so calling "fSegIndex(_size)" is always allowed. int n = fSegIndex(_size) + 1; _segments.SetSize(n); // treat last block differently if it is a partial entry int last = n; if (fSegRest(_size)) --last; // this block is partial, size is 1 .. kSegMax-1 else --n; // the last block is left as a null pointer int id = - 1; if (_position < 0) { // special aside id, figure out the real position d4_assert(_persist != 0); id = ~_position; _position = _persist->LookupAside(id); d4_assert(_position >= 0); } if (IsMapped()) { // setup for mapped files is quick, just fill in the pointers d4_assert(_position > 1); d4_assert(_position + (n - 1) *kSegMax <= Strategy()._dataSize); const t4_byte *map = Strategy()._mapStart + _position; for (int i = 0; i < n; ++i) { _segments.SetAt(i, (t4_byte*)map); // loses const map += kSegMax; } } else { int chunk = kSegMax; t4_i32 pos = _position; // allocate buffers, load them if necessary for (int i = 0; i < n; ++i) { if (i == last) chunk = fSegRest(_size); t4_byte *p = d4_new t4_byte[chunk]; _segments.SetAt(i, p); if (_position > 0) { d4_dbgdef(int n = )Strategy().DataRead(pos, p, chunk); d4_assert(n == chunk); pos += chunk; } } }
StrategySelector::StrategySelector() { active = true; strategies.push_back(Strategy(Races::Protoss, ProtossMain::getStrategyId())); strategies.push_back(Strategy(Races::Terran, TerranMain::getStrategyId())); strategies.push_back(Strategy(Races::Zerg, LurkerRush::getStrategyId())); strategies.push_back(Strategy(Races::Zerg, ZergMain::getStrategyId())); loadStats(); }
void SPTGSolver::solveSPTG(SPTG* s){ // This function is the core of the solver, it computes the strategies and values for the SPTG passed sptg = s; init(); show(); PGSolver ps(sptg, &pathsLengths, &vals, &strategies);//PGSolver will consider sptg as a pg thanks to inheritance bool notCycling = ps.extendedDijkstra(false); //If extendedDijkstra returns false, some states can't be treated and there is a cycle show(); while (notCycling && time > 0){ strategies.push_front(Strategy(size)); actualizeLambdas(); if(time.num == 1 && time.den == 1)//If it's the first turn, we have to "initialize" the value functions buildValueFcts(0); strategyIteration(); Fraction epsilon = nextEventPoint(); cout << "NextEventPoint: " << epsilon << endl; if((time - epsilon) < 0) epsilon = time; buildValueFcts(epsilon); actualizeVals(epsilon); strategies.front().setTime(time); show(); } if(notCycling){ cout << "====Result==== " << endl; show(); } else cout << "There is a cycle!" << endl; sptg = NULL; }
void SPTGSolver::init(){ // Initialization of all vectors and variables used by the solver size = sptg->getSize(); if(size != 0){ vals.push_back(vector<Fraction>()); vals[0].push_back(Fraction(0)); vals[0].push_back(Fraction(0)); strategies.push_front(Strategy(size, time)); strategies.front().insert(0,0,false); pathsLengths.push_back(0); lambdas.push_back(vector<Fraction>()); lambdas[0].push_back(Fraction(0)); lambdas[0].push_back(Fraction(0)); valueFcts.push_back(list<Point>()); // Fill the initial valors, strategies and the ensemble of states for (unsigned int i = 1; i < size; ++i){ vals.push_back(vector<Fraction>()); vals[i].push_back(Fraction(ifnty)); vals[i].push_back(Fraction(0)); strategies.front().insert(i, -1, false); pathsLengths.push_back(0); lambdas.push_back(vector<Fraction>()); lambdas[i].push_back(0); lambdas[i].push_back(0); valueFcts.push_back(list<Point>()); } } }
void variable_elimination(std::list<annotated<Arg, F> >& factors, const domain<Arg>& retain, const commutative_semiring<Arg, F>& csr, Strategy strategy = Strategy()) { // construct the Markov graph for the input factors undirected_graph<Arg> graph; for (const annotated<Arg, F>& factor : factors) { graph.make_clique(factor.domain); } // eliminate variables eliminate(graph, [&](Arg arg) { if (!retain.count(arg)) { // Combine all factors that have this variable as an argument annotated<Arg, F> combination = csr.combine_init(); for (auto it = factors.begin(); it != factors.end();) { if (it->domain.count(arg)) { csr.combine_in(combination, *it); factors.erase(it++); } else { ++it; } } factors.push_back(csr.eliminate(combination, arg)); } }, strategy); }
void test_convex_hull(Geometry const& geometry, std::size_t size_original, std::size_t size_hull, double expected_area, bool reverse) { Hull hull; // Test version with output iterator bg::detail::convex_hull::convex_hull_insert(geometry, std::back_inserter(hull.outer())); check_convex_hull(geometry, hull, size_original, size_hull, expected_area, reverse); // Test version with ring as output bg::clear(hull); bg::convex_hull(geometry, hull.outer()); check_convex_hull(geometry, hull, size_original, size_hull, expected_area, false); // Test version with polygon as output bg::clear(hull); bg::convex_hull(geometry, hull); check_convex_hull(geometry, hull, size_original, size_hull, expected_area, false); // Test version with strategy bg::clear(hull); bg::convex_hull(geometry, hull.outer(), Strategy()); check_convex_hull(geometry, hull, size_original, size_hull, expected_area, false); // Test version with output iterator and strategy bg::clear(hull); bg::detail::convex_hull::convex_hull_insert(geometry, std::back_inserter(hull.outer()), Strategy()); check_convex_hull(geometry, hull, size_original, size_hull, expected_area, reverse); }
/** (Re)initialize for on-demand loading * * Calling Rollback will cancel all uncommitted changes. */ bool c4_Storage::Rollback(bool full_) { c4_Persist *pers = Persist(); bool f = Strategy().IsValid() && pers->Rollback(full_); // adjust our copy when the root view has been replaced *(c4_View*)this = &pers->Root(); return f; }
bool c4_Column::RequiresMap()const { if (_persist != 0 && Strategy()._mapStart != 0) for (int i = _segments.GetSize(); --i >= 0;) if (UsesMap((t4_byte*)_segments.GetAt(i))) return true; return false; }
NTSTATUS CUsbDkFilterDeviceInit::Configure(ULONG InstanceNumber) { PAGED_CODE(); WDF_OBJECT_ATTRIBUTES requestAttributes; WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&requestAttributes, WDF_REQUEST_CONTEXT); requestAttributes.ContextSizeOverride = CUsbDkFilterDevice::CStrategist::GetRequestContextSize(); SetRequestAttributes(requestAttributes); SetFilter(); CString DeviceName; auto status = DeviceName.Create(TEXT("\\Device\\UsbDkFilter"), InstanceNumber); if (!NT_SUCCESS(status)) { TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Failed to allocate filter device name (%!STATUS!)", status); return status; } status = SetName(*DeviceName); if (!NT_SUCCESS(status)) { TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! SetName failed %!STATUS!", status); return status; } SetPowerCallbacks([](_In_ WDFDEVICE Device) { return Strategy(Device)->MakeAvailable(); }); SetIoInCallerContextCallback([](_In_ WDFDEVICE Device, WDFREQUEST Request) { return Strategy(Device)->IoInCallerContext(Device, Request); }); SetFileEventCallbacks(WDF_NO_EVENT_CALLBACK, [](_In_ WDFFILEOBJECT FileObject) { WDFDEVICE Device = WdfFileObjectGetDevice(FileObject); Strategy(Device)->OnClose(); }, WDF_NO_EVENT_CALLBACK); status = SetPreprocessCallback([](_In_ WDFDEVICE Device, _Inout_ PIRP Irp) { return Strategy(Device)->PNPPreProcess(Irp); }, IRP_MJ_PNP); return status; }
void DBufferLFRU::Write(int fileId,int segId,int &ofileId,int &osegId){ ofileId = -1; osegId = -1; if(buf.size() >= mBlockNums){ Strategy(fileId,segId,ofileId,osegId); } else{ AddBlock(fileId,segId); } }
void DBufferDWS::Write(int fileId,int segId,int &ofileId,int &osegId){ ofileId = -1; osegId = -1; if(lruQueue.size() >= mBlockNums){ Strategy(fileId,segId,ofileId,osegId); } else{ AddBlock(fileId,segId); } }
void Enemy::Update(int x_tile, int y_tile, Tilemap* map) { anim.Tick(); time_until_next_step.Update(); offset_from_tile *= 0.9; int player_x, player_y; map->PlayerObject(player_x, player_y); // Check if this enemy actually cares about the player at the moment Vector dist((float)player_x - (float)x_tile, (float)player_y - (float)y_tile); if (dist.X()*dist.X() + dist.Y()*dist.Y() <= radius_of_caring*radius_of_caring) { // I'm pretty sure its quicker to multiply that run a sqare root. Doubt it makes any real difference though FaceDirection(Strategy(Vector(x_tile, y_tile), Vector(player_x, player_y), map)); if (!map->IsMovementBlocked()) { int new_x = x_tile, new_y = y_tile; Vector tile_offset; switch (dir) { case up: new_y = y_tile > 0 ? (int)y_tile - 1 : y_tile; tile_offset = Vector(0.0, tile_dim.Y()); break; case down: new_y = y_tile < 10 ? y_tile + 1 : y_tile; tile_offset = Vector(0.0, -tile_dim.Y()); break; case left: new_x = x_tile > 0 ? (int)x_tile - 1 : x_tile; tile_offset = Vector(tile_dim.X(), 0.0); break; case right: new_x = x_tile < 10 ? x_tile + 1 : x_tile; tile_offset = Vector(-tile_dim.X(), 0.0); break; case nowhere: default: // Stay still break; } if (time_until_next_step) { offset_from_tile = tile_offset; TileObject* obj_swapping_with = map->ObjectAt(new_x, new_y); if (obj_swapping_with != NULL && obj_swapping_with->WhatAmI() == player1) ((Player*)(map->ObjectAt(new_x, new_y)))->CollidedWithEnemy(map); else { owner->SwapObjects(map->GetTile(new_x, new_y)); time_until_next_step.SetTicks(step_time); } } } } }
void DBufferFIFOS::Write(int fileId,int segId,int &ofileId,int &osegId){ ofileId = -1; osegId = -1; assert(m_blockList.size() <= mBlockNums); if(m_blockList.size() < mBlockNums){ m_blockList.push_back(Block(fileId,segId)); } else{ Strategy(fileId,segId,ofileId,osegId); } }
//analysis module to update velocity info to Coach FieldState from memory info //and activates a strategy of choice (player made) void yellowPlayerAnalysis(Coach *ourCoach) { // updates velocity using only two positions (current and last), then calls basicStrat ourCoach->fs.ball.speed_x = (ourCoach->memory()->at(4).balls(0).x() - ourCoach->memory()->at(3).balls(0).x()) / (ourCoach->memory()->at(4).t_sent() - ourCoach->memory()->at(3).t_sent()); ourCoach->fs.ball.speed_y = (ourCoach->memory()->at(4).balls(0).y() - ourCoach->memory()->at(3).balls(0).y()) / (ourCoach->memory()->at(4).t_sent() - ourCoach->memory()->at(3).t_sent()); for(int i = 0; i < ourCoach->memory()->at(4).robots_blue_size(); i++) { for(int j = 0; j < ourCoach->memory()->at(3).robots_blue_size(); j++) { if(ourCoach->memory()->at(4).robots_blue(i).robot_id() == ourCoach->memory()->at(3).robots_blue(j).robot_id()) { // v = d1 - d2 / t for(int k = 0; k < ourCoach->fs.bBots.size(); ++k) { if(ourCoach->memory()->at(4).robots_blue(i).robot_id() == ourCoach->fs.bBots[k].id) { ourCoach->fs.bBots[k].speed_x = (ourCoach->memory()->at(4).robots_blue(i).x() - ourCoach->memory()->at(3).robots_blue(j).x()) / (ourCoach->memory()->at(4).t_sent() - ourCoach->memory()->at(3).t_sent()); ourCoach->fs.bBots[k].speed_y = (ourCoach->memory()->at(4).robots_blue(i).y() - ourCoach->memory()->at(3).robots_blue(j).y()) / (ourCoach->memory()->at(4).t_sent() - ourCoach->memory()->at(3).t_sent()); } } } } } for(int i = 0; i < ourCoach->memory()->at(4).robots_yellow_size(); i++) { for(int j = 0; j < ourCoach->memory()->at(3).robots_yellow_size(); j++) { if(ourCoach->memory()->at(4).robots_yellow(i).robot_id() == ourCoach->memory()->at(3).robots_yellow(j).robot_id()) { // v = d1 - d2 / t for(int k = 0; k < ourCoach->fs.bBots.size(); ++k) { if(ourCoach->memory()->at(4).robots_yellow(i).robot_id() == ourCoach->fs.bBots[k].id) { ourCoach->fs.yBots[k].speed_x = (ourCoach->memory()->at(4).robots_yellow(i).x() - ourCoach->memory()->at(3).robots_yellow(j).x()) / (ourCoach->memory()->at(4).t_sent() - ourCoach->memory()->at(3).t_sent()); ourCoach->fs.yBots[k].speed_y = (ourCoach->memory()->at(4).robots_yellow(i).y() - ourCoach->memory()->at(3).robots_yellow(j).y()) / (ourCoach->memory()->at(4).t_sent() - ourCoach->memory()->at(3).t_sent()); } } } } } Strategy myStrat = Strategy(); myStrat.implement(ourCoach); }
void AIMain() { if (GetStatus() -> team_id) { /*Vector speed2={100,100,100}; Move(GetStatus()->objects[0].id,speed2);*/ return; } srand(time(0)); for(;;){ //if (abs(GetTime()-1000)<=5 || me.health>10000) //printf("time=%d\thealth=%d\tability=%d\n",GetTime(),me.health,me.ability); Init(); speed=MaximumSpeed(speed); Move(me.id,speed); Strategy(); } }
void SPTGSolver::solveSPTG(){ cout << "====SolveSPTG====" << endl; // This function is the core of the solver, it computes the strategies and values for the SPTG passed PGSolver* ps; bool notCycling = false; if(solvePTG){ cout << "ici" << endl; ps = new PGSolver(sptg, pathsLengths, vals, strategies, bottoms, resets);//PGSolver will consider sptg as a pg thanks to inheritance notCycling = ps->extendedDijkstra(true); cout << "ici" << endl; } else{ ps = new PGSolver(sptg, pathsLengths, vals, strategies, resets);//PGSolver will consider sptg as a pg thanks to inheritance notCycling = ps->extendedDijkstra(false); //If extendedDijkstra returns false, some states can't be treated and there is a cycle } //sptg->show(); /*for (unsigned int i = 0; i < size; ++i){ cout << (*bottoms)[i] << " "; } cout << endl; show();*/ while (notCycling && time > 0){ strategies->push_front(Strategy(size)); actualizeLambdas(); if(time.num == 1 && time.den == 1)//If it's the first turn, we have to "initialize" the value functions buildValueFcts(0); strategyIteration(); Fraction epsilon = nextEventPoint(); //cout << "NextEventPoint: " << epsilon << endl; if((time - epsilon) < 0) epsilon = time; buildValueFcts(epsilon); actualizeVals(epsilon); strategies->front().setTime(time); //show(); } /*if(notCycling){ cout << "====Result==== " << endl; show(); } else cout << "There is a cycle!" << endl;*/ sptg = NULL; }
void robotPlace(int *recEmptiesArray, int recCurPos) { int ChosenColIndex=0; //determines which columns are possible (not full) based on empites array int PossibleIndices[MAXCOL] = {0, 0, 0, 0, 0, 0, 0}; int count = 0; ChosenColIndex = Strategy(); if (ChosenColIndex == -1) { for (int col = 0; col < MAXCOL; col ++) { if (recEmptiesArray[col] >= 0) { PossibleIndices[count] = col; count += 1; } } count -= 1; /*corrects for count going one too far at this point, Possible indices contains the column indices of non-full columns and count contains how many not full columns there are */ ChosenColIndex = PossibleIndices[random[count]]; // random number between 0 and count displayString(4, "ChosenCol: %d", ChosenColIndex); } //now place piece in the selected column GameBoard[recEmptiesArray[ChosenColIndex]][ChosenColIndex] = 2; updateEmpties(recEmptiesArray); displayEmpties(recEmptiesArray); displayGameBoard(); moveHor(recCurPos, ChosenColIndex); //wait to give robot a change to stabilize wait1Msec(stabilize); dropPiece(); }
void MuScale() { //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== // event category enumeration enum { eMuMu2HLT=1, eMuMu1HLT1L1, eMuMu1HLT, eMuMuNoSel, eMuSta, eMuTrk }; // event category enum TString outputDir = "MuScaleResults"; vector<TString> infilenamev; infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zmumu/ntuples/data_select.trkCuts.root"); // data infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zmumu/ntuples/zmm_select.raw.trkCuts.root"); // MC const Double_t MASS_LOW = 60; const Double_t MASS_HIGH = 120; const Double_t PT_CUT = 25; const Double_t ETA_CUT = 2.4; const Double_t MU_MASS = 0.105658369; vector<pair<Double_t,Double_t> > scEta_limits; scEta_limits.push_back(make_pair(0.0,1.2)); scEta_limits.push_back(make_pair(1.2,2.1)); scEta_limits.push_back(make_pair(2.1,2.4)); CPlot::sOutDir = outputDir; const TString format("png"); //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== enum { eData=0, eMC }; char hname[100]; vector<TH1D*> hMCv, hDatav; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { sprintf(hname,"mc_%i_%i",ibin,jbin); hMCv.push_back(new TH1D(hname,"",80,MASS_LOW,MASS_HIGH)); hMCv.back()->Sumw2(); sprintf(hname,"data_%i_%i",ibin,jbin); hDatav.push_back(new TH1D(hname,"",80,MASS_LOW,MASS_HIGH)); hDatav.back()->Sumw2(); } } // // Declare output ntuple variables // UInt_t runNum, lumiSec, evtNum; Float_t scale1fb, puWeight; UInt_t matchGen; UInt_t category; UInt_t npv, npu; Int_t q1, q2; TLorentzVector *dilep=0, *lep1=0, *lep2=0; for(UInt_t ifile=0; ifile<infilenamev.size(); ifile++) { cout << "Processing " << infilenamev[ifile] << "..." << endl; TFile *infile = TFile::Open(infilenamev[ifile]); assert(infile); TTree *intree = (TTree*)infile->Get("Events"); assert(intree); intree->SetBranchAddress("runNum", &runNum); // event run number intree->SetBranchAddress("lumiSec", &lumiSec); // event lumi section intree->SetBranchAddress("evtNum", &evtNum); // event number intree->SetBranchAddress("scale1fb", &scale1fb); // event weight intree->SetBranchAddress("puWeight", &puWeight); // pileup reweighting intree->SetBranchAddress("matchGen", &matchGen); // event has both leptons matched to MC Z->ll intree->SetBranchAddress("category", &category); // dilepton category intree->SetBranchAddress("npv", &npv); // number of primary vertices intree->SetBranchAddress("npu", &npu); // number of in-time PU events (MC) intree->SetBranchAddress("q1", &q1); // charge of lead lepton intree->SetBranchAddress("q2", &q2); // charge of trail lepton intree->SetBranchAddress("dilep", &dilep); // dilepton 4-vector intree->SetBranchAddress("lep1", &lep1); // lead lepton 4-vector intree->SetBranchAddress("lep2", &lep2); // trail lepton 4-vector for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) { intree->GetEntry(ientry); Double_t weight = 1; if(ifile==eMC) { //if(!matchGen) continue; weight=scale1fb*puWeight*1.1*TMath::Power(10,7)/5610.0; } if((category!=eMuMu2HLT) && (category!=eMuMu1HLT) && (category!=eMuMu1HLT1L1)) continue; if(q1 == q2) continue; if(dilep->M() < MASS_LOW) continue; if(dilep->M() > MASS_HIGH) continue; if(lep1->Pt() < PT_CUT) continue; if(lep2->Pt() < PT_CUT) continue; if(fabs(lep1->Eta()) > ETA_CUT) continue; if(fabs(lep2->Eta()) > ETA_CUT) continue; TLorentzVector vLep1(0,0,0,0); TLorentzVector vLep2(0,0,0,0); vLep1.SetPtEtaPhiM(lep1->Pt(), lep1->Eta(), lep1->Phi(), MU_MASS); vLep2.SetPtEtaPhiM(lep2->Pt(), lep2->Eta(), lep2->Phi(), MU_MASS); TLorentzVector vDilep = vLep1 + vLep2; Int_t bin1=-1, bin2=-1; for(UInt_t i=0; i<scEta_limits.size(); i++) { Double_t etalow = scEta_limits.at(i).first; Double_t etahigh = scEta_limits.at(i).second; if(fabs(lep1->Eta())>=etalow && fabs(lep1->Eta())<=etahigh) bin1=i; if(fabs(lep2->Eta())>=etalow && fabs(lep2->Eta())<=etahigh) bin2=i; } assert(bin1>=0); assert(bin2>=0); Int_t ibin= (bin1<=bin2) ? bin1 : bin2; Int_t jbin= (bin1<=bin2) ? bin2 : bin1; UInt_t n=jbin-ibin; for(Int_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); if(ifile==eData) hDatav[n]->Fill(vDilep.M(),weight); if(ifile==eMC) hMCv[n]->Fill(vDilep.M(),weight); } delete infile; infile=0, intree=0; } // // Fit for energy scale and resolution corrections // char vname[100]; // buffer for RooFit object names char pname[100]; char str1[100]; char str2[100]; TCanvas *c = MakeCanvas("c","c",800,600); // Dummy histograms for TLegend (I can't figure out how to properly pass RooFit objects...) TH1D *hDummyData = new TH1D("hDummyData","",0,0,10); hDummyData->SetMarkerStyle(kFullCircle); hDummyData->SetMarkerSize(0.9); TH1D *hDummyMC = new TH1D("hDummyMC","",0,0,10); hDummyMC->SetLineColor(kBlue); hDummyMC->SetFillColor(kBlue); hDummyMC->SetFillStyle(3002); TH1D *hDummyFit = new TH1D("hDummyFit","",0,0,10); hDummyFit->SetLineColor(kGreen+2); RooRealVar mass("mass","M_{#mu#mu}",60.0,120.0,"GeV") ; mass.setBins(1600,"cache"); RooRealVar massmc("massmc","massmc",0.0,150.0,"GeV"); // mass variable for building MC template RooCategory zscEta_cat("zscEta_cat","zscEta_cat"); RooSimultaneous combscalefit("combscalefit","combscalefit",zscEta_cat); map<string,TH1*> hmap; // Mapping of category labels and data histograms RooArgList scalebins; // List of RooRealVars storing per bin energy scale corrections RooArgList sigmabins; // List of RooRealVars storing per bin energy resolution corrections Int_t intOrder = 1; // Interpolation order for for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { sprintf(vname,"scale_%i",ibin); RooRealVar *scalebinned = new RooRealVar(vname,vname,1.0,0.5,1.5); scalebins.add(*scalebinned); sprintf(vname,"sigma_%i",ibin); RooRealVar *sigmabinned = new RooRealVar(vname,vname,1.0,0.0,2.0); sigmabins.add(*sigmabinned); } for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { UInt_t n=jbin-ibin; for(UInt_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); sprintf(vname,"masslinearshifted_%i_%i",ibin,jbin); RooFormulaVar *masslinearshifted = new RooFormulaVar(vname,vname,"sqrt(@0*@1)",RooArgList(*scalebins.at(ibin),*scalebins.at(jbin))); sprintf(vname,"massshiftedscEta_%i_%i",ibin,jbin); RooLinearVar *massshiftedscEta = new RooLinearVar(vname,vname,mass,*masslinearshifted,RooConst(0.0)); // MC-based template sprintf(vname,"zmassmcscEta_%i_%i",ibin,jbin); RooDataHist *zmassmcscEta = new RooDataHist(vname,vname,RooArgList(massmc),hMCv[n]); sprintf(vname,"masstemplatescEta_%i_%i",ibin,jbin); RooHistPdf *masstemplatescEta = new RooHistPdf(vname,vname,RooArgList(*massshiftedscEta),RooArgList(massmc),*zmassmcscEta,intOrder); // Gaussian smearing function sprintf(vname,"sigmascEta_%i_%i",ibin,jbin); RooFormulaVar *sigmascEta = new RooFormulaVar(vname,vname,"sqrt(@0*@0+@1*@1)",RooArgList(*sigmabins.at(ibin),*sigmabins.at(jbin))); sprintf(vname,"resscEta_%i_%i",ibin,jbin); RooGaussian *resscEta = new RooGaussian(vname,vname,mass,RooConst(0.),*sigmascEta); // Fit model: MC-template convoluted with Gaussian sprintf(vname,"fftscEta_%i_%i",ibin,jbin); RooFFTConvPdf *fftscEta = new RooFFTConvPdf(vname,vname,mass,*masstemplatescEta,*resscEta); fftscEta->setBufferStrategy(RooFFTConvPdf::Flat); // Add bin as a category char zscEta_catname[100]; sprintf(zscEta_catname,"zscEta_cat_%i_%i",ibin,jbin); zscEta_cat.defineType(zscEta_catname); zscEta_cat.setLabel(zscEta_catname); hmap.insert(pair<string,TH1*>(zscEta_catname,hDatav[n])); combscalefit.addPdf(*fftscEta,zscEta_catname); } } // perform fit RooDataHist zdatascEta_comb("zdatascEta_comb","zdatascEta_comb",RooArgList(mass),zscEta_cat,hmap,1.0); combscalefit.fitTo(zdatascEta_comb,PrintEvalErrors(kFALSE),Minos(kFALSE),Strategy(0),Minimizer("Minuit2","")); Double_t xval[scEta_limits.size()]; Double_t xerr[scEta_limits.size()]; Double_t scaleDatatoMC[scEta_limits.size()]; Double_t scaleDatatoMCerr[scEta_limits.size()]; Double_t scaleMCtoData[scEta_limits.size()]; Double_t scaleMCtoDataerr[scEta_limits.size()]; Double_t sigmaMCtoData[scEta_limits.size()]; Double_t sigmaMCtoDataerr[scEta_limits.size()]; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; xval[ibin] = 0.5*(etahigh+etalow); xerr[ibin] = 0.5*(etahigh-etalow); scaleDatatoMC[ibin] = ((RooRealVar*)scalebins.at(ibin))->getVal(); scaleDatatoMCerr[ibin] = ((RooRealVar*)scalebins.at(ibin))->getError(); scaleMCtoData[ibin] = 1.0/scaleDatatoMC[ibin]; scaleMCtoDataerr[ibin] = scaleDatatoMCerr[ibin]/scaleDatatoMC[ibin]/scaleDatatoMC[ibin]; sigmaMCtoData[ibin] = ((RooRealVar*)sigmabins.at(ibin))->getVal(); sigmaMCtoDataerr[ibin] = ((RooRealVar*)sigmabins.at(ibin))->getError(); } TGraphErrors *grScaleDatatoMC = new TGraphErrors(scEta_limits.size(),xval,scaleDatatoMC,xerr,scaleDatatoMCerr); TGraphErrors *grScaleMCtoData = new TGraphErrors(scEta_limits.size(),xval,scaleMCtoData,xerr,scaleMCtoDataerr); TGraphErrors *grSigmaMCtoData = new TGraphErrors(scEta_limits.size(),xval,sigmaMCtoData,xerr,sigmaMCtoDataerr); CPlot plotScale1("mu_scale_datatomc","","Muon |#eta|","Data scale correction"); plotScale1.AddGraph(grScaleDatatoMC,"",kBlue); plotScale1.SetYRange(0.98,1.02); plotScale1.AddLine(0,1,2.5,1,kBlack,7); plotScale1.Draw(c,kTRUE,format); CPlot plotScale2("mu_scale_mctodata","","Muon |#eta|","MC#rightarrowData scale correction"); plotScale2.AddGraph(grScaleMCtoData,"",kBlue); plotScale2.SetYRange(0.98,1.02); plotScale2.AddLine(0,1,2.5,1,kBlack,7); plotScale2.Draw(c,kTRUE,format); CPlot plotRes("mu_res_mctodata","","Muon |#eta|","MC#rightarrowData additional smear [GeV]"); plotRes.AddGraph(grSigmaMCtoData,"",kBlue); plotRes.SetYRange(0,1.6); plotRes.Draw(c,kTRUE,format); double nData=0; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { UInt_t n=jbin-ibin; for(UInt_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); // Post-fit plot RooPlot *frame = mass.frame(); char catname[100]; sprintf(catname,"zscEta_cat_%i_%i",ibin,jbin); char cutstr[100]; sprintf(cutstr,"zscEta_cat==zscEta_cat::%s",catname); RooDataHist zmc(catname,catname,RooArgList(mass),hMCv[n]); RooHistPdf mctemplate(catname,catname,RooArgList(mass),zmc,intOrder); //mctemplate.plotOn(frame,LineColor(kBlue),LineWidth(1),Normalization(hDatav[n]->GetEntries())); mctemplate.plotOn(frame,LineColor(kBlue),LineWidth(1),Normalization(hDatav[n]->Integral())); //mctemplate.plotOn(frame,LineColor(kBlue),FillColor(kBlue),FillStyle(3002),DrawOption("F"),Normalization(hDatav[n]->GetEntries())); mctemplate.plotOn(frame,LineColor(kBlue),FillColor(kBlue),FillStyle(3002),DrawOption("F"),Normalization(hDatav[n]->Integral())); zdatascEta_comb.plotOn(frame,Cut(cutstr),MarkerStyle(kFullCircle),MarkerSize(1.0),DrawOption("ZP")); combscalefit.plotOn(frame,Slice(zscEta_cat,catname),ProjWData(RooArgSet(mass,catname),zdatascEta_comb), LineColor(kGreen+2)); sprintf(pname,"postfit_%i_%i",ibin,jbin); sprintf(str1,"[%.1f, %.1f]",scEta_limits.at(ibin).first,scEta_limits.at(ibin).second); sprintf(str2,"[%.1f, %.1f]",scEta_limits.at(jbin).first,scEta_limits.at(jbin).second); CPlot plot(pname,frame,"","m(#mu^{+}#mu^{-}) [GeV/c^{2}]","Events / 0.6 GeV/c^{2}"); plot.AddTextBox(str1,0.21,0.80,0.45,0.87,0,kBlack,-1); plot.AddTextBox(str2,0.21,0.73,0.45,0.80,0,kBlack,-1); plot.SetLegend(0.75,0.64,0.93,0.88); plot.GetLegend()->AddEntry(hDummyData,"Data","PL"); plot.GetLegend()->AddEntry(hDummyMC,"Sim","FL"); plot.GetLegend()->AddEntry(hDummyFit,"Fit","L"); plot.Draw(c,kTRUE,format); nData += hDatav[n]->Integral(); } } cout<<"nData = "<<nData<<endl; //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << endl; ofstream txtfile; char txtfname[100]; sprintf(txtfname,"%s/summary.txt",outputDir.Data()); txtfile.open(txtfname); assert(txtfile.is_open()); txtfile << " Data->MC scale correction" << endl; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; txtfile << "$" << etalow << " < |\\eta| < " << etahigh << "$ & "; txtfile << "$" << ((RooRealVar*)scalebins.at(ibin))->getVal() << "$ \\pm $" << ((RooRealVar*)scalebins.at(ibin))->getError() << "$ \\\\" << endl; } txtfile << endl; txtfile << " MC->Data resolution correction [GeV]" << endl; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; txtfile << etalow << " < |\\eta| < " << etahigh << " & "; txtfile << "$" << ((RooRealVar*)sigmabins.at(ibin))->getVal() << "$ \\pm $" << ((RooRealVar*)sigmabins.at(ibin))->getError() << "$ \\\\" << endl; } txtfile.close(); cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; }
void WSLB::ReceiveStats(WSLBStatsMsg *m) { #if CMK_LBDB_ON if (neighbor_pes == 0) FindNeighbors(); if (m == 0) { // This is from our own node receive_stats_ready = 1; } else { const int pe = m->from_pe; // CkPrintf("Stats msg received, %d %d %d %d %p\n", // pe,stats_msg_count,m->n_objs,m->serial,m); int peslot = -1; for(int i=0; i < mig_msgs_expected; i++) { if (pe == neighbor_pes[i]) { peslot = i; break; } } if (peslot == -1 || statsMsgsList[peslot] != 0) { CkPrintf("*** Unexpected WSLBStatsMsg in ReceiveStats from PE %d ***\n", pe); } else { statsMsgsList[peslot] = m; statsDataList[peslot].from_pe = m->from_pe; statsDataList[peslot].total_walltime = m->total_walltime; statsDataList[peslot].total_cputime = m->total_cputime; statsDataList[peslot].idletime = m->idletime; statsDataList[peslot].bg_walltime = m->bg_walltime; statsDataList[peslot].bg_cputime = m->bg_cputime; statsDataList[peslot].proc_speed = m->proc_speed; statsDataList[peslot].obj_walltime = m->obj_walltime; statsDataList[peslot].obj_cputime = m->obj_cputime; statsDataList[peslot].vacate_me = m->vacate_me; statsDataList[peslot].usage = m->usage; stats_msg_count++; } } const int clients = mig_msgs_expected; if (stats_msg_count == clients && receive_stats_ready) { double strat_start_time = CkWallTimer(); receive_stats_ready = 0; LBMigrateMsg* migrateMsg = Strategy(statsDataList,clients); int i; // Migrate messages from me to elsewhere for(i=0; i < migrateMsg->n_moves; i++) { MigrateInfo& move = migrateMsg->moves[i]; const int me = CkMyPe(); if (move.from_pe == me && move.to_pe != me) { theLbdb->Migrate(move.obj,move.to_pe); } else if (move.from_pe != me) { CkPrintf("[%d] error, strategy wants to move from %d to %d\n", me,move.from_pe,move.to_pe); } } // Now, send migrate messages to neighbors thisProxy.ReceiveMigration(migrateMsg,mig_msgs_expected,neighbor_pes); // Zero out data structures for next cycle for(i=0; i < clients; i++) { delete statsMsgsList[i]; statsMsgsList[i]=0; } stats_msg_count=0; theLbdb->ClearLoads(); if (CkMyPe() == 0) { double strat_end_time = CkWallTimer(); CkPrintf("Strat elapsed time %f\n",strat_end_time-strat_start_time); } } #endif }
inline cross_track() { m_strategy = Strategy(); m_radius = m_strategy.radius(); }
// LDStats data sent to parent contains real PE // LDStats in parent should contain relative PE void HybridBaseLB::Loadbalancing(int atlevel) { int i; CmiAssert(atlevel >= 1); CmiAssert(tree->isroot(CkMyPe(), atlevel)); LevelData *lData = levelData[atlevel]; LDStats *statsData = lData->statsData; CmiAssert(statsData); // at this time, all objects processor location is relative, and // all incoming objects from outside group belongs to the fake root proc. // clear background load if needed if (_lb_args.ignoreBgLoad()) statsData->clearBgLoad(); currentLevel = atlevel; int nclients = lData->nChildren; DEBUGF(("[%d] Calling Strategy ... \n", CkMyPe())); double start_lb_time, strat_end_time; start_lb_time = CkWallTimer(); if ((statsStrategy == SHRINK || statsStrategy == SHRINK_NULL) && atlevel == tree->numLevels()-1) { // no obj and comm data LBVectorMigrateMsg* migrateMsg = VectorStrategy(statsData); strat_end_time = CkWallTimer(); // send to children thisProxy.ReceiveVectorMigration(migrateMsg, nclients, lData->children); } else { LBMigrateMsg* migrateMsg = Strategy(statsData); strat_end_time = CkWallTimer(); // send to children //CmiPrintf("[%d] level: %d nclients:%d children: %d %d\n", CkMyPe(), atlevel, nclients, lData->children[0], lData->children[1]); if (!group1_created) thisProxy.ReceiveMigration(migrateMsg, nclients, lData->children); else { // send in multicast tree thisProxy.ReceiveMigration(migrateMsg, group1); //CkSendMsgBranchGroup(CkIndex_HybridBaseLB::ReceiveMigration(NULL), migrateMsg, thisgroup, group1); } // CkPrintf("[%d] ReceiveMigration takes %f \n", CkMyPe(), CkWallTimer()-strat_end_time); } if (_lb_args.debug()>0){ CkPrintf("[%d] Loadbalancing Level %d (%d children) started at %f, elapsed time %f\n", CkMyPe(), atlevel, lData->nChildren, start_lb_time, strat_end_time-start_lb_time); if (atlevel == tree->numLevels()-1) { CkPrintf("[%d] %s memUsage: %.2fKB\n", CkMyPe(), lbName(), (1.0*useMem())/1024); } } // inform new objects that are from outside group if (atlevel < tree->numLevels()-1) { for (i=0; i<statsData->n_objs; i++) { CmiAssert(statsData->from_proc[i] != -1); // ??? if (statsData->from_proc[i] == nclients) { // from outside CmiAssert(statsData->to_proc[i] < nclients); int tope = lData->children[statsData->to_proc[i]]; // comm data CkVec<LDCommData> comms; // collectCommData(i, comms, atlevel); thisProxy[tope].ObjMigrated(statsData->objData[i], comms.getVec(), comms.size(), atlevel-1); } } } }
bool c4_Column::IsMapped()const { return _position > 1 && _persist != 0 && Strategy()._mapStart != 0; }
void CentralLB::simulationRead() { LBSimulation *simResults = NULL, *realResults; LBMigrateMsg *voidMessage = new (0,0,0,0) LBMigrateMsg(); voidMessage->n_moves=0; for ( ;LBSimulation::simStepSize > 0; --LBSimulation::simStepSize, ++LBSimulation::simStep) { // here we are supposed to read the data from the dump database int simFileSize = strlen(LBSimulation::dumpFile) + 4; char *simFileName = (char *)malloc(simFileSize); while (sprintf(simFileName, "%s.%d", LBSimulation::dumpFile, LBSimulation::simStep) >= simFileSize) { free(simFileName); simFileSize+=3; simFileName = (char *)malloc(simFileSize); } readStatsMsgs(simFileName); // allocate simResults (only the first step) if (simResults == NULL) { simResults = new LBSimulation(LBSimulation::simProcs); realResults = new LBSimulation(LBSimulation::simProcs); } else { // should be the same number of procs of the original simulation! if (!LBSimulation::procsChanged) { // it means we have a previous step, so in simResults there is data. // we can now print the real effects of the load balancer during the simulation // or print the difference between the predicted data and the real one. realResults->reset(); // reset to_proc of statsData to be equal to from_proc for (int k=0; k < statsData->n_objs; ++k) statsData->to_proc[k] = statsData->from_proc[k]; findSimResults(statsData, LBSimulation::simProcs, voidMessage, realResults); simResults->PrintDifferences(realResults,statsData); } simResults->reset(); } // now pass it to the strategy routine double startT = CkWallTimer(); preprocess(statsData); CmiPrintf("%s> Strategy starts ... \n", lbname); LBMigrateMsg* migrateMsg = Strategy(statsData); CmiPrintf("%s> Strategy took %fs memory usage: CentralLB: %d KB.\n", lbname, CkWallTimer()-startT, (int)(useMem()/1000)); // now calculate the results of the load balancing simulation findSimResults(statsData, LBSimulation::simProcs, migrateMsg, simResults); // now we have the simulation data, so print it and loop CmiPrintf("Charm++> LBSim: Simulation of load balancing step %d done.\n",LBSimulation::simStep); // **CWL** Officially recording my disdain here for using ints for bool if (LBSimulation::showDecisionsOnly) { simResults->PrintDecisions(migrateMsg, simFileName, LBSimulation::simProcs); } else { simResults->PrintSimulationResults(); } free(simFileName); delete migrateMsg; CmiPrintf("Charm++> LBSim: Passing to the next step\n"); } // deallocate simResults delete simResults; CmiPrintf("Charm++> Exiting...\n"); CkExit(); }
int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); int POPSIZE = atoi(argv[1]); int GENERATION = atoi(argv[2]); int NUM_GAMES = atoi(argv[3]); float CROSSOVER = atof(argv[4]); float MUTATION = atof(argv[5]); int i,j,k,q,s,b2d,count; int world_rank,world_size; unsigned int temp[2], temp2[2]; float RANDOM2 = drand48(); srand48(time(NULL)); pop *player = NULL; pop p[2]; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); MPI_Comm_size(MPI_COMM_WORLD, &world_size); /*------------------------MPI_STRUCT----------------------------------*/ MPI_Datatype mpi_pop; MPI_Datatype types[3] = {MPI_UNSIGNED,MPI_UNSIGNED,MPI_UNSIGNED}; int block[3] = {4,1,1}; MPI_Aint offset[3] = {offsetof(pop,history),offsetof(pop,fitness),offsetof(pop,move)}; MPI_Type_create_struct(3,block,offset,types,&mpi_pop); MPI_Type_commit(&mpi_pop); if (world_rank == 0) { if (world_size > POPSIZE/4) { printf("Too many processes for Population Size.\n Please input an even Population Size.\n"); MPI_Abort(MPI_COMM_WORLD, 1); } } /*---------------Allocate the memory for the players------------------*/ if (world_rank == 0) { player = malloc(POPSIZE*sizeof(pop)); for (i=0; i<POPSIZE; i++) { for(j=0; j<4; j++) { player[i].history[j] = lrand48() % 2; player[i].fitness = 0; } } printf("Processor %d has data:\n", world_rank); for (i=0; i<POPSIZE; i++) { for (j=0; j<4; j++) { printf("%d ", player[i].history[j]); } printf("\n"); } } int ARRAY_SIZE = POPSIZE/4; pop *sub_arrays = NULL; if (world_rank != 0) { sub_arrays = malloc(ARRAY_SIZE*sizeof(pop)); } /*-----------------------RUN THE ALGORITHM---------------------------*/ for (k=0; k<GENERATION; k++) { MPI_Scatter(player, ARRAY_SIZE, mpi_pop, sub_arrays, ARRAY_SIZE, mpi_pop, 0, MPI_COMM_WORLD); if (world_rank != 0) { for (i=0; i<ARRAY_SIZE; i++) { for (j=ARRAY_SIZE; j>=0; j--) { p[0] = player[i]; p[1] = player[j]; for(q=0; q<NUM_GAMES; q++) { b2d = ((p[0].history[0]*8) + (p[0].history[1]*4) + (p[0].history[2]*2) + p[0].history[3]); b2d = ((p[1].history[0]*8) + (p[1].history[1]*4) + (p[1].history[2]*2) + p[1].history[3]); Strategy(p[0], b2d); Strategy(p[1], b2d); Fitness(p); for (s=4; s>0; s--) { p[0].history[s] = p[0].history[s-1]; p[1].history[s] = p[1].history[s-1]; } p[0].history[0] = p[0].move; p[1].history[0] = p[1].move; } player[i] = p[0]; player[j] = p[1]; } } } MPI_Barrier(MPI_COMM_WORLD); MPI_Gather(sub_arrays, ARRAY_SIZE, mpi_pop, player, ARRAY_SIZE, mpi_pop, 0, MPI_COMM_WORLD); /*-----------------------Perform Selection-----------------------------*/ if (world_rank == 0) { for(count=0; count<2; count++) { int sumFitness = 0; for (i=0; i<POPSIZE; i++) { sumFitness += p[i].fitness; int RANDOM = lrand48() % sumFitness; if (sumFitness >= RANDOM) { p[count] = player[i]; } } } /*------------------------Crossover-------------------------------------*/ if (RANDOM2 < CROSSOVER) { temp [0] = p[0].history[2]; temp [1] = p[0].history[3]; temp2[0] = p[1].history[2]; temp2[1] = p[1].history[3]; p[0].history[2] = temp2[0]; p[0].history[3] = temp2[1]; p[1].history[2] = temp[ 0]; p[1].history[3] = temp[ 1]; } /*---------------------Mutate Players------------------------------------*/ if (RANDOM2 < MUTATION) { int mp = lrand48() % 4; for (count=0; count<2; count++) { if (p[count].history[mp] == 0) { p[count].history[mp] = 1; } else { p[count].history[mp] = 0; } } } player[lrand48() % POPSIZE] = p[0]; player[lrand48() % POPSIZE] = p[1]; } printf("Processor %d has data:\n", world_rank); for (i=0; i<POPSIZE; i++) { for (j=0; j<4; j++) { printf("%d ", player[i].history[j]); } printf("\n"); } } for(i=0; i<POPSIZE; i++) { for (j=0; j<4; j++) { printf("%d", player[i].history[j]); } printf("\n"); printf("Fitness: %d\n", player[i].fitness); } if (world_rank == 0) free(player); if (world_rank != 0) free(sub_arrays); MPI_Finalize(); return 0; }
/// Flush pending changes to file right now bool c4_Storage::Commit(bool full_) { return Strategy().IsValid() && Persist()->Commit(full_); }
void CentralLB::LoadBalance() { #if CMK_LBDB_ON int proc; const int clients = CkNumPes(); #if ! USE_REDUCTION // build data buildStats(); #else for (proc = 0; proc < clients; proc++) statsMsgsList[proc] = NULL; #endif theLbdb->ResetAdaptive(); if (!_lb_args.samePeSpeed()) statsData->normalize_speed(); if (_lb_args.debug()) CmiPrintf("\nCharmLB> %s: PE [%d] step %d starting at %f Memory: %f MB\n", lbname, cur_ld_balancer, step(), start_lb_time, CmiMemoryUsage()/(1024.0*1024.0)); // if we are in simulation mode read data if (LBSimulation::doSimulation) simulationRead(); char *availVector = LBDatabaseObj()->availVector(); for(proc = 0; proc < clients; proc++) statsData->procs[proc].available = (CmiBool)availVector[proc]; preprocess(statsData); // CkPrintf("Before Calling Strategy\n"); if (_lb_args.printSummary()) { LBInfo info(clients); // not take comm data info.getInfo(statsData, clients, 0); LBRealType mLoad, mCpuLoad, totalLoad; info.getSummary(mLoad, mCpuLoad, totalLoad); int nmsgs, nbytes; statsData->computeNonlocalComm(nmsgs, nbytes); CkPrintf("[%d] Load Summary (before LB): max (with bg load): %f max (obj only): %f average: %f at step %d nonlocal: %d msgs %.2fKB.\n", CkMyPe(), mLoad, mCpuLoad, totalLoad/clients, step(), nmsgs, 1.0*nbytes/1024); // if (_lb_args.debug() > 1) { // for (int i=0; i<statsData->n_objs; i++) // CmiPrintf("[%d] %.10f %.10f\n", i, statsData->objData[i].minWall, statsData->objData[i].maxWall); // } } #if CMK_REPLAYSYSTEM LDHandle *loadBalancer_pointers; if (_replaySystem) { loadBalancer_pointers = (LDHandle*)malloc(CkNumPes()*sizeof(LDHandle)); for (int i=0; i<statsData->n_objs; ++i) loadBalancer_pointers[statsData->from_proc[i]] = statsData->objData[i].handle.omhandle.ldb; } #endif LBMigrateMsg* migrateMsg = Strategy(statsData); #if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_)) migrateMsg->step = step(); #endif #if CMK_REPLAYSYSTEM CpdHandleLBMessage(&migrateMsg); if (_replaySystem) { for (int i=0; i<migrateMsg->n_moves; ++i) migrateMsg->moves[i].obj.omhandle.ldb = loadBalancer_pointers[migrateMsg->moves[i].from_pe]; free(loadBalancer_pointers); } #endif LBDatabaseObj()->get_avail_vector(migrateMsg->avail_vector); migrateMsg->next_lb = LBDatabaseObj()->new_lbbalancer(); // if this is the step at which we need to dump the database simulationWrite(); // calculate predicted load // very time consuming though, so only happen when debugging is on if (_lb_args.printSummary()) { LBInfo info(clients); // not take comm data getPredictedLoadWithMsg(statsData, clients, migrateMsg, info, 0); LBRealType mLoad, mCpuLoad, totalLoad; info.getSummary(mLoad, mCpuLoad, totalLoad); int nmsgs, nbytes; statsData->computeNonlocalComm(nmsgs, nbytes); CkPrintf("[%d] Load Summary (after LB): max (with bg load): %f max (obj only): %f average: %f at step %d nonlocal: %d msgs %.2fKB useMem: %.2fKB.\n", CkMyPe(), mLoad, mCpuLoad, totalLoad/clients, step(), nmsgs, 1.0*nbytes/1024, (1.0*useMem())/1024); for (int i=0; i<clients; i++) migrateMsg->expectedLoad[i] = info.peLoads[i]; } DEBUGF(("[%d]calling recv migration\n",CkMyPe())); #if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_)) lbDecisionCount++; migrateMsg->lbDecisionCount = lbDecisionCount; #endif envelope *env = UsrToEnv(migrateMsg); if (1) { // broadcast thisProxy.ReceiveMigration(migrateMsg); } else { // split the migration for each processor for (int p=0; p<CkNumPes(); p++) { LBMigrateMsg *m = extractMigrateMsg(migrateMsg, p); thisProxy[p].ReceiveMigration(m); } delete migrateMsg; } // Zero out data structures for next cycle // CkPrintf("zeroing out data\n"); statsData->clear(); stats_msg_count=0; #endif }