[saga-rg] Re: saga update (ii)

Andre Merzky andre at merzky.net
Sat Mar 18 04:10:05 CST 2006


Hi folx, 

lets do another, more complete example translation from
gridrpc to saga.  Todays example is the pi_client_sync.c
from the NinfG documentation.  The original code (changed
formating) is attached as pi_client_sync.c.

The SAGA version is included below.  I ommited the C version
this time, for brevity - please let me know if you would
like the direct comparison with C, and I'll try to come up
with that.

----------------------------------------------------------
/* This is sample program for Ninf-G, calculate PI on one server */
#include <saga.h>

std::string func_name   = "pi/pi_trial";
std::string config_file = "client.conf";
int         port        = 0;

int main (int argc, char *argv[])
{
  if ( argc != 3 )
  {
    std::cerr << "\n\tUSAGE: " 
              << argv[0]
              << " <times> <hostname>\n\n";
    exit (2);
  }

  long   times = atol (argv[1]);
  string host  =       argv[2];

  try 
  {
    /* Initialize Function handle */
    saga::rpc handle (host, func_name);

    /* Synchronous call */
    long answer;
    handle.call (0, times, &answer);

    /* Compute and display pi. */
    std::cout << "PI = "
              << 4.0 * ((double) answer / times))
              << std::endl;

  }
  catch ( const saga::exception & e )
  {
    std::cerr << "Catched saga error: "
              << e.what ()
              << std::endl;
    exit (2);
  }


  return (0);
}
----------------------------------------------------------

Don't let yourself be fooled by the shortness of the
programm - that is mainly due to C++, not due to saga
(although again the session initialization/destroy is done
behind the scenes by default).

The semantics should be exactly the same as in GridRPC.

Well, thats for now, the next example should tackle a async
call I guess.

Again, I would be more than happy to see more realistic code
examples posted by you guys :-)

Cheers, Andre.


-- 
"So much time, so little to do..."  -- Garfield
-------------- next part --------------
/* This is sample program for Ninf-G, calculate PI on one server */
#include "grpc.h"

char *func_name   = "pi/pi_trial";
char *config_file = "client.conf";
int   port        = 0;

int main (int argc, char *argv[])
{
  grpc_function_handle_t handle;
  grpc_error_t           result = GRPC_NO_ERROR;
  char                 * host   = NULL;
  long                   times, answer;

  if ( argc != 3 )
  {
    fprintf (stderr, "USAGE: %s TIMES HOSTNAME\n", argv[0]);
    exit (2);
  }

  times = atol (argv[1]);
  host  = argv[2];

  /* Initialize */
  result = grpc_initialize (config_file);
  if ( result != GRPC_NO_ERROR ) 
  {
    fprintf (stderr, "grpc_initialize () error. (%s)\n",
             grpc_error_string (result));
    exit (2);
  }

  /* Initialize Function handle */
  result = grpc_function_handle_init (&handle, host, func_name);
  if ( result != GRPC_NO_ERROR ) 
  {
    fprintf (stderr, "grpc_function_handle_init() error. (%s)\n",
             grpc_error_string (result));
    exit (2);
  }

  /* Synchronous call */
  result = grpc_call (&handle, 0, times, &answer);
  if ( result != GRPC_NO_ERROR )
  {
    fprintf (stderr, "grpc_call() error. (%s)\n",
             grpc_error_string (result));
    exit (2);
  }

  /* Destruct Function handles */
  result = grpc_function_handle_destruct (&handle);
  if ( result != GRPC_NO_ERROR ) 
  {
    fprintf (stderr, "grpc_function_handle_destruct() error. (%s)\n",
             grpc_error_string (result));
    exit (2);
  }

  /* Compute and display pi. */
  printf ("PI = %f\n", 4.0 * ((double) answer / times));

  /* Finalize */
  result = grpc_finalize ();
  if ( result != GRPC_NO_ERROR ) 
  {
    fprintf (stderr, "grpc_finalize () error. (%s)\n",
             grpc_error_string (result));
    exit (2);
  }

  return (0);
}



More information about the saga-rg mailing list