Executing an external program

Top  Previous  Next

External programs may be run during a GAMS job either using the $Call,  Execute or Put_utility syntax.  The $Call procedure is executed at the moment that is encountered during compilation.  The Execute and Put_utility commands causes the external program to be run during GAMS program execution.  The contrast between these statements is important in two ways.

Influence on results that can be included in a GAMS program-- Anything run with $Call can generate files that can be included in the subsequent compilation.  On the other hand files generated with Execute and Put_utility cannot be included because $Include operates only at compile time (unless you use Save and Restart). Note there is one exception using a call of GAMS with GAMS as discussed below.
Influence on results that can be fed into the external program-- Obviously when one is running an external program there is the desire to pass it data depicting results of the GAMS execution.  $Call cannot do this as the data passed have to exist at compile time and cannot use the result of any GAMS calculations and solves in the current program.  Execute commands on the other hand can use any data generated during a run which arise before the Execute and Put_utility command's position in the file through passage via put files or other mechanisms.

The big difference between the $Call and Execute is

$Call
can generate results to be immediately incorporated back into GAMS
cannot use GAMS results generated within this run because the $Call is executed at compile time.
Execute and Put_utility
can cause a program to be started using results generated by the GAMS program (note such results do have to have been saved in an external file using a command like put)
cannot generate results which can be immediately reincluded into the GAMS program because new material can only be added compile time.  (Excepting through use of a GAMS from GAMS approach as discussed below.)

 

$Call

Execute

Put_utility

Timing of execution with $Call and Execute