Esempio n. 1
0
 /*@@
   @routine    PUGH_ArrayGroupSize
   @author     Gabrielle Allen
   @date       11 Apr 1999
   @desc
               Returns size of arrays in a group, in a given direction.
               Either group index or its name must be given,
               the name takes precedence.
   @enddesc
   @calls      CCTK_GroupIndex
               CCTK_FirstVarIndexI


   @var        GH
   @vdesc      Pointer to CCTK grid hierarchy
   @vtype      const cGH *
   @vio        in
   @endvar
   @var        dir
   @vdesc      direction to return size of
   @vtype      int
   @vio        in
   @endvar
   @var        group
   @vdesc      index of group
   @vtype      int
   @vio        in
   @endvar
   @var        groupname
   @vdesc      name of group
   @vtype      const char *
   @vio        in
   @endvar

   @returntype const int *
   @returndesc
               pointer to the size variable for the given direction, or
               NULL if given direction or group index/name are invalid
   @endreturndesc
@@*/
const int *PUGH_ArrayGroupSize (const cGH *GH,
                                int dir,
                                int group,
                                const char *groupname)
{
  int first_var;
  pGA *GA;
  const int *retval;


  if (groupname)
  {
    group = CCTK_GroupIndex (groupname);
  }

  first_var = CCTK_FirstVarIndexI (group);
  if (first_var >= 0)
  {
    /* get pointer to pGA for a timelevel of first variable in this group */
    GA = (pGA *) PUGH_pGH (GH)->variables[first_var][0];

    if (GA->storage == PUGH_STORAGE)
    {
      if (dir >= 0 && dir < GA->extras->dim)
      {
        retval = &GA->extras->lnsize[dir];
      }
      else
      {
        CCTK_WARN (1, "Wrong value for dir");
        retval = NULL;
      }
    }
    else
    {
      retval = &_cctk_one;
    }
  }
  else
  {
    if (groupname)
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "PUGH_ArrayGroupSize: Invalid group name '%s'",
                  groupname);
    }
    else
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "PUGH_ArrayGroupSize: Invalid group ID %d",
                  group);
    }

    retval = NULL;
  }

  return (retval);
}
Esempio n. 2
0
 /*@@
   @routine    CCTKi_CommandLineParameterLevel
   @date       Wed Feb 21 2001
   @author     Gabrielle Allen
   @desc
               Sets the parameter checking level from a command line argument.
   @enddesc
   @calls      CCTKi_SetParameterLevel

   @var        argument
   @vdesc      option argument
   @vtype      const char *
   @vio        in
   @endvar
@@*/
void CCTKi_CommandLineParameterLevel (const char *argument)
{
  int parameterlevel;


  if (CCTK_Equals (argument, "strict"))
  {
    parameterlevel = CCTK_PARAMETER_STRICT;
  }
  else if (CCTK_Equals (argument, "normal"))
  {
    parameterlevel = CCTK_PARAMETER_NORMAL;
  }
  else if (CCTK_Equals (argument, "relaxed"))
  {
    parameterlevel = CCTK_PARAMETER_RELAXED;
  }
  else
  {
    CCTK_VWarn (1, __LINE__, __FILE__, "Cactus",
                "CCTKi_CommandLineParameterLevel: Parameter checking level "
                "'%s' not recognized, defaulting to normal", argument);
    parameterlevel = CCTK_PARAMETER_NORMAL;
  }

  CCTKi_SetParameterLevel (parameterlevel);
}
Esempio n. 3
0
 /*@@
   @routine    PUGH_InitializeMemory
   @author     Thomas Radke
   @date       Thu 30 Aug 2001
   @desc
               Initializes allocated memory to all zeros (all variable types)
               or NaNs (floating point types only)
   @enddesc

   @var        initialize_memory
   @vdesc      keyword describing how to initialize memory
   @vtype      const char *
   @vio        in
   @endvar
   @var        vtype
   @vdesc      CCTK variable type of the variable to initialize
   @vtype      int
   @vio        in
   @endvar
   @var        bytes
   @vdesc      total number of bytes to initialize
   @vtype      int
   @vio        in
   @endvar
   @var        data
   @vdesc      pointer to data to initialize
   @vtype      void *
   @vio        in
   @endvar
@@*/
static void PUGH_InitializeMemory (const char *initialize_memory,
                                   int vtype,
                                   int bytes,
                                   void *data)
{
  const char *vtypename;


  /* zero out variable */
  if (CCTK_Equals (initialize_memory, "zero"))
  {
    memset (data, 0, bytes);
  }
  /* set elements to Not-a-Number values (floating point variables only) */
  else if (CCTK_Equals (initialize_memory, "NaN"))
  {
    vtypename = CCTK_VarTypeName (vtype);
    if (strncmp (vtypename, "CCTK_VARIABLE_REAL",    18) == 0 ||
        strncmp (vtypename, "CCTK_VARIABLE_COMPLEX", 22) == 0)
    {
      memset (data, -1, bytes);
    }
  }
  else if (! CCTK_Equals (initialize_memory, "none"))
  {
    CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
                "InitializeMemory: Unknown keyword '%s' for "
                "parameter 'initialize_memory'", initialize_memory);
  }
}
Esempio n. 4
0
int SetCartSymGI(cGH *GH, int *sym, int gi) 
{
  
  DECLARE_CCTK_PARAMETERS

  int domainsym[MAX_FACE];
  SymmetryGHex *sGHex; 
  int first_vari,numvars,vi;
  int dir;
  
  sGHex  = (SymmetryGHex *)GH->extensions[CCTK_GHExtensionHandle("Symmetry")];

  first_vari = CCTK_FirstVarIndexI(gi);
  numvars    = CCTK_NumVarsInGroupI(gi);

  if (first_vari<0)
  {
    CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,
	       "Cannot find group %s (grp.index: %d) in SetCartSymGI",
	       CCTK_GroupName(gi),first_vari);
    return(-1);
  }

  /* Reference the hash table in the GHex and tell it what kind of
     symmetry is being applied 
     (depending on sym and the grid layout) 
     If there is no symmetry necessary,set ESYM_NOSYM
     When we apply a symmetry and find ESYM_UNSET, something went wrong! 
   */
  for (vi=first_vari; vi<first_vari+numvars; vi++) 
  {

#ifdef SYM_DEBUG
    printf("SetSymmetry: %s   [%d,%d,%d]\n",CCTK_VarName(vi), 
	   sym[0],sym[1],sym[2]);
#endif
    
    DecodeSymParameters3D (domainsym);
    for (dir=0; dir<MAX_FACE; dir++) 
    {
      if (domainsym[dir]) 
      {
	sGHex->GFSym[vi][dir] = sym[dir/2];
      }
      else 
      {
	sGHex->GFSym[vi][dir] = GFSYM_NOSYM;
      }
    }

#ifdef SYM_DEBUG
    printf("SetSymmetry: %s   [%d,%d,%d]\n\n",imp_gf, 
	   sGHex->GFSym[vi][0],
	   sGHex->GFSym[vi][2],
	   sGHex->GFSym[vi][4]);
#endif
  }
  USE_CCTK_PARAMETERS;   return(0);
}
Esempio n. 5
0
 /*@@
   @routine    PUGH_DisableComm
   @date       Mon Jun 05 2000
   @author     Thomas Radke
   @desc
               This frees the communication buffers
               of a given comm structure.
   @enddesc
   @history
               Separated from routine PUGH_DisableGArrayDataStorage()
   @endhistory
@@*/
static int PUGH_DisableComm(pGH *pughGH,
                            pComm *comm)
{
#ifdef CCTK_MPI
  int i;                  /* looper */
  pGA *GA;                /* GA structure the comm structure belongs to */


  /* get the GA to which the comm structure belongs to
     For a comm structure this is the first variable within this group. */
  GA = (pGA *) pughGH->variables [comm->first_var][comm->sync_timelevel];

#ifdef DEBUG_PUGH
  printf (" PUGH_DisableComm: freeing comm buffer for group of %d vars and "
          "first var '%s'\n", comm->n_vars, GA->name);
  fflush (stdout);
#endif

  if (comm->commflag != PUGH_NOCOMM)
  {
    /* free memory for communication buffers: 2 faces per direction */
    for (i = 0; i < 2 * GA->extras->dim; i++)
    {
      if (comm->send_buffer[i])
      {
        free(comm->send_buffer[i]);
        comm->send_buffer[i] = NULL;
      }

      if (comm->recv_buffer[i])
      {
        free(comm->recv_buffer[i]);
        comm->recv_buffer[i] = NULL;
      }

      comm->buffer_sz[i] = 0;
    }

    comm->commflag = PUGH_NOCOMM;
  }
  else
  {
    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                "PUGH_DisableComm: Communication already disabled for "
		"group of %d vars "
                "and first var '%s'", comm->n_vars, GA->name);
  }

