embeddedMultiInstance.gms : Handling multiple instances of the embedded code facility at once

Description

The embedded code facility allows to integrate external code (e.g. Python) during
both compile and execution time of a GAMS program. GAMS symbols are shared with
the external code, so no communication via disk is necessary.

This example demonstrates that multiple instances of the embedded code facility
can be used in parallel without disturbing each other.

Contributor: Lutz Westermann, July 2017


Category : GAMS Data Utilities library


Main file : embeddedMultiInstance.gms   includes :  embeddedMultiInstance.gms

$Title Handling multiple instances of the embedded code facility at once

$ontext
The embedded code facility allows to integrate external code (e.g. Python) during
both compile and execution time of a GAMS program. GAMS symbols are shared with
the external code, so no communication via disk is necessary.

This example demonstrates that multiple instances of the embedded code facility
can be used in parallel without disturbing each other.

Contributor: Lutz Westermann, July 2017
$offtext


* On the major platforms, GMSPYTHONHOME gets set automatically, otherwise the user has to set it
* This condition can also be removed, if one has set up its Python environment appropriately
$escape &
$if "%sysEnv.GMSPYTHONHOME%"=="%&sysEnv.GMSPYTHONHOME%&" $abort.noError Embedded code Python not ready to be used

* Check if the command line option pyMultInst was set to '1' in order to enable multiple python instances
$if not %sysEnv.GMSPYTHONMULTINST%==1 $abort.noError Start with command line option pyMultInst=1


embeddedCode Python:
myString = 'I am #1'
pauseEmbeddedCode

Scalar h1 Handle for embedded code;
h1 = embeddedHandle;

embeddedCode Python:
myString = 'I am #2'
pauseEmbeddedCode

Scalar h2 Handle for embedded code;
h2 = embeddedHandle;

continueEmbeddedCode h1:
gams.printLog(myString);
endEmbeddedCode

continueEmbeddedCode h2:
gams.printLog(myString);
endEmbeddedCode