memmon1.gms : Test procTreeMemMonitor=1 behavior

Description

Test that if we run a model that uses a good chunk of memory, this
memory usage is reported properly with procTreeMemMonitor=1.

Contributor: Steve, Jun 2020
  On the major platforms (Windows, Linux, Mac), GMSPYTHONLIB gets automatically set
  to use the internal Python installation in sysdir/GMSPython.


Small Model of Type : GAMS


Category : GAMS Test library


Main file : memmon1.gms

$title 'Test procTreeMemMonitor=1 behavior' (MEMMON1,SEQ=823)

$ontext
Test that if we run a model that uses a good chunk of memory, this
memory usage is reported properly with procTreeMemMonitor=1.

Contributor: Steve, Jun 2020
$offtext
* On the major platforms (Windows, Linux, Mac), GMSPYTHONLIB gets automatically set 
* to use the internal Python installation in sysdir/GMSPython.
$if not setEnv GMSPYTHONLIB $abort.noError Embedded code Python not ready to be used
$log --- Using Python library %sysEnv.GMSPYTHONLIB%


$onecho > muchmem.gms
sets
  i / i1 * i4 /
  j / j1 * j1000 /
  k / k1 * k1100 /
  ;
parameters  a(i,j,k), b(i,j,k), c(i,j,k);
scalar t;
a(i,j,k) = 77 + ord(i);
b(i,j,k) = (ord(j) + 3 * sin(a(i,j,k)))*pi + log(ord(k));
c(i,j,k) = a(i,j,k) + b(i,j,k+1) * 10;
t = sum{(i,j,k), b(i,j,k) + c(i,j,k)};
t = t + sleep(2.5);
display t;
$offecho

$call.checkErrorLevel gams muchmem.gms lo=2 procTreeMemMonitor=1
$onEmbeddedCode Python:
target = 400000000 # made larger so it fails
with open('muchmem.log') as fp:
  for l in fp:
    r = l.split()
    if len(r)>0 and r[0]=='highwater' and r[1] in ['VSS:','RSS:'] and int(r[2])<=target:
      raise NameError(f'\n***\n*** {r[1][:-1]} too small: want ({r[1][:-1]}={r[2]}) > (target={target})')
$offEmbeddedCode
$if not errorfree $abort Test failed

$log Test passed