First, we need to define the CnC graph:
The CnC graph states that
oddNums is a Tag Collection with strings as the tags.
Currently, strings are the only supported tag types in CnC-Python.
Next, we define the Item Collection
primes which has strings as tags and integer as its values. These types are defined in the format
tagType->itemType before the name of the Item Collection.
We define the implementation language of the Step in the Step prescription as in
(python compute). In CnC-Python, python is the only allowable value. In future releases we plan to expan this value to include other languages such as C, C++, Fortran, Matlab, etc.
env is a special keyword representing the environment and in this example we define the environment will put string tags into the
oddNums Tag Collection and read the results from the
primes Item Collection.
After defining the CnC graph, we need to run this file using the CnC-Python translator using the following command:
Running the command will generate the following directories:
hj-main. In short, these are what the directories represent:
Wrapper classes for the HJ-CnC runtime used by Babel while generating SIDL server/client code
SIDL files used by the program. This includes the SIDL file for the runtime wrapper classes as well as the Step and Item Collections for the current program
The java client generated from the SIDL files used by the HJ program to call into the python implementation
The generated python files that are invoked from the HJ program
This is the only directory the user should need to edit. It will contain template files for the python Steps as well as an application class to attach start and end event handlers. The even handlers are used to place values from the environment into Item Collections and read results back from Item Collections.
The generated HJ files that manages code to make native invocations into the python implementations using the Babel runtime. The user launches the CnC-Python program using a generated script that invokes the generated HJ main class.
Back to the example, once the translator completes running there should be the following files in the
Rename both files to
userFindPrimesApp.py provides the
onEnd functions. The function signatures are determined by detecting the environment interactions in the CnC graph. The
onStart function also provides access to any command line arguments used while launching the program. The
userComputeStep.py file provides the file the user needs to edit to provide the Step implementation. A Step needs to implement the
compute functions. The
createAwaitsList function allows the user to specify the input data dependences on Item Collections. Once these dependences have been satisfied the
compute function will be invoked.
Below are simple implementations for the two python files:
Please refer to the Partition-String example to see an example of how to implement the
Running this program with an input of
100 should produce the following output: