Exemplo n.º 1
0
int PUGH_EnableGroupComm(cGH *GH, const char *groupname)
{
  int group;               /* group index */
  cGroup pgroup;           /* group information */
  int rc;                  /* return code */

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

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

  if (pgroup.grouptype == CCTK_SCALAR)
  {
    rc = 1;
  }
  else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
  {
    rc = PUGH_EnableGArrayGroupComm(PUGH_pGH(GH),
                                    CCTK_FirstVarIndexI(group),
                                    PUGH_ALLCOMM);
  }
  else
  {
    CCTK_WARN(1, "Unknown group type in PUGH_EnableGroupComm");
    rc = 0;
  }

  return (rc);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
int PUGH_DisableGroupComm(cGH *GH, const char *groupname)
{
  int group;               /* group index */
  cGroup pgroup;           /* pointer to group information */
  int rc;                  /* return code */

  pGH *pughGH;
  int var;

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

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

  if (pgroup.grouptype == CCTK_SCALAR)
  {
    rc = 1;
  }
  else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
  {
    pughGH=PUGH_pGH(GH);
    var = CCTK_FirstVarIndexI(group);

    /* FIXME:  workaround.  This one is really bad ! */
    rc = PUGH_DisableGArrayGroupComm(pughGH, var,(((pGA ***)pughGH->variables)[var][0])->groupcomm);
  }
  else
  {
    CCTK_WARN(1, "Unknown group type in PUGH_DisableGroupComm");
    rc = 0;
  }

  return (rc);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
 /*@@
   @routine    PUGH_DestroyPGH
   @date       Thu Aug 21 11:38:10 1997
   @author     Paul Walker
   @desc
               Destroys a GH object.
   @enddesc

   @var        GHin
   @vdesc      address of PUGH GH extensions object to be destroyed
   @vtype      pGH **
   @vio        in
   @endvar
@@*/
void PUGH_DestroyPGH (pGH **GHin)
{
  pGH    *GH;
  pGA    *GA;
  cGroup pgroup;
  int i;
  int variable;
  int group;
  int this_var;


  GH = *GHin;

#ifdef CCTK_MPI
  CACTUS_MPI_ERROR (MPI_Comm_free (&GH->PUGH_COMM_WORLD));

  CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex));
#ifdef CCTK_REAL4
  CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex8));
#endif
#ifdef CCTK_REAL8
  CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex16));
#endif
#ifdef CCTK_REAL16
  CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex32));
