public void Abort() => thread.Abort(); // An extreme step private void run() { var opencl = new OpenCLWrapper(settings.GpuWorkChunkDimension, settings.Device, settings.WorldSeed); long start = getnFromWorkRadius(settings.Start / settings.GpuWorkChunkDimension); long stop = getnFromWorkRadius(settings.Stop / settings.GpuWorkChunkDimension); for (long i = start; i < stop; i++) { var coords = scaleByWorkSize(getSpiralCoords(i)); opencl.Work(coords); opencl.candidates.ForEach((c, id) => { if (c >= settings.CandidateThreshold) { (long x, long z) = unflattenPosition(id, coords); results.UncheckedCandidates.Add(new Result(x, z, c)); } }); } Completed = true; }
private static bool parseArgs(string[] args) { var stng = settingsResults.Settings; try { bool seedInput = false; bool shouldShowHelp = false; bool printReadme = false; string inputFile = null; bool deviceInput = false; var options = new OptionSet { { "s|seed=", "world seed, type long", (long s) => { stng.WorldSeed = s; seedInput = true; } }, { "i|in=", "input file to continue saved work", i => inputFile = i }, { "o|out=", "file to save the results", o => stng.OutputFile = o }, { "h|help", "show this message and exit", h => shouldShowHelp = h != null }, { "start=", "the start \"radius\" of the search area in blocks/meters", (int s) => stng.Start = s }, { "stop=", "the end \"radius\" of the search area in blocks/meters", (int s) => stng.Stop = s }, { "w|work-size=", "length of the square chunk of work sent to the GPU at once less than 2^14", (short w) => stng.GpuWorkChunkDimension = w }, { "r|readme", "print the readme and exit. Includes a how-to", r => printReadme = r != null }, { "d|device=", "the index of the OpenCL device to use", (int d) => { stng.Device = OpenCLWrapper.GetDevices()[d]; deviceInput = true; } } }; options.Parse(args); if (shouldShowHelp) { Console.Write(optionsHeader); options.WriteOptionDescriptions(Console.Out); Console.WriteLine(optionsFooter); return(false); } if (printReadme) { Console.WriteLine(getOptionsOutputString(System.IO.File.ReadAllText("README-copy.md"))); return(false); } if (!seedInput) { Console.WriteLine(getOptionsOutputString("A world seed must be specified with -s [world seed]")); return(false); } if (!string.IsNullOrEmpty(inputFile)) { throw new NotImplementedException(); } if (!deviceInput) { try { List <Device> devices = OpenCLWrapper.GetDevices(); string output = devices.Select((d, i) => $"[{i}]: {d.DeviceInfoLine()}").Aggregate((a, b) => $"{a}\n{b}"); Console.Write("Devices:\n\n" + output + "\nSelect a device index: "); int index = int.Parse(Console.ReadLine()); stng.Device = devices[index]; } catch (Exception) { Console.WriteLine("Invalid device number selected"); return(false); } } } catch (OptionException e) { Console.WriteLine(getOptionsOutputString(e.Message)); return(false); } return(true); }