Differences solver times and real time

36 views
Skip to first unread message

Jhoan Duque

unread,
Mar 23, 2023, 11:50:33 PM3/23/23
to AMPL Modeling Language
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_cast<chrono::milliseconds> (tfinR5 - tiniR5).count() / double(1000);
            cout << durationauxR5 << " ";

Many thanks in advance for your help.
Modex.mod
eje.run
date.dat

AMPL Google Group

unread,
Mar 25, 2023, 3:43:22 PM3/25/23
to AMPL Modeling Language
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.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2193254957-115327#}

John Matovu

unread,
Apr 2, 2023, 11:08:13 AM4/2/23
to am...@googlegroups.com
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 received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-2193254957-6542570273-1679773399-1659207136%40helpscout.net.
--
Matovu John Mary
RTDC
Tel: 256-776-130913

AMPL Google Group

unread,
Apr 3, 2023, 1:58:12 PM4/3/23
to AMPL Modeling Language
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.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2193254957-115327#}
On Sun, Apr 2, 2023 at 3:08 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
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

On Sat, Mar 25, 2023 at 7:43 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
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.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
Reply all
Reply to author
Forward
0 new messages