Measuring memory usage

402 views
Skip to first unread message

Kiyo

unread,
Jun 17, 2022, 3:19:31 AM6/17/22
to AMPL Modeling Language
Hi,

I'm using AMPL Python API with CPLEX solver, and I have one question.

Can I measure the memory usage (i.e., the maximum memory usage) during the AMPL process?
If I use 'psutil' of python module, I cannot distinguish the memory usage used by AMPL or other processes.
So, If there is some command in AMPL for measuring the memory usage, I'd like to use it.

Thank you in advance.

AMPL Google Group

unread,
Jun 20, 2022, 10:13:47 AM6/20/22
to AMPL Modeling Language
Which operating system are you using? In order to know the total memory usage the most reliable option is to invoke your python script with "/usr/bin/time -l python script.py" on macOS, or "/usr/bin/time -v python script.py" on Linux. On Windows you may try "psutil.Process(os.getpid()).memory_info_ex().peak_wset", but I am not sure if you will get the total peak usage including all subprocesses. AMPL has options for detailed time and memory usage information during model generation (options: times, gentimes, show_stats), however, that will not give you the maximum amount used since the solver is another process invoked from AMPL and a substancial amount of memory will usually be used by it.


--
Filipe Brandão
am...@googlegroups.com
{#HS:1923541165-110600#}

Kiyo

unread,
Jun 21, 2022, 11:49:54 PM6/21/22
to AMPL Modeling Language
Thank you so much your comment!
I'm using Ubuntu, so I'll try "/usr/bin/time -v python script.py".
At the same time, I'm going to ask to CPLEX support for measuring the memory usage.

Thank you again!

2022年6月20日月曜日 23:13:47 UTC+9 AMPL Google Group:

AMPL Google Group

unread,
Jun 22, 2022, 5:12:52 AM6/22/22
to AMPL Modeling Language
In order to time cplex you can also use /usr/bin/time, you can create a script in the ampl.linux-intel64 directory called for instance cplextime and mark it as executable (cmod +x cplextime) with the following content:

#!/bin/bash
/usr/bin/time -v cplex $*

You can then use it in AMPL:

ampl: model diet.mod;
ampl: data diet.dat;
ampl: option solver cplextime.sh;
ampl: solve;
CPLEX 20.1.0.0:
Command being timed: "cplex /tmp/at72633 -AMPL"

User time (seconds): 0.00

System time (seconds): 0.00

Percent of CPU this job got: 7%

Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.13

Average shared text size (kbytes): 0

Average unshared data size (kbytes): 0

Average stack size (kbytes): 0

Average total size (kbytes): 0

Maximum resident set size (kbytes): 11016

Average resident set size (kbytes): 0

Major (requiring I/O) page faults: 63

Minor (reclaiming a frame) page faults: 351

Voluntary context switches: 58

Involuntary context switches: 0

Swaps: 0

File system inputs: 12488

File system outputs: 8

Socket messages sent: 0

Socket messages received: 0

Signals delivered: 0

Page size (bytes): 4096

Exit status: 0
optimal solution; objective 88.2
1 dual simplex iterations (0 in phase I)
ampl:



--
Filipe Brandão
am...@googlegroups.com
{#HS:1923541165-110600#}
On Wed, Jun 22, 2022 at 3:50 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thank you so much your comment!
I'm using Ubuntu, so I'll try "/usr/bin/time -v python script.py".
At the same time, I'm going to ask to CPLEX support for measuring the memory usage.

Thank you again!

2022年6月20日月曜日 23:13:47 UTC+9 AMPL Google Group:

Which operating system are you using? In order to know the total memory usage the most reliable option is to invoke your python script with "/usr/bin/time -l python script.py" on macOS, or "/usr/bin/time -v python script.py" on Linux. On Windows you may try "psutil.Process(os.getpid()).memory_info_ex().peak_wset", but I am not sure if you will get the total peak usage including all subprocesses. AMPL has options for detailed time and memory usage information during model generation (options: times, gentimes, show_stats), however, that will not give you the maximum amount used since the solver is another process invoked from AMPL and a substancial amount of memory will usually be used by it.

--
Filipe Brandão
On Mon, Jun 20, 2022 at 2:13 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Which operating system are you using? In order to know the total memory usage the most reliable option is to invoke your python script with "/usr/bin/time -l python script.py" on macOS, or "/usr/bin/time -v python script.py" on Linux. On Windows you may try "psutil.Process(os.getpid()).memory_info_ex().peak_wset", but I am not sure if you will get the total peak usage including all subprocesses. AMPL has options for detailed time and memory usage information during model generation (options: times, gentimes, show_stats), however, that will not give you the maximum amount used since the solver is another process invoked from AMPL and a substancial amount of memory will usually be used by it.


--
Filipe Brandão
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages