/// <summary> /// DoRun sends inputs specified in job contract to aspen simulation and runs /// the simulation. /// </summary> /// <param name="job"></param> /// <param name="stest"></param> /// <param name="combinedDict"></param> protected void DoRun(IJobConsumerContract job, sinter.ISimulation stest, JObject defaultsDict, JObject inputDict) { Debug.WriteLine(String.Format("Send Inputs to Job {0}", job.Id), "SinterConsumer.DoRun"); try { if (defaultsDict != null) { stest.sendDefaults(defaultsDict); } stest.sendInputs(inputDict); } catch (Exception ex) { job.Error(String.Format( "Error sending Inputs to Aspen: {0}, traceback {1}", ex.Message, ex.StackTrace)); Debug.WriteLine(String.Format("Moved Job {0} to Error", job.Id), "SinterConsumer.DoRun"); throw; } job.Message("sinter inputs sent, running simulation"); Debug.WriteLine(String.Format("Job {0}: sendInputsToSim ", job.Id), "SinterConsumer.DoRun"); try { running = true; lock (this) { stest.sendInputsToSim(); Debug.WriteLine(String.Format("Job {0}: runSim ", job.Id), "SinterConsumer.DoRun"); stest.runSim(); Debug.WriteLine(String.Format("Job {0}: recvOutputsFromSim ", job.Id), "SinterConsumer.DoRun"); stest.recvOutputsFromSim(); } running = false; if (isTerminated) { throw new TerminateException( "Monitor thread Terminated Simulation"); } } catch (Exception ex) { Debug.WriteLine(String.Format("Moving Job {0} to Error", job.Id), "SinterConsumerRun.DoRun"); Debug.WriteLine(ex.Message, "SinterConsumerRun.DoRun"); Debug.WriteLine(ex.StackTrace, "SinterConsumerRun.DoRun"); job.Error(String.Format( "Error running simulation: {0}, traceback {1}", ex.Message, ex.StackTrace)); throw; } }
/// <summary> /// DoInitialize initializes the Aspen Engine if specified in the job contract. /// </summary> /// <param name="job"></param> /// <param name="stest"></param> /// <param name="defaultsDict"></param> private void DoInitialize(IJobConsumerContract job, sinter.ISimulation stest, JObject defaultsDict) { if (!job.Initialize()) { return; } Debug.WriteLine(String.Format("Start warm-up run on job {0}", job.Id), "SinterConsumer.Run"); try { stest.sendInputs(defaultsDict); } catch (Exception ex) { job.Error(String.Format( "Error sending Defaults to Aspen for warm-up run: {0}, traceback {1}", ex.Message, ex.StackTrace)); Debug.WriteLine(String.Format("Moved Job {0} to Error", job.Id), "SinterConsumer.Run"); throw; } job.Message("Warm-up inputs sent, running simulation"); Debug.WriteLine(String.Format("Calling run Simulation for warm-up on Job {0}", job.Id), "SinterConsumer.Run"); try { running = true; lock (this) { stest.sendInputsToSim(); stest.runSim(); stest.recvOutputsFromSim(); } running = false; if (isTerminated) { throw new TerminateException( "Monitor Terminated Initializing Simulation"); } } catch (Exception ex) { Debug.WriteLine(String.Format("Moving Job {0} to Error", job.Id), "SinterConsumer.Run"); job.Error(String.Format( "Error running warm-up simulation: {0}, traceback {1}", ex.Message, ex.StackTrace)); throw; } job.Message("Warm-up complete and successful. Reseting Sim for real run."); Debug.WriteLine(String.Format("Warm-up complete and successful. Reseting Sim for real run {0}", job.Id), "SinterConsumer.Run"); }
/// <summary> /// DoRun sends inputs specified in job contract to aspen simulation and runs /// the simulation. /// </summary> /// <param name="job"></param> /// <param name="stest"></param> /// <param name="combinedDict"></param> protected void DoRun(IJobConsumerContract job, sinter.ISimulation stest, JObject defaultsDict, JObject inputDict) { Debug.WriteLine(String.Format("Send Inputs to Job {0}", job.Id), "SinterConsumer.DoRun"); try { Debug.WriteLine("Default: " + JsonConvert.SerializeObject(defaultsDict), "SinterConsumerRun.DoRun"); Debug.WriteLine("Input: " + JsonConvert.SerializeObject(inputDict), "SinterConsumerRun.DoRun"); if (defaultsDict != null) { stest.sendDefaults(defaultsDict); } stest.sendInputs(inputDict); } catch (Exception ex) { Debug.WriteLine(String.Format( "Error sending Inputs: {0}, traceback {1}", ex.Message, ex.StackTrace), "SinterConsumerRun.DoRun"); if (job.IsTerminated()) { throw new TerminateException("Job was terminated by producer"); } job.Error(String.Format( "Error sending Inputs: {0}, traceback {1}", ex.Message, ex.StackTrace)); Debug.WriteLine(String.Format("Moved Job {0} to Error", job.Id), "SinterConsumer.DoRun"); throw; } job.Message("sinter inputs sent, running simulation"); Debug.WriteLine(String.Format("Job {0}: sendInputsToSim ", job.Id), "SinterConsumer.DoRun"); try { running = true; lock (this) { stest.sendInputsToSim(); Debug.WriteLine(String.Format("Job {0}: runSim ", job.Id), "SinterConsumer.DoRun"); stest.runSim(); Debug.WriteLine(String.Format("Job {0}: recvOutputsFromSim ", job.Id), "SinterConsumer.DoRun"); if (stest.runStatus == sinter.sinter_AppError.si_OKAY) { stest.recvOutputsFromSim(); job.Message("Real Run was complete and successful."); Debug.WriteLine(String.Format("Real Run was complete and successful. Job Id: {0}", job.Id), "SinterConsumer.Run"); } else if (stest.runStatus == sinter.sinter_AppError.si_SIMULATION_WARNING) { stest.recvOutputsFromSim(); job.Message("Real Run was completed with warning."); Debug.WriteLine(String.Format("Real Run was completed with warning. Job Id: {0}", job.Id), "SinterConsumer.Run"); } else { job.Message(String.Format("Real Run failed, runStatus={0}", stest.runStatus)); Debug.WriteLine(String.Format("Real Run was complete and failed. Job Id: {0}, runStatus={1}", job.Id, stest.runStatus), "SinterConsumer.Run"); } } running = false; if (isTerminated) { throw new TerminateException( "Monitor thread Terminated Simulation"); } } catch (System.Runtime.InteropServices.COMException ex) { Debug.WriteLine(String.Format("Moving Job {0} to Error", job.Id), "SinterConsumerRun.DoRun"); Debug.WriteLine(ex.Message, "SinterConsumerRun.DoRun"); Debug.WriteLine(ex.StackTrace, "SinterConsumerRun.DoRun"); if (this.terminateSimAndJob() == false) { Debug.WriteLine("Failed to terminate the simulation", "SinterConsumerRun.DoRun()"); if (sim != null) { Debug.WriteLine("1) Simulation is not Null", "SinterConsumerRun.DoRun()"); sim.closeSim(); if (sim != null) { KillProcessAndChildren(sim.ProcessID); } sim = null; //sim.terminate(); } } job.Error(String.Format( "Error running simulation: {0}, traceback {1}", ex.Message, ex.StackTrace)); } catch (Exception ex) { Debug.WriteLine(String.Format("Moving Job {0} to Error", job.Id), "SinterConsumerRun.DoRun"); Debug.WriteLine(ex.Message, "SinterConsumerRun.DoRun"); Debug.WriteLine(ex.StackTrace, "SinterConsumerRun.DoRun"); if (job.IsTerminated()) { throw new TerminateException("Job was terminated by producer"); } job.Error(String.Format( "Error running simulation: {0}, traceback {1}", ex.Message, ex.StackTrace)); throw; } }