GAMS [ Home | Support | Sales | Solvers | Documentation | Model Libraries | Search | Contact Us ]

GAMS FAQ for keyword: PLATFORM


How can a GAMS process communicate with another process
Sometimes, you want to exchange data between a running
GAMS process and some other process.  The following example
shows how to do that.  Here a GAMS program and a C program
continuously exchange data (a scalar).  The communication
is done through ASCII and GDX files and the synchronization
through some semaphores:

$Title Trivial example of two asynchronous processes
(one is GAMS) that exchange data through ASCII files

$onechoV > wait.cmd
@echo off
printf "--- Waiting for %1%done"
:loop
if exist %1%done goto finish
printf "."
sleep 5
goto loop
:finish
printf "\n"
rm -f %1%done
$offecho

$onechoV > read.gms
Scalar Ccnt /
$include Ccnt.txt
/
$offecho

* C Program that reads data from GAMS and provides date for a running GAMS job
$onechoV > gc.c
#include 

void main() {
  FILE *fp;
  int  Gcnt=0;

  printf("C - Program started\n");

  while (Gcnt<10) {
    system("wait.cmd G");           /* Wait for GAMS to write Gcnt.txt */

    printf("--- Reading Gcnt.txt\n"); /* Read Gcnt.txt */
    fp = fopen("Gcnt.txt","r");
    fscanf(fp,"%d",&Gcnt);
    fclose(fp);

    Gcnt = 2*Gcnt;
    printf("--- Writing Ccnt.txt (%d)\n", Gcnt); /* Write Ccnt.txt */
    fp = fopen("Ccnt.txt","w");
    fprintf(fp,"%d",Gcnt);
    fclose(fp);
    system("touch Cdone"); /* Tell the GAMS program we are done writing */
  }
  printf("C - Program terminated\n");
}
$offecho
* Next line call your favorite C compiler
* $call cl gc.c

* Remove old semaphores
$call rm -f Cdone Gdone

* Start up the C Program (you can start this also from a different Window)
$call start cmd /K gc.exe

* The GAMS Process
$eolcom //
scalar cnt /3/;
file fx / Gcnt.txt /;

while (cnt < 10,
  cnt=cnt - 1;
  putclose fx cnt:0:0                       // write out the current scalar
  execute 'touch Gdone';                    // Tell the C program GAMS writing is done
  execute 'wait.cmd C';                     // wait for the C program to write out the updated scalar
  execute 'gams read.gms gdx read.gdx lo=2' // From the ASCII file with the scalar create a GDX file
  execute_load 'read', cnt=Ccnt;            // Load the updated scalar from the GDX file
  display cnt;
);

* make sure the C program also gets to write out the current scalar
putclose fx cnt:0:0
execute 'touch Gdone';

How to get 3 GB of memory for a single process under Windows XP Professional
The maximum amount of memory that can be supported on Windows XP
Professional is 4 GB. (see for details:
http://www.microsoft.com/whdc/system/platform/server/pae/PAEmem.mspx)

The virtual address space of processes and applications is still
limited to 2 GB unless the application is enabled for a larger address
space *and* the XP machine is configured to support the extended
address space.

I)  Enable application for extended address space
    a) Have GAMS distribution 21.4 or higher
or b) Set the LARGEADDRESSAWARE flag for all executables in the GAMS
       system directory using binedit. binedit is part of MS Visual
       Studio (experts only!)
II) Configure your machine for extended address space
    a) Edit your boot.ini (see details
       http://support.microsoft.com/default.aspx?scid=kb;EN-US;q289022).
       Add the /3GB switch to the line with /fastdetect:
       multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP
Professional" /fastdetect /3GB
    b) Increase the size of the paging file on your machine to 4 GB.
       My Computer->Properties->Advanced->Performance
Settings->Advanced->Virtual Memory Change

III) Reboot.

Now your machine should be ready for the extended address space.

