Chapter 2. Assembling and Running a CCA Application

$Revision: 1.5 $

$Date: 2007/08/24 06:25:49 $

Table of Contents

2.1. Using the GUI Front-End to Ccaffeine
2.1.1. Running Ccaffeine with the GUI
2.1.2. 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,

Integrators:

integrators.MonteCarlo, integrators.Trapezoid, integrators.Simpson

Functions:

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.

2.1.1. Running Ccaffeine with the GUI

Ccaffeine and its GUI are run as two separate processes, possibly on two different machines. In any event, you'll need two separate terminal sessions to control and monitor the two processes. We will refer to these as “Ccaffeine host” and “GUI host”.

In this exercise, we will invoke Ccaffeine on the Ccaffeine host with:

gui-backend.sh --port 3314 \ 1
             --ccafe-rc rc_file 2

1

This tells Ccaffeine the port number to expect the GUI to connect to. Typically, it can be any port number between 1025 and 65535 that doesn't conflict with another application wanting to use the same port. In this Guide, we will use port 3314, but you can change this if it is problematic.

[Warning] Warning

If you're working in a setting in which there may be more than one person using Ccaffeine on the same system, you must choose different ports, or you will conflict! Choosing anything besides the default port, the chances of a conflict are small.

If you're participating in an organized CCA tutorial, we'll assign you a port number to use for the GUI as part of your account information as a simple way to insure there are no conflicts. Please use your assigned port number in this case!

2

An rc file is required in order to set the component search path and load the required components into the framework's palette. In a bocca-based code tree, an rc file is automatically generated for use with the GUI that will load all of the components built in the tree. For this exercise, you can use the one in the tutorial-src tree ($TUTORIAL_SRC/components/tests/test_gui_rc). If you want to modify it (for example to not load certain components), you can copy it from this location and edit it.

The default for ccafe-client (and ccafe-batch) is to direct most of their own output, as well as the output from applications within them, to files named pOutn (for the stdout stream) and pErrn (for the stderr stream), where n denotes the MPI rank of the process. (In this Guide, we'll be running sequentially, so we'll have only pOut0 and pErr0.) The gui-backend.sh script invokes ccafe-client with the --ccafe-io2tty to direct its output to the terminal instead of to the files (the files will still be created, but will contain just a few startup messages relating to the MPI rank and the process id). Using --ccafe-io2tty is more convenient for more interactive development work, but if you're going to run an actual application, you probably want to capture the output in the files instead. With the current gui-backend.sh, this would require modifying the script, but for “production” computing with CCA, we expect most people to use the rc approach of the previous section rather than the GUI.

The Ccaffeine GUI is implemented in Java, and is available as a jar file that can be used with any recent version of the Java runtime or the full software development kit. Because the Java invocation is long and hard to remember, we provide convenience scripts to simplify using it. Which one you need depends on your circumstances:

gui.sh

This is the script to use if you're running the GUI on the same machine as the backend. This script is configured and installed as part of the CCA tools build process.

simple-gui.sh

This is the script to use if you're running the GUI on a Linux-like machine and want to connect to Ccaffeine running remotely. You will need to download this to your local machine, along with the GUI's jar file, following the directions in Section B.2, “The Ccaffeine GUI”.

simple-gui.bat

This is the script to use if you're running the GUI on a Windows machine and want to connect to Ccaffeine running remotely. You will need to download this to your local machine, along with the GUI's jar file, following the directions in Section B.2, “The Ccaffeine GUI”.

Below, we will refer to simple-gui.sh, but you should replace it with whichever command is appropriate for your situation.

[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 the GUI-Ccaffeine connection over your ssh connection is a straightforward way to deal with firewalls that often prevent direct access to most ports on remote hosts. It has the added advantage, for the purposes of this Guide, that you would use the same arguments to invoke the GUI running remotely through a tunnel or locally on the same machine as the backend. 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, we will invoke the GUI on the GUI host with:

simple-gui.sh --builderPort 3314 \ 1
        --host localhost 2

1

This tells the GUI which port to use for the connection to Ccaffeine host. In general, it should match the ccafe-client --port option (though when tunneling the connection through ssh, that need not be the case).

2

This tells the GUI which host to connect to for the Ccaffeine backend. In general, it should be the Ccaffeine host (though when tunneling the connection through ssh, it would be localhost).

[Note] Note

Since gui.sh is designed to be used on the same machine as Ccaffeine is running on, it does not take a --host argument. The simple-gui scripts do require it.

[Note] Note

Ccaffeine should be running and ready to receive the GUI's connection before you start the GUI. If you're scripting their execution, especially on the same machine, the sleep command can help build in a few seconds of delay.

[Note] Note

Once the GUI displays on your screen, it may take a few more seconds before it will respond to user actions.

2.1.2. Assembling and Running an Application Using the GUI

  1. Run gui-backend.sh on the Ccaffeine host using the appropriate port and the test_gui_rc rc file. The command will look something like:

    gui-backend.sh --port 3314 \
                   --ccafe-rc $TUTORIAL_SRC/components/tests/test_gui_rc
    

    depending on the port number assigned to you, and whether or not you've copied the rc file to your local directory.

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

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

  2. Run the simple-gui.sh 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.

    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.