static int runSystem(const NBodyCtx* ctx, NBodyState* st, const NBodyFlags* nbf) { const real tstop = ctx->timeEvolve - ctx->timestep / 1024.0; if (nbf->visualizer) { launchVisualizer(st, nbf->visArgs); } while (st->tnow < tstop) { updateDisplayedBodies(st); if (stepSystem(ctx, st)) /* advance N-body system */ return 1; nbodyCheckpoint(ctx, st); } if (BOINC_APPLICATION || ctx->checkpointT >= 0) { mw_report("Making final checkpoint\n"); if (writeCheckpoint(ctx, st)) return warn1("Failed to write final checkpoint\n"); } return 0; }
void idle() { // Trigger the next timestep if the time since the last step exceeds the threshold const scalar& current_time = timingutils::seconds(); if( !g_paused && current_time-g_last_time >= g_sec_per_frame ) { computeFPS(); g_last_time = current_time; stepSystem(); glutPostRedisplay(); } assert( renderingutils::checkGLErrors() ); }
void idle() { //std::cout << "g_last_time: " << g_last_time << std::endl; // Trigger the next timestep double current_time = timingutils::seconds(); //std::cout << "current_time: " << current_time << std::endl; //std::cout << "g_sec_per_frame: " << g_sec_per_frame << std::endl; if( !g_paused && current_time-g_last_time >= g_sec_per_frame ) { g_last_time = current_time; stepSystem(); glutPostRedisplay(); } assert( renderingutils::checkGLErrors() ); }
void headlessSimLoop() { scalar nextpercent = 0.02; std::cout << outputmod::startpink << "Progress: " << outputmod::endpink; for( int i = 0; i < 50; ++i ) std::cout << "-"; std::cout << std::endl; std::cout << " "; while( true ) { scalar percent_done = ((double)g_current_step)/((double)g_num_steps); if( percent_done >= nextpercent ) { nextpercent += 0.02; std::cout << "." << std::flush; } stepSystem(); } }
void keyboard( unsigned char key, int x, int y ) { // Handle general keyboard options shared across simulations // Exit on escape key or q if( key == 27 || key == 'q' || key == 'Q' ) { exit(0); } // Step the system forward one timestep else if( key == 's' || key =='S' ) { stepSystem(); glutPostRedisplay(); } // Space bar pauses and unpauses else if( key == ' ' ) { g_paused = !g_paused; } // else if( key == 'c' || key == 'C' ) // { // centerCamera(); // g_display_controller.reshape(g_display_controller.getWindowWidth(),g_display_controller.getWindowHeight()); // glutPostRedisplay(); // } #ifdef PNGOUT // Save a png screenshot else if( key == 'i' || key == 'I' ) { std::cout << outputmod::startpink << "TDSmoke STATUS: " << outputmod::endpink << "Saving screenshot as 'output.png'." << std::endl; dumpPNG("output.png"); } #endif // Allow the simulation to respond to keyboard input on its own g_simulation_ensemble->keyboard(key,x,y); glutPostRedisplay(); assert( renderingutils::checkGLErrors() ); }
void headlessSimLoop() { if( g_final_step == INT_MAX ) { std::cerr << outputmod::startred << "TDSmoke ERROR: " << outputmod::endred << " Must specify a final time in headless mode." << std::endl; exit(1); } scalar nextpercent = 0.02; std::cout << outputmod::startpink << "Progress: " << outputmod::endpink; for( int i = 0; i < 50; ++i ) std::cout << "-"; std::cout << std::endl; std::cout << " "; while( true ) { scalar percent_done = ((scalar)g_current_step)/((scalar)g_final_step); if( percent_done >= nextpercent ) { nextpercent += 0.02; std::cout << "." << std::flush; } stepSystem(); } }
void keyboard( unsigned char key, int x, int y ) { g_display_controller.keyboard(key,x,y); if( key == 27 || key == 'q' ) { exit(0); } else if( key == 's' || key =='S' ) { stepSystem(); glutPostRedisplay(); } else if( key == ' ' ) { // int x = fork(); // if(x==0) { // system("play thermo.dat"); // exit(1); // } g_paused = !g_paused; } else if( key == 'c' || key == 'C' ) { centerCamera(); g_display_controller.reshape(g_display_controller.getWindowWidth(),g_display_controller.getWindowHeight()); glutPostRedisplay(); } else if( key == 'i' || key == 'I' ) { std::cout << outputmod::startpink << "FOSSSim message: " << outputmod::endpink << "Saving screenshot as 'output.svg'." << std::endl; g_executable_simulation->renderSceneSVG("output.svg"); } assert( renderingutils::checkGLErrors() ); }
bool NaiveAlgorithm::tick() { cpFloat bestFitness = -INFINITY; // we want zero fitness cpFloat worstFitness = INFINITY; cpFloat lastBestFitness = bestIndividual ? bestIndividual->fitness : bestFitness; std::vector<SystemInfo *>nextGen = spawnChildren(); // add old population for (size_t popIter = 0; popIter <population.size(); popIter++) { // reset the individual... by copying! SystemInfo *individual = population[popIter]; MachineSystem *original = individual->system; MachineSystem *copy = new MachineSystem(*original); individual->system = copy; delete original; nextGen.push_back(individual); } for (size_t popIter = 0; popIter <nextGen.size(); popIter++) { SystemInfo *individual = nextGen[popIter]; stepSystem(individual); individual->fitness = evaluateSystem(individual); } // cut the population back down to size std::sort(nextGen.begin(), nextGen.end(), isMoreFit); bestIndividual = nextGen.front(); bestFitness = bestIndividual->fitness; worstFitness = nextGen.back()->fitness; std::vector<SystemInfo *>::iterator deleteIt = nextGen.begin()+population.size(); while (deleteIt != nextGen.end()) { SystemInfo *unfit = *deleteIt; assert(unfit != bestIndividual); delete unfit; deleteIt = nextGen.erase(deleteIt); } if (bestFitness > allTimeBestFitness) allTimeBestFitness = bestFitness; assert(nextGen.size() == population.size()); population = nextGen; fprintf(stderr, "BEST FITNESS: %f \n", bestFitness); fprintf(stderr, "WORST FITNESS: %f \n", worstFitness); if (lastBestFitness == bestFitness) stagnantGenerations++; else stagnantGenerations = 0; bool stop = (generations >= maxGenerations) || goodEnoughFitness(bestFitness) || (stagnantGenerations >= maxStagnation); generations++; logPopulationStatistics(); if (stop) { fprintf(stderr, "ALL TIME BEST FITNESS: %f\n", allTimeBestFitness); } return stop; }