Functions

matlab_gs_info.c File Reference

#include <stdio.h>
#include <string.h>
#include <matrix.h>
#include <mex.h>
#include "grpc.h"
#include "comm_data.h"
#include "matlab_gs.h"
Include dependency graph for matlab_gs_info.c:

Go to the source code of this file.

Functions

void matlab_gs_info (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])

Detailed Description

Matlab client call

Definition in file matlab_gs_info.c.


Function Documentation

void matlab_gs_info ( int  nlhs,
mxArray *  plhs[],
int  nrhs,
const mxArray *  prhs[] 
)

Make a GridSolve synchronous call and returns the status of the grpc_call (0 on OK and -1 on error).

Parameters:
nlhs - Number of left hand side arguments from Matlab
plhs - Pointer to left hand side arguments from Matlab
rlhs - Number of right hand side arguments from Matlab
plhs - Pointer to right hand side arguments from Matlab

Definition at line 30 of file matlab_gs_info.c.

{
  int i;
  grpc_function_handle_t *handle = NULL;
  char func_name[1024];
  gs_argument_t *argp = NULL;
  gs_problem_t *problem;
  char *problem_encoding = NULL;
  grpc_error_t status;
  int first_arg;
  char *str1 = NULL;
  char *str2 = NULL;
  int rc;

  /* reset global error setting */
  matlab_gs_error_num = 0;  

  /* Initialize */
  rc = grpc_initialize(NULL);
  if ((rc != GRPC_NO_ERROR) && (rc != GRPC_ALREADY_INITIALIZED)) DO_ERROR_MACRO(grpc_errno);

  /* Matlab uses column major indexing */
  if (grpc_set_client_major("Column") != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);

  /* Get some global information */
  if (nrhs == 1) {
    if (grpc_get_servers(&str1) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
    if (grpc_get_problems(&str2) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
    mexPrintf("%s \n", str1);
    mexPrintf("%s \n", str2);
    free(str1);
    free(str2);

  } else if (nrhs == 2) {
    
    /* Get problem name from Matlab */
    if (!mxIsChar(prhs[1])) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
    if (mxGetString(prhs[1],func_name,1024) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
    
    /* Get problem info from agent, along with a default server assignment */
    /* TODO We want to avoid assigning server, because that will cause
       the load to be temporarily increased as a heuristic */
    handle = (grpc_function_handle_t*)matlab_gs_calloc(1, sizeof(grpc_function_handle_t));
    if (handle == NULL) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
    if ((status=grpc_function_handle_default(handle, func_name)) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
    if (handle->problem_desc == NULL) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
    
    /* Write out problem description */
    problem = handle->problem_desc;
    
    /* Write out problem description */
    if (gs_encode_problem(&problem_encoding, problem) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
    if (problem_encoding) {
      mexPrintf("Description of call:\n");
      mexPrintf("%s\n", problem_encoding);
    }
    free(problem_encoding); /* allocated by gridrpc so memory is not handled in matlab */

    /* Write out problem description */
    mexPrintf("Matlab call prototype:\n");
    first_arg = 1;
    mexPrintf("[ ");
    for (argp=problem->arglist; argp!=NULL; argp=argp->next) 
      if (argp->inout == GS_OUT || argp->inout == GS_INOUT || argp->inout == GS_VAROUT) {
    if (argp->inout == GS_WORKSPACE) continue;
    if (matlab_gs_arg_is_sparse_index_or_pointer(argp, problem)) continue;
    if (! first_arg) mexPrintf(",", argp->name);
    if (argp->name) mexPrintf("%s ", argp->name);
    first_arg = 0;
      }
    mexPrintf("]");
    mexPrintf(" = gs_call ('%s'", problem->name);
    for (argp=problem->arglist; argp!=NULL; argp=argp->next) {
      if (argp->inout == GS_IN || argp->inout == GS_INOUT) {
    if (matlab_gs_arg_is_sparse_index_or_pointer(argp, problem)) continue;
    mexPrintf(", %s", argp->name);
      }
    }
    mexPrintf(")\n");
    
    /* Finalize */
    if ((status=grpc_function_handle_destruct(handle)) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
    handle = matlab_gs_free(handle);
    return;

  } else {

    mexPrintf("Usage: gs_info \n");
    mexPrintf("Usage: gs_info('service_name') \n");
    return;
  }

  return;


  /* Error */
 error:
  for (i=0;i<nlhs;i++) plhs[i] = mxCreateDoubleMatrix(0,0,mxREAL); 
  printf("Warning: GridSolve call failed: %d:%d: %s; %s\n", grpc_errno, grpc_minor_errno, grpc_error_string(grpc_errno), grpc_minor_error_string(grpc_minor_errno));  

  if (problem_encoding) free(problem_encoding);
  if (handle && (status=grpc_function_handle_destruct(handle)) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
  handle = matlab_gs_free(handle);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function: