PaCO++  0.05
Controlled Class Reference

#include <Controlled.h>

Inheritance diagram for Controlled:
Collaboration diagram for Controlled:

List of all members.

Public Member Functions

virtual void clientFree ()
virtual PieceToSendcomputePiecesToSend (unsigned &size)
 Controlled ()
virtual bool freeComId (long id)
virtual void * getClientData (void *pid, int server_node, long &size, long &length, bool &end)
virtual void * getDescr ()
virtual PaCO::PacoTopology_t getDestTopology ()
long getMaxLen ()
virtual long getNodeRank ()
virtual void * getServerData (long &length)
virtual PaCO::PacoTopology_t getSourceTopology ()
virtual bool insertData (void *rcptBuf, unsigned long element_nb)
void readFromFile (char *filename)
virtual void serverFree ()
virtual bool setComId (long id)
virtual void setCommunicator (void *group)
virtual void setDataPtr (void *dataPtr)
virtual void setDescr (void *descr)
virtual void setDestTopology (PaCO::PacoTopology_t topo)
void setEltSize (unsigned long size)
void setMaxLocalLen (unsigned long elt_nb)
virtual void setNodeRank (long Rank)
virtual void setSourceTopology (PaCO::PacoTopology_t topo)
virtual ~Controlled ()

Protected Member Functions

void _setDestTopology (unsigned long total)
void _setLocalLen (unsigned long elt_nb)
void _setSourceTopology (unsigned long total)

Private Attributes

char * _clientBuffer
ControlledLib::ControlledDescr _clientDescr
CommMatrix_cm
unsigned _config
PaCO::PacoTopology_t _dTopo
unsigned _llen
unsigned _maxllen
unsigned _nodeRank
CommMatrix_remaining_cm
char * _serverBuffer
ControlledLib::ControlledDescr_serverDescr
unsigned long _serverToReceived
PaCO::PacoTopology_t _sTopo
unsigned _unitsize

Detailed Description

Definition at line 15 of file Controlled.h.


Constructor & Destructor Documentation

Definition at line 19 of file Controlled.cc.

References _clientBuffer, _clientDescr, _cm, _config, _dTopo, _maxllen, _nodeRank, _remaining_cm, _serverBuffer, _serverDescr, _sTopo, ControlledLib::ControlledDescr::lens, and PaCO::PacoTopology_s::total.

{
#ifdef DEBUG_INTERNAL
  std::cerr<<"[new] Controlled"<<std::endl;
#endif  

  // Common
  _config = 0;

  // By default 1->1 :)
  _sTopo.total=1;
  _dTopo.total=1;
  _nodeRank=0;
  
  // Client side
  _clientBuffer=NULL;
  _cm = new CommMatrix(_sTopo.total,_dTopo.total);
  _maxllen=0;
  _remaining_cm = NULL;
  _clientDescr.lens.length(0);

  // Server side
  _serverDescr=NULL;
  _serverBuffer=NULL;

#ifdef DEBUG_INTERNAL
  std::cerr<<"[new] Controlled done"<<std::endl;
#endif  

}
Controlled::~Controlled ( ) [virtual]

Definition at line 50 of file Controlled.cc.

References _cm.

{
#ifdef DEBUG_INTERNAL
  std::cerr<<"[del] Controlled"<<std::endl;
#endif  
  delete _cm;
}

Member Function Documentation

void Controlled::_setDestTopology ( unsigned long  total) [protected]

Definition at line 93 of file Controlled.cc.

References setDestTopology(), and PaCO::PacoTopology_s::total.

Referenced by readFromFile().

{
  PaCO::PacoTopology_t topo;
  topo.total = total;
  setDestTopology(topo);
}

Here is the call graph for this function:

void Controlled::_setLocalLen ( unsigned long  elt_nb) [protected]

Definition at line 150 of file Controlled.cc.

References _llen.

Referenced by setDescr().