#endif
#endif

  /* Great. Now go about the work of destroying me. */
  variable = 0;
  for(group = 0; group < CCTK_NumGroups(); group++)
  {
#ifdef DEBUG_PUGH
    printf("Calling Destroying Group %s\n", CCTK_GroupName(group));
    fflush(stdout);
#endif

    CCTK_GroupData(group,&pgroup);

    if (pgroup.grouptype == CCTK_ARRAY || pgroup.grouptype == CCTK_GF)
    {
      GA = (pGA *) GH->variables[variable][0];

      /* Destroy group comm buffers */
      if (GA->groupcomm)
      {
        if (GA->groupcomm->commflag != PUGH_NOCOMM)
        {
          PUGH_DisableGArrayGroupComm (GH, variable, GA->groupcomm);
        }
        PUGH_DestroyComm (&GA->groupcomm);
      }

      /* Destroy the group's connectivity and extras structure
         for CCTK_ARRAY groups.
         Remember that the connectivity and extras for CCTK_GF types
         are shared between all such groups and are destroyed later. */
      if (GA->connectivity != GH->Connectivity[pgroup.dim-1])
      {
        PUGH_DestroyConnectivity (&GA->connectivity);
      }
      if (GA->extras != GH->GFExtras[pgroup.dim-1])
      {
        PUGH_DestroyPGExtras (&GA->extras);
      }
    }

    for (this_var = 0; this_var < pgroup.numvars; this_var++, variable++)
    {
      for(i = 0 ; i < pgroup.numtimelevels; i++)
      {
        switch(pgroup.grouptype)
        {
          case CCTK_GF:
          case CCTK_ARRAY:
            PUGH_DestroyGArray(&(((pGA ***)GH->variables)[variable][i]));
            break;
          case CCTK_SCALAR:
            if (GH->variables[variable][i])
            {
              free(GH->variables[variable][i]);
            }
            break;
        }
      }
      free(GH->variables[variable]);
    }
  }

  for (i=1;i<=GH->dim;i++)
  {
    PUGH_DestroyConnectivity(&GH->Connectivity[i-1]);
    PUGH_DestroyPGExtras(&GH->GFExtras[i-1]);
  }

  if(GH->identity_string)
  {
    free(GH->identity_string);
  }
  free(GH->Connectivity);
  free(GH->GFExtras);
  free(GH->variables);
  free(GH);
  *GHin = NULL;
}
Exemplo n.º 6
0
 /*@@
   @routine    PUGH_DisableGroupStorage
   @author     Tom Goodale
   @date       30 Mar 1999
   @desc
               Disables storage for all variables in the group
               indicated by groupname.
   @enddesc
   @calls      CCTK_GroupIndex
               CCTK_GroupData
               CCTK_FirstVarIndexI
               PUGH_DisableGArrayGroupStorage

   @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
                1 if storage for given group was disabled
               -1 if group type is invalid
   @endreturndesc
@@*/
int PUGH_DisableGroupStorage (cGH *GH, const char *groupname)
 {
  DECLARE_CCTK_PARAMETERS
  int group;               /* group index */
  cGroup pgroup;           /* group information */
  int vtypesize, retval;
  pGA ***variables;
  int first_var, var, level;
  int unchanged;           /* count how many aren't toggled */
  char *temp;


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

  group = CCTK_GroupIndex (groupname);
  CCTK_GroupData (group, &pgroup);

  /* get global index of first variable in group */
  first_var = CCTK_FirstVarIndexI (group);

  variables = (pGA ***) PUGH_pGH (GH)->variables;

  /* get the group info from its index */
  unchanged = 0;

  retval = 1;
  if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
  {
    for (var = first_var; var < first_var+pgroup.numvars; var++)
    {
      for (level = 0; level < pgroup.numtimelevels; level++)
      {
        unchanged += PUGH_DisableGArrayDataStorage (variables[var][level]);
      }
    }
  }
  else if (pgroup.grouptype == CCTK_SCALAR)
  {
    vtypesize = CCTK_VarTypeSize (pgroup.vartype);
    for (var = first_var; var < first_var+pgroup.numvars; var++)
    {
      for (level = 0; level < pgroup.numtimelevels; level++)
      {
        temp = (char *) variables[var][level];
        if (temp[vtypesize] == PUGH_STORAGE)
        {
          temp[vtypesize] = PUGH_NOSTORAGE;
        }
        else
        {
          unchanged++;
        }
      }
    }
  }
  else
  {
    CCTK_WARN (1, "Unknown group type in PUGH_DisableGroupStorage");
    retval = -1;
  }

  /* Report on memory usage */
  if (!CCTK_Equals(storage_verbose,"no") && retval >= 0)
  {
    if (unchanged == 0)
    {

      /* Memory toggled */
      if (pgroup.grouptype == CCTK_GF)
      {
        totalnumberGF  -= pgroup.numvars;
      }
      else if (pgroup.grouptype == CCTK_ARRAY)
      {
        totalnumberGA  -= pgroup.numvars;
      }
      totalstorage -= (variables[first_var][0]->extras->npoints *
                       variables[first_var][0]->varsize *
                       pgroup.numtimelevels * pgroup.numvars) /
                      (float) (1024 * 1024);
      if (CCTK_Equals(storage_verbose,"yes"))
      {
        CCTK_VInfo (CCTK_THORNSTRING, "Switched memory off for group '%s'"
                    "  [GFs: %d GAs: %d Total Size: %6.2fMB]",
                    groupname, totalnumberGF, totalnumberGA, totalstorage);
      }
    }
    else if (unchanged == pgroup.numvars)
    {
      /* Memory already off */
      if (CCTK_Equals(storage_verbose,"yes"))
      {
        CCTK_VInfo (CCTK_THORNSTRING, "Memory already off for group '%s'", groupname);
      }
    }
    else
    {
      CCTK_WARN (1, "PUGH_DisableGroupStorage: Inconsistency in group memory assignment");
    }
  }

  USE_CCTK_PARAMETERS;   return (retval);
}
Exemplo n.º 7
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);
}