#else

  /* get rid of compiler warning about unused parameters */
  pughGH = pughGH;
  comm = comm;

#endif   /* CCTK_MPI */

  return (1);
}
Esempio n. 6
0
int PUGH_SyncGroup(cGH *GH, const char *groupname)
{
  cGroup pgroup;           /* group information */
  int group;               /* group index */
  int rc;                  /* return code */

#ifdef DEBUG_PUGH
  printf (" PUGH_SyncGroup: request for group '%s'\n", groupname);
  fflush (stdout);
#endif

  /* get the group info from its index */
  group = CCTK_GroupIndex(groupname);
  if (group < 0)
  {
    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                "PUGH_SyncGroup: Unknown group: %s", groupname);
    rc = -1;
  }
  else
  {
    CCTK_GroupData(group, &pgroup);

    if (pgroup.grouptype == CCTK_SCALAR)
    {
      rc = 0;
      CCTK_VWarn(4, __LINE__, __FILE__, CCTK_THORNSTRING,
		 "PUGH_SyncGroup: Synchronising scalar group: %s",groupname);
    }
    else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
    {
      rc = PUGH_SyncGArrayGroup(PUGH_pGH(GH), CCTK_FirstVarIndexI(group));
    }
    else
    {
      CCTK_WARN(1, "PUGH_SyncGroup: Unknown group type");
      rc = 0;
    }
  }

  return (rc);
}
Esempio n. 7
0
/* callback for CCTK_TraverseString() to set the output flag
   for the given variable */