{
#ifdef DEBUG_INTERNAL
  std::cerr << "-- setLotalNbElt: " << elt_nb << std::endl;
#endif
  _llen = elt_nb;
}
void Controlled::_setSourceTopology ( unsigned long  total) [protected]

Definition at line 60 of file Controlled.cc.

References setSourceTopology(), and PaCO::PacoTopology_s::total.

Referenced by readFromFile().

{
  PaCO::PacoTopology_t topo;
  topo.total = total;
  setSourceTopology(topo);
}

Here is the call graph for this function:

void Controlled::clientFree ( ) [virtual]

Implements DistributionLibrary.

Definition at line 333 of file Controlled.cc.

References _remaining_cm.

{

#ifdef DEBUG_INTERNAL
  std::cerr << "-- clientFree\n";
#endif
  delete _remaining_cm;
  _remaining_cm=NULL;
}
PieceToSend * Controlled::computePiecesToSend ( unsigned &  size) [virtual]

Implements DistributionLibrary.

Definition at line 236 of file Controlled.cc.

References _cm, _config, _nodeRank, _unitsize, CORRECT_CONFIG, PieceToSend::destNode, CommMatrix::get(), CommMatrix::getReceiverSize(), CommMatrix::getSenderSize(), PieceToSend::id, PieceToSend::size, and PieceToSend::sourceNode.

{

  PieceToSend * sched;

#ifdef DEBUG_INTERNAL
  std::cerr << "computePiecesToSend-------------------- in\n";
  std::cerr << " config = "<<_config<<endl;
  std::cerr << " #sender: "<<_cm->getSenderSize()<<std::endl;
  std::cerr << " #recv: "<<_cm->getReceiverSize()<<std::endl;  
#endif

  if (_config != CORRECT_CONFIG) {
    std::cerr << "Controlled: incorrect configuration state "<< _config<<"/"<<CORRECT_CONFIG<<endl;
    abort();
  }

  sched = new PieceToSend[_cm->getSenderSize()*_cm->getReceiverSize()];

  unsigned count=0;
  for(unsigned j=0;j<_cm->getReceiverSize();j++) {  
    if (_cm->get(_nodeRank,j)>0) {
#ifdef DEBUG_INTERNAL
      std::cerr << " "<<_nodeRank<<" -> "<<j<<" : "<<_cm->get(_nodeRank,j)<<std::endl;
#endif
      sched[count].sourceNode = _nodeRank; 
      sched[count].destNode   = j;
      sched[count].size       = _cm->get(_nodeRank,j)*_unitsize;
      sched[count].id         = (void*) -1; /* not used */
      count++;
    }
  }
  
  size_out = count;
  
#ifdef DEBUG_INTERNAL
  std::cerr << "computePiecesToSend-------------------- done\n";
#endif

  return sched;
}

Here is the call graph for this function:

virtual bool DistributionLibrary::freeComId ( long  id) [inline, virtual, inherited]

Reimplemented in BasicBC, and GaBro.

Definition at line 41 of file DistributionLibrairie.h.

{ return false;}
void * Controlled::getClientData ( void *  pid,
int  server_node,
long &  size,
long &  length,
bool &  end 
) [virtual]

Implements DistributionLibrary.

Definition at line 288 of file Controlled.cc.

References _clientBuffer, _clientDescr, _cm, _nodeRank, _remaining_cm, _unitsize, CommMatrix::get(), CommMatrix::getSenderSize(), ControlledLib::ControlledDescr::lens, ControlledLib::ControlledDescr::llen, and CommMatrix::sub().

