Exemplo n.º 1
0
        /// <summary>Find simulations/experiments to run.</summary>
        /// <param name="model">The model and its children to search.</param>
        /// <param name="parentJob">The parent job to add the child jobs to.</param>
        /// <param name="simulationNames">Simulations names found.</param>
        private void FindAllSimulationsToRun(IModel model, JobParallel parentJob, List <string> simulationNames)
        {
            // Get jobs to run and give them to job manager.
            List <JobManager.IRunnable> jobs = new List <JobManager.IRunnable>();

            if (model is Experiment)
            {
                parentJob.Jobs.Add(model as Experiment);
                simulationNames.AddRange((model as Experiment).Names());
            }
            else if (model is Simulation)
            {
                simulationNames.Add(model.Name);
                if (model.Parent == null)
                {
                    parentJob.Jobs.Add(model as Simulation);
                }
                else
                {
                    parentJob.Jobs.Add(new RunClonedSimulation(model as Simulation));
                }
            }
            else
            {
                // Look for simulations.
                foreach (Model child in model.Children)
                {
                    if (child is Experiment || child is Simulation || child is Folder)
                    {
                        FindAllSimulationsToRun(child, parentJob, simulationNames);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Called to start the job.</summary>
        /// <param name="jobManager">The job manager running this job.</param>
        /// <param name="workerThread">The thread this job is running on.</param>
        public void Run(JobManager jobManager, BackgroundWorker workerThread)
        {
            JobSequence   parentJob       = new JobSequence();
            JobParallel   simulationJobs  = new JobParallel();
            List <string> simulationNames = new List <string>();

            FindAllSimulationsToRun(model, simulationJobs, simulationNames);
            parentJob.Jobs.Add(simulationJobs);
            parentJob.Jobs.Add(new RunAllCompletedEvent(simulations));

            // IF we are going to run all simulations, we can delete all tables in the DataStore. This
            // will clean up order of columns in the tables and removed unused ones.
            // Otherwise just remove the unwanted simulations from the DataStore.
            DataStore store = Apsim.Child(simulations, typeof(DataStore)) as DataStore;

            if (model is Simulations)
            {
                store.DeleteAllTables(true);
            }
            else
            {
                store.RemoveUnwantedSimulations(simulations, simulationNames);
            }
            store.Disconnect();

            if (runTests)
            {
                foreach (Tests tests in Apsim.ChildrenRecursively(model, typeof(Tests)))
                {
                    parentJob.Jobs.Add(tests);
                }
            }
            jobManager.AddChildJob(this, parentJob);
        }
Exemplo n.º 3
0
    private void Update()
    {
        for (int i = 0; i < 1000; i++)
        {
            NativeArray <float> values = new NativeArray <float>(500, Allocator.TempJob);
            var job = new JobParallel()
            {
                values = values, offset = 5
            };

            JobHandle jobHandle = job.Schedule(values.Length, 32);
            jobHandle.Complete();
            values.Dispose();
        }
    }