Perform Solution While Specifying Solution Handler and the Number of Cores

Goal

The following script executes the solution process and:

  1. Sets the Solution Process Settings to the My Computer, Background setting.

  2. Completes solutions for core settings.

  3. Tracks how long each solution takes when solved using a different number of cores.

Code

# Get the existing My Computer, Background solve configuration
config =  ExtAPI.Application.SolveConfigurations["My Computer, Background"]
config.SetAsDefault()

for cores in range(8,13):
    config.SolveProcessSettings.MaxNumberOfCores = cores
    Model.Analyses[0].Solution.ClearGeneratedData()
    # pass in True to wait for the solve to complete
    Model.Analyses[0].Solution.Solve(True)
    Model.Analyses[0].Solution.GetResults()
    elapsed_time = Model.Analyses[0].Solution.ElapsedRunTime
    print "%d cores took %d secs" % (cores, elapsed_time)