[AMPL 24593] Differences solver times and real time

Hi AMPL teams,

I am using visual studio community 2022 with API of AMPL for C++ to solve large instances of MIP problems. when calculating the solution time of a large problem, I do it with the c++ chrono commands calculating only the “solve” line (time cpp). and when comparing with the AMPL solver time commands. I find that the closest time to the cpp is the “_ampl_elapsed_time”.

  1. Does this last time represent the calculation of the whole AMPL process, from reading, to solving?
  2. Why does the “_total_solve_elapsed_time” differ so much from the real time?

I attach a sample of the time calculation in c++, and a .mod and .dat of a large worked problem

Times:

_ampl_elapsed_time = 4.953
_ampl_system_time = 0.203125
_ampl_user_time = 4.67188
_ampl_time = 4.875
_shell_elapsed_time = 0
_shell_system_time = 0
_shell_user_time = 0
_shell_time = 0
_solve_elapsed_time = 0.156
_solve_system_time = 0.15625
_solve_user_time = 0.53125
_solve_time = 0.6875
_total_shell_elapsed_time = 0
_total_shell_system_time = 0
_total_shell_user_time = 0
_total_shell_time = 0
_total_solve_elapsed_time = 0.156
_total_solve_system_time = 0.15625
_total_solve_user_time = 0.53125
_total_solve_time = 0.6875

time cpp: 5.101 s.

c++ chrono time:

auto tiniR5 = chrono::high_resolution_clock::now(); //inicicializo el tiempo
ampl.getOutput(“solve;”);
auto tfinR5 = chrono::high_resolution_clock::now(); //inicicializo el tiempo
double durationauxR5 = chrono::duration_castchrono::milliseconds (tfinR5 - tiniR5).count() / double(1000);
cout << durationauxR5 << " ";

Many thanks in advance for your help.

Modex.mod (23 KB)

eje.run (774 Bytes)

date.dat (33.5 KB)

When the AMPL application runs a solver, it spawns a separate solver process, and waits for that process to finish before continuing. Since AMPL and the solver are never running at the same time, their elapsed time can be separated out:

  • _solve_elapsed_time = time taken for the most recent solver process
  • _total_solve_elapsed_time = sum of _solve_elapsed_time for all solver processes
  • _ampl_elapsed_time = time taken by the AMPL process, not counting any solver process times
    The total elapsed time for an AMPL session is _ampl_elapsed_time + _total_solve_elapsed_time. In your example this is 4.953 + 0.156 = 5.109 which is consistent with the “time cpp” that you record.

Here are some details to note:

  1. Timing starts when the AMPL application begins running, and whenever there is a “reset;”.
  2. The _solve_time is the sum of the “CPU times” on all of the processor cores. Thus when a solver like CPLEX uses multiple cores in parallel, the _solve_elapsed_time is a much better measure of effectiveness.

Is there any package working within AMPL to produce graphs after solving problem. Also related, is there any econometrics package implemented in AMPL that I can use. Am trying to avoid moving around various softwares.

John

You will need to provide these facilities from other software. Python, R, and MATLAB are good for these purposes, and there are interfaces (APIs) for connecting AMPL to them; more information is available on our AMPL APIs page.