AvailableThreads: Integer;
The AvailableThreads property determines the number of threads on modeling problem calculation.
Features of property use:
If the property is set to 0, the number of processor cores is used to calculate modeling problem.
If the property is set to 1, the single-threaded modeling problem calculation is used.
The property value affects the IMsCalculationChainMultiDimIterator.MultiThreaded property if multithreaded calculation of multidimensional iterators is used.
Executing the example requires that the repository contains a modeling problem with the PROBLEM identifier and a metamodel with the METAMODEL identifier that is used on modeling problem calculation.
Add links to the Metabase, Ms system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Problem: IMsProblem;
Settings: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
Start, Stop, Temp: Integer;
MetaModel: IMsMetaModel;
Chain: IMsCalculationChainEntries;
i: Integer;
Iter: IMsCalculationChainMultiDimIterator;
Begin
MB := MetabaseClass.Active;
// Get modeling problem
Problem := MB.ItemById("PROBLEM").EditTemporary As IMsProblem;
// Get metamodel and metamodel calculation chain
MetaModel := MB.ItemById("METAMODEL").Edit As IMsMetaModel;
Chain := MetaModel.CalculationChain;
// Enable multidimensional calculation for calculation chain elements
For i := 0 To Chain.Count - 1 Do
If Chain.Item(i).Type = MsCalculationChainEntryType.MultiDimIterator Then
Iter := Chain.Item(i) As IMsCalculationChainMultiDimIterator;
Iter.MultiThreaded := True;
End If;
End For;
(MetaModel As IMetabaseObject).Save;
// Get settings used on modeling problem calculation
Settings := Problem.CreateCalculationSettings;
// Set number of threads for calculation
Settings.AvailableThreads := 4;
// Create an object that calculates problem
Calc := Problem.Calculate(Settings);
Calc.SaveData := False;
Calc.OverwriteSameValues := False;
Start := DateTime.Ticks;
// Calculate modeling problem
Calc.Run;
// Calculate time time spent on calculation and display it in the console
Stop := DateTime.Ticks;
Temp := Stop - Start;
Debug.WriteLine("Time spent on calculation: " + (Temp / 1000).ToString + " sec");
End Sub UserProc;
After executing the example, the modeling problem is calculated using multithreaded calculation of multidimensional iterator to speed up modeling problem calculation. The console displays the time spent on modeling problem calculation.
See also: