vensim compiled simulation

Use this forum to post Vensim related questions.
Post Reply
davide
Junior Member
Posts: 18
Joined: Mon Jul 17, 2006 9:11 am

vensim compiled simulation

Post by davide »

I'm trying to compile a model from Vensim 5.9. The compiler I'm using is Microsoft Visual C++ 2008 Express Edition.

I’ve edited the file MDL.BAT to reset the path statements and I’ve indicated in Vensim the correct MDL.BAT to be called (Tools->Options->Startup, compiled simulation path).

Nevertheless, when starting the compiled simulation, I get an error messages, such as:

“CL” NOT RECOGNISED AS INTERNAL/EXTERNAL COMMAND, EXECUTIVE PROGRAM OR BATCH FILE. THERE WHERE ERRORS WHILE COMPILING – CHECK THE PATHS IN MDL.BAT IN VENSIM/COMP

In other words, it seems cl.exe (located in C:\program files\Microsoft Visual Studio 9.0\VC\bin ) can’t be found when starting the compiling process.

Guess I've missed something in terms of base settings but can’t find where the problem is. Anybody had similar problems and/or can indicate me where I’ve made something wrong?
Administrator
Super Administrator
Posts: 4838
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

The best thing to do is edit MDL.bat, and just after the "@ECHO OFF" command, insert

call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"

Now make sure all the rest of the lines down to "if exist mdl.obj del mdl.obj " are either deleted or have REM in front of them.

This calls the Microsoft batch file for setting the environment and should be correct.

A copy of my MDL.BAT is below.

Tony.





@ECHO OFF

call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"

if exist mdl.obj del mdl.obj
if exist %3.dll del %3.dll
if .%2 == . goto noinclude
CL /O2 /c /I "%2" /DWIN32 mdl.c
goto aftercomp
:noinclude
CL /O2 /c /DWIN32 mdl.c
:aftercomp
if errorlevel 1 goto :error1
if not exist mdl.obj goto :error2
LINK /DLL /OUT:%3.dll /def:%1sim.def mdl.obj
if errorlevel 1 goto :error3
if not exist %3.dll goto :error3
REM clean up .lib and .exp files - they are not neaded
del %3.lib
del %3.exp
goto :exit
:error1
echo There were errors while compiling - check the paths in mdl.bat in vensim\comp
goto exit2
:error2
echo Unable to compile. You probably need to set paths in mdl.bat in vensim\comp
goto exit2
:error3
echo Errors while linking %3.dll - make sure compiled simulations were properly installed
goto :exit2
:exit2
pause
goto :exit3
:exit
echo ----------
echo Compilation of %3 seems to have been successful.
echo Close this window and continue.
:exit3
davide
Junior Member
Posts: 18
Joined: Mon Jul 17, 2006 9:11 am

Post by davide »

Thanks Tony for your reply.
With your suggestion I've finally managed to run the compiled simulation, but I still have a question..
It seems that in some cases Vensim generates a floating point error running interpret simulations, while the model runs without problems with compiled simulations..
Did you have similar experiences?
Any idea on the possible causes?

[Edited on 14-7-2010 by davide]
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

It may be that an internal computation in an equation with something such as IF THEN ELSE(a/b > c,d,e) where a/b is really big, but would only generate a floating point exception if converted to a 4 byte number - that happens in the interpreter, but in compiled the comparison is done using extended precision (roughly 10 byte) numbers.

It is possible that adding the switch /fp:except to the options on the CL line might make compiled behave more like interpreted, but the above situation will still be difference.
Post Reply