{
  if (!_remaining_cm)
    _remaining_cm = new CommMatrix(_cm);

  long rgsz = _remaining_cm->get(_nodeRank, dnode)*_unitsize;
  unsigned rglen;

  if (rgsz > remaining_size_octet) {
    rglen = remaining_size_octet/_unitsize;
    end=false;
  } else {
    rglen = _remaining_cm->get(_nodeRank, dnode);
    end=true;
  }    

  if (rglen>0) {

    returned_length_element=rglen;
    remaining_size_octet-=(returned_length_element*_unitsize);
    _remaining_cm->sub(_nodeRank, dnode, rglen);
  
    unsigned descr_len  = _clientDescr.lens.length();
    _clientDescr.lens.length(descr_len+1);
    _clientDescr.lens[descr_len]=rglen;

    unsigned total=0;
    for(unsigned i=0;i<_cm->getSenderSize();i++) {
      total+=_cm->get(i, dnode);
    }
    _clientDescr.llen = total;

  }
#ifdef DEBUG_INTERNAL
  std::cerr << __FUNCTION__ << ": getClientData returns #elt: "<<rglen<<endl;
#endif

  //  int dummy;
  //  fscanf(stdin, "%d", &dummy);  


  return _clientBuffer;
}

Here is the call graph for this function:

void * Controlled::getDescr ( ) [virtual]

Implements DistributionLibrary.

Definition at line 344 of file Controlled.cc.

References _clientDescr, ControlledLib::ControlledDescr::lens, and ControlledLib::ControlledDescr::llen.

{
#ifdef DEBUG_INTERNAL
  std::cerr << "-- descr:llen: "<<_clientDescr.llen<<std::endl;
#endif

  _clientDescr.lens.length(0);

  return &_clientDescr;
}

Implements DistributionLibrary.

Definition at line 117 of file Controlled.cc.

References _dTopo.

{
  std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n";
  abort();
  return _dTopo;
}

Definition at line 169 of file Controlled.cc.

References _maxllen.

{
  return _maxllen;
}
long Controlled::getNodeRank ( ) [virtual]

Implements DistributionLibrary.

Definition at line 134 of file Controlled.cc.

References _nodeRank.

{
  return _nodeRank;
}
void * Controlled::getServerData ( long &  length) [virtual]

Implements DistributionLibrary.

Definition at line 377 of file Controlled.cc.

References _llen, and _serverBuffer.

{
  length= _llen;
#ifdef DEBUG_INTERNAL
  std::cerr << "-- getServerData: ptr : "<<(void*)_serverBuffer<<" #element:"<<length<<std::endl;
#endif  
  return (void*) _serverBuffer;
}

Implements DistributionLibrary.

Definition at line 84 of file Controlled.cc.

References _sTopo.

{
  std::cerr << "****** Why is the method " << __FUNCTION__ << "called?\n";
  abort();
  return _sTopo;
}
bool Controlled::insertData ( void *  rcptBuf,
unsigned long  element_nb 
) [virtual]

Implements DistributionLibrary.

Definition at line 356 of file Controlled.cc.

References _serverBuffer, _serverToReceived, and _unitsize.

{
  // cp from recpBuf to _serverBuffer
#ifdef DEBUG_INTERNAL
  std::cerr << "-- insertData:"<<element_nb<<std::endl;
#endif
  
  unsigned long llen = element_nb*_unitsize;
  _serverToReceived -= llen;

  memcpy(_serverBuffer+_serverToReceived, rcptBuf, llen);

#ifdef DEBUG_INTERNAL
  std::cerr << "-- insertData: "<<_serverToReceived<<" octects"<<std::endl;
#endif
  

  return (_serverToReceived==0);
}
void Controlled::readFromFile ( char *  filename)

Definition at line 175 of file Controlled.cc.

References _cm, _maxllen, _setDestTopology(), _setSourceTopology(), CommMatrix::dump(), CommMatrix::set(), and setMaxLocalLen().

