Non-blocking Usage

The examples in this section will be written in C using the SIDL file given in Section 15.5.2.

Calling a oneway Babel RMI function is syntactically exactly like calling a normal Babel function. The difference is just the danger of not being able to receive any exceptions beyond the initial communication. Example:


foo_Bar b1 = foo_Bar__createRemote("simhandle://pc1:9999", &_ex);SIDL_CHECK(_ex);

foo_Bar_initSimulation(b1, "Test Simulation 1", 0, &_ex); SIDL_CHECK(_ex);

Non-blocking calls are a bit more complex, requiring Tickets in order to get the return values. Here's an example program, now using a non-blocking call. Notice that the inout argument y is passed as an in argument in the send (as a value), and an out argument in the recv (as a pointer).


foo_Bar b1 = foo_Bar__createRemote("simhandle://pc1:9999", &_ex);SIDL_CHECK(_ex);
sidl_rmi_Ticket t = NULL;
double x, y, z;

foo_Bar_initSimulation(b1, "Test Simulation 1", 0, &_ex); SIDL_CHECK(_ex);
t = foo_Bar_runSimulation_send(b1, x, y, &_ex); SIDL_CHECK(_ex);
/* ... Work ... */
foo_Bar_runSimulation_recv(b, t, &y, &z, &_ex); SIDL_CHECK(_ex); //blocks on return
sidl_rmi_Ticket_deleteRef(t , &_ex); SIDL_CHECK(_ex);

Now, next is an example of a more complex program, that utilizes the power of TicketBooks to make multiple remote calls, work, and deal with the responses when they return.


foo_Bar b1 = foo_Bar__createRemote("simhandle://pc1:9999", &_ex);SIDL_CHECK(_ex);
foo_Bar b2 = foo_Bar__createRemote("simhandle://pc2:9999", &_ex);SIDL_CHECK(_ex);
foo_Bar b3 = foo_Bar__createRemote("simhandle://pc3:9999", &_ex);SIDL_CHECK(_ex);

sidl_rmi_Ticket t = NULL;
sidl_rmi_TicketBook tb = NULL;
double x, y, z;
int id1, id2, id3, tmpid;

foo_Bar_initSimulation(b1, "Test Simulation 1", 0, &_ex); SIDL_CHECK(_ex);
foo_Bar_initSimulation(b2, "Test Simulation 2", 0, &_ex); SIDL_CHECK(_ex);
foo_Bar_initSimulation(b3, "Test Simulation 3", 0, &_ex); SIDL_CHECK(_ex);

t = foo_Bar_runSimulation_send(b1, x, y, &_ex); SIDL_CHECK(_ex);
tb = sidl_rmi_Ticket_createEmptyTicketBook(t, &_ex); SIDL_CHECK(_ex);
id1 = sidl_rmi_TicketBook_insert(tb, t, &_ex); SIDL_CHECK(_ex); 
sidl_rmi_Ticket_deleteRef(t , &_ex); SIDL_CHECK(_ex);

t = foo_Bar_runSimulation_send(b2, x, y, &_ex); SIDL_CHECK(_ex);
id2 = sidl_rmi_TicketBook_insert(tb, t, &_ex); SIDL_CHECK(_ex); 
sidl_rmi_Ticket_deleteRef(t , &_ex); SIDL_CHECK(_ex);

t = foo_Bar_runSimulation_send(b3, x, y, &_ex); SIDL_CHECK(_ex);
id3 = sidl_rmi_TicketBook_insert(tb, t, &_ex); SIDL_CHECK(_ex); 
sidl_rmi_Ticket_deleteRef(t , &_ex); SIDL_CHECK(_ex);

/* ... Work ... */

while(!sidl_tmi_TicketBook_isEmpty(tb, &_ex)) {
  SIDL_CHECK(_ex);
  tmpid = sidl_tmi_TicketBook_removeReady(&t,&_ex); SIDL_CHECK(_ex);
  switch(tmpid) {
  case id1:
    foo_Bar_runSimulation_recv(b, t, &y, &z, &_ex); SIDL_CHECK(_ex);
    /* Do something with data from Simulation 1 */
    break;
  case id2:
    foo_Bar_runSimulation_recv(b, t, &y, &z, &_ex); SIDL_CHECK(_ex);
    /* Do something with data from Simulation 2 */
    break;
  case id3:
    foo_Bar_runSimulation_recv(b, t, &y, &z, &_ex); SIDL_CHECK(_ex);
    /* Do something with data from Simulation 3 */
    break;

  }
  sidl_rmi_Ticket_deleteRef(t , &_ex); SIDL_CHECK(_ex);
}





babel-1.4.0
users_guide Last Modified 2008-10-16

http://www.llnl.gov/CASC/components
components@llnl.gov