The mem.exe utility (http://www.gams.com/contrib/mem.exe) allocates
memory in one MB chunks and stops when the OS refuses to provide more
memory. This can be used as a quick test, if the configuration of your
system worked:

- without the /3GB switch you should get less than 2 GB, something like
      1919 MB allocated
- with the /3 GB switch you should get close to 3 GB, like:
      2882 MB allocated

We experienced some instability of the OS on a machine with only 2 GB
of core memory after enabling the /3GB switch, so we recommend only to
turn the /3GB switch on if your machine has at least 3 GB of real memory.

GAMS crash after upgrade to Windows 2000
Upgrading from Windows 95/98/ME to W2k by installing on top of the old OS may
create problems with the 'ComSpec' environment variable which will cause GAMS
to crash:
C:\temp>gams trnsport
...
---    6 rows, 7 columns, and 19 non-zeroes.
--- Executing BDMLP
Bad command or file name
--- Restarting execution
...

Look for the 'ComSpec' environment, it should end with  '\cmd.exe' as shown
below.

C:\temp>set
...
ComSpec=C:\WINNT\system32\cmd.exe
...

In some cases the old 16 bit command processor 'command.com' is specified
instead. This needs to be changed to cmd.exe.
To change the values of 'ComSpec' you need to be logged in as administrator
to your local computer.
1.	Open  System in Control Panel.
2.	On the Advanced tab, click Environment Variables, then click on the
        'ComSpec' system variable and click Edit to correct the entry.

How do I run GAMS in the background on a UNIX machine?
> How do I run GAMS in the background?
>
>     gams trnsport &
>
> does not seem to work.

That is correct. GAMS writes directly to /dev/tty and a
background job does not have access to that. The following command
will do the job:

     gams -lo 0 trnsport &

The log option flag tells GAMS not to write anything to the screen.
An even better way is to use a small script called "gamsbatch" that
reads:

     #!/bin/csh -f
     set basename=$1:r
     gams $* -ll 1 -lo 2 -lf $basename.log &

This will write what normally goes to the screen to a log file instead.
For example, if called as "gamsbatch trnsport", transport.log will be
created. Many GAMS systems contain this script. If not, it can be
created and made executable by using "chmod +x gamsbatch".

On some systems after you log out even background processes will
get killed. On those systems use:

     nohup gamsbatch trnsport

Now it is safe to log off and go home.

Finding GAMS errors using the vi editor
> On my UNIX workstation I use vi as my editor. Using vi it is
> difficult to find the error messages in the GAMS listing, which are
> marked by '****'.

Vi will interpret the * as a wildcard, just like for instance the '.'
and the '$. You can instruct vi not to do this by saying:

     set nomagic

You even can put this in your .exrc file (in your home directory), so
that this is executed each time you start up vi.

The other possibility is to have GAMS not write stars but something
else, like '%%%%'. This can be accomplished with the dollar control
statement:

     $stars '%%%%'

How much memory does my UNIX box have ?
> How can I find out how much memory I have on my UNIX
> workstation?

This is a tricky question. First of all there are different sorts of
memory. First there is the amount of RAM installed on the machine,
then there is the amount of virtual memory available, and the amount
of memory a user can get.

First the RAM or real memory. On some machine the boot sequence
displays how much RAM there is on the system, and for instance on
the SUN running SUNOS 4.x one can find out what this was by
saying:

     /etc/dmesg | grep mem

which displays something like:

     mem = 16384K (0x1000000) avail mem = 14938112

Because GAMS and most of the solvers under GAMS access
memory rather randomly with the notion of locality this gives you
important information: solving models that require more workspace
than this number will result in lots of disk I/O, and slowing down of
the system (trashing). Another way to find this onformation is on the
invoice of your computer.

The amount of virtual memory can be interrogated by for instance on
a SUN:

     /etc/pstat -s

which outputs:

     1648k allocated + 468k reserved = 2116 used, 41752k available

on a SUN, and for instance for the RS/6000:

     /etc/lsps -a

which says:

Page Space  Physical Volume   Volume Group    Size   %Used  Active  Auto  Type
hd62        hdisk2            rootvg          24MB       9     yes   yes    lv
hd61        hdisk1            rootvg          24MB       9     yes   yes    lv
hd6         hdisk0            rootvg         424MB       2     yes   yes    lv

The amount of virtual memory should be large than the amount of real
memory.

The amount of memory an individual user can get is an other story. Of
course the amount of virtual memory is an upperbound, but quota's
can reduce this further. On AIX for instance smit user allows the
super user to change user limits. When running the c-shell (csh) the
command limit will display user limits:

        cputime        unlimited
        filesize       unlimited
        datasize       524280 kbytes i
        stacksize      8192 kbytes
        coredumpsize   unlimited
        memoryuse      unlimited
        descriptors    64

One other easy way is to write a small c program that allocates
memory, and tells how much it can allocate:

#include

#define KB  1024
#define MB  (1000*KB)

long maxavail(init)
long init;
{
     long lo, up, new;
     char *p;
     long maxdiff;

     /* find initial interval */
     lo = 0;
     up = init;
     while ( (p = malloc(up)) != NULL) {
       free(p);
       lo = up;
        up = 2*up;
     }


     /* now reduce interval to acceptable size */
     maxdiff = KB;

     while ( (up-lo) > maxdiff ) {
        new = (up+lo) / 2;
        if ( (p = malloc(new)) != NULL) {
                free(p);
                lo = new;
        }
        else
                up = new;
     }

     return(lo);
}

main() {

       long avail;
        double mb;

       avail = maxavail(MB);
       mb = ((double) avail)/((double)MB);
       printf("Could allocate %g MB\n",mb);
}

On some systems this is still an overestimate, because until you
physically touch all the pages, it is still not sure you can get the
memory. On AIX for instance a process may be killed by the
operating system, because not enough swap space (virtual memory)
was available, when is was really needed. This is sometimes difficult
to trace down. AIX offers a version of malloc that really touches all
the pages called psmalloc, the source of which can be found in
/usr/lpp/bos/samples/psmalloc.c.

Notice that on some systems (BSD, AIX 3.1) one extra byte
requested can result in a doubling of the memory allocated to your
process. On these system memory is allocated using the buddy
systems, which uses blocks in sizes of powers of two. This is done
to keep the fragmentation of the memory space small. Fragmentation
results in many free blocks which are very small, and quite useless,
so that a job requesting a big block can not run, while the total of free
space would be sufficient.

In GAMS we use dynamic memory inside GAMS itself where we use
Pascal's new or C's malloc. Allocation and freeing of memory in very
small chunks is on most machines very expensive, therefore we
allocate larger blocks, which we manage then ourselves. For the
solvers written in C (Cplex, Loqo, XA) malloc is used. Fortran does
not have dynamic memory, but most Fortran based solvers under
GAMS use the GAMS interface software which provides means to
allocate a large array, which then can be partitioned into useful
arrays. On many machines this is done by a wrapper around malloc.
We don't use psmalloc on AIX because it is rather slow.

Missing /bin/csh on AIX
> I tried to run GAMS on my RS/6000 running AIX, but it was
> complaining that it could not find /bin/csh.

Parts of the GAMS system are shell scripts written in c-shell.
These parts need to be executed by the c-shell which is invoked by
/bin/csh. The c-shell on AIX is an optional program product, and is
not loaded to the hard disk if you do a minimal installation. To install
the c-shell afterwards, become super- user, put the original AIX
distribution tape in the tape drive, and run smit instupdt. Follow the
directions and answer the questions in the SMIT menus. Choose the
package: bosext1.csh.obj. For more information consult the
installation guide of AIX.

GAMS/CPLEX license transfer with the GAMSIDE
To transfer a GAMS/CPLEX license from one PC to another do the
following.

0) Assume a GAMS/CPLEX is installed on machine A, you want to
   transfer it to B

