haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Quintiq file version 2.0
#parent: #root
Method CanStart () as Boolean
{
  Description:
  [*
    This method checks if the `LibOpt_Run` that corresponds to this `LibOpt_ControllerRun` can be started. 
    This method is called every `LibOpt_OptimizerRunController.PollingDuration` milliseconds until it returns `true`.
  *]
  TextBody:
  [*
    // evr3 Apr-26-2022 (created)
    controller := this.OptimizerRunController();
    
    // The run that was requested the longest ago will start first, even when new runs could already start
    // This is to ensure that new runs that request few threads won't block an old run that requests many threads.
    canstart := controller.FirstUnstartedRun() = this 
                and controller.ConcurrentRuns() < controller.ConcurrentRunsMax()
                and controller.CPUThreadsUsedTotal() + this.CPUThreadsRequested() <= controller.CPUThreadsMax(); 
    
    if( canstart )
    {
      // It is very tempting to call StartRun reactively so that we can make CanStart const. 
      // However, you don't want to do that, as the start attributes need to be set in the same transaction.
      // This ensures that CPUThreadsUsedTotal is correct when another run calls CanStart.
      this.Start();
    }
    
    return canstart;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}