Attaching to Remote Contexts

Introduction

This is a simple example to illustrate how an HPC++ context may attach to another (existing) HPC++ context and invoke methods on it. This example is different from the context creation example in that both the client and the server contexts are started separately and then the client context attaches to the server context and makes a set of remote invocations on it.

Building The Example

The example is divided into three directories:
  • Common: Contains classes that are required by both the client and server and are of a utility nature. They include implementation of the classes HPCxx_String and hpcxx_byte.
  • GramClient: The client side code.
  • GramServer: The server side code.
  • The Example can be compiled on three different architectures: SGI Irix 64 bit, SGI Irix 32 bit and Sun Solaris 2.6. In order to build the example for a specific architecture, you need to edit the file "Makefile.base" in the example's root directory, as specified in that file. The modifications are fairly simple and involve uncommenting a few lines depending on the architecture at hand, and specifying some standard paths for HPC++, Globus etc. The file contains sample paths that are applicable for the environment of the Extreme! Lab at Indiana University. Next, just type in "make" at the command prompt to build the client side and the server side code. "make" will go through all the three directories and build the client and the server executables. The executables are built in directories depending on the specific architectures. For example, for SGI 64 bit architecture, the client executable goes in "GramClient/sgi64" directory and the server executable goes in "GramServer/sgi64" directory. Similarly, Solaris and SGI 32 bit executables go in "Gram*/solaris" and "Gram*/sgi32" directories respectively.

    Running The Example

    The server is started first. For example, if the current working directory is "GramServer" and if the host is a solaris machine, then the following line starts the server:

    ./solaris/GramServer

    This will start a server context which will listen for attachment requests on some port. For this simple example, the port number is hard-coded to 13123.

    Next, the client is run. Assuming that the current working directory is "GramClient" and the client's host is an SGI 64 bit machine, the following line will start the client:

    ./sgi64/GramClient 13123

    Source Code for The Example

    Client Side Code

    The client side code consists of the following tasks:
  • Initialize HPC++ by calling hpcxx_init. This function must be called exactly once by a context before doing any HPC++ related activity.
  • Parse the command line arguments to figure out the server's machine and port.
  • Register all the functions that will be called through remote method invocation. HPC++ requires that all remotely invoked functions be registered with the HPC++ run-time so that they can be properly delivered to the server context.
  • Connect (i.e. attaches or grabs) to the server context by calling hpcxx_grabContext. This function returns a context ID for the server context.
  • Use the context ID to make the remote function call returnServerGp on the server context. This function returns a global pointer to the server object.
  • Use the global pointer to invoke the method sayHello on the server object in the server context.
  • Call killMe on the server object to make the server context to exit.
  • Finally, the context exits by calling hpcxx_exit.
  • This client side code consists of a single source file:
  • Main.C: This is the client program
  • Server Side Code

    The server side code consists of the following tasks:
  • Initialize the context by calling hpcxx_init.
  • The server object is created as a global object and as such will be instantiated when the server context starts.
  • Register all the functions that will be invoked by remote clients.
  • Service remote requests from the client.
  • Exit this context (by calling hpcxx_exit) when the killme function is called.
  • This server side code is divided among the following source files:
  • Main.C: This is the main server program
  • Server.h: Header file for the Server class
  • Server.C: Source file for the Server class
  • Common Code

    The directory "Common" contains utility classes used by both the client and the server. It has two parts:
  • HPCxx_String class: This is used to send C++ strings among communicating contexts.
  • HPCxx_String.h: Header file for the class HPCxx_String
  • HPCxx_String.C: Source file for the class HPCxx_String
  • hpcxx_byte class: This is used internally by the HPC++ system for communication.
  • hpcxx_byte.h: Header file for the class hpcxx_byte
  • hpcxx_byte.C: Source file for the class hpcxx_byte
  • Later on, these classes may become a part of the standard HPC++ distribution, thus removing the need for the "Common" directory.

    Download the Complete Example

    This is a gzipped tar file.
    hpc++@extreme.indiana.edu

    Last modified: Fri Feb 12 11:04:57 EST 1999