{
#ifdef DEBUG_INTERNAL
  std::cerr << "readFromFile-------------------- done\n";
#endif

  //open comms file
  FILE *comms_file = fopen(filename, "r");
  if (comms_file == NULL) {
    perror("unable to open comms file");
    throw -1;
  }

  unsigned int senders, receivers;
  fscanf(comms_file, "%dx%d\n", &senders, &receivers);

  std::cerr<<" #s: "<<senders<<"  #r:"<<receivers<<std::endl;

  _setSourceTopology(senders);
  _setDestTopology(receivers);
   
  unsigned maxs[senders];
  for(unsigned int i = 0 ; i < senders ; i++)
    maxs[i]=0;

  //read edges in file, and add edges
  for(unsigned int i = 0 ; i < senders * receivers ; i++) {
    unsigned int value;
    fscanf(comms_file, "%d", &value); 
    unsigned int node2 = i % receivers;
    unsigned int node1 = (i - node2) / receivers;
    if (value != 0) {
      _cm->set(node1, node2, value);
#ifdef DEBUG_INTERNAL
      std::cerr << " "<<node1<<" -> "<<node2<<" : "<<value<<endl;
#endif

      maxs[node1]+=value;
    }
  }  
    
  fclose(comms_file);
  
  unsigned long max=0;
  for(unsigned int i = 0 ; i < senders ; i++)
    if (maxs[i]>max)
      max=maxs[i];

  if (_maxllen && (max>_maxllen))
    {
      std::cerr << "MaxLocalLen was set to small: "<<_maxllen<<" vs "<<max<<" (0: not set)"<<std::endl;
      abort();
    }

  setMaxLocalLen(max);

  _cm->dump();

}  

Here is the call graph for this function:

void Controlled::serverFree ( ) [virtual]

Implements DistributionLibrary.

Definition at line 415 of file Controlled.cc.

References _serverBuffer.

{ 
#ifdef DEBUG_INTERNAL
  std::cerr << "-- serverFree: "<<(void*)_serverBuffer<<endl;
#endif
  free(_serverBuffer);
  _serverBuffer=NULL; // the orb (or the user) need to free the memory!
}
virtual bool DistributionLibrary::setComId ( long  id) [inline, virtual, inherited]

Reimplemented in BasicBC, and GaBro.

Definition at line 40 of file DistributionLibrairie.h.

{ return false;}
virtual void Controlled::setCommunicator ( void *  group) [inline, virtual]

Implements DistributionLibrary.

Definition at line 61 of file Controlled.h.

{}
void Controlled::setDataPtr ( void *  dataPtr) [virtual]

Implements DistributionLibrary.

Definition at line 279 of file Controlled.cc.

References _clientBuffer.

{
  _clientBuffer = (char *) dataPtr;
#ifdef DEBUG_INTERNAL
  cerr << "-- _clientBuffer set to "<<dataPtr<<endl;
#endif
}
void Controlled::setDescr ( void *  descr) [virtual]

Implements DistributionLibrary.

Definition at line 387 of file Controlled.cc.

References _dTopo, _llen, _serverBuffer, _serverDescr, _serverToReceived, _setLocalLen(), _sTopo, _unitsize, ControlledLib::ControlledDescr::llen, and PaCO::PacoTopology_s::total.

{
  std::cerr << "-- setDescr "<<endl;

  _serverDescr = (ControlledLib::ControlledDescr*) descr;

  // Descr already received

  if ( _serverBuffer == NULL)
    {
      // 1st time -> allocate memory & init
      //this->setEltSize(_descr->usz); BUG: usz can be different in client and server (32bit vs 64bit)
      unsigned long len = _serverDescr->llen*_unitsize;
      this->_setLocalLen(_serverDescr->llen);
      
#ifdef DEBUG_INTERNAL
      fprintf(stderr, "-- setDescr: stopo: %ld\tdtopo: %ld\n",_sTopo.total, _dTopo.total);
      fprintf(stderr, "   setDescr: local len: %ld\n", _serverDescr->llen);
#endif  
      _serverBuffer = (char*) malloc(len*_unitsize);
#ifdef DEBUG_INTERNAL
      std::cerr << "-- serverMalloc: "<<(void*)_serverBuffer<<" - "<<_llen<<endl;
#endif
      _serverToReceived = len;
    }
}

