Chapter 2. Assembling and Running a CCA Application

$Revision: 1.11 $

$Date: 2007/11/10 16:51:48 $

Table of Contents

2.1. Using the GUI Front-End to Ccaffeine
2.1.1. Tools to Use when GUI host and Ccaffeine host are Identical
2.1.2. Tools to Use when GUI host and Ccaffeine host are Separate
2.1.3. Assembling and Running an Application Using the GUI
2.2. Running Ccaffeine Using an rc File
2.3. Notes on More Advanced Usage of the GUI

In this exercise, you will work with pre-built components from the integrator example to compose several CCA-based applications and execute them. The integrator application is a simple example, designed to illustrate the basics of creating, building, and running component-based applications without scientific complexities a more realistic application would also present. The purpose of this application is to numerically integrate a one-dimensional function. Several different integrators and functions are available, in the form of components. A “driver” component controls the calculation, and for the Monte Carlo integrator, a random number generator is also required. The specific components available are:

Drivers:

drivers.CXXDriver, drivers.F90Driver, drivers.PYDriver

Integrators:

integrators.MonteCarlo, integrators.Simpson, integrators.Trapezoid

Functions:

functions.CosFunction (cos(x), which integrates to sin(1), or roughly 0.841), functions.CubeFunction (x3, which integrates to 0.25), functions.LinearFunction (x, which integrates to 0.5), functions.PiFunction (4/(1+x2), which integrates to π), functions.QuinticFunction (x5-4x4, which integrates to 1/6 - 4/5, or roughly -0.633), functions.SquareFunction (x2, which integrates to 1/3)

Random Number Generators:

randomgens.RandNumGenerator (required by integrators.MonteCarlo)

The Ccaffeine framework provide three different ways for users to interact with it in order to assemble and run CCA applications. You can type commands in yourself at the framework's prompt, execute a script containing those same commands, or use a graphical user interface. The graphical approach is the easiest for most people to get a feel for how components work, so we will start with that (Section 2.1, “Using the GUI Front-End to Ccaffeine”) and later discuss how actions in the GUI map onto instructions in a script (see Section 2.2, “Running Ccaffeine Using an rc File”).

In practice, most users set the GUI interface aside after they become more comfortable with the CCA environment in favor of the scripting approach. That's especially true once they've developed a bunch of components and want to run simulations with them in batch jobs, where GUIs tend not to be so convenient. Of course it is entirely up to you which approach you use in the long run.

[Note] Note

This exercise uses the tutorial-src code tree. If you are participating in an organized tutorial, the tree will have been built for you in advance, and the location will be noted on your account information handout. If you're working through this exercise on your own, you'll need to build the code tree, following the instructions in Appendix C, Building the Tutorial Code Tree.

[Tip] Tip

