private MapSectionWorkResult CreateWorkResult(FJobResult fJobResult) { int[] counts = fJobResult.GetValues(); MapSectionWorkResult result = new MapSectionWorkResult(counts); return(result); }
public void WriteWorkResult(KPoint key, MapSectionWorkResult val, bool overwriteResults) { // When writing include the Area's offset. KPoint transKey = key.ToGlobal(_position); try { lock (_repoLock) { if (overwriteResults) { _countsRepo.Change(transKey, val); //WorkResultReWriteCount++; } else { _countsRepo.Add(transKey, val, saveOnWrite: false); //WorkResultWriteCount++; } } } catch { Debug.WriteLine($"Could not write data for x: {transKey.X} and y: {transKey.Y}."); } }
public bool RetrieveWorkResultFromRepo(KPoint key, MapSectionWorkResult workResult) { // When writing include the Area's offset. KPoint transKey = key.ToGlobal(_position); lock (_repoLock) { bool result = _countsRepo.ReadParts(transKey, workResult); return(result); } }
private MapSectionWorkResult RetrieveWorkResultFromRepo(KPoint key, Job localJob, bool readZValues) { MapSectionWorkResult workResult = GetEmptyResult(readZValues, Job.SECTION_WIDTH, Job.SECTION_HEIGHT); if (localJob.RetrieveWorkResultFromRepo(key, workResult)) { return(workResult); } else { return(null); } }
private MapSectionWorkResult GetEmptyResult(KPoint key) { //if(area.Size.W != SECTION_WIDTH || area.Size.H != SECTION_HEIGHT) //{ // Debug.WriteLine("Wrong Area."); //} if (_emptyResult == null) { _emptyResult = new MapSectionWorkResult(SECTION_WIDTH * SECTION_HEIGHT, hiRez: false, includeZValuesOnRead: false); } return(_emptyResult); }
private MapSectionResult ProcessSubJob(SubJob subJob) { if (subJob.ParentJob.CancelRequested) { Debug.WriteLine("Not Processing Sub Job."); return(null); } if (!(subJob.ParentJob is Job localJob)) { throw new InvalidOperationException("When processing a subjob, the parent job must be implemented by the Job class."); } MapSectionWorkRequest mswr = subJob.MapSectionWorkRequest; KPoint key = new KPoint(mswr.HPtr, mswr.VPtr); MapSectionWorkResult workResult = RetrieveWorkResultFromRepo(key, localJob, readZValues: false); MapSectionResult result; if (workResult == null) { result = CalculateMapValues(subJob, localJob, ref workResult); } else { if (workResult.IterationCount == 0 || workResult.IterationCount == mswr.MaxIterations) { // The WorkResult read from file has the correct iteration count. (Or we are not tracking the interation count.) result = new MapSectionResult(localJob.JobId, mswr.MapSection, workResult.Counts); } else if (workResult.IterationCount < mswr.MaxIterations) { // Fetch the entire WorkResult with ZValues workResult = RetrieveWorkResultFromRepo(key, localJob, readZValues: true); // Use the current work results to continue calculations to create // a result with the target iteration count. result = CalculateMapValues(subJob, localJob, ref workResult); } else { throw new InvalidOperationException("Cannot reduce the number of iterations of an existing job."); } } return(result); }
private MapSectionWorkResult BuildMSWR(int size) { int[] counts = new int[size]; int iterationCount = 100; bool[] doneFlags = new bool[size]; DPoint[] zValues = new DPoint[size]; for (int i = 0; i < size; i++) { zValues[i] = new DPoint(i, i); } MapSectionWorkResult result = new MapSectionWorkResult(counts, iterationCount, zValues, doneFlags); return(result); }
private SubJob CreateSubJob(FJobResult jobResult, JobForMq parentJob) { MapSectionWorkResult workResult = CreateWorkResult(jobResult); MapSectionWorkRequest workRequest = CreateMSWR(jobResult, parentJob.SMapWorkRequest.MaxIterations); MapSectionResult msr = CreateMapSectionResult(parentJob.JobId, workRequest.MapSection, workResult); SubJob subJob = new SubJob(parentJob, workRequest) { MapSectionResult = msr }; // We need to keep track if the last sub job has been sent, not received. //if (jobResult.IsFinalResult) parentJob.SetIsLastSubJob(true); return(subJob); }
public CountsRepoReader(string repofilename, bool hiRez, int blockWidth, int blockHeight) { _hiRez = hiRez; _blockWidth = blockWidth; int blockLength = blockWidth * blockHeight; if (_hiRez) { _countsRepoHiRez = new ValueRecords <KPoint, SubJobResult>(repofilename, useHiRezFolder: _hiRez); _workResultHiRez = SubJobResult.GetEmptySubJobResult(blockLength, "0", false); } else { _countsRepo = new ValueRecords <KPoint, MapSectionWorkResult>(repofilename, useHiRezFolder: _hiRez); _workResult = new MapSectionWorkResult(blockLength, hiRez: hiRez, includeZValuesOnRead: false); } }
public void GetHistogramTest() { int w = 108; // blocks int h = 72; CanvasSize imageSize = new CanvasSize(w * 100, h * 100); string fn = "17"; string filename = $"MandlebrodtMapInfo ({fn})"; string imagePath = Path.Combine(BasePath, $"MBB({fn})_{imageSize.Width}.png"); IDictionary <int, int> hist = new Dictionary <int, int>(); ValueRecords <RectangleInt, MapSectionWorkResult> countsRepo = new ValueRecords <RectangleInt, MapSectionWorkResult>(filename, useHiRezFolder: false); RectangleInt key = new RectangleInt(new PointInt(0, 0), new SizeInt(100, 100)); MapSectionWorkResult workResult = new MapSectionWorkResult(10000, hiRez: false, includeZValuesOnRead: false); for (int vBPtr = 0; vBPtr < h; vBPtr++) { key.Point.Y = vBPtr * 100; for (int hBPtr = 0; hBPtr < w; hBPtr++) { key.Point.X = hBPtr * 100; if (countsRepo.ReadParts(key, workResult)) { foreach (int cntAndEsc in workResult.Counts) { int cnt = cntAndEsc / 10000; if (hist.TryGetValue(cnt, out int occurances)) { hist[cnt] = occurances + 1; } else { hist[cnt] = 1; } } } } } Debug.WriteLine($"The histogram has {hist.Count} entries."); }
private MapSectionResult CalculateMapValues(SubJob subJob, Job localJob, ref MapSectionWorkResult workResult) { MapSectionWorkRequest mswr = subJob.MapSectionWorkRequest; bool overwriteResults; if (workResult == null) { workResult = BuildInitialWorkingValues(mswr); overwriteResults = false; } else { overwriteResults = true; } double[] xValues = localJob.SamplePoints.XValueSections[mswr.HPtr]; double[] yValues = localJob.SamplePoints.YValueSections[mswr.VPtr]; //DateTime t0 = DateTime.Now; //workResult = _mapCalculator.GetWorkingValues(xValues, yValues, mswr.MaxIterations, workResult); //DateTime t1 = DateTime.Now; //int[] testCounts = new int[10000]; //DateTime t2 = DateTime.Now; //_mapCalculator.ComputeApprox(xValues, yValues, mswr.MaxIterations, testCounts); //List<int> misMatcheIndexes = GetMismatchCount(workResult.Counts, testCounts, out double avgGap); //DateTime t3 = DateTime.Now; //Debug.WriteLine($"Block: v={mswr.VPtr}, h={mswr.HPtr} has {misMatcheIndexes.Count} mis matches, avgGap={avgGap} and avg {GetAverageCntValue(workResult.Counts)}."); //Debug.WriteLine($"Standard: {GetElaspedTime(t0, t1)}, Approx: {GetElaspedTime(t2, t3)}."); //_mapCalculator.ComputeApprox(xValues, yValues, mswr.MaxIterations, workResult.Counts); workResult = _mapCalculator.GetWorkingValues(xValues, yValues, mswr.MaxIterations, workResult); KPoint key = new KPoint(mswr.HPtr, mswr.VPtr); localJob.WriteWorkResult(key, workResult, overwriteResults); MapSectionResult msr = new MapSectionResult(localJob.JobId, mswr.MapSection, workResult.Counts); return(msr); }
private MapSectionWorkResult BuildInitialWorkingValues(MapSectionWorkRequest mswr) { int width = mswr.MapSection.CanvasSize.Width; int height = mswr.MapSection.CanvasSize.Height; int len = width * height; int[] counts = new int[len]; bool[] doneFlags = new bool[len]; DPoint[] zValues = new DPoint[len]; for (int ptr = 0; ptr < len; ptr++) { zValues[ptr] = new DPoint(0, 0); } MapSectionWorkResult result = new MapSectionWorkResult(counts, mswr.MaxIterations, zValues, doneFlags); return(result); }
public void TestMethod1() { string filename = "Center1"; using (ValueRecords <RectangleInt, MapSectionWorkResult> repo = new ValueRecords <RectangleInt, MapSectionWorkResult>(filename, useHiRezFolder: false)) { RectangleInt key = new RectangleInt(new PointInt(0, 0), new SizeInt(100, 100)); MapSectionWorkResult val = BuildMSWR(100 * 100); repo.Add(key, val); MapSectionWorkResult val2 = new MapSectionWorkResult(100 * 100, hiRez: false, includeZValuesOnRead: true); repo.ReadParts(key, val2); } using (ValueRecords <RectangleInt, MapSectionWorkResult> repo = new ValueRecords <RectangleInt, MapSectionWorkResult>(filename, useHiRezFolder: false)) { RectangleInt key = new RectangleInt(new PointInt(0, 0), new SizeInt(100, 100)); MapSectionWorkResult val2 = new MapSectionWorkResult(100 * 100, hiRez: false, includeZValuesOnRead: true); repo.ReadParts(key, val2); } }
private MapSectionWorkResult GetEmptyResult(bool readZValues, int jobSectionWidth, int jobSectionHeight) { //if (area.Size.W != jobSectionWidth || area.Size.H != jobSectionHeight) //{ // Debug.WriteLine("Wrong Area."); //} if (readZValues) { if (_emptyResultWithZValues == null) { _emptyResultWithZValues = new MapSectionWorkResult(jobSectionWidth * jobSectionHeight, hiRez: false, includeZValuesOnRead: true); } return(_emptyResultWithZValues); } else { if (_emptyResult == null) { _emptyResult = new MapSectionWorkResult(jobSectionWidth * jobSectionHeight, hiRez: false, includeZValuesOnRead: false); } return(_emptyResult); } }
private MapSectionResult CreateMapSectionResult(int jobId, MapSection mapSection, MapSectionWorkResult workResult) { MapSectionResult result = new MapSectionResult(jobId, mapSection, workResult.Counts); return(result); }