Пример #1
0
 public void Start()
 {
     CurrentProgress = () => Child.Progress;
     foreach (var runName in ExecuteRuns())
     {
         try
         {
             RunName = runName;
             Child.Start();
         }
         catch (ThreadAbortException)
         {
             // in any case we continue to exit on a thread abort exception
             throw;
         }
         catch (Exception e)
         {
             if (!ContinueAfterError)
             {
                 throw;
             }
             SaveException(e);
         }
         if (Exit)
         {
             return;
         }
     }
 }
Пример #2
0
 private void InitializeHost()
 {
     if (HostModelSystem != null)
     {
         Status = () => "Running host model system";
         HostModelSystem.Start();
     }
 }
Пример #3
0
        private void OurRun()
        {
            string cwd   = null;
            string error = null;

            try
            {
                this.MST = this.Project.CreateModelSystem(ref error, this.ModelSystemIndex);
            }
            catch (Exception e)
            {
                SendValidationError(e.Message);
                return;
            }
            if (MST == null)
            {
                SendValidationError(error);
                return;
            }
            var MSTStructure = this.Project.ModelSystemStructure[this.ModelSystemIndex];

            try
            {
                AlertValidationStarting();
                var path = Path.Combine(this.Config.ProjectDirectory, this.Project.Name, this.RunName);
                cwd = System.IO.Directory.GetCurrentDirectory();
                System.IO.Directory.SetCurrentDirectory(path);
                MSTStructure.Save(Path.GetFullPath("RunParameters.xml"));
                if (!this.RunTimeValidation(ref error, MSTStructure))
                {
                    this.SendRuntimeValidationError(error);
                }
                else
                {
                    this.SetStatusToRunning();
                    MST.Start();
                }
            }
            catch (Exception e)
            {
                this.SendRuntimeError(e);
            }
            finally
            {
                Thread.MemoryBarrier();
                this.CleanUpModelSystem(MSTStructure);
                MSTStructure = null;
                MST          = null;
                (this.Config as Configuration).ModelSystemExited();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                Thread.MemoryBarrier();
                System.IO.Directory.SetCurrentDirectory(cwd);
                SendRunComplete();
            }
        }
Пример #4
0
 public void Start()
 {
     try
     {
         SetupNetworkInterface();
         MainModelSystem.Start();
     }
     finally
     {
         Host.Shutdown();
     }
 }
Пример #5
0
 public void Start()
 {
     InitializeNetworking();
     if (Initialization != null)
     {
         Initialization.Start();
     }
     SignalReady();
     while (!Exit)
     {
         Thread.Sleep(10);
     }
 }
Пример #6
0
 public void Start()
 {
     CurrentProgress = () => Child.Progress;
     if (CopyBatchFileTo != null)
     {
         try
         {
             File.Copy(BatchRunFile.GetFilePath(), CopyBatchFileTo.GetFilePath(), true);
         }
         catch (IOException e)
         {
             throw new XTMFRuntimeException(this, e, $"Unable to copy the multi-run batch file {CopyBatchFileTo.GetFilePath()}. {e.Message}");
         }
     }
     foreach (var runName in ExecuteRuns())
     {
         try
         {
             RunName = runName;
             Child.Start();
         }
         catch (ThreadAbortException)
         {
             // in any case we continue to exit on a thread abort exception
             throw;
         }
         catch (Exception e)
         {
             if (!ContinueAfterError)
             {
                 throw;
             }
             SaveException(e);
         }
         if (Exit)
         {
             return;
         }
     }
 }
Пример #7
0
        private void RunModelSystem(out List <ErrorWithPath> errors, IModelSystemStructure mstStructure)
        {
            errors = new List <ErrorWithPath>(0);
            AlertValidationStarting();
            // check to see if the directory exists, if it doesn't create it
            DirectoryInfo info = new DirectoryInfo(RunDirectory);

            if (!info.Exists)
            {
                info.Create();
            }
            Directory.SetCurrentDirectory(RunDirectory);
            mstStructure.Save(Path.GetFullPath("RunParameters.xml"));

            if (!RunTimeValidation(new List <int>(), errors, mstStructure))
            {
                InvokeRuntimeValidationError(errors);
            }
            else
            {
                SetStatusToRunning();
                _MST.Start();
            }
        }
