Functions | Variables

problem_util.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "portability.h"
#include "problem.h"
#include "comm_encode.h"
#include "utility.h"
#include "proxylib.h"
Include dependency graph for problem_util.c:

Go to the source code of this file.

Functions

static int gs_free_problem_common (gs_problem_t *, int)
enum inout gs_parse_inout (const char *str)
enum datatype gs_parse_datatype (const char *str)
enum objecttype gs_parse_objecttype (const char *str)
enum probtype gs_parse_probtype (const char *str)
char * gs_problem_getinfo (gs_problem_t *problem, char *type, char *defaultvalue)
void gs_infolist_dump (gs_info_t *infolist)
void gs_arg_dump (gs_argument_t *arg)
void gs_arglist_dump (gs_argument_t *arglist)
void gs_problem_dump (gs_problem_t *problem)
void gs_problemlist_dump (gs_problem_t *problem)
char * gs_problem_prototype (gs_problem_t *problem)
int gs_dup_problem (gs_problem_t *dest, gs_problem_t *src)
int gs_create_request_id (char *template)
int gs_read_problem_from_file (char *fname, gs_problem_t *problem)
int gs_read_server_from_file (char *fname, gs_server_t *server)
int gs_free_problem (gs_problem_t *problem)
int gs_free_problem_and_data (gs_problem_t *problem)
int gs_free_enumlist (gs_arg_enum_t *elist)
int gs_free_arglist (gs_argument_t *arg, int free_data)
int gs_free_infolist (gs_info_t *info)
int gs_create_error_file (char *req, int err)
int gs_create_timestamp_file (char *req, char *fname, double run_time)
int gs_gen_sparse_mat_common (int datatype, size_t el_size, int m, int rmin, int rmax, void **a, int **ip, int **p)
int gs_gen_sparse_mat_double (int m, int rmin, int rmax, double **a, int **ip, int **p)
int gs_gen_sparse_mat_float (int m, int rmin, int rmax, float **a, int **ip, int **p)
int gs_gen_sparse_mat_int (int m, int rmin, int rmax, int **a, int **ip, int **p)
int gs_gen_sparse_mat_char (int m, int rmin, int rmax, char **a, int **ip, int **p)
gs_sparse_dup_t * gs_dup_sparse_mat (int nnz, int dim, size_t el_size, void *m, int *ind, int *ptr)
gs_argument_t * gs_arg_lookup_by_name (char *name, gs_argument_t *arglist)
int gs_arg_is_sparse_attr (char *name, gs_argument_t *arglist)
int gs_datatype_sizeof (int datatype)

Variables

char * gs_inout []
char * gs_c_datatype []
char * gs_objecttype []
char * gs_probtype []
char * gs_const []
char * gs_service_error []

Detailed Description

This file contains various utility functions for manipulating problems.

Definition in file problem_util.c.


Function Documentation

void gs_arg_dump ( gs_argument_t *  arg  ) 

Dumps information about the given argument to the console.

Parameters:
arg -- the argument to be dumped.

Definition at line 291 of file problem_util.c.

{
  if(!arg) {
    printf("NULL arg\n");
    return;
  }

  printf("  Argument Name:     %s\n", arg->name);
  printf("  Description:       %s\n", arg->description);
  printf("  In/out mode:       %s\n", gs_inout[arg->inout]);
  printf("  Data type:         %s\n", gs_c_datatype[arg->datatype]);
  printf("  Object type:       %s\n", gs_objecttype[arg->objecttype]);
  printf("  Row size expr:     %s\n", arg->rowexp);
  printf("  Column size expr:  %s\n", arg->colexp);
}

Here is the caller graph for this function:

int gs_arg_is_sparse_attr ( char *  name,
gs_argument_t *  arglist 
)

Checks whether the specified argument is one of the three attributes of a sparse matrix (nnz, indices, or pointer).

Parameters:
name -- the name of the argument to check
arglist -- the list of all arguments
Returns:
TRUE if this is a sparse attribute (nnz, indices, or pointer). returns FALSE otherwise.

Definition at line 1146 of file problem_util.c.

{
  gs_argument_t *arg;

  for(arg = arglist; arg != NULL; arg = arg->next) {
    if(arg->objecttype == GS_SPARSEMATRIX) {
      if(!strcmp(name, arg->sparse_attr.nnzexp) ||
         !strcmp(name, arg->sparse_attr.indices) ||
         !strcmp(name, arg->sparse_attr.pointer))
        return TRUE;
    }
  }

  return FALSE;
}

Here is the caller graph for this function:

gs_argument_t* gs_arg_lookup_by_name ( char *  name,
gs_argument_t *  arglist 
)

Checks whether the specified name corresponds to an arguement name

Parameters:
name -- the name of the argument to check
arglist -- the list of all arguments
Returns:
pointer to argument if one has that name returns NULL otherwise.

Definition at line 1124 of file problem_util.c.

{
  gs_argument_t *arg;
  for (arg = arglist; arg != NULL; arg = arg->next) 
    if (!strcmp(name, arg->name) )
      return(arg);
  return NULL;
}

Here is the caller graph for this function:

void gs_arglist_dump ( gs_argument_t *  arglist  ) 

Dumps the given argument list to the console.

Parameters:
arglist -- the list of arguments to be dumped.

Definition at line 314 of file problem_util.c.

{
  gs_argument_t *p;
  int i=0;

  for(p = arglist; p != NULL; p = p->next) {
    printf("Argument %d:\n", i++);
    gs_arg_dump(p);
    printf("\n");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_create_error_file ( char *  req,
int  err 
)

Creates an error file in the service directory named "error". The file contains the service error code.

Parameters:
req -- the request ID of the previously submitted request.
err -- the service error code
Returns:
Returns 0 on success, -1 on failure.

Definition at line 813 of file problem_util.c.

{
  char *filename;
  FILE *error_file;

  if(!req) return -1;

  /* allocate enough for reqid + "/error" */
  filename = malloc(strlen(req) + 7);

  if(!filename)
    return -1;

  sprintf(filename, "%s/error", req);

  error_file = fopen(filename, "w");

  free(filename);

  if(error_file) {
    fprintf(error_file, "%d\n", err);
    fclose(error_file);
  }
  else
    return -1;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_create_request_id ( char *  template  ) 

Creates a request ID, which [hopefully] will uniquely identify a particular non-blocking request. This allows the client to disconnect and pick up the data later.

Parameters:
template -- any 'X' in this string will be replaced by a random character from a-z, A-Z, or 0-9. For example, if variable foo contains "foo_XXXX", then upon return foo might contain "foo_oi4G".
Returns:
Returns 0 on success, -1 on failure.

Definition at line 471 of file problem_util.c.

{
  static char alphabet[] =
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  char *p;
  unsigned int seed;

  if(!template)
    return -1;

#ifdef WIN32
  seed = (unsigned)time(NULL);
#else
  {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    seed = tv.tv_usec;
  }
#endif
  srand(seed);

  p = template;

  while(*p) {
    if(*p == 'X')
      *p = alphabet[rand() % 62];
    p++;
  }

  return 0;
}

Here is the caller graph for this function:

int gs_create_timestamp_file ( char *  req,
char *  fname,
double  run_time 
)

Creates a timestamp file in the service directory.

Creates a file in the service dierctory (named as specified in the 'fname' parameter) for the given request ID signifying that the computation is complete/cancelled/whatever. The current date and time is written to the file.

Parameters:
req -- the request ID of the previously submitted request.
fname -- the name of the file to create within the request output subdirectory.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 858 of file problem_util.c.

{
  char *filename;
  FILE *timestamp_file;

  if(!req || !fname)
    return -1;

  filename = malloc(strlen(req) + strlen(fname) + 2);

  if(!filename)
    return -1;

  sprintf(filename, "%s/%s", req, fname);

  timestamp_file = fopen(filename, "w");

  free(filename);

  if(timestamp_file) {
    char timestr[100];
    struct tm *ptr;
    time_t tm;

    tm = time(NULL);
    ptr = localtime(&tm);
    strftime(timestr, 100, "%a %b %d %H:%M:%S %Z %Y", ptr);

    fprintf(timestamp_file, "%s\n", timestr);
    fprintf(timestamp_file, "%lf\n", run_time);

    fclose(timestamp_file);
  }
  else
    return -1;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_datatype_sizeof ( int  datatype  ) 

Returns the sizeof a GS datatype

Parameters:
datatype -- the datatype to check (integer)
Returns:
size of valid datatype returns -1 otherwise.

Definition at line 1172 of file problem_util.c.

{
  switch(datatype) {
  case GS_INT:
    return sizeof(int);
    break;
  case GS_FLOAT:
    return sizeof(float);
    break;
  case GS_DOUBLE:
    return sizeof(double);
    break;
  case GS_SCOMPLEX:
    return sizeof(gs_scomplex);
    break;
  case GS_DCOMPLEX:
    return sizeof(gs_dcomplex);
    break;
  case GS_CHAR:
    return sizeof(char);
    break;
  default:
    return -1;
    break;
  }
}

Here is the caller graph for this function:

int gs_dup_problem ( gs_problem_t *  dest,
gs_problem_t *  src 
)

Duplicates the given problem.

Parameters:
dest -- problem struct into which the duplicated problem will be stored. This should already be allocated with enough memory to hold the problem (i.e. sizeof(gs_problem_t)), but the memory for all other fields will be allocated here.
src -- the source problem (i.e. the one to be duplicated).
Returns:
Returns 0 on success, -1 on failure.

Definition at line 413 of file problem_util.c.

{
  gs_argument_t *src_arg, *dest_arg;
  char *msg = NULL;

  if(!dest || !src)
    return -1;

  /* first copy most of the stuff the easy way - just encode the src and
     decode to the dest.  this won't copy everything however. */

  if(gs_encode_problem(&msg, src) < 0)
    return -1;

  if(gs_decode_problem(msg, dest) < 0) {
    if(msg)
      free(msg);
    return -1;
  }

  free(msg);

  /* now copy the remaining relevant information not contained in the
     encoding. */

  src_arg = src->arglist;
  dest_arg = dest->arglist;

  while(src_arg) {
    dest_arg->rows = src_arg->rows;
    dest_arg->cols = src_arg->cols;
    dest_arg->data = src_arg->data;

    src_arg = src_arg->next;
    dest_arg = dest_arg->next;
  }

  dest->major = src->major;
  dest->work = NULL;
  dest->worksize = 0;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gs_sparse_dup_t* gs_dup_sparse_mat ( int  nnz,
int  dim,
size_t  el_size,
void *  m,
int *  ind,
int *  ptr 
)

Duplicates a CSR matrix.

Parameters:
nnz -- number of non-zero elements in the matrix
dim -- dimension of the matrix
el_size -- size (in bytes) of a data element
m -- pointer to matrix data
ind -- column index array
ptr -- row pointer array
Returns:
struct containing copy on success, NULL on failure.

Definition at line 1085 of file problem_util.c.

{
  gs_sparse_dup_t *new_sp;

  new_sp = (gs_sparse_dup_t *) malloc(sizeof(gs_sparse_dup_t));

  if(!new_sp) return NULL;

  new_sp->m = (void *)malloc(sizeof(double) * el_size * nnz);
  new_sp->ind = (int *)malloc(nnz * sizeof(int));
  new_sp->ptr = (int *)malloc(dim * sizeof(int));

  if(!new_sp->m || !new_sp->ind || !new_sp->ptr) {
    if(new_sp->m) free(new_sp->m);
    if(new_sp->ind) free(new_sp->ind);
    if(new_sp->ptr) free(new_sp->ptr);
    if(new_sp) free(new_sp);
    ERRPRINTF("malloc failed.\n");
    return NULL;
  }

  memcpy(new_sp->m, m, nnz * el_size);
  memcpy(new_sp->ind, ind, nnz * sizeof(int));
  memcpy(new_sp->ptr, ptr, dim * sizeof(int));

  return new_sp;
}

int gs_free_arglist ( gs_argument_t *  arg,
int  free_data 
)

Frees all arguments in the given list of arguments, recursively frees all fields in each argument.

Parameters:
arg -- the list of arguments to be freed.
free_data -- if TRUE, the argument data itself is freed.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 677 of file problem_util.c.

{
  gs_argument_t *tmpa, *prev;

  if(!arg)
    return -1;

  tmpa = arg;
  while(tmpa) {
    if(tmpa->name)
      free(tmpa->name);
    if(tmpa->description)
      free(tmpa->description);
    if(tmpa->rowexp)
      free(tmpa->rowexp);
    if(tmpa->colexp)
      free(tmpa->colexp);
    if(tmpa->sparse_attr.nnzexp)
      free(tmpa->sparse_attr.nnzexp);
    if(tmpa->sparse_attr.indices)
      free(tmpa->sparse_attr.indices);
    if(tmpa->sparse_attr.pointer)
      free(tmpa->sparse_attr.pointer);

    if(free_data && tmpa->data)
      free(tmpa->data);

    gs_free_enumlist(tmpa->arg_enum);

    prev = tmpa;
    tmpa = tmpa->next;
    free(prev);
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_free_enumlist ( gs_arg_enum_t *  elist  ) 

Definition at line 643 of file problem_util.c.

{
  gs_arg_enum_t *tmpe;

  if(!elist)
    return -1;

  tmpe = elist;
  while(tmpe) {
    if(tmpe->val)
      free(tmpe->val);
    tmpe = tmpe->next;
  }

  /* the enum list is built a bit differently, so we don't need
   * to free each element, just the head.
   */

  free(elist);

  return 0;
}

Here is the caller graph for this function:

int gs_free_infolist ( gs_info_t *  info  ) 

Frees all elements in the given list of attributes, recursively frees all fields in each attribute.

Parameters:
info -- the list of attributes to be freed.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 781 of file problem_util.c.

{
  gs_info_t *tmpi, *prev;

  if(!info)
    return -1;

  tmpi = info;
  while(tmpi) {
    if(tmpi->type)
      free(tmpi->type);
    if(tmpi->value)
      free(tmpi->value);
    prev = tmpi;
    tmpi = tmpi->next;
    free(prev);
  }

  return 0;
}

Here is the caller graph for this function:

int gs_free_problem ( gs_problem_t *  problem  ) 

Frees all problems in the given problem list, recursively frees all fields in each problem.

Parameters:
problem -- the list of problems to be freed.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 581 of file problem_util.c.

{
  return gs_free_problem_common(problem, FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_free_problem_and_data ( gs_problem_t *  problem  ) 

Frees all problems in the given problem list, recursively frees all fields in each problem (including the data itself). Currently I think this would only be called on the server side since you would not want to attempt to free the user's data.

Parameters:
problem -- the list of problems to be freed.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 598 of file problem_util.c.

{
  return gs_free_problem_common(problem, TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int gs_free_problem_common ( gs_problem_t *  problem,
int  free_data 
) [static]

Common code for freeing problem structs. Frees all problems in the given problem list, recursively frees all fields in each problem, and optionally frees the data itself.

Parameters:
problem -- the list of problems to be freed.
free_data -- if TRUE, the argument data itself is freed.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 615 of file problem_util.c.

{
  gs_problem_t *tmpp, *prev;

  if(!problem)
    return -1;

  tmpp = problem;
  while(tmpp) {
    if(tmpp->name)
      free(tmpp->name);
    if(tmpp->description)
      free(tmpp->description);
    if(tmpp->callsig)
      free(tmpp->callsig);
    if(tmpp->work)
      free(tmpp->work);

    gs_free_arglist(tmpp->arglist, free_data);
    gs_free_infolist(tmpp->infolist);
    prev = tmpp;
    tmpp = tmpp->next;
    free(prev);
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_gen_sparse_mat_char ( int  m,
int  rmin,
int  rmax,
char **  a,
int **  ip,
int **  p 
)

Creates a random sparse matrix.

Parameters:
m -- number of rows
rmin -- minium row length
rmax -- maximum row length
a -- non-zero elements
ip -- column indices
p -- row pointers
Returns:
Returns 0 on success, -1 on failure.

Definition at line 1064 of file problem_util.c.

{
  return gs_gen_sparse_mat_common(GS_CHAR, sizeof(char), m, rmin, rmax,
    (void *)a, ip, p);
}

Here is the call graph for this function:

int gs_gen_sparse_mat_common ( int  datatype,
size_t  el_size,
int  m,
int  rmin,
int  rmax,
void **  a,
int **  ip,
int **  p 
)

Creates a random sparse matrix.

Parameters:
datatype -- data type of the matrix
el_size -- size of a data element
m -- number of rows
rmin -- minium row length
rmax -- maximum row length
a -- non-zero elements
ip -- column indices
p -- row pointers
Returns:
Returns 0 on success, -1 on failure.

Definition at line 914 of file problem_util.c.

{
  int i, ii, j, idx, nnz, *ptr, *ind;
  void *mat;

  nnz = 0;

  ptr = (int *) malloc((m+1) * sizeof(int));
  if(!ptr) return -1;

  ptr[0] = 0;
  for(i=1;i<=m;i++) {
    int colsize = random() % (rmax-rmin+1) + rmin;

    ptr[i] = ptr[i-1] + colsize;

    nnz += colsize;
  }

  ind = (int *)malloc(nnz * sizeof(int));
  if(!ind) return -1;
  mat = (void *) malloc(sizeof(double) * nnz * el_size);
  if(!mat) return -1;

  ii = idx = 0;
  for(i=0;i<m;i++) {
    int up, lo, remain, l = ptr[i+1]-ptr[i];

    remain = l;
    lo = -1;

    for(j=0;j<l;j++) {
      up = m - remain;
      lo = lo + 1;

      switch(datatype) {
        case GS_DOUBLE:
          ((double *)mat)[ii] = drand48();
          break;
        case GS_FLOAT:
          ((float *)mat)[ii] = (float)drand48();
          break;
        case GS_INT:
          ((int *)mat)[ii] = random();
          break;
        case GS_CHAR:
          ((int *)mat)[ii] = (random() % 26) + 'a';
          break;
        default:
          ERRPRINTF("Bad data type\n");
      }

      if(up != 0) {
        idx = random() % (up-lo) + lo;

        remain--;
      }
      else
        idx = lo;

      ind[ii] = idx;
      lo = idx;
      ii++;
    }
  }

  *p = ptr;
  *ip = ind;
  *a = mat;
  return nnz;
}

Here is the caller graph for this function:

int gs_gen_sparse_mat_double ( int  m,
int  rmin,
int  rmax,
double **  a,
int **  ip,
int **  p 
)

Creates a random sparse matrix.

Parameters:
m -- number of rows
rmin -- minium row length
rmax -- maximum row length
a -- non-zero elements
ip -- column indices
p -- row pointers
Returns:
Returns 0 on success, -1 on failure.

Definition at line 1001 of file problem_util.c.

{
  return gs_gen_sparse_mat_common(GS_DOUBLE, sizeof(double), m, rmin, rmax,
    (void *)a, ip, p);
}

Here is the call graph for this function:

int gs_gen_sparse_mat_float ( int  m,
int  rmin,
int  rmax,
float **  a,
int **  ip,
int **  p 
)

Creates a random sparse matrix.

Parameters:
m -- number of rows
rmin -- minium row length
rmax -- maximum row length
a -- non-zero elements
ip -- column indices
p -- row pointers
Returns:
Returns 0 on success, -1 on failure.

Definition at line 1022 of file problem_util.c.

{
  return gs_gen_sparse_mat_common(GS_FLOAT, sizeof(float), m, rmin, rmax,
    (void *)a, ip, p);
}

Here is the call graph for this function:

int gs_gen_sparse_mat_int ( int  m,
int  rmin,
int  rmax,
int **  a,
int **  ip,
int **  p 
)

Creates a random sparse matrix.

Parameters:
m -- number of rows
rmin -- minium row length
rmax -- maximum row length
a -- non-zero elements
ip -- column indices
p -- row pointers
Returns:
Returns 0 on success, -1 on failure.

Definition at line 1043 of file problem_util.c.

{
  return gs_gen_sparse_mat_common(GS_INT, sizeof(int), m, rmin, rmax,
    (void *)a, ip, p);
}

Here is the call graph for this function:

void gs_infolist_dump ( gs_info_t *  infolist  ) 

Dumps the given attribute list to the console.

Parameters:
infolist -- the list of attributes to be dumped.

Definition at line 272 of file problem_util.c.

{
  gs_info_t *p;

  if(!infolist)
    return;

  printf("Problem attributes:\n");
  for(p = infolist; p != NULL; p = p->next)
    printf("  %s: %s\n", p->type, p->value);
}

Here is the caller graph for this function:

enum datatype gs_parse_datatype ( const char *  str  ) 

Given a string, determine the data type it represents.

Parameters:
str -- the string representation of the data type.
Returns:
GS_INT if integer, GS_FLOAT if single precision floating point, GS_DOUBLE if double-precision floating point, or GS_CHAR if character. On error, return GS_BAD_DTYPE.

Definition at line 159 of file problem_util.c.

{
  if(!str)
    return GS_BAD_DTYPE;

  if(!strcasecmp(str, gs_c_datatype[GS_INT]))
    return GS_INT;
  if(!strcasecmp(str, gs_c_datatype[GS_FLOAT]))
    return GS_FLOAT;
  if(!strcasecmp(str, gs_c_datatype[GS_DOUBLE]))
    return GS_DOUBLE;
  if(!strcasecmp(str, gs_c_datatype[GS_SCOMPLEX]))
    return GS_SCOMPLEX;
  if(!strcasecmp(str, gs_c_datatype[GS_DCOMPLEX]))
    return GS_DCOMPLEX;
  if(!strcasecmp(str, gs_c_datatype[GS_CHAR]))
    return GS_CHAR;

  return GS_BAD_DTYPE;
}

Here is the caller graph for this function:

enum inout gs_parse_inout ( const char *  str  ) 

Given a string, determine whether it represents input-only, input/output, or output-only.

Parameters:
str -- the string representation of the keyword.
Returns:
GS_IN if input-only, GS_INOUT if input/output, GS_OUT if output-only, or GS_WORKSPACE if workspace. On error, return GS_BAD_INOUT.

Definition at line 129 of file problem_util.c.

{
  if(!str)
    return GS_BAD_INOUT;

  if(!strcasecmp(str, gs_inout[GS_IN]))
    return GS_IN;
  if(!strcasecmp(str, gs_inout[GS_INOUT]))
    return GS_INOUT;
  if(!strcasecmp(str, gs_inout[GS_OUT]))
    return GS_OUT;
  if(!strcasecmp(str, gs_inout[GS_VAROUT]))
    return GS_VAROUT;
  if(!strcasecmp(str, gs_inout[GS_WORKSPACE]))
    return GS_WORKSPACE;

  return GS_BAD_INOUT;
}

Here is the caller graph for this function:

enum objecttype gs_parse_objecttype ( const char *  str  ) 

Given a string, determine the object type it represents.

Parameters:
str -- the string representation of the object type.
Returns:
GS_SCALAR if scalar, GS_VECTOR if a one-dimensional array, or GS_MATRIX if a two-dimensional array. On error, return GS_BAD_OTYPE.

Definition at line 191 of file problem_util.c.

{
  if(!str)
    return GS_BAD_OTYPE;

  if(!strcasecmp(str, gs_objecttype[GS_SCALAR]))
    return GS_SCALAR;
  if(!strcasecmp(str, gs_objecttype[GS_VECTOR]))
    return GS_VECTOR;
  if(!strcasecmp(str, gs_objecttype[GS_MATRIX]))
    return GS_MATRIX;
  if(!strcasecmp(str, gs_objecttype[GS_SPARSEMATRIX]))
    return GS_SPARSEMATRIX;
  if(!strcasecmp(str, gs_objecttype[GS_FILE]))
    return GS_FILE;
  if(!strcasecmp(str, gs_objecttype[GS_PACKEDFILE]))
    return GS_PACKEDFILE;

  return GS_BAD_OTYPE;
}

Here is the caller graph for this function:

enum probtype gs_parse_probtype ( const char *  str  ) 

Given a string, determine the problem type it represents.

Parameters:
str -- the string representation of the problem type.
Returns:
GS_SUBROUTINE if a subroutine (i.e. has no return value, GS_FUNCTION if a function. On error, return GS_BAD_PTYPE.

Definition at line 222 of file problem_util.c.

{
  if(!str)
    return GS_BAD_PTYPE;

  if(!strcasecmp(str, gs_probtype[GS_SUBROUTINE]))
    return GS_SUBROUTINE;
  if(!strcasecmp(str, gs_probtype[GS_FUNCTION]))
    return GS_FUNCTION;

  return GS_BAD_PTYPE;
}

Here is the caller graph for this function:

void gs_problem_dump ( gs_problem_t *  problem  ) 

Dumps information about the given problem to the console.

Parameters:
problem -- the problem to be dumped.

Definition at line 333 of file problem_util.c.

{
  if(!problem) {
    printf("NULL problem\n");
    return;
  }

  printf("\n");
  printf("Problem Name: %s\n", problem->name);
  printf("\n");
  printf("Problem Description:\n  %s\n", problem->description);
  printf("\n");
  gs_arglist_dump(problem->arglist);
  gs_infolist_dump(problem->infolist);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* gs_problem_getinfo ( gs_problem_t *  problem,
char *  type,
char *  defaultvalue 
)

For the given problem, looks up the given type (name) in the problem's infolist and returns the associated value. This routine does not allocate new memory, so be careful with freeing.

Parameters:
problem -- the problem whose attributes should be searched.
type -- the attribute tag to search for.
defaultvalue -- the default value to return if no matching attribute was found. This can be NULL.
Returns:
Returns either the matching attribute value or the specified default value.

Definition at line 251 of file problem_util.c.

{
  gs_info_t *info;

  if(!problem || !type)
    return NULL;

  for(info = problem->infolist; info != NULL; info = info->next)
    if(!strcmp(info->type, type))
      return info->value;

  return defaultvalue;
}

Here is the caller graph for this function:

char* gs_problem_prototype ( gs_problem_t *  problem  ) 

Return a prototype string for a problem.

The prototype string does not contain variable names or descriptions, and can be used to compare new versions of the same problem name to make sure that they match the old versions. The memory for the string is allocated here and needs to be deallocated by the user.

Parameters:
problem -- the problem whose prototype should be generated.
Returns:
Returns prototype string on success, NULL on failure.

Definition at line 381 of file problem_util.c.

{
  char *s, *stmp = NULL;
  gs_argument_t *arg = NULL;

  if(!problem) return NULL;

  s = strdup("");
  for(arg = problem->arglist; arg != NULL; arg = arg->next) {
    stmp = dstring_sprintf("inout=\"%s\" datatype=\"%s\" \
      objecttype=\"%s\" rowexp=\"%s\" colexp=\"%s\" \n",
      gs_inout[arg->inout], gs_c_datatype[arg->datatype],
      gs_objecttype[arg->objecttype], arg->rowexp, arg->colexp);
    s = dstring_append_free(s, stmp);
  }

  return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gs_problemlist_dump ( gs_problem_t *  problem  ) 

Dumps the given problem list to the console.

Parameters:
problem -- the list of problems to be dumped.

Definition at line 356 of file problem_util.c.

{
  gs_problem_t *p;

  printf("<problemlist>\n");
  for(p = problem; p != NULL; p = p->next)
    gs_problem_dump(p);
  printf("</problemlist>\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_read_problem_from_file ( char *  fname,
gs_problem_t *  problem 
)

Reads the problem description from a file and fills out the given problem struct with the information.

Parameters:
fname -- the name of the file containing the problem description.
problem -- the problem structure into which the information should be written. This should already have sizeof(gs_problem_t) bytes of memory allocated.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 516 of file problem_util.c.

{
  char *problemstring = NULL;

  if(!fname || !problem)
    return -1;

  if(gs_get_contents_of_file(fname, &problemstring) < 0)
    return -1;

  /* parse buffer into problem structure */
  if(gs_decode_problem(problemstring, problem) < 0) {
    free(problemstring);
    return -1;
  }

  free(problemstring);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_read_server_from_file ( char *  fname,
gs_server_t *  server 
)

Reads the server description from a file and fills out the given server struct with the information.

Parameters:
fname -- the name of the file containing the server description.
problem -- the server structure into which the information should be written. This should already have sizeof(gs_server_t) bytes of memory allocated.
Returns:
Returns 0 on success, -1 on failure.

Definition at line 550 of file problem_util.c.

{
  char *serverstring = NULL;

  if(!fname || !server)
    return -1;

  if(gs_get_contents_of_file(fname, &serverstring) < 0)
    return -1;

  /* parse buffer into server structure */
  if(gs_decode_server(serverstring, server) < 0) {
    free(serverstring);
    return -1;
  }

  free(serverstring);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* gs_c_datatype[]
Initial value:
 {
  "int",
  "float",
  "double",
  "gs_scomplex",
  "gs_dcomplex",
  "char",
  "bad data type"
}

Mapping from enum datatype to the C data type

Definition at line 40 of file problem_util.c.

char* gs_const[]
Initial value:
 {
  "10",
  "5.0",
  "10.0",
  "__scval",
  "__dcval",
  "'n'",
  "bad const"
}

Some constants for generating example code

Definition at line 69 of file problem_util.c.

char* gs_inout[]
Initial value:
 {
  "in",
  "inout",
  "out",
  "workspace",
  "varout",
  "bad inout"
}

Mapping from enum inout to a string representation

Definition at line 30 of file problem_util.c.

char* gs_objecttype[]
Initial value:
 {
  "scalar",
  "vector",
  "matrix",
  "sparsematrix",
  "file",
  "packedfile",
  "bad object type"
}

Mapping from enum objecttype to a string

Definition at line 51 of file problem_util.c.

char* gs_probtype[]
Initial value:
 {
  "subroutine",
  "function",
  "bad prob type"
}

Mapping from enum probtype to a string

Definition at line 62 of file problem_util.c.

Definition at line 79 of file problem_util.c.