static void SetOutputFlag (int vindex, const char *optstring, void *arg)
{
  char *flags = (char *) arg;


  flags[vindex] = 1;

  if (optstring)
  {
    CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
                "Optional string '%s' in variable name ignored", optstring);
  }
}
Esempio n. 8
0
int SetCartSymGN(cGH *GH, int *sym, const char *gn) 
{
  int gi = CCTK_GroupIndex(gn);
  
  if (gi>-1)
  {
    return(SetCartSymGI(GH, sym, gi));
  }
  else
  {
    CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,
	       "Cannot find group %s in SetCartSymGN",gn);
    return(-1);
  }
}
Esempio n. 9
0
int SetCartSymVN(cGH *GH, int *sym, const char *vn) {
  int vi;
  vi = CCTK_VarIndex(vn);
  
  if (vi>-1)
  {
    return(SetCartSymVI(GH, sym, vi));
  }
  else
  {
    CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,
	       "Cannot find variable %s in SetCartSymVN",vn);
    return(-1);
  }
}
Esempio n. 10
0
 /*@@
   @routine    IOASCII_TimeFor1D
   @date       Sat March 6 1999
   @author     Gabrielle Allen
   @desc
               Decides if it is time to output a variable
               using the IO 1D output method
   @enddesc

   @var        GH
   @vdesc      Pointer to CCTK GH
   @vtype      const cGH *
   @vio        in
   @endvar
   @var        vindex
   @vdesc      index of variable
   @vtype      int
   @vio        in
   @endvar

   @returntype int
   @returndesc
               1 if output should take place at this iteration, or<BR>
               0 if not
   @endreturndesc
@@*/
int IOASCII_TimeFor1D (const cGH *GH, int vindex)
{
  int return_type;
  asciiioGH *myGH;
  char *fullname;


  /* Default is do not do output */
  return_type = 0;

  /* Get the GH extensions for IOASCII */
  myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");

  CheckSteerableParameters (myGH);

  /* return if no output requested */
  if (myGH->out1D_every <= 0)
  {
    return (0);
  }

  /* Check if this variable should be output */
  if (myGH->do_out1D[vindex] &&
      GH->cctk_iteration % myGH->out1D_every == 0)
  {
    /* Check if this variable wasn't already output this iteration */
    if (myGH->out1D_last[vindex] == GH->cctk_iteration)
    {
      fullname = CCTK_FullName (vindex);
      CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "Already done IOASCII 1D output for '%s' in current "
                  "iteration (probably via triggers)", fullname);
      free (fullname);
    }
    else
    {
      return_type = 1;
    }
  }

  return (return_type);
}
Esempio n. 11
0
 /*@@
   @routine    IOBasic_TimeForScalarOutput
   @date       Sat March 6 1999
   @author     Gabrielle Allen
   @desc
               Decides if it is time to do Scalar output.
   @enddesc

   @var        GH
   @vdesc      Pointer to CCTK GH
   @vtype      const cGH *
   @vio        in
   @endvar
   @var        vindex
   @vdesc      index of variable
   @vtype      int
   @vio        in
   @endvar

   @returntype int
   @returndesc
               1 if output should take place at this iteration, or<BR>
               0 if not
   @endreturndesc
@@*/
int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex)
{
  int return_type;
  iobasicGH *myGH;
  char *fullname;


  /* Default is do not do output */
  return_type = 0;

  /* Get the GH extension for IOBasic */
  myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");

  CheckSteerableParameters (myGH);

  /* check if any output was requested */
  if (myGH->outScalar_every <= 0)
  {
    return (0);
  }

  /* Check if this variable should be output */
  if (myGH->do_outScalar [vindex] &&
      (GH->cctk_iteration % myGH->outScalar_every) == 0)
  {
    /* Check if variable wasn't already output this iteration */
    if (myGH->outScalar_last [vindex] == GH->cctk_iteration)
    {
      fullname = CCTK_FullName (vindex);
      CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "Already done IOBasic scalar output for '%s' in "
                  "current iteration (probably via triggers)", fullname);
      free (fullname);
    }
    else
    {
      return_type = 1;
    }
  }

  return (return_type);
}
Esempio n. 12
0
/* check if this variable can be output (static conditions) */
static int CheckOutputVar (int vindex)
{
  int retval;
  int grouptype;
  char *fullname;


  /* check the variable type */
  grouptype = CCTK_GroupTypeFromVarI (vindex);
  retval = grouptype != CCTK_GF && grouptype != CCTK_ARRAY;
  if (retval)
  {
    fullname = CCTK_FullName (vindex);
    CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                "CheckOutputVar: No IOASCII 1D output for '%s' (not a grid "
                "function or an array)", fullname);
    free (fullname);
  }

  return (retval);
}
Esempio n. 13
0
CCTK_INT Hyperslab_DefineGlobalMappingByIndex (
           const cGH *GH,
           CCTK_INT vindex,
           CCTK_INT dim,
           const CCTK_INT *direction  /* vdim*dim */,
           const CCTK_INT *origin     /* vdim */,
           const CCTK_INT *extent     /* dim */,
           const CCTK_INT *downsample /* dim */,
           CCTK_INT table_handle,
           CCTK_INT target_proc,
           t_hslabConversionFn conversion_fn,
           CCTK_INT *hsize            /* dim */)
{
  unsigned int vdim, hdim, num_dirs;
  int retval;
  int stagger_index;
  int myproc;
  int npoints;
  hslab_mapping_t *mapping;
  const char *error_msg;
  const pGH *pughGH;              /* pointer to the current pGH */
  const pGA *GA;                  /* the variable's GA structure from PUGH */
  cGroup vinfo;


  /* PUGHSlab doesn't use table information */
  if (table_handle >= 0)
  {
    CCTK_WARN (1, "Hyperslab_DefineGlobalMappingByIndex: table information is "
                  "ignored");
  }

  /* check parameter consistency */
  retval = 0;
  error_msg = NULL;
  if (CCTK_GroupData (CCTK_GroupIndexFromVarI (vindex), &vinfo) < 0)
  {
    error_msg = "invalid variable index given";
    retval = -1;
  }
  else if (vinfo.grouptype != CCTK_GF && vinfo.grouptype != CCTK_ARRAY)
  {
    error_msg = "invalid variable group type given "
                "(not a CCTK_GF or CCTK_ARRAY type)";
    retval = -2;
  }
  else if (dim < 0 || dim > vinfo.dim)
  {
    error_msg = "invalid hyperslab dimension given";
    retval = -2;
  }
  else if (! direction || ! origin || ! extent || ! hsize)
  {
    error_msg = "NULL pointer(s) passed for direction/origin/extent/hsize "
                "parameters";
    retval = -3;
  }
  else if (target_proc >= CCTK_nProcs (GH))
  {
    error_msg = "invalid target procesor ID given";
    retval = -4;
  }
  else if ((pughGH = (const pGH *) PUGH_pGH (GH)) == NULL)
  {
    error_msg = "no PUGH GH extension registered (PUGH not activated ?)";
    retval = -4;
  }
  else
  {
    for (vdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
    {
      retval |= origin[vdim] < 0;
      if (vdim < (unsigned int) dim)
      {
        retval |= extent[vdim] <= 0;
        if (downsample)
        {
          retval |= downsample[vdim] <= 0;
        }
      }
    }
    if (retval)
    {
      error_msg = "invalid hyperslab origin/extent/downsample vectors given";
      retval = -5;
    }
  }
  if (! retval)
  {
    mapping = (hslab_mapping_t *) malloc (sizeof (hslab_mapping_t));
    if (mapping)
    {
      mapping->vectors = (int *) malloc ((6*vinfo.dim + 2*dim) * sizeof (int));
    }
    if (mapping == NULL || mapping->vectors == NULL)
    {
      if (mapping)
      {
        free (mapping);
      }
      error_msg = "couldn't allocate hyperslab mapping structure";
      retval = -6;
    }
  }

  /* return in case of errors */
  if (retval)
  {
    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                "Hyperslab_DefineGlobalMappingByIndex: %s", error_msg);
    return (retval);
  }

  mapping->hdim = (unsigned int) dim;
  mapping->vinfo = vinfo;
  mapping->target_proc = target_proc;
  mapping->conversion_fn = conversion_fn;

  /* assign memory for the other vectors */
  mapping->local_startpoint  = mapping->vectors + 0*vinfo.dim;
  mapping->local_endpoint    = mapping->vectors + 1*vinfo.dim;
  mapping->global_startpoint = mapping->vectors + 2*vinfo.dim;
  mapping->global_endpoint   = mapping->vectors + 3*vinfo.dim;
  mapping->do_dir            = mapping->vectors + 4*vinfo.dim;
  mapping->downsample        = mapping->vectors + 5*vinfo.dim;
  mapping->local_hsize       = mapping->vectors + 6*vinfo.dim + 0*dim;
  mapping->global_hsize      = mapping->vectors + 6*vinfo.dim + 1*dim;

  /* check direction vectors */
  for (hdim = 0; hdim < mapping->hdim; hdim++)
  {
    num_dirs = 0;
    for (vdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
    {
      if (direction[hdim*vinfo.dim + vdim])
      {
        num_dirs++;
      }
    }
    if (num_dirs == 0)
    {
      free (mapping->vectors); free (mapping);
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "Hyperslab_DefineGlobalMappingByIndex: %d-direction vector "
                  "is a null vector", hdim);
      return (-7);
    }

    mapping->is_diagonal_in_3D = num_dirs == 3 && mapping->hdim == 1;
    if (num_dirs != 1 && ! mapping->is_diagonal_in_3D)
    {
      free (mapping->vectors); free (mapping);
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "Hyperslab_DefineGlobalMappingByIndex: %d-direction vector "
                  "isn't axis-orthogonal", hdim);
      return (-7);
    }
  }

  /* diagonals can be extracted from non-staggered 3D variables only */ 
  if (mapping->is_diagonal_in_3D && vinfo.stagtype != 0)
  {
    free (mapping->vectors); free (mapping);
    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                "Hyperslab_DefineGlobalMappingByIndex: diagonals can be "
                "extracted from non-staggered 3D variables only");
    return (-7);
  }

  for (vdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
  {
    mapping->do_dir[vdim] = 0;
    for (hdim = 0; hdim < mapping->hdim; hdim++)
    {
      if (direction[hdim*vinfo.dim + vdim])
      {
        mapping->do_dir[vdim]++;
      }
    }
    if (mapping->do_dir[vdim] > 1)
    {
      free (mapping->vectors); free (mapping);
      CCTK_WARN (1, "Hyperslab_DefineGlobalMappingByIndex: duplicate direction "
                    "vectors given");
      return (-8);
    }
  }

  /* get the pGH pointer and the variable's GA structure */
  GA     = (const pGA *) pughGH->variables[vindex][0];
  myproc = CCTK_MyProc (GH);

  /* check extent */
  for (vdim = hdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
  {
    if (mapping->do_dir[vdim] && hdim < mapping->hdim)
    {
      if (origin[vdim] + extent[hdim] > GA->extras->nsize[vdim])
      {
        free (mapping->vectors); free (mapping);
        CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                    "Hyperslab_DefineGlobalMappingByIndex: extent in "
                    "%d-direction exceeds grid size", hdim);
        return (-8);
      }
      hdim++;
    }
    else if (mapping->is_diagonal_in_3D &&
             origin[vdim] + extent[0] > GA->extras->nsize[vdim])
    {
      free (mapping->vectors); free (mapping);
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "Hyperslab_DefineGlobalMappingByIndex: extent in "
                  "%d-direction exceeds grid size", vdim);
      return (-8);
    }
  }

  /* now fill out the hyperslab mapping structure */
  for (vdim = hdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
  {
    mapping->downsample[vdim] = 1;

    if (mapping->do_dir[vdim] && hdim < mapping->hdim)
    {
      if (downsample)
      {
        mapping->downsample[vdim] = downsample[hdim];
      }
      mapping->global_hsize[hdim] = extent[hdim] / mapping->downsample[vdim];
      if (extent[hdim] % mapping->downsample[vdim])
      {
        mapping->global_hsize[hdim]++;
      }
      /* subtract ghostzones for periodic BC */
      if (GA->connectivity->perme[vdim])
      {
        mapping->global_hsize[hdim] -= 2 * GA->extras->nghostzones[vdim];
      }
      hdim++;
    }
    else if (mapping->is_diagonal_in_3D)
    {
      mapping->totals = extent[0] / mapping->downsample[0];
      if (extent[0] % mapping->downsample[0])
      {
        mapping->totals++;
      }
      /* subtract ghostzones for periodic BC */
      if (GA->connectivity->perme[vdim])
      {
        mapping->totals -= 2 * GA->extras->nghostzones[vdim];
      }
      if ((unsigned int) mapping->global_hsize[0] > mapping->totals)
      {
        mapping->global_hsize[0] = mapping->totals;
      }
    }
  }

  /* check whether the full local data patch was requested as hyperslab */
  mapping->is_full_hyperslab = IsFullHyperslab (GA, origin, extent, mapping);
  if (mapping->is_full_hyperslab)
  {
    memset (mapping->local_startpoint, 0, vinfo.dim * sizeof (int));
    memcpy (mapping->local_endpoint, GA->extras->lnsize, vinfo.dim*sizeof(int));
    mapping->totals = GA->extras->npoints;
  }
  else if (mapping->is_diagonal_in_3D)
  {
    /* just initialize the downsample and global_startpoint vectors */
    for (vdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
    {
      mapping->downsample[vdim] = mapping->downsample[0];
      mapping->global_startpoint[vdim] = origin[vdim];
    }
  }
  else
  {
    /* compute the global endpoint */
    for (vdim = hdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
    {
      mapping->global_endpoint[vdim] = origin[vdim] +
                                   (mapping->do_dir[vdim] ? extent[hdim++] : 1);
    }

    /* compute this processor's global startpoint from the global ranges */
    for (vdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
    {
      stagger_index = CCTK_StaggerDirIndex (vdim, vinfo.stagtype);

      if (origin[vdim] < MY_GLOBAL_EP (GA->extras, myproc, stagger_index, vdim))
      {
        mapping->global_startpoint[vdim] = origin[vdim];
        if (origin[vdim] < MY_GLOBAL_SP (GA->extras, myproc,stagger_index,vdim))
        {
          npoints = (MY_GLOBAL_SP (GA->extras, myproc, stagger_index, vdim)
                     - origin[vdim]) / mapping->downsample[vdim];
          if ((MY_GLOBAL_SP (GA->extras, myproc, stagger_index, vdim)
               - origin[vdim]) % mapping->downsample[vdim])
          {
            npoints++;
          }
          mapping->global_startpoint[vdim] += npoints*mapping->downsample[vdim];
        }
      }
      else
      {
        mapping->global_startpoint[vdim] = -1;
      }
    }

    /* compute the local start- and endpoint from the global ranges */
    mapping->totals = 1;
    for (vdim = hdim = 0; vdim < (unsigned int) vinfo.dim; vdim++)
    {
      stagger_index = CCTK_StaggerDirIndex (vdim, vinfo.stagtype);

      if (mapping->global_startpoint[vdim] >= 0 &&
          mapping->global_startpoint[vdim] <  MY_GLOBAL_EP (GA->extras, myproc,
                                                            stagger_index,vdim))
      {
        mapping->local_startpoint[vdim] = mapping->global_startpoint[vdim] -
                                          GA->extras->lb[myproc][vdim];
      }
      else
      {
        mapping->local_startpoint[vdim] = -1;
      }

      if (mapping->global_endpoint[vdim] > MY_GLOBAL_SP (GA->extras, myproc,
                                                         stagger_index, vdim))
      {
        mapping->local_endpoint[vdim] =
          MIN (MY_LOCAL_EP (GA->extras, stagger_index, vdim),
                            mapping->global_endpoint[vdim] -
                            GA->extras->lb[myproc][vdim]);
      }
      else
      {
        mapping->local_endpoint[vdim] = -1;
      }

#ifdef DEBUG
      printf ("direction %d: global ranges [%d, %d), local ranges[%d, %d)\n",
              vdim,
              mapping->global_startpoint[vdim], mapping->global_endpoint[vdim],
              mapping->local_startpoint[vdim], mapping->local_endpoint[vdim]);
#endif

      if (mapping->local_endpoint[vdim] < 0 ||
          mapping->local_startpoint[vdim] < 0)
      {
        mapping->totals = 0;
        mapping->local_endpoint[vdim] = mapping->local_startpoint[vdim];
      }

      if (mapping->do_dir[vdim])
      {
        /* compute the local size in each hyperslab dimension */
        mapping->local_hsize[hdim] = (mapping->local_endpoint[vdim] -
                                   mapping->local_startpoint[vdim]) /
                                  mapping->downsample[vdim];
        if ((mapping->local_endpoint[vdim] - mapping->local_startpoint[vdim]) %
            mapping->downsample[vdim])
        {
          mapping->local_hsize[hdim]++;
        }
        mapping->totals *= mapping->local_hsize[hdim];
        hdim++;
      }
    }
  } /* end of else branch for 'if (mapping->is_full_hyperslab)' */

#ifdef DEBUG
  printf ("total number of hyperslab data points: %d\n", mapping->totals);
#endif

#if 0
  if (mapping->totals > 0)
  {
    /* if requested, compute the offsets into the global hyperslab */
    if (hoffset_global)
    {
      for (i = hdim = 0; i < vinfo.dim; i++)
      {
        if (mapping->do_dir[i])
        {
          if (mapping->is_full_hyperslab)
          {
            hoffset_global[hdim] = GA->extras->lb[myproc][i];
          }
          else
          {
            hoffset_global[hdim] = (mapping->global_startpoint[i] -
                                    origin[i]) / mapping->downsample[i];
            if (GA->connectivity->perme[i])
            {
              hoffset_global[hdim] -= GA->extras->nghostzones[i];
            }
          }
#ifdef DEBUG
          printf ("hoffset_global, hsize in direction %d: %d, %d\n",
                  hdim, hoffset_global[hdim], mapping->local_hsize[hdim]);
#endif
          hdim++;
        }
      }
    }
  }
#endif

  /* add this mapping to the mapping list */
  if (mapping_list)
  {
    mapping_list->prev = mapping;
  }
  mapping->prev = NULL;
  mapping->next = mapping_list;
  mapping_list = mapping;

  mapping->handle = nmapping_list++;

  /* set the global hsize in the return arguments */
  if (hsize)
  {
    for (hdim = 0; hdim < mapping->hdim; hdim++)
    {
      hsize[hdim] = mapping->global_hsize[hdim];
    }
  }

  return (mapping->handle);
}
Esempio n. 14
0
 /*@@
   @routine    PUGH_EnableGArrayDataStorage
   @author     Tom Goodale
   @date       30 Mar 1999
   @desc
               Allocates storage for a single variable.
               For now this routine cannot be made static because it's used
               in BAM :-(
   @enddesc
   @calls      Util_CacheMalloc

   @var        GA
   @vdesc      Pointer to the variable's info structure
   @vtype      pGA *
   @vio        in
   @endvar
   @var        this_proc
   @vdesc      the processor ID
   @vtype      int
   @vio        unused
   @endvar
   @var        initialize_memory
   @vdesc      how to initialize allocated memory
   @vtype      const char *
   @vio        in
   @endvar
   @var        padding_active, padding_cacheline_bits, padding_size,
               padding_address_spacing
   @vdesc      padding information
   @vtype      int
   @vio        unused
   @endvar

   @returntype int
   @returndesc
                0 if storage was enabled
               -1 if memory allocation failed
   @endreturndesc
@@*/
/* static */ int PUGH_EnableGArrayDataStorage (pGA *GA,
                                         int this_proc,
                                         const char *initialize_memory,
                                         int padding_active,
                                         int padding_cacheline_bits,
                                         int padding_size,
                                         int padding_address_spacing)
{
  int retval;


  /* avoid compiler warnings about unused parameters */
  this_proc = this_proc;
  padding_active = padding_active;
  padding_cacheline_bits = padding_cacheline_bits;
  padding_size = padding_size;
  padding_address_spacing = padding_address_spacing;

  retval = 0;
  if (GA->storage == PUGH_NOSTORAGE)
  {

#ifdef DEBUG_PUGH
    printf (" PUGH_EnableGArrayDataStorage: allocating storage "
            "for var '%s'\n", GA->name);
    fflush (stdout);
#endif

    if(GA->vector_size > 1 && GA->vector_entry > 0)
    {
      GA->data = (char *)(GA->vector_base->data) + GA->extras->npoints * GA->varsize * GA->vector_entry;
      retval = 0;
    }
    else
    {

      /* Now assign memory for the variable itself */
      if (GA->padddata)
      {
        free (GA->padddata);
        GA->padddata = NULL;
      }

      if (GA->extras->npoints * GA->varsize <= 0)
      {
        CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                    "PUGH_EnableGArrayDataStorage: Tried to allocate storage "
                    "for zero-sized variable '%s'", GA->name);
        GA->data = GA->padddata = NULL;
      }
      else if (! padding_active)
      {
        /* Easy case. */
        GA->data = malloc (GA->extras->npoints * GA->varsize);
        GA->padddata = GA->data;
      }
      else
      {
        /* Use the Cactus Cache alignment function */
        GA->data = Util_CacheMalloc (GA->arrayid,
                                     GA->extras->npoints * GA->varsize * GA->vector_size,
                                     &GA->padddata);
      }

      /* Initialize the memory if desired. */
      if (GA->data && ! CCTK_Equals (initialize_memory, "none"))
      {
        PUGH_InitializeMemory (initialize_memory, GA->vtype,
                               GA->extras->npoints * GA->varsize, GA->data);
      }
    }

    if (GA->extras->npoints * GA->varsize > 0 && GA->padddata == NULL)
    {
      CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "PUGH_EnableGArrayDataStorage: Cannot allocate data for "
                  "'%s' [%d]", GA->name, GA->id);
      retval = -1;
    }
  }

  GA->storage = PUGH_STORAGE;

  return (retval);
}
Esempio n. 15
0
 /*@@
   @routine    PUGH_EnableGroupStorage
   @author     Tom Goodale
   @date       30 Mar 1999
   @desc
               Enables storage for all variables in the group
               indicated by groupname.
   @enddesc
   @calls      CCTK_GroupIndex
               CCTK_GroupData
               PUGH_EnableScalarGroupStorage
               PUGH_EnableGArrayGroupStorage

   @var        GH
   @vdesc      Pointer to CCTK grid hierarchy
   @vtype      cGH *
   @vio        in
   @endvar
   @var        groupname
   @vdesc      name of the group to enable storage for
   @vtype      const char *
   @vio        in
   @endvar

   @returntype int
   @returndesc
                return code of @seeroutine PUGH_EnableScalarGroupStorage or
                @seeroutine PUGH_EnableGArrayGroupStorage: <BR>
                1 if storage was already enabled, or <BR>
                0 if storage was successfully enabled <BR>
               -1 if group type is not one of the above <BR>
               -2 if an invalid GH pointer was given <BR>
               -3 if invalid groupname was given
   @endreturndesc
@@*/
int PUGH_EnableGroupStorage (cGH *GH, const char *groupname)
{
  DECLARE_CCTK_PARAMETERS
  int group;               /* group index */
  int first_var;           /* first variable's index */
  cGroup pgroup;           /* group information */
  int retval;
  pGA *GA;
  pGH *pughGH;


#ifdef DEBUG_PUGH
  printf (" PUGH_EnableGroupStorage: request for group '%s'\n", groupname);
  fflush (stdout);
#endif

  pughGH = PUGH_pGH (GH);
  group = CCTK_GroupIndex (groupname);

  if (pughGH && group >= 0)
  {
    first_var = CCTK_FirstVarIndexI (group);

    /* get the group info from its index */
    CCTK_GroupData (group, &pgroup);

    if (pgroup.grouptype == CCTK_SCALAR)
    {
      retval = PUGH_EnableScalarGroupStorage (pughGH,
                                              first_var,
                                              pgroup.numvars,
                                              pgroup.numtimelevels);
    }
    else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
    {
      retval = PUGH_EnableGArrayGroupStorage (pughGH,
                                              first_var,
                                              pgroup.numvars,
                                              pgroup.numtimelevels);
      if (!CCTK_Equals(storage_verbose,"no") && retval == 0)
      {
        /* get GA pointer of first var in group */
        GA = (pGA *) pughGH->variables[first_var][0];
        if (pgroup.grouptype == CCTK_GF)
        {
          totalnumberGF  += pgroup.numvars * pgroup.numtimelevels;
        }
        else
        {
          totalnumberGA  += pgroup.numvars * pgroup.numtimelevels;
        }
        totalstorage += (GA->extras->npoints * GA->varsize *
                         pgroup.numtimelevels * pgroup.numvars) /
                        (float) (1024*1024);
        if (totalstorage > maxstorage)
        {
          numberGF = totalnumberGF;
          numberGA = totalnumberGA;
          maxstorage = totalstorage;
        }

        /* Report on memory usage */
        if (CCTK_Equals(storage_verbose,"yes"))
        {
          CCTK_VInfo (CCTK_THORNSTRING, "Switched memory on for group '%s'"
                      "  [GFs: %d GAs: %d Total Size: %6.2fMB]",
                      groupname, totalnumberGF, totalnumberGA, totalstorage);
        }
      }

    }
    else
    {
      CCTK_WARN (1, "PUGH_EnableGroupStorage: Unknown group type");
      retval = -1;
    }

  }
  else
  {
    if (! pughGH)
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "PUGH_EnableGroupStorage: Error with cctkGH pointer "
                  "for group %s", groupname);
      retval = -2;
    }
    else
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "PUGH_EnableGroupStorage: Invalid group %s", groupname);
      retval = -3;
    }
  }

  USE_CCTK_PARAMETERS;   return (retval);
}
Esempio n. 16
0
 /*@@
   @routine    PUGH_QueryGroupStorage
   @author     Gabrielle Allen
   @date       13 Apr 1999
   @desc
               Checks if group has storage assigned.
               Either group index or its name must be given,
               the name takes precedence.
   @enddesc
   @calls      CCTK_GroupIndex
               CCTK_FirstVarIndexI
               CCTK_GroupTypeI

   @var        GH
   @vdesc      Pointer to CCTK grid hierarchy
   @vtype      const cGH *
   @vio        in
   @endvar
   @var        group
   @vdesc      index of group
   @vtype      int
   @vio        in
   @endvar
   @var        groupname
   @vdesc      name of the group to be queried
   @vtype      const char *
   @vio        in
   @endvar

   @returntype int
   @returndesc
                1 if storage for this group is assigned
                0 if storage for this group is not assigned
               -1 if given group index/name is invalid
   @endreturndesc
@@*/
int PUGH_QueryGroupStorage (const cGH *GH, int group, const char *groupname)
{
  int first_var;
  int storage;
  int grouptype;
  int vtypesize;
  int retval;
  pGH *pughGH;


  retval = -1;

  if (groupname)
  {
    group = CCTK_GroupIndex (groupname);
  }

  /* get first variable in group */
  first_var = CCTK_FirstVarIndexI (group);
  if (first_var >= 0)
  {
    pughGH = PUGH_pGH (GH);
    grouptype = CCTK_GroupTypeI (group);
    if (grouptype == CCTK_SCALAR)
    {
      vtypesize = CCTK_VarTypeSize (CCTK_VarTypeI (first_var));
      storage = ((char *) pughGH->variables[first_var][0])[vtypesize];
    }
    else if (grouptype == CCTK_GF || grouptype == CCTK_ARRAY)
    {
      storage = ((pGA *) pughGH->variables[first_var][0])->storage;
    }
    else
    {
      storage = -1;
      CCTK_WARN (1, "Unknown group type in PUGH_QueryGroupStorage");
    }

    if (storage == PUGH_STORAGE)
    {
      retval = 1;
    }
    else if (storage == PUGH_NOSTORAGE)
    {
      retval = 0;
    }
    else
    {
      CCTK_WARN (1, "Inconsistency in PUGH_QueryGroupStorage");
    }
  }
  else
  {
    if (groupname)
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "PUGH_ArrayGroupSize: Invalid group name '%s'",
                  groupname);
    }
    else
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "PUGH_ArrayGroupSize: Invalid group ID %d",
                  group);
    }
  }

  return (retval);
}