bool Timer::timeReached(double seconds) { if (m_running && timePassed() > seconds) { return true; } return false; }
int main(int argc,char **argv) { double acceptRate, RunCount, acceptCount; int ResampleCount, MeasureCount; int ranIniValue = 1; iniMPI(argc, argv); loadParameters(0,false); startTimer(); if (LogLevel>1) printf("Timer started. Passed time: %f\n",timePassed()); if (LogLevel>1) printf("Number of arguments = %d\n",argc); int I; for (I=0; I<argc; I++) { if (LogLevel>1) printf("Argument %d: %s\n",I+1,argv[I]); } int JobNr = -1; if (argc>=2) { if (sscanf(argv[1],"%d",&JobNr)!=1) JobNr = -1; } int MultiProcessNr = -1; if (argc>=3) { if (sscanf(argv[2],"%d",&MultiProcessNr)!=1) MultiProcessNr= -1; } if (JobNr>0) { ranIniValue = JobNr * (ownNodeID+1); if (LogLevel>1) printf("Use Job-Nr*(ownID+1) = %d*(%d+1) = %d for rand seed generation.\n",JobNr,ownNodeID, ranIniValue); } else { ranIniValue = 5517*(ownNodeID+1); if (LogLevel>1) printf("Start rand seed from system time only.\n"); JobNr = 1; } if (MultiProcessNr>0) { if (LogLevel>1) printf("Use multi-start number: %d for simulation parameter determination.\n",MultiProcessNr); } else { if (LogLevel>1) printf("Single Job-start.\n"); MultiProcessNr = 0; } if (LogLevel>0) printf("\n"); iniTools(ranIniValue); loadParameters(MultiProcessNr,true); buildOutputFileNameExtension(JobNr); fermiOps = new FermionMatrixOperations(Parameter_L0,Parameter_L1,Parameter_L2,Parameter_L3, Parameter_RHO, Parameter_R, Parameter_Y); HMCProp = new HMCPropagator(fermiOps, Parameter_Lambda, Parameter_Kappa, Parameter_Nf, 1.0); if (Parameter_FLAG_xFFT==1) { fermiOps->setxFFTusage(true); } else { fermiOps->setxFFTusage(false); } if (ownNodeID>0) { HMCProp->SlaveController(); if (LogLevel>1) printf("Hybrid Monte Carlo Slave finished!!! ==> EXITING !!!\n"); exit(0); } readCurrentStateDescriptor(); fermiOps->testFourierTrafo(true); if ((Parameter_AutomaticPreconditioningMetros>0) && (AutomaticPreconRunCount<Parameter_AutomaticPreconditioningMetros)) { double swapFrac = 0.25; if (LogLevel>1) printf("Performing %d Automatic Preconditioning Metroplis steps...\n",Parameter_AutomaticPreconditioningMetros-AutomaticPreconRunCount); if (AutomaticPreconRunCount==0) { fermiOps->setPreconditioner(true, 1, 0); } for (ResampleCount=0; true; ResampleCount++) { RunCount = 0; acceptCount = 0; for (MeasureCount=0; MeasureCount<Parameter_Measurements; MeasureCount++) { HMCProp->samplePhiMomentumField(); HMCProp->sampleOmegaFields(); if (propagateFields(Parameter_Iterations, Parameter_Epsilon, Parameter_PropTOL, Parameter_FinalTOL)) { if (AutomaticPreconRunCount<swapFrac*Parameter_AutomaticPreconditioningMetros) { HMCProp->improvePreconditioningParameters(10, 5, Parameter_PropTOL); } acceptCount++; AutomaticPreconRunCount++; writeCurrentStateDescriptor(1); } RunCount++; } if (AutomaticPreconRunCount>=swapFrac*Parameter_AutomaticPreconditioningMetros) { HMCProp->improvePreconditioningParameters(10*Parameter_Measurements, 10*Parameter_Measurements, Parameter_PropTOL); } acceptRate = acceptCount / RunCount; if (LogLevel>2) printf("Average (preconditioning) update quote: %1.2f\n",acceptRate); automaticAdaption(acceptRate); if (AutomaticPreconRunCount>Parameter_AutomaticPreconditioningMetros) break; if (timeOver()) { writeCurrentStateDescriptor(0); if (LogLevel>1) printf("Time limit reached. ==> EXITING!\n"); desini(); exit(0); } } double PrecM, PrecS; bool PrecUse; fermiOps->getPreconditionerParameter(PrecUse, PrecM, PrecS); if (LogLevel>1) printf("...Preconditioning ready. Best Preconditioning Parameters PrecM = %1.3f, PrecS = %1.3f\n", PrecM, PrecS); } if (ThermalizingRunCount<Parameter_ThermalizingMetros) { if (LogLevel>1) printf("Performing %d thermalizing Metroplis steps...\n",Parameter_ThermalizingMetros-ThermalizingRunCount); fermiOps->printPreconditionerParameter(); for (ResampleCount=0; true; ResampleCount++) { RunCount = 0; acceptCount = 0; for (MeasureCount=0; MeasureCount<Parameter_Measurements; MeasureCount++) { HMCProp->samplePhiMomentumField(); HMCProp->sampleOmegaFields(); if (propagateFields(Parameter_Iterations, Parameter_Epsilon, Parameter_PropTOL, Parameter_FinalTOL)) { acceptCount++; ThermalizingRunCount++; writeCurrentStateDescriptor(1); } RunCount++; } acceptRate = acceptCount / RunCount; if (LogLevel>2) printf("Average (thermalizing) update quote: %1.2f\n",acceptRate); automaticAdaption(acceptRate); if (ThermalizingRunCount>Parameter_ThermalizingMetros) break; if (timeOver()) { writeCurrentStateDescriptor(0); if (LogLevel>1) printf("Time limit reached. ==> EXITING!\n"); desini(); exit(0); } } if (LogLevel>1) printf("...Thermalizing ready.\n"); } if (TotallyMeasuredConfigurationsCount<Parameter_TotalData) { if (LogLevel>1) printf("Performing %d Measurements...\n",Parameter_TotalData-TotallyMeasuredConfigurationsCount); fermiOps->printPreconditionerParameter(); for (ResampleCount=0; true; ResampleCount++) { RunCount = 0; acceptCount = 0; for (MeasureCount=0; MeasureCount<Parameter_Measurements; MeasureCount++) { HMCProp->samplePhiMomentumField(); HMCProp->sampleOmegaFields(); if (propagateFields(Parameter_Iterations, Parameter_Epsilon, Parameter_PropTOL, Parameter_FinalTOL)) { if (Parameter_FLAG_WriteConditionNumber==1) { writeConditionNumber(); } measureAndWrite(); acceptCount++; TotallyMeasuredConfigurationsCount++; writeCurrentStateDescriptor(1); } else { if (LogLevel>1) printf("No measurement.\n"); } RunCount++; } acceptRate = acceptCount / RunCount; if (LogLevel>1) printf("-->Update quote: %1.2f\n\n",acceptRate); automaticAdaption(acceptRate); if (TotallyMeasuredConfigurationsCount>=Parameter_TotalData) break; if (timeOver()) { writeCurrentStateDescriptor(0); if (LogLevel>1) printf("Time limit reached. ==> EXITING!\n"); desini(); exit(0); } } } writeCurrentStateDescriptor(0); if (LogLevel>1) printf("Hybrid Monte Carlo ready. Collected %d data samples!!!\n", TotallyMeasuredConfigurationsCount); desini(); }
bool timeOver() { if (timePassed()>Parameter_MaxRunTime*3600) return true; return false; }
double ProgressBar::timeRemaining() { if (currentPercent == 0) return 0.0; return timePassed() * (1 / currentPercent * 100 - 1); }
void ProjectManager::onTimePassed(const QTime& time) { emit timePassed(time); }
void wyScroller::extendDuration(int extend) { int passed = timePassed(); m_duration = passed + extend; m_durationReciprocal = 1.0f / (float)m_duration; m_finished = false; }
double Timer::timeUntil(double seconds) { return seconds - timePassed(); }
int main(int argc,char **argv) { LogLevel = 3; iniMPI(argc, argv); fftw_init_threads(); fftw_plan_with_nthreads(1); loadCommandLineParameters(argc,argv); loadDataFromAnalyzerToDoList(); iniTools(537*Parameter_Job_ID); startTimer(); if (Parameter_Job_ID>0) randomDelay(1000); SDReader = new StateDescriptorReader(Parameter_SD_FileName); int threadCountPerNode = 1; int ParaOpMode = 0; char* fftPlanDescriptor = NULL; bool usexFFT = false; readOptimalFermionVectorEmbeddingAndFFTPlanFromTuningDB(SDReader->getL0(), SDReader->getL1(), SDReader->getL2(), SDReader->getL3(), threadCountPerNode, ParaOpMode, usexFFT, SDReader->getUseP(), SDReader->getUseQ(), SDReader->getUseR(), SDReader->getUseQHM(), fftPlanDescriptor); delete[] fftPlanDescriptor; char* fileNameExtension = SDReader->getFileNameExtension(); ioControl = new AnalyzerIOControl(fileNameExtension, Parameter_Job_ID); delete[] fileNameExtension; fermiOps = new FermionMatrixOperations(SDReader->getL0(), SDReader->getL1(), SDReader->getL2(), SDReader->getL3(), SDReader->getRho(), SDReader->getR(), SDReader->getYN()); fermiOps->setMassSplitRatio(SDReader->getMassSplit()); fermiOps->setAntiPeriodicBoundaryConditionsInTime(SDReader->useAntiPeriodicBoundaryConditionsInTimeDirection()); iniAnalyzerObs(); iniAuxVecs(); createFolders(); ioControl->removeDeprecatedInProgressFiles(48.0); if (LogLevel>2) printf("\nEntering main Analyzer-Loop.\n"); int confID = -1; while (((confID=getNextConfIDforAnalysis())>=0) && (timePassed()<3600*Parameter_MaxRunTime)) { ioControl->markAsInProgress(confID); bool keepMarked = false; char* confFileName = ioControl->getPhiConfFileName(confID); AnalyzerPhiFieldConfiguration* phiFieldConf = new AnalyzerPhiFieldConfiguration(confFileName, fermiOps); delete[] confFileName; if (phiFieldConf->getErrorState() == 0) { for (int I=0; I<analyzerObsCount; I++) { bool activeObs = false; for (int I2=0; I2<Parameter_tagCount; I2++) { if (analyzerObs[I]->isNick(Parameter_tags[I2])) activeObs = true; } if (activeObs) { if ((!analyzerObs[I]->isConfAnalyzed(confID)) && (analyzerObs[I]->shallConfBeAnalyzed(confID))) { if (LogLevel>2) printf("Analyzing Observable %s...\n",analyzerObs[I]->getObsName()); bool b = analyzerObs[I]->analyze(phiFieldConf, auxVecs); phiFieldConf->clearPhiFieldCopies(); if (b) { analyzerObs[I]->saveAnalyzerResults(confID); } else { keepMarked = true; if (LogLevel>1) { printf(" *** Could not analyze observable %s on configuration %d. Continue with next configuration.\n",analyzerObs[I]->getObsName(),confID); } } } } } } else { keepMarked = true; if (LogLevel>1) { printf(" *** Could not load configuration file %d --> Skipping configuration file\n",confID); } } delete phiFieldConf; if (!keepMarked) ioControl->unmarkAsInProgress(confID); if (Parameter_Job_ID>0) randomDelay(2); } if (LogLevel>2) printf("\nLeaving main Analyzer-Loop.\n\n"); desini(); desiniTools(); fftw_cleanup_threads(); if (LogLevel>1) printf("Analyzer terminated correctly.\n"); }
void Game::search() { m_bSearching = true; m_bestMove = 0; m_bestValue = 0; m_bInterrupted = false; m_evalCount = 0; // 50 move rule and repetition check // no need to search if the game has allready ended if(m_board->isEnded()){ m_bSearching = false; return; } int move = searchDB(); if(move != 0){ m_bestMove = move; m_bSearching = false; return; } startTime(); DEBUG_PRINT("Start alphabeta iterative deepening\n", 0); char buf[20]; // reset principal variation for this search int i; for(i = 0; i < MAX_DEPTH; i++){ m_arrPVMoves[i] = 0; } int reachedDepth = 0; boolean bContinue = true; for(m_searchDepth = 1; m_searchDepth < (MAX_DEPTH-QUIESCE_DEPTH); m_searchDepth++) { DEBUG_PRINT("Search at depth %d\n", m_searchDepth); bContinue = alphaBetaRoot(m_searchDepth, -ChessBoard::VALUATION_MATE, ChessBoard::VALUATION_MATE); // todo ----------------------------------------------------------- //break; //debug if(bContinue){ #if DEBUG_LEVEL & 2 DEBUG_PRINT("\n +-+-+-+-+-+-+-+-PV: ", 0); for(i = 0; i < m_searchDepth; i++){ Move::toDbgString(m_arrPVMoves[i], buf); DEBUG_PRINT(" > %s", buf); } DEBUG_PRINT(" {%d}\n", m_bestValue); #endif reachedDepth++; if(m_bestValue == ChessBoard::VALUATION_MATE){ DEBUG_PRINT("Found checkmate, stopping search\n", 0); break; } // bail out if we're over 50% of time, next depth will take more than sum of previous if(usedTime()){ DEBUG_PRINT("Bailing out\n", 0); break; } } else { if(m_bInterrupted){ DEBUG_PRINT("Interrupted search\n", 0); } else { DEBUG_PRINT("No continuation, only one move\n", 0); } break; } } //#if DEBUG_LEVEL & 3 Move::toDbgString(m_bestMove, buf); DEBUG_PRINT("\n=====\nSearch\nvalue\t%d\nevalCnt\t%d\nMove\t%s\ndepth\t%d\nTime\t%ld ms\nNps\t%.2f\n", m_bestValue, m_evalCount, buf, reachedDepth, timePassed(), (double)m_evalCount / timePassed()); //#endif m_bSearching = false; }
double Timer::timeUntil(double unixTime) { return unixTime - timePassed(); }
void Timer::stop() { m_timePassed = timePassed(); m_running = false; }