Parallel Programming with OmniRPC

One aim of OmniRPC is to perform parallel programming with RPC. We execute the "calc_sin" function in parallel on multiple remote hosts by showing one example of parallel programming, as in 3. Programming with OmniRPC .

There are two ways to parallel program with OmniRPC.

  1. Use an asynchronous call.
  2. Use multi-thread programming with OpenMP.

Execution environment
Parallel programming with asynchronous call
Hostfile and execution
Parallel programming with OpenMP

Execution environment

We assume an execution environment like the following.

  1. The client host's name is jones
  2. We use three hosts (dennis, alice, jack) as remote hosts.
  3. rsh can be executed from jones to the remote hosts without password authentication. In other words, jones is registered at /etc/host.equiv or at the user's .rhost on a remote host.
  4. OmniRPC is installed in the default path(/usr/local/omrpc/) on both hosts.
  5. And, calc_sin.rex which is the remote executable program of the "calc_sin" function, is registered on each remote host, as in previous example.

Parallel programming with asynchronous call

We show an example of an asynchronous call with OmniRPC as follows.

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

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

   OmniRpcInit(&argc,&argv);

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

  OmniRpcFinalize();

}

The OmniRpcCallAsync API activates the remote procedure call and returns without waiting for its call termination. Its API returns an OmniRpcRequest value which corresponds to the remote procedure call as a return value. We store its value in an array, and by using OmniRpcWaitAll API, the program waits for termination of all RPC calls. For more details about this API, see 15. C API index.

Hostfile and Execution

Before program execution, you should prepare a hostfile.

<?xml version="1.0" ?>
<OmniRpcConfig>
   <Host name="alice" />
   <Host name="dennis" />
   <Host name="jack" />
</OmniRpcConfig>

The rest of the procedure is the same the former example. The relationship between the agent and rex is shown below.

fig2

Parallel programming with OpenMP

We can do parallel programming by calling OmniRpcCall on a multi-thread program with Omni OpenMP, which is one of OpenMP compiler of an implementation using a thread. We show an example as follows.

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

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

   OmniRpcInit(&argc,&argv);

   x = 0.0;
#pragma omp parallel for
   for(i = 0; i < 10; i++){
       req[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();

}

When you want to run this program, remember to set the OMP_NUM_THREADS environmental value, which specifies the number of OpenMP threads, to a value more than the number of remote hosts.