moab
moab::gs_data Class Reference

#include <gs.hpp>

List of all members.

Classes

class  crystal_data

Public Member Functions

 gs_data (uint n, const long *label, const ulong *ulabel, uint maxv, const unsigned int nlabels, const unsigned int nulabels, crystal_data *crystal, ErrorCode &Init_Result)
 gs_data ()
 ~gs_data ()
ErrorCode initialize (uint n, const long *label, const ulong *ulabel, uint maxv, const unsigned int nlabels, const unsigned int nulabels, crystal_data *crystal)
void reset ()
void gs_data_op (realType *u, int op)
void gs_data_op_vec (realType *u, uint n, int op)
void gs_data_op_many (realType **u, uint n, int op)

Public Attributes

sintlocal_cm

Detailed Description

Definition at line 14 of file gs.hpp.


Constructor & Destructor Documentation

moab::gs_data::gs_data ( uint  n,
const long *  label,
const ulong ulabel,
uint  maxv,
const unsigned int  nlabels,
const unsigned int  nulabels,
crystal_data crystal,
ErrorCode Init_Result 
) [inline]

Constructor for moab_gs_data: takes all arguments and initializes moab_gs_data. If needs_reset is false after calling constructor, initialization has failed.

param n number of tuples in tuple list param label pointer to signed labels param ulabel pointer to unsigned labels param maxv max vector size param nlabels number of signed long labels (not including gid) param nulabels number of unsigned long labels param crystal moab_crystal_data contains MPI_Comm and is used for message passing

Definition at line 186 of file gs.hpp.

                                                        {
      Init_Result = this->initialize (n, label, ulabel, maxv, nlabels,
                      nulabels, crystal);
    };
moab::gs_data::gs_data ( ) [inline]

Default constructor (Note: moab_gs_data must be initialized before use!)

Definition at line 198 of file gs.hpp.

               {
    };

Definition at line 201 of file gs.hpp.

{ reset(); }

Member Function Documentation

void moab::gs_data::gs_data_op ( realType u,
int  op 
)

Definition at line 705 of file gs.cpp.

{
  local_condense(u, op, this->local_cm);
#ifdef USE_MPI
  this->nlinfo->nonlocal(u,op,_comm);
#endif
  local_uncondense(u, local_cm);
}
void moab::gs_data::gs_data_op_many ( realType **  u,
uint  n,
int  op 
)

Definition at line 728 of file gs.cpp.

{
  uint i;
#ifdef USE_MPI
  if (n>nlinfo->_maxv)
    moab::fail("%s: initialized with max vec size = %d,"
      " but called with vec size = %d\n",__FILE__,nlinfo->_maxv,n);
#endif
  for (i = 0; i < n; ++i)
    local_condense(u[i], op, local_cm);

  moab::fail("%s: initialized with max vec size = %d,"
      " but called with vec size = %d\n", __FILE__, 6, n);

#ifdef USE_MPI
  this->nlinfo->nonlocal_many(u,n,op,_comm);
#endif
  for (i = 0; i < n; ++i)
    local_uncondense(u[i], local_cm);
}
void moab::gs_data::gs_data_op_vec ( realType u,
uint  n,
int  op 
)

Definition at line 714 of file gs.cpp.

{
#ifdef USE_MPI
  if (n>nlinfo->_maxv)
    moab::fail("%s: initialized with max vec size = %d,"
      " but called with vec size = %d\n",__FILE__,nlinfo->_maxv,n);
#endif
  local_condense_vec(u, n, op, local_cm);
#ifdef USE_MPI
  this->nlinfo->nonlocal_vec(u,n,op,_comm);
#endif
  local_uncondense_vec(u, n, local_cm);
}
ErrorCode moab::gs_data::initialize ( uint  n,
const long *  label,
const ulong ulabel,
uint  maxv,
const unsigned int  nlabels,
const unsigned int  nulabels,
crystal_data crystal 
)

Sets up the moab_gs_data; see constructor for parameter documentation

Definition at line 753 of file gs.cpp.

