Remote Functions and Member Calls

For a user defined class C with a member function foo:

class C{
   int foo(float, char);

The standard way to invoke the member through a pointer is an expression of the form:

C *p;                    
p->foo(3.14, 'x');

It is a bit more work to make the member function call though a global pointer. First, for each type C we must register the class and all members that will be called through global pointers. Registering the class is easy. There is a macro that will accomplish this task and it should be called at the top level. We next must register the member as shown below.

hpcxx_registerClass((C *) NULL);

int main(int argc, char *argv[]){
    HPCxx_Group *g;
    hpxx_init(&argc, &argv, g);
    hpcxx_id_t foo_id = hpcxx_register(C::foo, 24);

The overloaded register templated function builds a table for systems information about registered functions, classes, and member functions, and returns its location as an ID. The arguments to the registration is the function to be registered and the index key for the table look-up. Because this ID is an index into the table, it is essential that each context register the members with the same value for the table index.

Remote function invocation is accomplished through the use of the hpcxx_invoke() and hpcxx_ainvoke() functions. The first form is used as a blocking call, the second asynchronous. You must first define and initiate the remote context on which you want to execute the function, like so:

#define PATH_sgi64 "/tmp_mnt/nfs/olympus/home/user1/btemko/hpc++/gp_sgi64/hptb"
HPCxx_ContextID *p_sgi64 = 
    hpcxx_createContext("", PATH_sgi64);

The function hpcxx_createContext() returns an HPCxx_ContextID, which is used to identify a seperate context from the calling context. This ID is then used in the hpcxx_invoke and hpcxx_ainvoke functions to identify the remote context on which to execute the function. The first argument is the name of the machine on which you desire to activate the context, the second is a full path name to an executable.

While just this function is sufficient for creating a remote context for a Nexus based HPC++ implementation, the process of context creation is slightly more involved for an HPC++ implementation with Globus as the run-time system. Please refer to the section on remote context creation for details.

Now that you have registered your function and have activated the remote context, you can execute the function:

int ret_val;
hpcxx_invoke(*p_sgi64, ret_val, foo_id, 3.14, 'x');

The first argument is the ID of the remote context we created above, the next is the return value you expect from the function, the next is the id of the function which you got from registering it, and the rest of the arguments are the parameters to the function itself. The hpcxx_invoke and hpcxx_ainvoke functions have been overloaded to cover different types of function calls. For example, you may register a global function which is not a part of some class and then invoke it on another context. The number of parameters is obviously variable from function to function, as are return value types.

For a more detailed example of Global Pointers look at the example code section.

Last modified: Wed Apr 21 18:07:40 EST 1999