next up previous contents
Next: Compilation Up: Building a server application Previous: Declaring services   Contents


Let us consider the same example as in Chapter 4, where a function scal_mat_prod performs the product of a matrix and a scalar and returns the time required for the computation:

int scal_mat_prod(double alpha, double *M, int nb_rows, int nb_cols, float *time);
Our program will first define the solve function that consists of the link between DIET and this function. Then, the main function defines one service and adds it in the service table with its associated solve function.
#include <stdio.h>
#include "DIET_server.h"
#include "scal_mat_prod.h"

int solve_smprod(diet_profile_t *pb)
  double *alpha;
  double *M;
  float  time;
  size_t m, n;
  int res;

  /* Get arguments */
  diet_scalar_get(diet_parameter(pb,0), &alpha, NULL);
  diet_matrix_get(diet_parameter(pb,1), &M, NULL, &m, &n, NULL);
  /* Launch computation */
  res = scal_mat_prod(*alpha, M, m, n, &time);
  /* Set OUT arguments */
  diet_scalar_desc_set(diet_parameter(pb,2), &time);
  /* Free IN data */

  return res;

int main(int argc, char* argv[])
  diet_profile_desc_t *profile;
  /* Initialize table with maximum 1 service */
  /* Define smprod profile */
  profile = diet_profile_desc_alloc("smprod",0, 1, 2);
  diet_generic_desc_set(diet_param_desc(profile,0), DIET_SCALAR, DIET_DOUBLE);
  diet_generic_desc_set(diet_param_desc(profile,1), DIET_MATRIX, DIET_DOUBLE);
  diet_generic_desc_set(diet_param_desc(profile,2), DIET_SCALAR, DIET_FLOAT);
  /* Add the service (the profile descriptor is deep copied) */
  diet_service_table_add(profile, NULL, solve_smprod);
  /* Free the profile descriptor, since it was deep copied. */

  /* Launch the SeD: no return call */
  diet_SeD("./SeD.cfg", argc, argv);

  return 0;

The DIET Team - Ven 6 jul 2012 11:19:05 CEST