コード例 #1
0
        public async Task <PopulationRunResults> RunPopulationAsync(IModelCoreSimulation simulation, RunOptions runOptions, DataTable populationData, DataTable agingData = null, DataTable initialValues = null)
        {
            try
            {
                var numberOfCoresToUse = runOptions.NumberOfCoresToUse;
                if (numberOfCoresToUse < 1)
                {
                    numberOfCoresToUse = 1;
                }

                _populationDataSplitter  = new PopulationDataSplitter(numberOfCoresToUse, populationData, agingData, initialValues);
                _cancellationTokenSource = new CancellationTokenSource();
                _populationRunResults    = new PopulationRunResults();

                _numberOfSimulationsToRun     = _populationDataSplitter.NumberOfIndividuals;
                _numberOfProcessedSimulations = 0;

                _simulationName = simulation.Name;
                _parameterCache = _entitiesInSimulationRetriever.ParametersFrom(simulation);

                //create simmodel-XML
                var simulationExport = await CreateSimulationExportAsync(simulation, SimModelExportMode.Optimized);

                //Starts one task per core
                var tasks = Enumerable.Range(0, numberOfCoresToUse)
                            .Select(coreIndex => runSimulation(coreIndex, simulationExport, _cancellationTokenSource.Token)).ToList();

                await Task.WhenAll(tasks);

                //all tasks are completed. Can return results

                _populationRunResults.SynchronizeResults();

                return(_populationRunResults);
            }
            finally
            {
                _populationRunResults   = null;
                _populationDataSplitter = null;
                _parameterCache         = null;
                RaiseTerminated(this, EventArgs.Empty);
            }
        }
コード例 #2
0
        public async Task <PopulationRunResults> RunPopulationAsync(IModelCoreSimulation simulation, DataTable populationData, DataTable agingData = null, DataTable initialValues = null)
        {
            try
            {
                if (NumberOfCoresToUse < 1)
                {
                    NumberOfCoresToUse = 1;
                }

                agingData               = agingData ?? undefinedAgingData();
                initialValues           = initialValues ?? undefinedInitialValues();
                _populationDataSplitter = new PopulationDataSplitter(populationData, agingData, initialValues, NumberOfCoresToUse);
                _cancelationTokenSource = new CancellationTokenSource();
                _populationRunResults   = new PopulationRunResults();

                _numberOfSimulationsToRun     = _populationDataSplitter.NumberOfIndividuals;
                _numberOfProcessedSimulations = 0;

                _simulationName = simulation.Name;
                //create simmodel-XML
                string simulationExport = await CreateSimulationExportAsync(simulation, SimModelExportMode.Optimized);

                //Starts one task per core
                var tasks = Enumerable.Range(0, NumberOfCoresToUse)
                            .Select(coreIndex => runSimulation(coreIndex, simulationExport, _cancelationTokenSource.Token)).ToList();

                await Task.WhenAll(tasks);

                //all tasks are completed. Can return results

                _populationRunResults.SynchronizeResults();

                return(_populationRunResults);
            }
            finally
            {
                _populationRunResults   = null;
                _populationDataSplitter = null;
                RaiseTerminated(this, EventArgs.Empty);
            }
        }