float runMultiGame(ScoreFactors sf) { Simulation sims[3] = {Simulation(race1), Simulation(race2), Simulation(race3)}; thread workers[3]; double scores[3] = {0}; for(int i = 0; i < 3; i++) { workers[i] = thread(gameRunner, sims[i], sf, &scores[i]); } for(int i = 0; i < 3; i++) { workers[i].join(); } double score = 0.0f; for(int i = 0; i < 3; i++) { score += scores[i]; } return score/3.0f; }
int main(int argc, char *argv[]) { // Validate arguments if (argc != 3) { std::cout << "Incorrect number of arguments\n"; std::cout << "Desired input: $./a.out input.txt output.txt\n"; // Note that the output file is not used currently - to be expanded in a // future assignment. return 1; } Simulation sim = Simulation(argv[1], argv[2], 9, 80, 1, FCFS); if (not sim.GetNumProcesses()) { fprintf(stderr, "No processes found in input file"); return 1; } // Run simulation for FCFS (First Come First Serve) process order sim.Run(); sim.AppendStatistics(argv[2]); // Run simulation for SRT (Shortest Remaining Time) process order sim.SetMode(SRT); std::cout << "\n"; sim.Run(); sim.AppendStatistics(argv[2]); // Run simulation for RR (Round Robin) process order sim.SetMode(RR); std::cout << "\n"; sim.Run(); sim.AppendStatistics(argv[2]); return 0; }
int metrosim::run(int argc, char** argv) { SimulationArgs args = SimulationArgs(); //args.useNeighborList = false; if (!getCommands(argc, argv, &args)) { exit(EXIT_FAILURE); } DeviceContext context = DeviceContext(); if (args.simulationMode == SimulationMode::Parallel) { if (!openDeviceContext(&context, MIN_MAJOR_VER, MIN_MINOR_VER, args.deviceIndex)) { exit(EXIT_FAILURE); } } if (args.simulationMode == SimulationMode::Parallel) { fprintf(stdout, "Beginning simulation using GPU...\n"); } else { fprintf(stdout, "Beginning simulation using CPU...\n"); } Simulation sim = Simulation(args); sim.run(); fprintf(stdout, "Finishing simulation...\n\n"); if (args.simulationMode == SimulationMode::Parallel) { if (!closeDeviceContext(&context)) { exit(EXIT_FAILURE); } } exit(EXIT_SUCCESS); }
HelpNode *find_help(string keyword, HelpNode *parent = NULL) { HelpNode *node = NULL; if (keyword == "Simulation") { node = new HelpNode(parent, ""); Simulation().help(node); } else if (keyword == "Controller") { node = new HelpNode(parent, ""); Controller(NULL).help(node); } else if (keyword == "WeightingFunctions") { FOUND_HELP(WeightingFunction_Factory, WeightingFunction_Help); } else if (keyword == "Symbols") { FOUND_HELP(SymbolFactory, Symbol_Help); } else if (keyword == "Integrators") { FOUND_HELP(Integrator_Factory, Integrator_Help); } else if (keyword == "Phase") { node = new HelpNode(parent, ""); Phase(NULL).help(node); } else if (keyword == "Forces") { FOUND_HELP(GenFType, Force_Help); } else if (keyword == "Boundaries") { FOUND_HELP(Boundary_Factory, Boundary_Help); } else if (keyword == "Reflectors") { FOUND_HELP(Reflector_Factory, Reflector_Help); } else if (keyword == "ParticleCreators") { FOUND_HELP(ParticleCreator_Factory, ParticleCreator_Help); } else if (keyword == "PairCreators") { FOUND_HELP(PairCreator_Factory, PairCreator_Help); } else if (keyword == "Meters") { FOUND_HELP(Meter_Factory, Meter_Help); } else if (keyword == "Postprocessors") { FOUND_HELP(Postprocessor_Factory, Postprocessor_Help); } else if (keyword == "Callables") { FOUND_HELP(Callable_Factory, Callable_Help); } else if (keyword == "GridMeters") { FOUND_HELP(GridMeter_Factory, GridMeter_Help); } return node; }
Simulation FreshComputation::simulate(const EncryptionParameters &parms) { return Simulation(parms); }
int metrosim::run(int argc, char** argv) { SimulationArgs args = SimulationArgs(); if (!getCommands(argc, argv, &args)) { exit(EXIT_FAILURE); } #ifdef _OPENACC int numDevices = acc_get_num_devices(acc_device_nvidia); // Ensure args.simulationMode is either Serial or Parallel if (args.simulationMode == SimulationMode::Default) { if (numDevices < 1) { fprintf(stdout, "No GPU devices found; defaulting to CPU " "execution.\n"); args.simulationMode = SimulationMode::Serial; } else { fprintf(stdout, "%d GPU device(s) found; running on GPU.\n", numDevices); // FIXME (blm) fprintf(stdout, "WARNING: Not all features support GPU offloading at " "this time. Results may be inaccurate.\n"); args.simulationMode = SimulationMode::Parallel; } } if (args.simulationMode == SimulationMode::Parallel) { if (numDevices == 0) { fprintf(stdout, "ERROR: Cannot find suitable GPU!\n"); exit(EXIT_FAILURE); } // Implicitly sets the device acc_init(acc_device_nvidia); } #else // Without OpenACC, only serial calculations are supported if (args.simulationMode == SimulationMode::Parallel) { fprintf(stdout, "Must compile with OpenACC capability to run in " "parallel mode.\n"); exit(EXIT_FAILURE); } else { args.simulationMode = SimulationMode::Serial; fprintf(stdout, "Beginning simulation using CPU...\n"); } #endif Simulation sim = Simulation(args); sim.run(); fprintf(stdout, "Finishing simulation...\n\n"); // Shutdown the device if we were using the GPU #ifdef _OPENACC if (args.simulationMode == SimulationMode::Parallel) { acc_shutdown(acc_device_nvidia); } #endif exit(EXIT_SUCCESS); }
/** * @param order The number of requested scatterings * @param ntimes The number of times on input workspace * @return A reference to a new Simulation object */ Simulation &SimulationAggregator::newSimulation(const size_t order, const size_t ntimes) { results.push_back(Simulation(order, ntimes)); return results.back(); }
//---------------------------------------------------------------------------- int BeadSlide::Main (int, char**) { Simulation(); return 0; }
Node Janggi::MCTS(Turn turn) { rootNode.Init(); cout << endl << endl; for (int i = 0; i < MCTS_ITERATION; i++) { Turn currTurn = turn; std::stack<Node*> visited; Node* pCur = &rootNode; std::stack<double> rewards; int selected = 0; double curReward = 0.0f; // Selection Node* first = NULL; while (!pCur->isLeaf) { selected = pCur->Selection(currTurn); pCur = pCur->GetChild(selected); if (first == NULL) { first = pCur; } visited.push(pCur); curReward = pCur->GetValue(); //curReward = pCur->GetScore(); rewards.push(curReward); currTurn = (currTurn == TURN_CHO ? TURN_HAN : TURN_CHO); } #if DEBUG_MCTS if (first) { cout << "init : (" << first->GetAction().prev.x << "," << first->GetAction().prev.y << ") => (" << first->GetAction().next.x << "," << first->GetAction().next.y << ")" << endl; } #endif // Expand pCur->Expand(currTurn); selected = pCur->Selection(currTurn); pCur = pCur->GetChild(selected); // Simulation double value = Simulation(*pCur, currTurn == TURN_CHO ? TURN_HAN : TURN_CHO); pCur->totalScore = value; // Back Propagation while (!visited.empty()) { pCur = visited.top(); if (currTurn == TURN_CHO) pCur->totalScore = min(rewards.top(), value); else pCur->totalScore = max(rewards.top(), value); visited.pop(); rewards.pop(); currTurn = (currTurn == TURN_CHO ? TURN_HAN : TURN_CHO); } } int bestNode = 0; double bestValue; if (turn == TURN_CHO) { bestValue = -std::numeric_limits<double>::max(); for (int i = 0; i < rootNode.children.size(); i++) { double value = rootNode.children[i].GetScore(); if (value > bestValue) { bestValue = value; bestNode = i; } #if DEBUG_MCTS double deb_score = rootNode.children[i].GetScore(); if (deb_score > 0 && deb_score < 0.001) deb_score = 0.001; else if (deb_score < 0 && deb_score > -0.001) deb_score = -0.001; else if (deb_score == 0) deb_score = 0; std::cout << "(" << rootNode.children[i].GetAction().prev.x << ", " << rootNode.children[i].GetAction().prev.y << ") => (" << rootNode.children[i].GetAction().next.x << ", " << rootNode.children[i].GetAction().next.y << ") : " << deb_score << endl; #endif } } else { bestValue = std::numeric_limits<double>::max(); for (int i = 0; i < rootNode.children.size(); i++) { double value = rootNode.children[i].GetScore(); if (value < bestValue) { bestValue = value; bestNode = i; } #if DEBUG_MCTS double deb_score = rootNode.children[i].GetScore(); if (deb_score > 0 && deb_score < 0.001) deb_score = 0.001; else if (deb_score < 0 && deb_score > -0.001) deb_score = -0.001; else if (deb_score == 0) deb_score = 0; std::cout << "(" << rootNode.children[i].GetAction().prev.x << ", " << rootNode.children[i].GetAction().prev.y << ") => (" << rootNode.children[i].GetAction().next.x << ", " << rootNode.children[i].GetAction().next.y << ") : " << deb_score << endl; #endif } } return rootNode.children[bestNode]; }
Simulation readInput(FILE* inputFile) { int xnumber; char ch = ' '; fscanf(inputFile, "%d", &xnumber); if(xnumber < 0) { printf("xnumber must be > 0\n"); exit(0); } int ynumber; fscanf(inputFile, "%d", &ynumber); if(ynumber < 0) { printf("ynumber must be > 0\n"); exit(0); } int znumber; fscanf(inputFile, "%d", &znumber); if(znumber < 0) { printf("znumber must be > 0\n"); exit(0); } while(ch != '\n') { fscanf(inputFile, "%c", &ch); } double xsize; fscanf(inputFile, "%lf", &xsize); if(xsize < 0) { printf("xsize must be > 0\n"); exit(0); } double ysize; fscanf(inputFile, "%lf", &ysize); if(ysize < 0) { printf("ysize must be > 0\n"); exit(0); } double zsize; fscanf(inputFile, "%lf", &zsize); if(zsize < 0) { printf("zsize must be > 0\n"); exit(0); } ch = ' '; while(ch != '\n') { fscanf(inputFile, "%c", &ch); } double temperature; fscanf(inputFile, "%lf", &temperature); if(temperature < 0) { printf("temperature must be > 0\n"); exit(0); } ch = ' '; while(ch != '\n') { fscanf(inputFile, "%c", &ch); } double density; fscanf(inputFile, "%lf", &density); if(density < 0) { printf("density must be > 0\n"); exit(0); } ch = ' '; while(ch != '\n') { fscanf(inputFile, "%c", &ch); } double Ex; fscanf(inputFile, "%lf", &Ex); double Ey; fscanf(inputFile, "%lf", &Ey); double Ez; fscanf(inputFile, "%lf", &Ez); ch = ' '; while(ch != '\n') { fscanf(inputFile, "%c", &ch); } double Bx; fscanf(inputFile, "%lf", &Bx); double By; fscanf(inputFile, "%lf", &By); double Bz; fscanf(inputFile, "%lf", &Bz); ch = ' '; while(ch != '\n') { fscanf(inputFile, "%c", &ch); } int maxIterations; fscanf(inputFile, "%d", &maxIterations); if(maxIterations < 0) { printf("max iterations must be > 0\n"); exit(0); } ch = ' '; while(ch != '\n') { fscanf(inputFile, "%c", &ch); } double maxTime; fscanf(inputFile, "%lf", &maxTime); if(maxTime < 0) { printf("max time must be > 0\n"); exit(0); } ch = ' '; while(ch != '\n') { fscanf(inputFile, "%c", &ch); } int particlesPerBin; fscanf(inputFile, "%d", &particlesPerBin); if(particlesPerBin < 0) { printf("particles per bin must be > 0\n"); exit(0); } return Simulation(xnumber, xsize, temperature, density, Ex, Ey, Ez, Bx, By, Bz, maxIterations, maxTime, particlesPerBin); }