Index of /ptolemyII/ptII8.0/ptII8.0.1/ptolemy/codegen

[ICO]NameLast modifiedSizeDescription

[DIR]Parent Directory  -  
[DIR]actor/20-Oct-2010 22:41 -  
[DIR]c/20-Oct-2010 22:42 -  
[   ]codegen.jar20-Oct-2010 22:43 774K 
[TXT]codegen.xml23-Oct-2009 11:02 1.8K 
[DIR]demo/20-Oct-2010 22:43 -  
[DIR]gui/20-Oct-2010 22:42 -  
[DIR]java/20-Oct-2010 22:42 -  
[DIR]kernel/20-Oct-2010 22:41 -  
[TXT]makefile03-Dec-2009 20:35 2.6K 
[DIR]rtmaude/20-Oct-2010 22:42 -  
[DIR]test/03-Oct-2010 11:42 -  
[DIR]util/20-Oct-2010 22:42 -  

Code Generation

Code Generation

This code generator is patterned after the Ptolemy Classic code generator where actors have template files consisting of code blocks. The code blocks are stitched together to create the resulting file.

Simple Demo

  1. Open $PTII/ptolemy/codegen/demo/Ramp/Ramp.xml
  2. Click on the StaticSchedulingCodeGeneratorIcon.
  3. A dialog box will appear, click on "Generate"
  4. The code will be generated, compiled, run and the results displayed.
Other Codegen Demonstrations

Limitations

This is a highly preliminary code generator facility, with many limitations. It is best viewed as a concept demonstration.

FAQ

Problems Generating Code

Generating code results in IOException: java.io.IOException: CreateProcess: make -f Model.mk error=2
This will happen if make is not in your path. Under Windows, you may need to install Cygwin, see the Ptolemy II Cygwin installer. Under Windows, if Cygwin is installed, then be sure that C:\cygwin\bin is in your Windows path. To edit your path, do Start Menu -> Settings -> Control Panels -> System -> Advanced -> Environment Variables.
Models that use a plotter fail to compile.
Models that use the plotter use the Java Native Interface (JNI) to invoke the plotter from within the C process. This is done so that the plotter is interactive while the model is running as opposed to plotting the data after the model completes. The JNI facility requires that a Java Development Kit (JDK) be installed instead of a Java Runtime Environment (JRE). The Ptolemy II Windows installer includes a JRE which is optionally installed. If the Windows installer is installed with the bundled JRE, then models that use the plotter will probably fail to compile with message like:
make: *** [Ramp] Error 1

Problems Running

Models that use the plotter require setup
To properly run a model that has a plotter, you must have jvm.dll in your path. If you do not, then when you run the executable, it will immediately exit with no message! For example, place
C:\Progra~1\Java\jdk1.5.0_11\jre\bin\client
in your path. If you are running Vergil from the command line as $PTII/bin/ptinvoke, then this has been handled for you. If you are running via Eclipse, then you must update your path by hand.
When in Windows, clicking on a .exe produced by the code generator fails to start up. The message is:
The procedure entry point _impure_ptr could not be located in the dynamic link library cygwin1.dll
The solution is to add C:\cygwin\bin to the Windows path by doing: Start Menu -> Settings -> Control Panels -> System -> Advanced -> Environment Variables and adding C:\cygwin\bin to the path.
To get rid of the console, compile with the exe with -mwindows:
make -f Model.mk CC_FLAGS=-mwindows

Extending the Code Generator

Why are some of my ports being generated as Tokens in the C output?
The simple rule for the the type resolution in codegen is that any resolved Ptolemy types the codegen kernel defines to be non-primitive will be Token type in the generated code. User code (helper classes) is responsible for making the distinction between different data types, which mean the helper code may have different code blocks for handling different resolved type in the generated code. The CodeGeneratorHelper.isPrimitive() method is what is used to determine if a type is primitive. Also, a good example to look at is the codegen/c/actor/lib/ArrayElement helper.
How do I get timing data from the C output?
At the top of the generated C file, insert
#include <sys/time.h>
At the beginning of main() method, insert:
struct timespec start, end;
double dT = 0.0;
clock_gettime(CLOCK_REALTIME, &start);
Toward the end of main() method, insert:
clock_gettime(CLOCK_REALTIME, &end);
dT = end.tv_sec - start.tv_sec + (end.tv_nsec - start.tv_nsec) * 1.0e-9;
printf("execution time: %g seconds\n", dT);
You can also get the time resolution of your system by inserting the following code:
struct timespec res;
clock_getres(CLOCK_REALTIME, &res);
printf(" time resolution: %ld ns\n", res.tv_nsec);

Compiling Large C Files

make -f ModelName.mk WARNING_CC_FLAGS= USER_CC_FLAGS="-pipe -O0
--verbose -Q"
Each of the options above:
No -Wall
avoid any optimization
-pipe
avoid temporary files
-O0
avoid optimization
--verbose
print out steps
-Q
print out summary information.