1) Open the GAMSIDE on B an create an initial GAMS/CPLEX license code
   by running:

   File->Options->Licenses->Cplex->Get initial license code

   You will get a 28 character hexcode.

2) Open the GAMSIDE on A an run

   File->Options->Licenses->Cplex->Transfer a license

   You will be ask to enter a code. Please enter the code you obtained
   in step 1. You will get another 28 character hexcode.

3) Go back to machine B and run

   File->Options->Licenses->Cplex->Update exisiting license

   You will be ask to enter a code. Please enter the code you obtained
   in step 2.

That's it.

Excecuting GAMS using the run command in Windows
> I am using RUN in Windows to run the file. I want GAMS to save (write) my
> output (*.lst) file also in the subdirectory where the *.gms is located.

GAMS depends on the current directory to locate source files and to
place output files.  It is difficult to generalize this when you use
the Run command. I think you would find it much easier to use a
command prompt (also called a console) from within Windows.  From the
console, cd to the directory containing the gams source file and just
do

gams myfile.gms

Also, if you want to avoid the command prompt, you can use the GAMS IDE,
our Windows integrated development environment.  This is a powerful tool
for running GAMS under Windows.  You can download the IDE and the latest
GAMS system for trial by going to the URL
http://www.gams.de/5download/cd.htm.

How to use GAMS from a Unix shell

> Could you give me some clue as to how to run my MIP model on UNIX.

On a Unix box you are best of doing the following, all at the Unix
command prompt:

1. Make sure the gams system directory is in your PATH.
2. cd to a directory you will put your model in (e.g. ~/models/superfund)
3. gamslib trnsport
4. gams trnsport

If you can do steps 3 and 4 to solve the transport model (see the
tutorial section of the GAMS User's Guide for more info, you can
download this from the Web if necessary), GAMS is installed correctly.
Now, to solve your model, you will need to ftp your files to the Unix
machine and run GAMS in the same way.  If you want to test a MIP from
the model library, do

gamslib magic
gams magic

As far as looking at output, etc., that depends on what system tools
(editors, print queues, etc.) your have installed there.  Every Unix
system will have vi, but after that it is harder to say for sure.

How to execute GAMS from different directories

> Suppose GAMS.exe file is in the "c:\gams", and gms files are in the
> "c:\gams\lib", how can I execute GAMS staying in the "C:\gams\lib"?

Have a look at the autoexec.bat file, located in the root directory,
i.e. c:\.  You can add gams to the path by adding at the bottom the
autoexec file:

...
path=c:\gams;%path%

Remember, you need to execute the new autoexec file or reboot the
system.

Instead of using the path you can also specify the 'absolute path'
when calling gams. For example, you could type:
c:\gams\gams myfile ........