{
  nlinfo = NULL;
  unsigned int j;
  TupleList nonzero, primary;
  ErrorCode rval;
#ifdef USE_MPI
  TupleList shared;
#else
  moab::TupleList::buffer buf;
#endif
  VALGRIND_CHECK_MEM_IS_DEFINED(label, nlabels * sizeof(long));
  VALGRIND_CHECK_MEM_IS_DEFINED(ulabel, nlabels * sizeof(ulong));
#ifdef USE_MPI
  MPI_Comm_dup(crystal->_comm,&this->_comm);
#else
  buf.buffer_init(1024);
#endif

  /* construct list of nonzeros: (index ^, label) */
  nonzero.initialize(1, nlabels, nulabels, 0, n);
  nonzero.enableWriteAccess();
  {
    uint i;
    sint *nzi;
    long *nzl;
    unsigned long *nzul;
    nzi = nonzero.vi_wr;
    nzl = nonzero.vl_wr;
    nzul = nonzero.vul_wr;
    for (i = 0; i < n; ++i)
      if (label[nlabels * i] != 0)
      {
        nzi[0] = i;
        for (j = 0; j < nlabels; j++)
          nzl[j] = label[nlabels * i + j];
        for (j = 0; j < nulabels; j++)
          nzul[j] = ulabel[nulabels * i + j];
        nzi++;
        nzl += nlabels;
        nzul += nulabels;
        nonzero.inc_n();
      }
  }

  /* sort nonzeros by label: (index ^2, label ^1) */
#ifndef USE_MPI
  nonzero.sort(1, &buf);
#else
  nonzero.sort(1,&crystal->all->buf);
#endif

  /* build list of unique labels w/ lowest associated index:
   (index in nonzero ^, primary (lowest) index in label, count, label(s),
   ulabel(s)) */
  primary.initialize(3, nlabels, nulabels, 0, nonzero.get_n());
  primary.enableWriteAccess();
  {
    uint i;
    sint *nzi = nonzero.vi_wr, *pi = primary.vi_wr;
    slong *nzl = nonzero.vl_wr, *pl = primary.vl_wr;
    ulong *nzul = nonzero.vul_wr, *pul = primary.vul_wr;
    slong last = -1;
    for (i = 0; i < nonzero.get_n();
          ++i, nzi += 1, nzl += nlabels, nzul += nulabels)
    {
      if (nzl[0] == last)
      {
        ++pi[-1];
        continue;
      }
      last = nzl[0];
      pi[0] = i;
      pi[1] = nzi[0];
      for (j = 0; j < nlabels; j++)
        pl[j] = nzl[j];
      for (j = 0; j < nulabels; j++)
        pul[j] = nzul[j];
      pi[2] = 1;
      pi += 3, pl += nlabels;
      pul += nulabels;
      primary.inc_n();
    }
  }

  /* calculate size of local condense map */
  {
    uint i, count = 1;
    sint *pi = primary.vi_wr;
    for (i = primary.get_n(); i; --i, pi += 3)
      if (pi[2] > 1)
        count += pi[2] + 1;
    this->local_cm = (sint*) malloc(count * sizeof(sint));
  }

  /* sort unique labels by primary index:
   (nonzero index ^2, primary index ^1, count, label ^2) */
#ifndef USE_MPI
  primary.sort(0, &buf);
  buf.reset();
  //buffer_free(&buf);
#else
  primary.sort(0,&crystal->all->buf);
#endif

  /* construct local condense map */
  {
    uint i, ln;
    sint *pi = primary.vi_wr;
    sint *cm = this->local_cm;
    for (i = primary.get_n(); i > 0; --i, pi += 3)
      if ((ln = pi[2]) > 1)
      {
        sint *nzi = nonzero.vi_wr + 1 * pi[0];
        for (j = ln; j > 0; --j, nzi += 1)
          *cm++ = nzi[0];
        *cm++ = -1;
      }
    *cm++ = -1;
  }
  nonzero.reset();
#ifndef USE_MPI
  primary.reset();
#else
  /* assign work proc by label modulo np */
  {
    uint i;
    sint *pi=primary.vi_wr;
    slong *pl=primary.vl_wr;
    for (i=primary.get_n(); i; --i, pi+=3, pl+=nlabels)
      pi[0]=pl[0]%crystal->_num;
  }
  rval = crystal->gs_transfer(1,primary,0); /* transfer to work procs */
  if (rval != MB_SUCCESS)
    return rval;
  /* primary: (source proc, index on src, useless, label) */
  /* sort by label */
  primary.sort(3,&crystal->all->buf);
  /* add sentinel to primary list */
  if (primary.get_n()==primary.get_max())
    primary.resize( (primary.get_max() ? primary.get_max()+(primary.get_max()+1)/2+1 : 2));
  primary.vl_wr[nlabels*primary.get_n()] = -1;
  /* construct shared list: (proc1, proc2, index1, label) */
#ifdef USE_MPI
  shared.initialize(3,nlabels,nulabels,0,primary.get_n());
  shared.enableWriteAccess();
#endif
  {
    sint *pi1=primary.vi_wr, *si=shared.vi_wr;
    slong lbl, *pl1=primary.vl_wr, *sl=shared.vl_wr;
    ulong *pul1=primary.vul_wr, *sul=shared.vul_wr;
    for (  ;(lbl=pl1[0])!=-1;  pi1+=3, pl1+=nlabels, pul1+=nulabels)
    {
      sint *pi2=pi1+3;
      slong *pl2=pl1+nlabels;
      ulong *pul2=pul1+nulabels;
      for (  ;pl2[0]==lbl;  pi2+=3, pl2+=nlabels, pul2+=nulabels)
      {
        if (shared.get_n()+2 > shared.get_max())
          shared.resize((shared.get_max() ? shared.get_max()+(shared.get_max()+1)/2+1 : 2)),
        si=shared.vi_wr+shared.get_n()*3;
        sl=shared.vl_wr+shared.get_n()*nlabels;
        sul=shared.vul_wr+shared.get_n()*nulabels;
        si[0] = pi1[0];
        si[1] = pi2[0];
        si[2] = pi1[1];
        for (j = 0; j < nlabels; j++)
          sl[j] = pl2[j];
        for (j = 0; j < nulabels; j++)
          sul[j] = pul2[j];
        si+=3;
        sl+=nlabels;
        sul+=nulabels;
        shared.inc_n();
        si[0] = pi2[0];
        si[1] = pi1[0];
        si[2] = pi2[1];
        for (j = 0; j < nlabels; j++)
          sl[j] = pl1[j];
        for (j = 0; j < nulabels; j++)
          sul[j] = pul1[j];
        si+=3;
        sl+=nlabels;
        sul+=nulabels;
        shared.inc_n();
      }
    }
  }
  primary.reset();
  rval = crystal->gs_transfer(1,shared,0); /* segfaulting transfer to dest procs */
  if (rval != MB_SUCCESS)
  return rval;
  /* shared list: (useless, proc2, index, label) */
  /* sort by label */
  shared.sort(3,&crystal->all->buf);
  /* sort by partner proc */
  shared.sort(1,&crystal->all->buf);
  /* count partner procs */
  {
    uint i, count=0;
    sint proc=-1,*si=shared.vi_wr;
    for (i=shared.get_n(); i; --i,si+=3)
      if (si[1]!=proc) {
        ++count;
        proc=si[1];
      }
    //this->nlinfo = new nonlocal_info();
    //this->nlinfo->initialize(count,shared.get_n(),
    //                          nlabels, nulabels, maxv);
    this->nlinfo = new nonlocal_info(count,shared.get_n(),
        nlabels, nulabels, maxv);
  }
  /* construct non-local info */
  {
    uint i;
    sint proc=-1,*si=shared.vi_wr;
    slong *sl = shared.vl_wr;
    ulong *ul = shared.vul_wr;
    uint *target = this->nlinfo->_target;
    uint *nshared = this->nlinfo->_nshared;
    uint *sh_ind = this->nlinfo->_sh_ind;
    slong *slabels = this->nlinfo->_slabels;
    ulong *ulabels = this->nlinfo->_ulabels;
    for (i=shared.get_n(); i; --i,si+=3)
    {
      if (si[1]!=proc)
      {
        proc=si[1];
        *target++ = proc;
        *nshared++ = 0;
      }
      ++nshared[-1];
      *sh_ind++=si[2];
      // don't store 1st slabel
      sl++;
      for (j = 0; j < nlabels-1; j++)
        slabels[j] = sl[j];
      for (j = 0; j < nulabels; j++)
        ulabels[j] = ul[j];
      slabels+=nlabels-1;
      ulabels+=nulabels;
      sl+=nlabels-1;
      ul+=nulabels;
    }
  }
  shared.reset();
#endif
  return MB_SUCCESS;
}

Definition at line 1005 of file gs.cpp.

{
  free(local_cm);
  local_cm = NULL;
#ifdef USE_MPI
  if(nlinfo != NULL)
  {
    nlinfo->nlinfo_free();
    delete this->nlinfo;
    MPI_Comm_free(&_comm);
    nlinfo = NULL;
  }
#endif
}

Member Data Documentation

Definition at line 167 of file gs.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines