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.
We assume the environment below as a simple explanation.
In addition, OmniRPC does not need to share the file system in both hosts.
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.
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).
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 .
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.
#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.
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 .
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.
Below is a summary of the general procedure when using OmniRpc.