Пример #8
0
        public void Start()
        {
            int generation = 0;

            Status = () => "Initializing Parameters";
            LoadParameters();
            Status = () => "Initializing Networking";
            SetupNetworking();
            // ReSharper disable InconsistentlySynchronizedField
            PendingResults = new BlockingCollection <ResultMessage>();
            using (var finishedGeneration = new MessageQueue <bool?>())
            {
                //execute the host model system
                Status = () => "Running Host Model System";
                HostModelSystem?.Start();
                Status = () => "Distributing Tasks: Generation " + (CurrentIteration + 1) + " / " + TotalIterations;
                Task processResults = Task.Factory.StartNew(() =>
                {
                    foreach (var result in PendingResults.GetConsumingEnumerable())
                    {
                        // only process things from the current generation
                        // ReSharper disable once AccessToModifiedClosure
                        if (generation == result.Generation)
                        {
                            lock (CurrentJobs)
                            {
                                var currentJob       = CurrentJobs[result.ProcessedIndex];
                                currentJob.Value     = result.ProcessedValue;
                                currentJob.Processed = true;
                                // store the result before starting the next generation
                                // so the AI can play with the values after we write
                                StoreResult(currentJob);
                            }
                            Progress += 1.0f / (TotalIterations * CurrentJobs.Count);
                            //scan the rest of the jobs to see if they have been processed
                            // ReSharper disable once AccessToDisposedClosure (Task Finishes before closer ends)
                            finishedGeneration.Add(CheckForAllDone());
                        }
                    }
                });

                for ( ; generation < TotalIterations & Exit == false; generation++)
                {
                    CurrentIteration = generation;
                    CurrentJobs      = AI.CreateJobsForIteration();
                    System.Threading.Thread.MemoryBarrier();
                    StartGeneration();
                    bool?done;
                    while (Exit == false && (done = finishedGeneration.GetMessageOrTimeout(100)) != true)
                    {
                        if (done == null && Host.ConnectedClients.Count > 0)
                        {
                        }
                        System.Threading.Thread.MemoryBarrier();
                    }
                    AI.IterationComplete();
                    // make sure to clear this to make sure we exit fine
                    System.Threading.Thread.MemoryBarrier();
                }
                PendingResults.CompleteAdding();
                processResults.Wait();
            }
            if (ResultFileWriter != null)
            {
                ResultFileWriter.Close();
            }
            lock (Host)
            {
                foreach (var client in Host.ConnectedClients)
                {
                    client.SendCancel("End of model run");
                }
            }
            Host.Shutdown();
        }
Пример #9
0
        private void OurRun()
        {
            string cwd   = null;
            string error = null;
            IModelSystemStructure MSTStructure;

            try
            {
                if (ModelSystemStructureModelRoot == null)
                {
                    MST          = Project.CreateModelSystem(ref error, ModelSystemIndex);
                    MSTStructure = Project.ModelSystemStructure[ModelSystemIndex];
                }
                else
                {
                    MST          = ((Project)Project).CreateModelSystem(ref error, Configuration, ModelSystemStructureModelRoot.RealModelSystemStructure);
                    MSTStructure = ModelSystemStructureModelRoot.RealModelSystemStructure;
                }
            }
            catch (Exception e)
            {
                SendValidationError(e.Message);
                return;
            }
            if (MST == null)
            {
                SendValidationError(error);
                return;
            }

            try
            {
                AlertValidationStarting();
                cwd = Directory.GetCurrentDirectory();
                // check to see if the directory exists, if it doesn't create it
                DirectoryInfo info = new DirectoryInfo(RunDirectory);
                if (!info.Exists)
                {
                    info.Create();
                }
                Directory.SetCurrentDirectory(RunDirectory);
                MSTStructure.Save(Path.GetFullPath("RunParameters.xml"));
                if (!RunTimeValidation(ref error, MSTStructure))
                {
                    SendRuntimeValidationError(error);
                }
                else
                {
                    SetStatusToRunning();
                    MST.Start();
                }
            }
            catch (Exception e)
            {
                if (!(e is ThreadAbortException))
                {
                    SendRuntimeError(e);
                }
            }
            finally
            {
                Thread.MemoryBarrier();
                CleanUpModelSystem(MSTStructure);
                MSTStructure = null;
                MST          = null;
                if (Configuration is Configuration)
                {
                    ((Configuration as Configuration)).ModelSystemExited();
                }
                else
                {
                    ((Configuration as RunProxy.ConfigurationProxy)).ModelSystemExited();
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                Thread.MemoryBarrier();
                Directory.SetCurrentDirectory(cwd);
                SendRunComplete();
            }
        }
Пример #10
0
 private void OurRun()
 {
     string cwd = null;
     string error = null;
     try
     {
         this.MST = this.Project.CreateModelSystem( ref error, this.ModelSystemIndex );
     }
     catch ( Exception e )
     {
         SendValidationError( e.Message );
         return;
     }
     if ( MST == null )
     {
         SendValidationError( error );
         return;
     }
     var MSTStructure = this.Project.ModelSystemStructure[this.ModelSystemIndex];
     try
     {
         AlertValidationStarting();
         var path = Path.Combine( this.Config.ProjectDirectory, this.Project.Name, this.RunName );
         cwd = System.IO.Directory.GetCurrentDirectory();
         System.IO.Directory.SetCurrentDirectory( path );
         MSTStructure.Save( Path.GetFullPath( "RunParameters.xml" ) );
         if ( !this.RunTimeValidation( ref error, MSTStructure ) )
         {
             this.SendRuntimeValidationError( error );
         }
         else
         {
             this.SetStatusToRunning();
             MST.Start();
         }
     }
     catch ( Exception e )
     {
         this.SendRuntimeError( e );
     }
     finally
     {
         Thread.MemoryBarrier();
         this.CleanUpModelSystem( MSTStructure );
         MSTStructure = null;
         MST = null;
         ( this.Config as Configuration ).ModelSystemExited();
         GC.Collect();
         GC.WaitForPendingFinalizers();
         GC.Collect();
         Thread.MemoryBarrier();
         System.IO.Directory.SetCurrentDirectory( cwd );
         SendRunComplete();
     }
 }