Top Up Prev Next Bottom Contents Index Search

1.6 Building standalone programs that use Ptolemy libraries.


Sometimes it is necessary to create small standalone programs that use part of the Ptolemy libraries.

Examples of this are the desire to use Ptolemy kernel classes such as StringList or the need to isolate an obscure bug or memory leak. The $PTOLEMY/mk/standalone.mk file provides the make definitions to make this possible. This file provides make rule definitions to build various binaries some using the Pure Sofware Inc.1 utilities.

The usage for this makefile is:

make -f $PTOLEMY/mk/standalone.mk stars.mk_variable_defs filename.suffix

Where stars.mk_variable_defs is zero or more makefile variables used in $PTOLEMY/mk/stars.mk, such as SDF=1. filename is the base name of the file to be compiled, and the basename of the output file. and
Suffix Binary Type
.bin Standard binary
.debug Binary with debug symbols
.purify Binary with Purify and debug symbols
.quantify Binary with Quantify linked in
.purecov Binary with Pure Coverage linked in
suffix is one of the forms listed in table
1-1.

TABLE 1-1: Table of filename suffixes and binary types.

It is possible to use these makefiles to create binaries that do not have any Ptolemy code. A reason why you might want to do this is to take advantage of the Pure Software make definitions in standalone.mk. To specify no Ptolemy libraries, use the make argument NOPTOLEMY=1.

1.6.1 Standalone example using StringList

For example, say you want to use the StringList class in a standalone program named bar.cc:

#include
#include "StringList.h"
main() {
StringList testing = "This is a test\n";
cout << testing;
}
To build it you would type:

make -f $PTOLEMY/mk/standalone.mk bar.bin If you wanted to make a new standalone program that also uses part of the CG domain, just define the domain make variables (as used in stars.mk) on the make command line:

make -f $PTOLEMY/mk/standalone.mk CG=1 bar.bin If you are going to do this often, it may be useful to create a new directory in which to test this program. In this directory, execute the commands:

ln -s $PTOLEMY/mk/standalone.mk makefile
ln -s $PTOLEMY/mk/standalone.mk make.template
By having these symbolic links, you will not have to supply the make argument
-f $PTOLEMY/mk/standalone.mk as before.

1.6.2 Standalone example that tests a Scheduler

Here is an example of a minimal file that can be used to call the setup in a Scheduler for instance. If the file testAcyLoopSched.cc contains:

#include <iostream.h>
#include "Galaxy.h"
#include "SDFStar.h"
#include "AcyCluster.h"
#include "AcyLoopScheduler.h"
#include "SDFPortHole.h"

main() {
// First create a simple galaxy and some stars.
SDFStar star[3];
Galaxy topGalaxy;
topGalaxy.setDomain("SDF");
topGalaxy.setName("topGalaxy");
topGalaxy.addBlock(star[0],"star0");
topGalaxy.addBlock(star[1],"star1");
topGalaxy.addBlock(star[2],"star2");

// Add ports to stars.
OutSDFPort p0,p1;
InSDFPort p2,p3;

// initialize the ports
p0.setPort("output1",&star[0],FLOAT,2);
star[0].addPort(p0);
p1.setPort("output2",&star[0],FLOAT,3);
star[0].addPort(p1);
p2.setPort("input",&star[1],FLOAT,3);
p3.setPort("input",&star[2],FLOAT,2);
star[1].addPort(p2);
star[2].addPort(p3);

// Connect `em up. The graph is
// star[1] (3) <--- (2) star[0] (3) ---> (2) star[2]
p0.connect(p2,0);
p1.connect(p3,0);

// Scheduling
AcyLoopScheduler sched;
sched.setGalaxy(topGalaxy);
cout << "No problem till now. Calling sched.setup()...\n";
sched.setup();
int i;
for (i = 0 ; i < 3 ; i++) {
cout << star[i].fullName() << "\n";
cout << "Repetitions = " << star[i].reps() << "\n";
}
StringList sch = sched.displaySchedule();
cout << sch;
}
The command to compile this and produce a standalone binary would be:

make -f $PTOLEMY/mk/standalone.mk OPTIMIZER= SDF=1 \
USE_SHARED_LIBS=yes testAcyLoopSched.debug



Top Up Prev Next Bottom Contents Index Search

1 Rational (http://www.rational.com) sells tools such as:
Purify, which can be used to find memory leaks and out of bounds memory accesses.
Quantify, which can be used to profile performance.
Purecov, which can be used to provide code coverage information.

Copyright © 1990-1997, University of California. All rights reserved.