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 (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%
* 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