Example #1
0
        public SubJob GetNextSubJob()
        {
            if (IsCompleted)
            {
                return(null);
            }

            if (_hSectionPtr > SamplePoints.NumberOfHSections - 1)
            {
                _hSectionPtr = 0;
                _vSectionPtr++;

                if (_vSectionPtr > SamplePoints.NumberOfVSections - 1)
                {
                    IsCompleted = true;
                    return(null);
                }
            }
            //System.Diagnostics.Debug.WriteLine($"Creating SubJob for hSection: {_hSectionPtr}, vSection: {_vSectionPtr}.");

            int left = _hSectionPtr * SECTION_WIDTH;
            int top  = _vSectionPtr * SECTION_HEIGHT;

            MapSection            mapSection = new MapSection(new Point(left, top), new CanvasSize(SECTION_WIDTH, SECTION_HEIGHT));
            MapSectionWorkRequest mswr       = new MapSectionWorkRequest(mapSection, MaxIterations, _hSectionPtr++, _vSectionPtr);
            SubJob result = new SubJob(this, mswr);

            return(result);
        }
Example #2
0
        private MapSectionWorkRequest CreateMSWR(FJobResult jobResult, int maxIterations)
        {
            MapSection            mapSection = new MapSection(jobResult.Area);
            MapSectionWorkRequest result     = new MapSectionWorkRequest(mapSection, maxIterations, 0, 0);

            return(result);
        }
Example #3
0
        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);
        }
        //     [TestMethod]
        //     public void CreateJob()
        //     {

        //         //CanvasSize canvasSize = new CanvasSize(1440, 960);
        //CanvasSize canvasSize = new CanvasSize(188, 125);

        ////Size canvasSize = new Size(7200, 4800);
        ////Size canvasSize = new Size(10800, 7200);
        ////Size canvasSize = new Size(14400, 9600);
        ////Size canvasSize = new Size(21600, 14400);

        ////DPoint leftBot = new DPoint(-0.7764118407199196, 0.13437492059936854);
        ////DPoint rightTop = new DPoint(-0.7764117329761986, 0.13437499747905846);

        //DPoint leftBot = new DPoint(-2, -1);
        //DPoint rightTop = new DPoint(1, 1);


        //int maxIterations = 100;
        //         MapInfo mapInfo = new MapInfo(leftBot, rightTop, maxIterations);

        //SCoords coords = new SCoords(new SPoint(leftBot), new SPoint(rightTop));
        //MapSection area = new MapSection(new Point(0, 0), canvasSize.GetWholeUnits(Engine.BLOCK_SIZE));

        //string connectionId = "dummy";

        //SMapWorkRequest mapWorkRequest = new SMapWorkRequest("FET", coords, canvasSize, area, maxIterations, connectionId);

        //Job job = new Job(mapWorkRequest);
        //mapWorkRequest.JobId = job.JobId;

        //SubJob subJob = null;
        //while((subJob = job.GetNextSubJob()) != null)
        //{
        //	int lx = subJob.MapSectionWorkRequest.MapSection.SectionAnchor.X;
        //	ProcessSubJob(subJob);
        //}
        //     }

        private void ProcessSubJob(SubJob subJob)
        {
            MapSectionWorkRequest mswr = subJob.MapSectionWorkRequest;

            //MapWorkingData2 workingData = new MapWorkingData2(mswr.MapSection.CanvasSize, mswr.MaxIterations, mswr.XValues, mswr.YValues);
            //int[] packedCntsAndEscVels = workingData.GetValues();

            Job parentJob = subJob.ParentJob as Job;

            double[] xValues = parentJob.SamplePoints.XValueSections[subJob.MapSectionWorkRequest.HPtr];
            double[] YValues = parentJob.SamplePoints.YValueSections[subJob.MapSectionWorkRequest.VPtr];


            MapCalculator workingData = new MapCalculator();

            int[] packedCntsAndEscVels = workingData.GetValues(xValues, YValues, subJob.MapSectionWorkRequest.MaxIterations);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
 public SubJob(IJob parentJob, MapSectionWorkRequest mapSectionWorkRequest)
 {
     ParentJob             = parentJob ?? throw new ArgumentNullException(nameof(parentJob));
     MapSectionWorkRequest = mapSectionWorkRequest ?? throw new ArgumentNullException(nameof(mapSectionWorkRequest));
     MapSectionResult      = null;
 }