These exercises can involve a fair amount of typing. You may find it convenient to use the online HTML version of this Guide (at http://www.cca-forum.org/tutorials/#sources to cut and paste the necessary inputs. Note, however, that not everything can be cut-and-based directly. Take particular care with lines that had to be broken for purposes of documentation, and for placeholder values such as “TUTORIAL_SRC”.

2.1. Using the GUI Front-End to Ccaffeine

There is a graphical front-end for Ccaffeine (known as ccafe-gui, or “the GUI”) which provides a fairly simple visual programming metaphor for the assembly of applications using CCA components. The current GUI is a Java tool, making it quite portable. It can also be used over network connections, so that you can run it on your local machine to create and run applications on a computer somewhere else. In this exercise, we'll use the Ccaffeine GUI to assemble and run several different “applications” using the components already available in the tutorial-src tree.

Ccaffeine and its GUI are run as two separate processes, possibly on two different machines. Depending on the specific circumstances, there are a variety of ways to invoke the GUI and the Ccaffeine framework. Bocca generates two helper scripts in the utils subdirectory of a project, which will serve most purposes. Which to use depends on whether the graphical display you're using (the “GUI host”) is directly attached to the machine on which you're running the framework (the “Ccaffeine host”), or whether they're separated by a network link.

2.1.1. Tools to Use when GUI host and Ccaffeine host are Identical

When you're working on a display that is directly attached to the Ccaffeine host, the bocca-generated utils/run-gui.sh script is the simplest one to use. It requires no arguments, and it automatically initializes the framework with a palette consisting of all of the components in the bocca project.

[Note] Note

While the GUI can be run remotely, using the X11 protocol to display on your local X11 server, this is generally unacceptably slow because of the way Java handles graphics in X11. You will probably get more satisfactory performance if you can run the GUI on your local system and allow it to connect over the network to the remote host where you're running Ccaffeine. Tunneling such a connection through an ssh session provides a straightfoward way to deal with intervening firewalls.

In this exercise, you will need to execute $TUTORIAL_SRC/utils/run-gui.sh in order to launch the front-end GUI and back-end framework with the pre-built components. In later exercises, you should be sure to invoke the utils/run-gui.sh script that corresponds to the bocca project you're working on.

2.1.2. Tools to Use when GUI host and Ccaffeine host are Separate

When working over the network, it is more effective to launch the GUI locally (since it is Java, it will work on Windows platforms as well as Mac, Linux, and unix) and simply transmit text commands over the network. This is the approach we generally use for organized tutorials, with the Ccaffeine host on a remote cluster, and your own laptop or another machine serving as the GUI host. Obviously this mode will require the use of two separate commands, one to launch the GUI and the other to launch the Ccaffeine framework. The bocca-generated utils/bocca-gui-backend.sh script can be used to launch the framework, while the simple-gui.sh (simple-gui.bat in Windows) script in the CCA tools installation launches the GUI.

The framework should be launched first, and must be told what port to listen on for the GUI connection: utils/bocca-gui-backend.sh --port port_num. Typically, it can be any port number between 1025 and 65535 that doesn't conflict with another application (CCA or any other) wanting to use the same port. In an organized tutorial, the likelihood of collisions is fairly high, so you will be assigned a port number in that case. The script automatically initializes the framework with a palette consisting of all of the components in the bocca project.

The simple-gui.sh command (simple-gui.bat for Windows) are used to launch the GUI. Though they are provided as part of the CCA tools installation, you must have a copy of them, and the GUI's jar file on your display machine, following the directions in Section B.2, “The Ccaffeine GUI”. To make the connection, the script must be told both the hostname and the port number to connect to the framework you just launched: simple-gui.sh --port port_num --host backend_host (equivalently for Windows).

[Tip] Tip

If you invoke the simple-gui.sh (simple-gui.bat) script without arguments, the GUI will pop up a dialog box asking you to specify the hostname and port number to connect to. Filling in these dialogs quickly gets tedious, so you're better off using the command line. (In Windows, launch a Command Prompt window, and change directories to wherever you put simple-gui.bat and the GUI jar file.) In both Windows and most Linux/unix shells, you can simply use the Up Arrow key to recall the previous command to be executed again.

[Tip] Tip

We have on occasion observed problems with the ccafe-gui interface hanging (most often while populating the palette as the GUI starts up). This seems to happen less often with Java version 1.4 than with more recent versions. If you're experiencing such problems, you might try switching to the latest Java 1.4 release.

[Note] Note

Connections between the GUI and the framework can be tunneled through an ssh connection in order to pass through firewalls between the GUI host and the Ccaffeine host. For more information, see Appendix A, Remote Access for the CCA Environment and in particular Section A.3, “Tunneling other Connections through SSH”.

In this exercise, you will need to execute $TUTORIAL_SRC/utils/bocca-gui-backend.sh --port port_num in order to launch the back-end framework with the pre-built components. In later exercises, you should be sure to invoke the utils/bocca-gui-backend.sh script that corresponds to the bocca project you're working on. The simple-gui.sh --port port_num --host backend_host invocations will remain the same throughout.

2.1.3. Assembling and Running an Application Using the GUI

For the purposes of this exercise, we will assume that you are working in and environment in which GUI host and Ccaffeine host are separate machines. If they are the same, you can use utils/run-gui.sh as described in Section 2.1.1, “Tools to Use when GUI host and Ccaffeine host are Identical” instead of the first two steps, below.

  1. Run $TUTORIAL_SRC/utils/bocca-gui-backend.sh --port port_num on the Ccaffeine host using the appropriate port.

    In the Ccaffeine host terminal window, you will see something like:

    (Ccaffeine host)
    my rank: -1, my pid: 9625
    Type: Server
    

  2. Run simple-gui.sh --port port_num --host backend_host (simple-gui.bat on Windows) on the GUI host.

    Once the GUI connects to Ccaffeine, Ccaffeine begins running the rc file it was invoked with. In the GUI host terminal window, you first see some startup messages from the GUI itself, followed by a series of messages as Ccaffeine processes the rc file and the GUI displays the results. These are debugging messages and can largely be ignored.

    In the Ccaffeine host terminal, you should see some additional messages as Ccaffeine processes the rc file, like:

    (Ccaffeine host)
    CCAFFEINE configured with spec (0.8.2) and babel (1.0.4).
    
    CCAFFEINE configured with classic (0.5.7).
    
    CCAFFEINE configured without neo and neo components.
    CmdLineClient parsing ...
    
    CmdContextCCA::initRC: Found components/tests/test_gui_rc.
    # There are allegedly 11 classes in the component path
    

    Finally, in the GUI host window, you should see some output associated with the GUI's initialization process, and the GUI itself should have appeared on your display, looking something like this:

    
      GUI with components in palette and empty arena

    [Tip] Tip

    The default layout has the palette area fairly narrow. You can click-and-drag on the bar separating the palette and the arena to adjust the width.

    [Note] Note

    You may see additional components in your palette, as we try to expand the variety of examples we provide in the tutorial-src.

    As mentioned above, the test_gui_rc sets up the path and loads the framework's palette with a set of available components. rc files are explained in detail in Section 2.2, “Running Ccaffeine Using an rc File”.

  3. We will begin by instantiating a drivers.CXXDriver component. Click-and-drag the component you want from the palette to the arena. When you release the mouse button in the arena, a dialog box will pop up prompting you to name this instance of the component. The default will be the last part of the component's class name (i.e. CXXDriver for drivers.CXXDriver) with a numerical suffix to insure the name is unique. The suffix starts at 0 and simply counts up according to the number of instances of that component you've created in that session. You can, of course, enter any instance name you like, as long as it is unique across all components in the arena, but for simplicity, we will always accept the default value in this Guide.

  4. For the first application, follow the same procedure to instantiate:

    • drivers.CXXDriver,

    • functions.PiFunction,

    • integrators.MonteCarlo,

    • randomgens.RandNumGenerator,

    (you may notice some debugging messages in the GUI host terminal window as you do this), and your GUI should look something like this:

    
      GUI with several components instantiated in arena (Step 4)

    [Tip] Tip

    You can drag components around the arena to arrange them as suits you -- just click on the black area of the compoment and drag it to the new location. The positions have no bearing on the operation of the GUI or your application.

  5. The next step is to begin making connections between the ports of your components. Click-and-release CXXDriver0's integrate uses port, then click-and-release MonteCarlo0's integrate provides port and a red line should be drawn between the two:

    
      Driver's integrator port connected to integrator's integrator port

    [Tip] Tip

    If you hover the cursor over a particular port on a component, a “tool tip” box will pop up with the port's name and type based on the arguments to the addProvidesPort or registerUsesPort calls in the component's setServices method. This can be useful for double checking to make sure you're connecting matching ports.

    Also notice that when you hover over a particular port (either uses or provides), matching ports of the opposite type (either provides or uses) will be highlighted.

    [Note] Note

    You can move components around even after their ports are connected -- the connections will automatically rearrange. There is no harm in connections crossing each other, nor in connections passing behind other components (though of course they may make it harder to interpret the “wiring diagram” correctly).

  6. Complete the first application by making the following connections:

    • CXXDriver0's integrate to MonteCarlo0's integrate

    • MonteCarlo0's function to PiFunction0's function

    • MonteCarlo0's RandomGeneratorPort to RandNumGenerator0's RandomGeneratorPort.

    At this point, your GUI should look something like:

    
      Fully connected application (Step 5)

  7. The application is now fully assembled and is ready to run. If you click-and-release the go button on the CXXDriver0 component, you should see the result appear in the Ccaffeine host terminal, “Value = 3.139160” (since Monte Carlo integration is based on random sampling, you will not get exactly the same result every time you run it, but for this example, it should always be reasonbly close to π) and the message “IN: ##specific go command successful” in the GUI host terminal.

  8. Next, we're going to use some of the other components to assemble a different application using the

    • integrators.Simpson and

    • functions.CubeFunction

    components. Since they're already in the palette, you can instantiate them in the same way as Step 3.

    
      Additional components instantiated (Step 7)

    [Tip] Tip

    As we've mentioned, wiring diagrams can become hard to interpret when they become cluttered, as is the case with the screen shot above. To help interpret the diagram, remember the following:

    • Wires” only connect to the sides of ports -- on the left side of provides ports (on the left side of the component), or on the right side of uses ports. Connections are never made to the top or bottom of a component.

    • The GUI's wire-drawing algorithm is aware only of the two components that are being connected. It will make no attempt to avoid other components or other wires. So wires can pass behind components without connecting to any of their ports, and wires may overlap.

    • If you're still uncertain how to interpret the connections try rearranging the components slightly. Connections attached to the component will follow as you drag it around, but others not associated with that component will remain unchanged.

  9. Next, we break the port connections we don't need so we can reconnect to the new components. Right-click on the integrate (either the user or the provider) and a dialog box will pop up asking you to confirm that you want to break the connection. (A bug in the GUI causes this dialog box to appear twice sometimes. Just respond appropriately both times.) You will need to break the following connections:

    • CXXDriver0's integrate to MonteCarlo0's integrate

    • MonteCarlo0's function to PiFunction0's function

    Whether or not MonteCarlo0 remains connected to RandNumGenerator0 is immaterial because neither component is connected to any other component in the arena and so will no be involved when a disjoint assembly of components is executed.

    [Note] Note

    Step 8 and Step 9 could have been done in either order.

  10. Assemble the new application by making the following connections:

    • CXXDriver0's integrate to Simpson0's integrate

    • Simpson0's function to PiFunction0's function

    
      Another application, with extraneous components still in arena
      (Step 9)

    Click-and-release the go button on the CXXDriver0 component, you should see the result appear in the Ccaffeine host terminal, “Value = 3.141593” and the message “IN: ##specific go command successful” in the GUI host terminal.

  11. Finally, create a third application by replacing PiFunction0 with CubeFunction0. When you click on the go you should get “Value = 0.250000” in the Ccaffeine host terminal (with a deterministic integrator, the result should be repeatable).

    
      A third application, with extraneous components still in arena
      (Step 10)

  12. At this point, you should understand how to instantiate components, how to connect and disconnect their ports, and how to execute the application with the go port. Feel free to use any and all of the components available in the palette to experiment with other integration applications.

    [Note] Note

    Observe that as a user of CCA components, you have no idea what language each component is implemented in. (Admittedly, the names of the drivers are suggestive of the implementation language, but those names were chosen at the convenience of the component developer, and they provide no guarantees regarding the components' implementations.) The language interoperability features of Babel allow components to be hooked together regardless of implementation language with complete transparency.

  13. To politely exit the GUI, select FileQuit. This will terminate both the GUI and the backend ccafe-client sessions.

    [Tip] Tip

    If you've used the GUI to setup and start a long-running simulation, and you don't want to leave the GUI running continuously, you can use the FileDetach option to close the GUI but leave the backend running. However it is currently impossible to reattach to a running session.