Here is the call graph for this function:

Implements DistributionLibrary.

Definition at line 101 of file Controlled.cc.

References _cm, _config, _dTopo, _sTopo, DST_TOPOLOGY, and PaCO::PacoTopology_s::total.

Referenced by _setDestTopology().

{
#ifdef DEBUG_INTERNAL
  std::cerr << "-- setDestTopology: " << topo.total << std::endl;
#endif
  _config |= DST_TOPOLOGY;

  if (_dTopo.total != topo.total) {
    _dTopo = topo;
    delete _cm;
    _cm = new CommMatrix(_sTopo.total,_dTopo.total);
  }

}
void Controlled::setEltSize ( unsigned long  size)

Definition at line 140 of file Controlled.cc.

References _config, _unitsize, and ELEMENT_SIZE.

{
#ifdef DEBUG_INTERNAL
  std::cerr << "-- setEltSize: " << size << std::endl;
#endif
  _config |= ELEMENT_SIZE;
  _unitsize = size;
}
void Controlled::setMaxLocalLen ( unsigned long  elt_nb)

Definition at line 159 of file Controlled.cc.

References _config, _maxllen, and LOCAL_SIZE.

Referenced by readFromFile().

{
#ifdef DEBUG_INTERNAL
  std::cerr << "-- setMaxLocalNbElt: " << elt_nb << std::endl;
#endif
  _config |= LOCAL_SIZE;
  _maxllen = elt_nb;
}
void Controlled::setNodeRank ( long  Rank) [virtual]

Implements DistributionLibrary.

Definition at line 125 of file Controlled.cc.

References _nodeRank.

{
#ifdef DEBUG_INTERNAL
  std::cerr << "-- setNodeRank: " << Rank << std::endl;
#endif
  _nodeRank = Rank;
}

Implements DistributionLibrary.

Definition at line 68 of file Controlled.cc.

References _cm, _config, _dTopo, _sTopo, SRC_TOPOLOGY, and PaCO::PacoTopology_s::total.

Referenced by _setSourceTopology().

{
#ifdef DEBUG_INTERNAL
  std::cerr << "-- setSourceTopology: " << topo.total << std::endl;
#endif
  _config |= SRC_TOPOLOGY;

  if (_sTopo.total != topo.total) {
    _sTopo = topo;
    delete _cm;
    _cm = new CommMatrix(_sTopo.total,_dTopo.total);

  }
}

Member Data Documentation

char* Controlled::_clientBuffer [private]

Definition at line 31 of file Controlled.h.

Referenced by Controlled(), getClientData(), and setDataPtr().

unsigned Controlled::_llen [private]

Definition at line 41 of file Controlled.h.

Referenced by _setLocalLen(), getServerData(), and setDescr().

unsigned Controlled::_maxllen [private]

Definition at line 37 of file Controlled.h.

Referenced by Controlled(), getMaxLen(), readFromFile(), and setMaxLocalLen().

unsigned Controlled::_nodeRank [private]

Definition at line 26 of file Controlled.h.

Referenced by computePiecesToSend(), Controlled(), getClientData(), getNodeRank(), and setNodeRank().

Definition at line 35 of file Controlled.h.

Referenced by clientFree(), Controlled(), and getClientData().

char* Controlled::_serverBuffer [private]

Definition at line 43 of file Controlled.h.

Referenced by Controlled(), getServerData(), insertData(), serverFree(), and setDescr().

Definition at line 45 of file Controlled.h.

Referenced by Controlled(), and setDescr().

unsigned long Controlled::_serverToReceived [private]

Definition at line 42 of file Controlled.h.

Referenced by insertData(), and setDescr().

unsigned Controlled::_unitsize [private]

Definition at line 27 of file Controlled.h.

Referenced by computePiecesToSend(), getClientData(), insertData(), setDescr(), and setEltSize().


The documentation for this class was generated from the following files: