/* generic binary operation on parallel vectors */
typedef struct _LA_Dvector_binop
{
    LA_Dvector *x;
    LA_Dvector *y;
    double      alpha;
    double      beta;

    MPI_Comm    comm;

    void *(*new)();
    void (*op)();    
    void (*destruct)(); 
    
} LA_Dvector_binop;

typedef struct _LA_Dvector_ddot_stride_binop
{
    LA_Dvector_binop binop;

    /* striding information */
    int local_start;
    int local_stride;

} LA_Dvector_nostride_ddot_binop;

LA_Dvector_binop *LA_Dvector_binop_new(LA_Dvector *x, LA_Dvector *y, double alpha, beta)
{
  LA_Dvector_binop *binop;
  binop = NEW_CLEAR_ITEM(LA_Dvector_binop, 1);
  if(binop == NULL) return(NULL);

  LA_Dvector_binop_init(binop, x, y, alpha, beta);
  return(binop);
}


void LA_Dvector_binop_init(LA_Dvector_binop *binop, LA_Dvector *x, LA_Dvector *y,
			   double alpha, beta)
{
    binop -> x = x;
    binop -> y = y;
    binop -> alpha = alpha;
    binop -> beta  = beta;
    binop -> error = 0;
}

LA_Dvector_nostride_ddot_binop *ddot_nostride_construct(LA_Dvector *x, LA_Dvector *y)
{
  LA_Dvector_binop_init(&(xy.binop), x, y, 0.0, 0.0);  /* base class */
  if (x->type != y->type)  /* Check for compatible types */
      xy -> error = MPI_FAILURE;

  /* check communicator compatibility: */
  MPI_Comm_compare(x -> comm, y -> comm, ...);

  /* check grid-shape compatibility: */

  /* use the appropriate communicator: */
  binop -> comm = 

  return(xy);
}

LA_Dvector_stride_ddot_binop *ddot_stride_construct()
{
  xy = LA_Dvector_binop_new(x, y, 0.0, 0.0);
  if (x->type != y->type)  /* Check for compatible types */
      xy -> error = MPI_FAILURE;

  return(xy);
}

void LA_Dvector_ddot_stride_init(LA_Dvector_ddot_stride_binop *xy, 
				 LA_Dvector *x, LA_Dvector *y)
{
  xy = LA_Dvector_binop(x, y, 0.0, 0.0);
  if (x->type != y->type)  /* Check for compatible types */
      xy -> error = MPI_FAILURE;

  if (x->type == LA_GRID_ROW)
  {
    xy -> local_start  = x->grid->p;
    xy -> local_stride = x->grid->P;
  }
  else
  {
    xy -> local_start  = x->grid->q;
    xy -> local_stride = x->grid->Q;
  }
  xy -> comm = x->grid->grid_comm;
}

void LA_Dvector_ddot_no_stride_init(LA_Dvector_binop *xy, 
				 LA_Dvector *x, LA_Dvector *y)
{
  if (x->type == LA_GRID_ROW)
  {
    xy -> comm         = x->grid->row_comm;
  }
  else
  {
    xy -> comm         = x->grid->col_comm;
  }
}


