matlab_gs_wait.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_wait.c:

Go to the source code of this file.


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

Detailed Description

Matlab client call

Definition in file matlab_gs_wait.c.

Function Documentation

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

Wait for the completion of a prevously submitted asynchronous call using grpc_wait, returning the status of the grpc_wait call (0 if OK, -1 if error).

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 32 of file matlab_gs_wait.c.

  int i = -1;
  int rc = -1;
  grpc_request_t *request = NULL;
  grpc_sessionid_t sessionID;
  grpc_error_t status;

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

  /* Check arguments */
  if (nrhs < 2) {
    mexErrMsgTxt("Usage: [outputargs,...] = gs_wait(sessionID, inputargs, ...)\n");
    for (i=0;i<nlhs;i++) plhs[i] = mxCreateDoubleMatrix(0,0,mxREAL);
  /* Get sessionid from rhs */
  sessionID = (int)mxGetPr(prhs[1])[0];
  /* Matlab uses column major indexing */
  if (grpc_set_client_major("Column") != GRPC_NO_ERROR) 
  /* Locate request structure */
  request = grpc_get_request(sessionID);
  if (request == NULL) DO_ERROR_MACRO(grpc_errno);
  /* We call gs_wait_common, because we need manipulate a request
     handle to extract the output and transfer to matlab before
     destroying it.  The standard gs_wait assumes that the user
     already has pointers to the output data location. Note: This is
     not the fault tolerant version of gs_wait */
  /* TODO Handle fault tolerant wait */
  status = gs_wait_common(request);
  if (status != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
  /* DBGPRINTF("get output\n"); */
  rc = matlab_gs_get_output(request->problem, nlhs, plhs, nrhs, prhs);

  /* Finalize */
  DBGPRINTF("Clean up\n");
  if (matlab_gs_free_args(request->handle->problem_desc, nlhs, plhs, nrhs, prhs) != 0) DO_ERROR_MACRO(GRPC_OTHER_ERROR_CODE);
  if (request && request->handle) if (grpc_function_handle_destruct(request->handle) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
  if (request && request->handle) request->handle = matlab_gs_free(request->handle); 
  if (grpc_request_destruct_free_clear(sessionID) != GRPC_NO_ERROR) DO_ERROR_MACRO(grpc_errno);
  /* TODO argstack? */


  for (i=0;i<nlhs;i++) plhs[i] = mxCreateDoubleMatrix(0,0,mxREAL);
  mexPrintf("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));  


Here is the call graph for this function:

Here is the caller graph for this function: