private MapSectionWorkResult CreateWorkResult(FJobResult fJobResult) { int[] counts = fJobResult.GetValues(); MapSectionWorkResult result = new MapSectionWorkResult(counts); return(result); }
private MapSectionWorkRequest CreateMSWR(FJobResult jobResult, int maxIterations) { MapSection mapSection = new MapSection(jobResult.Area); MapSectionWorkRequest result = new MapSectionWorkRequest(mapSection, maxIterations, 0, 0); return(result); }
public FJobResult GetResultFromSubJob(bool isFinalResult) { PointInt resultPos = new PointInt(Position.X * FGenerator.BLOCK_WIDTH, Position.Y * FGenerator.BLOCK_HEIGHT); MqMessages.SizeInt resultSize = new MqMessages.SizeInt(FGenerator.BLOCK_WIDTH, FGenerator.BLOCK_HEIGHT); MqMessages.RectangleInt area = new MqMessages.RectangleInt(resultPos, resultSize); FJobResult fJobResult = new FJobResult(ParentJob.JobId, area, SubJobResult.Counts, isFinalResult); return(fJobResult); }
private FJobResult GetResultFromSubJob(int jobId, PointInt position, SubJobResult subJobResult) { MqMessages.PointInt resultPos = new MqMessages.PointInt( position.X() * FGenerator.BLOCK_WIDTH, position.Y() * FGenerator.BLOCK_HEIGHT ); MqMessages.SizeInt resultSize = new MqMessages.SizeInt(FGenerator.BLOCK_WIDTH, FGenerator.BLOCK_HEIGHT); MqMessages.RectangleInt area = new MqMessages.RectangleInt(resultPos, resultSize); FJobResult fJobResult = new FJobResult(jobId, area, subJobResult.Counts); return(fJobResult); }
private void SendProcessor(BlockingCollection <SubJob> sendQueue, MessageQueue outQ, CancellationToken ct) { try { while (!ct.IsCancellationRequested) { if (sendQueue.TryTake(out SubJob subJob, -1, ct)) { Job parentJob = subJob.ParentJob; if (!parentJob.Closed) { parentJob.DecrementSubJobsRemainingToBeSent(); bool isFinalSubJob = subJob.ParentJob.IsLastSubJob; //Debug.WriteLine($"Sending subjob with x: {subJob.result.MapSection.SectionAnchor.X} " + // $"and y: {subJob.result.MapSection.SectionAnchor.Y}. " + // $"It has {subJob.result.ImageData.Length} count values."); FJobResult fJobResult = subJob.GetResultFromSubJob(isFinalSubJob); // Mark the SubJobResult as free. subJob.SubJobResult.IsFree = true; Message r = new Message(fJobResult) { CorrelationId = parentJob.RequestMsgId }; Console.WriteLine($"Sending corId = {FMsgId(parentJob.RequestMsgId)}, instance:{subJob.SubJobResult.ProcessorInstanceName} for id:{subJob.ParentJob.JobId} with {subJob.Position}."); outQ.Send(r); } else { // Mark the SubJobResult as free. subJob.SubJobResult.IsFree = true; } } } } catch (OperationCanceledException) { Debug.WriteLine("Send Queue Consuming Enumerable canceled."); throw; } catch (InvalidOperationException) { Debug.WriteLine("Send Queue Consuming Enumerable completed."); throw; } }
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); }
private void ProcessSubJob(JobProcessor2 jobProcessor, PointInt position, string requestMsgId, MessageQueue outQ) { int jobId = jobProcessor.FGenJob.JobId; //int w = jobProcessor.FGenJob.Area.W(); //uint[] counts = jobProcessor.GetCountsForLine(linePtr); SubJobResult subJobResult = jobProcessor.GetEmptySubJobResult(); jobProcessor.FillCountsForBlock(position, subJobResult); //Debug.WriteLine(ReportSampleOfCounts(subJobResult.Counts)); FJobResult fJobResult = GetResultFromSubJob(jobId, position, subJobResult); Message r = new Message(fJobResult) { CorrelationId = requestMsgId }; Console.WriteLine($"Sending a response message with corId = {FMsgId(requestMsgId)}, instance:{jobProcessor.InstanceNum}."); outQ.Send(r); }
private async Task ReceiveImageResultsAsync() { using (MessageQueue inQ = GetJobResponseQueue()) { while (!_cts.IsCancellationRequested /*&& !jobForMq.IsLastSubJob*/) { Message m = await MqHelper.ReceiveMessageByCorrelationIdAsync(inQ, _jobForMq.MqRequestCorrelationId, _waitDuration); if (m == null) { Debug.WriteLine($"No FGenResult message present for correlationId: {FMsgId(_jobForMq.MqRequestCorrelationId)}."); continue; } FJobResult jobResult = (FJobResult)m.Body; PointInt pos = jobResult.Area.Point; Debug.WriteLine($"Received FJobResult for correlationId: {FMsgId(_jobForMq.MqRequestCorrelationId)}, X:{pos.X}, Y:{pos.Y}."); SubJob subJob = CreateSubJob(jobResult, _jobForMq); _sendQueue.Add(subJob); } if (_jobForMq.IsLastSubJob) { Debug.WriteLine($"The result listener for {_jobForMq.JobId} is stopping. We have received the last result."); } else if (_cts.IsCancellationRequested) { Debug.WriteLine($"The result listener for {_jobForMq.JobId} has been cancelled."); } else { Debug.WriteLine($"The result listener for {_jobForMq.JobId} is stopping for unknown reason."); } } }