Programming with OmniRPC

Simple example
Execution environment
Write remote executable program
Registration of remote executable program
Client program
Create hostfile.xml
Execution of client program
Summary

Simple example

Let's begin programming with OmniRPC using a simple example. In this case, we consider a program to calculate from 1 to 10 using sine function.

#include <stdio.h>
#include <math.h>

int main(){
   int i;
   double x, res[10];
   x = 0.0;
   for(i = 0; i < 10; i++){
       res[i] = sin(x);
       x += 1.0;
   }
   for(i = 0; i < 10; i++) 
      printf("sin(%d)=%g\n",i,res[i]);
}

On this program, we calculate the sine in a remote node using OmniRPC. We label the computer node on which the program makes the Remote Procedure Cal (RPC) as the client host, and the computer node on which procedures are executed by the RPC call as the remote host.

Execution environment

We assume the environment below as a simple explanation.

  1. Client host's name is jones.
  2. Remote host's name is dennis.
  3. From jones to dennis, we can execute "rsh" with no password authentication. In other words, jones is registered to "/etc/host.equiv" or the user's ".rhost" on the remote host.
  4. On both hosts, OmniRPC is installed to the default path("/usr/local/omrpc/").

In addition, OmniRPC does not need to share the file system in both hosts.

OmniRPC agent and remote executable programs

In OmniRPC, to activate a remote executable program on a remote node which is described in the hostfile, the omrpc-agent is first activated when OmniRpcInit, which is an initialization API is called.

This agent is activated for each program, and runs during program execution. This agent is invoked by an authentication method such as rsh, Globus GRAM, or ssh. And agent provides access to the module information which was registered on the remote node and interface of the job scheduler, communication multiplexing, and so on. If you want to know more details about these features, please see the section, 12. Hostfile Description.

fig1

In the upper figure, agent stands for OmniRPC-agent, rex stands for remote executable program. In this example, the agent and rex are executed on the same host (dennis).

Write remote executable program

Here, we'll write a program which calculates the sine on a remote host. We will define the interface of sine function. We name the file which defines interfaces IDL(Interface Description Language) file. The IDL is discussed in detail later. For example, we can write the calc_sin.idl file as follows.
Module calc_sin;

Globals {
#include <math.h>
}

Define calc_sin(double IN x, double OUT result[]){
  *result = sin(x);
}

Module:
We define the module name in the IDL file. In this example, we set this module name as "calc_sin".

Define:
Interfaces are defined by the "Define" directive. In this example, we use sin. Arguments are the specified data type and whether the data is input or output. In OmniRPC, we cannot get the return value of the function as a value of the function's value like a original sin function. So, we get the value by specifying arguments as "OUT", as shown in the example. In the part surrounded with {...}, we can write a procedure which is executed on the remote host in C Language. This program calls the sine function and "result", which is an "OUT" argument, returns the since value.

Globals:
In the part assigned to "Globals", we can describe any C program which is necessary for functions that are defined in the modules. In this example, the IDL includes files which are required to call the "sin" function.

We can generate a remote executable program from the IDL file by using omrpc-cc, which is OmniRPC's remote executable module generator. So, let's convert using this command. ( "-lm" option is to link math library.)

$ omrpc-cc calc_sin.idl -lm

"calc_sin.rex" is generated by executing this program. This is the remote executable program.

By the way, the IDL can define multiple functions in a remote executable module. For Further details, see 13. IDL file Description .

Registration of remote executable program

After making the remote executable program, you should register it. For registration, we use the "omrpc-register" program.

$ omrpc-register -register calc_sin.rex

This program creates the ".omrpc_register" directory in the user's home directory and database, which consists of the module name, function name and path to the remote executable program.

After completing the above procedure, setup on the remote host side is finished. We move next to the setup on the client host side.

Client program

We rewrite the client program with OmniRpcCall.
#include <OmniRpc.h>
#include <stdio.h>
#include <math.h>

int main(int argc,char *argv[]){
   int i;
   double x, res[10];

   OmniRpcInit(&argc,&argv);

   x = 0.0;
   for(i = 0; i < 10; i++){
       OmniRpcCall("calc_sin",x,&res[i]);
       x += 1.0;
   }
   for(i = 0; i < 10; i++) 
      printf("sin(%d)=%g\n",i,res[i]);

  OmniRpcFinalize();

}

First, we call OmniRpcInit() before we use the OmniRPC library. And, at end of this program, we call OmniRpcFinalize(). Prototype definitions of these functions are described in OmniRpc.h, so the program must include the "OmniRpc.h" header file.

We compile this program.

 % omrpc-cc -o test.exe test.c

You can compile the directory without omrpc-cc.

  % cc -I/usr/local/omrpc/include -o test.exe test.c
	-L/usr/local/omrpc/lib -lomrpc_client -lomrpc_io

By default, OmniRPC software is installed at /usr/local/omrpc. If you install the software in an other directory, you should change /usr/loca/omrpc to the correct directory in which OmniRPC is installed.

Create hostfile.xml

In OmniRPC, usually we describe the execution environment in hostfile.xml with XML notation. In this example case, we describe the execution environment as follows.

<?xml version="1.0" ?>
<OmniRpcConfig>
   <Host name="prost" />
</OmniRpcConfig>

We write the above information in the hosts.xml file.

This example is in the simplest setting. You can see more details at 12. Hostfile's Description .

Execution of client program

The setup is finished. What we have to do next is to execute the program.

% test.exe --hostfile hosts.xml

This program searches for a remote function named sin on a remote host which is specified in the hosts.xml file and activates the remote module. If the "--hostfile" option is omitted, "--$HOME/.omrpc-registry/hosts.xml" file is used.

Summary

Below is a summary of the general procedure when using OmniRpc.

  1. Install OmniRPC on the client host and remote host.
  2. On the remote host, create a remote executable program of the remote function and register it.
    1. Create the IDL file which defines interfaces.
    2. Generate a remote executable module from the IDL file with the "omrpc-cc" program.
    3. Register with omrpc-register.
  3. On the client host, create hosts.xml which describes the remote host.
  4. Write the client program, and compile with omrpc-cc.
  5. Execute the client program, specifying hosts.xml.