static int SetInitialProfile(N_Vector uu, N_Vector up,  N_Vector id, 
                             N_Vector res, UserData data)
{
  int i, iloc, j, jloc, offset, loc, ixsub, jysub;
  int ixbegin, ixend, jybegin, jyend;
  realtype xfact, yfact, *udata, *iddata, dx, dy;
  
  /* Initialize uu. */ 
  
  udata = N_VGetArrayPointer_Parallel(uu);
  iddata = N_VGetArrayPointer_Parallel(id);
  
  /* Set mesh spacings and subgrid indices for this PE. */
  dx = data->dx;
  dy = data->dy;
  ixsub = data->ixsub;
  jysub = data->jysub;
  
  /* Set beginning and ending locations in the global array corresponding 
     to the portion of that array assigned to this processor. */
  ixbegin = MXSUB*ixsub;
  ixend   = MXSUB*(ixsub+1) - 1;
  jybegin = MYSUB*jysub;
  jyend   = MYSUB*(jysub+1) - 1;
  
  /* Loop over the local array, computing the initial profile value.
     The global indices are (i,j) and the local indices are (iloc,jloc).
     Also set the id vector to zero for boundary points, one otherwise. */
  
  N_VConst(ONE,id);
  for (j = jybegin, jloc = 0; j <= jyend; j++, jloc++) {
    yfact = data->dy*j;
    offset= jloc*MXSUB;
    for (i = ixbegin, iloc = 0; i <= ixend; i++, iloc++) {
      xfact = data->dx * i;
      loc = offset + iloc;
      udata[loc] = RCONST(16.0) * xfact * (ONE - xfact) * yfact * (ONE - yfact);
      if (i == 0 || i == MX-1 || j == 0 || j == MY-1) iddata[loc] = ZERO;
    }
  }
  
  /* Initialize up. */
  
  N_VConst(ZERO, up);    /* Initially set up = 0. */
  
  /* heatres sets res to negative of ODE RHS values at interior points. */
  heatres(ZERO, uu, up, res, data);
  
  /* Copy -res into up to get correct initial up values. */
  N_VScale(-ONE, res, up);
  
  return(0);
  
}
static int SetInitialProfile(UserData data, N_Vector uu, N_Vector up,
                             N_Vector id, N_Vector res)
{
    realtype xfact, yfact, *udata, *updata, *iddata;
    long int mm, mm1, i, j, offset, loc;

    mm = data->mm;
    mm1 = mm - 1;

    udata = NV_DATA_S(uu);
    updata = NV_DATA_S(up);
    iddata = NV_DATA_S(id);

    /* Initialize id to 1's. */
    N_VConst(ONE, id);

    /* Initialize uu on all grid points. */
    for (j = 0; j < mm; j++) {
        yfact = data->dx * j;
        offset = mm*j;
        for (i = 0; i < mm; i++) {
            xfact = data->dx * i;
            loc = offset + i;
            udata[loc] = RCONST(16.0) * xfact * (ONE - xfact) * yfact * (ONE - yfact);
        }
    }

    /* Initialize up vector to 0. */
    N_VConst(ZERO, up);

    /* heatres sets res to negative of ODE RHS values at interior points. */
    heatres(ZERO, uu, up, res, data);

    /* Copy -res into up to get correct interior initial up values. */
    N_VScale(-ONE, res, up);

    /* Finally, set values of u, up, and id at boundary points. */
    for (j = 0; j < mm; j++) {
        offset = mm*j;
        for (i = 0; i < mm; i++) {
            loc = offset + i;
            if (j == 0 || j == mm1 || i == 0 || i == mm1 ) {
                udata[loc] = BVAL;
                updata[loc] = ZERO;
                iddata[loc] = ZERO;
            }
        }
    }

    return(0);

}