MOOSE - Multiscale Object Oriented Simulation Environment
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SparseMsg Class Reference

#include <SparseMsg.h>

+ Inheritance diagram for SparseMsg:
+ Collaboration diagram for SparseMsg:

Public Member Functions

void clear ()
 
Msgcopy (Id origSrc, Id newSrc, Id newTgt, FuncId fid, unsigned int b, unsigned int n) const
 
ObjId findOtherEnd (ObjId end) const
 
Eref firstTgt (const Eref &src) const
 
vector< unsigned int > getColIndex () const
 
vector< unsigned int > getEntryPairs () const
 
SparseMatrix< unsigned int > & getMatrix ()
 
vector< unsigned int > getMatrixEntry () const
 
unsigned int getNumColumns () const
 
unsigned int getNumEntries () const
 
unsigned int getNumRows () const
 
double getProbability () const
 
vector< unsigned int > getRowStart () const
 
unsigned long getSeed () const
 
Id managerId () const
 
void pairFill (vector< unsigned int > src, vector< unsigned int > dest)
 
unsigned int randomConnect (double probability)
 
void setEntry (unsigned int row, unsigned int column, unsigned int value)
 
void setEntryPairs (vector< unsigned int > entries)
 
void setMatrix (const SparseMatrix< unsigned int > &m)
 
void setProbability (double value)
 
void setRandomConnectivity (double probability, long seed)
 
void setSeed (unsigned long value)
 
void sources (vector< vector< Eref > > &v) const
 
 SparseMsg (Element *e1, Element *e2, unsigned int msgIndex)
 
void targets (vector< vector< Eref > > &v) const
 
void transpose ()
 
void tripletFill (vector< unsigned int > src, vector< unsigned int > dest, vector< unsigned int > field)
 
void tripletFill1 (vector< unsigned int > entries)
 
void unsetEntry (unsigned int row, unsigned int column)
 
void updateAfterFill ()
 
 ~SparseMsg ()
 
- Public Member Functions inherited from Msg
Elemente1 () const
 
Elemente2 () const
 
ObjId getAdjacent (ObjId) const
 
vector< string > getDestFieldsOnE1 () const
 
vector< string > getDestFieldsOnE2 () const
 
Id getE1 () const
 
Id getE2 () const
 
vector< string > getSrcFieldsOnE1 () const
 
vector< string > getSrcFieldsOnE2 () const
 
bool isForward (const Element *src) const
 
ObjId mid () const
 
 Msg (ObjId mid, Element *e1, Element *e2)
 Constructor. More...
 
virtual void sources (vector< vector< Eref > > &v) const =0
 
virtual void targets (vector< vector< Eref > > &v) const =0
 
virtual ~Msg ()
 Destructor. More...
 

Static Public Member Functions

static const CinfoinitCinfo ()
 
static char * lookupMsg (unsigned int index)
 Static function for Msg access. More...
 
static unsigned int numMsg ()
 Msg lookup functions. More...
 
- Static Public Member Functions inherited from Msg
static void clearAllMsgs ()
 
static void deleteMsg (ObjId mid)
 
static const MsggetMsg (ObjId m)
 
static const CinfoinitCinfo ()
 
static unsigned int initMsgManagers ()
 
static bool isLastTrump ()
 True when MOOSE has been terminated and is being cleaned up. More...
 
static const MsglastMsg ()
 

Private Attributes

moose::MOOSE_UNIFORM_DISTRIBUTION
< double > 
dist_
 
SparseMatrix< unsigned int > matrix_
 
unsigned int nrows_
 
unsigned int numThreads_
 
double p_
 
moose::MOOSE_RANDOM_DEVICE rd_
 
moose::MOOSE_RNG_DEFAULT_ENGINE rng_
 
unsigned long seed_
 

Static Private Attributes

static Id managerId_
 
static vector< SparseMsg * > msg_
 

Friends

unsigned int Msg::initMsgManagers ()
 

Additional Inherited Members

- Protected Attributes inherited from Msg
Elemente1_
 Index of this Msg on the msg_ vector. More...
 
Elemente2_
 Element 1 attached to Msg. More...
 
ObjId mid_
 
- Static Protected Attributes inherited from Msg
static bool lastTrump_ = false
 Flag to indicate termination of program. More...
 
static Id msgManagerId_
 Element 2 attached to Msg. More...
 

Detailed Description

This is a parallelized sparse message. It is a general message type optimized for sparse matrix like projection patterns. For each source object[DataId] there can be a target object[DataId]. For parallel/multithreaded use, we need to guarantee that all requests to the same target object (and all its synapses) are on the same queue. So it builds up a separate SparseMatrix for each thread.

It has a function to do the node/thread decomposition to generate an equivalent of the original sparse matrix, but using only the appropriate RNG seed.

A typical case is from an array of IntFire objects to an array of Synapses, which are array fields of IntFire objects. The sparse connectivity maps between the source IntFire and target Synapses.

The location of the entry in the sparse matrix provides the index of the target IntFire. The data value in the sparse matrix provides the index of the Synapse at that specific connection. This assumes that only one Synapse mediates a given connection between any two IntFire objects.

It is optimized for input coming on Element e1, and going to Element e2. If you expect any significant backward data flow, please use BiSparseMsg. It can be modified after creation to add or remove message entries.

Definition at line 46 of file SparseMsg.h.

Constructor & Destructor Documentation

SparseMsg::SparseMsg ( Element e1,
Element e2,
unsigned int  msgIndex 
)

Definition at line 389 of file SparseMsg.cpp.

References matrix_, msg_, Element::numData(), rd_, rng_, seed_, and SparseMatrix< T >::setSize().

Referenced by copy().

390  : Msg( ObjId( managerId_, (msgIndex != 0) ? msgIndex: msg_.size() ),
391  e1, e2 ),
392  numThreads_( 1 ),
393  nrows_( 0 ),
394  p_( 0.0 ), seed_( 0 )
395 {
396  unsigned int nrows = 0;
397  unsigned int ncolumns = 0;
398  nrows = e1->numData();
399  ncolumns = e2->numData();
400  matrix_.setSize( nrows, ncolumns );
401  if ( msgIndex == 0 )
402  {
403  msg_.push_back( this );
404  }
405  else
406  {
407  if ( msg_.size() <= msgIndex )
408  msg_.resize( msgIndex + 1 );
409  msg_[ msgIndex ] = this;
410  }
411 
412  // cout << Shell::myNode() << ": SparseMsg constructor between " << e1->getName() << " and " << e2->getName() << endl;
413 
414  // Init rng with random device.
415  if( seed_ == 0 )
416  rng_.seed( rd_() );
417 }
double p_
Definition: SparseMsg.h:147
moose::MOOSE_RNG_DEFAULT_ENGINE rng_
Definition: SparseMsg.h:154
unsigned int nrows_
Definition: SparseMsg.h:146
Definition: ObjId.h:20
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
unsigned long seed_
Definition: SparseMsg.h:152
static Id managerId_
Definition: SparseMsg.h:148
void setSize(unsigned int nrows, unsigned int ncolumns)
Definition: SparseMatrix.h:126
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
unsigned int numThreads_
Definition: SparseMsg.h:145
moose::MOOSE_RANDOM_DEVICE rd_
Definition: SparseMsg.h:153
static vector< SparseMsg * > msg_
Definition: SparseMsg.h:149
Msg(ObjId mid, Element *e1, Element *e2)
Constructor.
Definition: Msg.cpp:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SparseMsg::~SparseMsg ( )

Definition at line 419 of file SparseMsg.cpp.

References ObjId::dataIndex, Msg::mid_, and msg_.

420 {
421  assert( mid_.dataIndex < msg_.size() );
422  msg_[ mid_.dataIndex ] = 0; // ensure deleted ptr isn't reused.
423 }
ObjId mid_
Definition: Msg.h:178
static vector< SparseMsg * > msg_
Definition: SparseMsg.h:149
unsigned int dataIndex
Definition: ObjId.h:99

Member Function Documentation

void SparseMsg::clear ( )

Definition at line 289 of file SparseMsg.cpp.

References SparseMatrix< T >::clear(), and matrix_.

Referenced by initCinfo().

290 {
291  matrix_.clear();
292 }
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Msg * SparseMsg::copy ( Id  origSrc,
Id  newSrc,
Id  newTgt,
FuncId  fid,
unsigned int  b,
unsigned int  n 
) const
virtual

Make a copy of this Msg. The original msg was on origSrc. The new Msg should go from newSrc to newTgt, and have the function fid, on bindIndex b. The copy may have to be a higher-order Msg type to handle arrays if n > 1. Note that n is not the number of msgs, but the multiplier by which numData will be scaled.

Implements Msg.

Definition at line 570 of file SparseMsg.cpp.

References Element::addMsgAndFunc(), Msg::e1(), Msg::e2(), Id::element(), matrix_, Msg::mid(), nrows_, setMatrix(), and SparseMsg().

572 {
573  const Element* orig = origSrc.element();
574  if ( n <= 1 )
575  {
576  SparseMsg* ret = 0;
577  if ( orig == e1() )
578  {
579  ret = new SparseMsg( newSrc.element(), newTgt.element(), 0 );
580  ret->e1()->addMsgAndFunc( ret->mid(), fid, b );
581  }
582  else if ( orig == e2() )
583  {
584  ret = new SparseMsg( newTgt.element(), newSrc.element(), 0 );
585  ret->e2()->addMsgAndFunc( ret->mid(), fid, b );
586  }
587  else
588  {
589  assert( 0 );
590  }
591  ret->setMatrix( matrix_ );
592  ret->nrows_ = nrows_;
593  return ret;
594  }
595  else
596  {
597  // Here we need a SliceMsg which goes from one 2-d array to another.
598  cout << "Error: SparseMsg::copy: SparseSliceMsg not yet implemented\n";
599  return 0;
600  }
601 }
Element * e2() const
Definition: Msg.h:68
ObjId mid() const
Definition: Msg.h:106
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
unsigned int nrows_
Definition: SparseMsg.h:146
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Definition: Element.cpp:128
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
Element * e1() const
Definition: Msg.h:61
void setMatrix(const SparseMatrix< unsigned int > &m)
Definition: SparseMsg.cpp:534
SparseMsg(Element *e1, Element *e2, unsigned int msgIndex)
Definition: SparseMsg.cpp:389

+ Here is the call graph for this function:

ObjId SparseMsg::findOtherEnd ( ObjId  ) const
virtual

Find the other end of this Msg. In most cases this is a straightforward return of e1 or e2, plus perhaps a DataId. But in some complex msgs we need to figure out DataIds that match with the target. In many-to-one cases we just return the first entry. If no Element match, return ObjId( Id(), DataId::bad() ) If Element e matches but not DataId, return ObjId( e.id(), DataId::bad() )

Implements Msg.

Definition at line 544 of file SparseMsg.cpp.

References BADINDEX, ObjId::dataIndex, Msg::e1(), Msg::e2(), ObjId::element(), SparseMatrix< T >::getColumn(), SparseMatrix< T >::getRow(), matrix_, and rowIndex().

545 {
546  if ( f.element() == e1() )
547  {
548  const unsigned int* entry;
549  const unsigned int* colIndex;
550  unsigned int num = matrix_.getRow( f.dataIndex, &entry, &colIndex );
551  if ( num > 0 ) // Return the first matching entry.
552  {
553  return ObjId( e2()->id(), colIndex[0] );
554  }
555  return ObjId( 0, BADINDEX );
556  }
557  else if ( f.element() == e2() ) // Bad! Slow! Avoid!
558  {
559  vector< unsigned int > entry;
560  vector< unsigned int > rowIndex;
561  unsigned int num = matrix_.getColumn( f.dataIndex, entry, rowIndex );
562  if ( num > 0 ) // Return the first matching entry.
563  {
564  return ObjId( e1()->id(), DataId( rowIndex[0] ) );
565  }
566  }
567  return ObjId( 0, BADINDEX );
568 }
Element * e2() const
Definition: Msg.h:68
unsigned int getRow(unsigned int row, const T **entry, const unsigned int **colIndex) const
Definition: SparseMatrix.h:288
Definition: ObjId.h:20
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
unsigned int rowIndex(const Element *e, const DataId &d)
Definition: SparseMsg.cpp:425
Element * e1() const
Definition: Msg.h:61
const unsigned int BADINDEX
Used by ObjId and Eref.
Definition: consts.cpp:25
unsigned int getColumn(unsigned int col, vector< T > &entry, vector< unsigned int > &rowIndex) const
Definition: SparseMatrix.h:342
unsigned int DataId
Definition: header.h:47

+ Here is the call graph for this function:

Eref SparseMsg::firstTgt ( const Eref src) const
virtual

Obtain the first target Eref for the specified Src Eref It is really meant only to work with messages with a single target ObjId for each given src, typically OneToOne.

Implements Msg.

Definition at line 433 of file SparseMsg.cpp.

References Eref::dataIndex(), Msg::e1_, Msg::e2_, Eref::element(), SparseMatrix< T >::getRow(), matrix_, and SparseMatrix< T >::nEntries().

434 {
435  if ( matrix_.nEntries() == 0 )
436  return Eref( 0, 0 );
437 
438  if ( src.element() == e1_ )
439  {
440  const unsigned int* fieldIndex;
441  const unsigned int* colIndex;
442  unsigned int n = matrix_.getRow( src.dataIndex(),
443  &fieldIndex, &colIndex );
444  if ( n != 0 )
445  {
446  return Eref( e2_, colIndex[0], fieldIndex[0] );
447  }
448  }
449  else if ( src.element() == e2_ )
450  {
451  return Eref( e1_, 0 );
452  }
453  return Eref( 0, 0 );
454 }
unsigned int nEntries() const
Definition: SparseMatrix.h:97
unsigned int getRow(unsigned int row, const T **entry, const unsigned int **colIndex) const
Definition: SparseMatrix.h:288
unsigned int dataIndex() const
Definition: Eref.h:50
Element * element() const
Definition: Eref.h:42
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
Definition: Eref.h:26
Element * e1_
Index of this Msg on the msg_ vector.
Definition: Msg.h:180
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181

+ Here is the call graph for this function:

vector< unsigned int > SparseMsg::getColIndex ( ) const

Definition at line 234 of file SparseMsg.cpp.

References SparseMatrix< T >::colIndex(), and matrix_.

Referenced by initCinfo().

235 {
236  return matrix_.colIndex();
237 }
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
const vector< unsigned int > & colIndex() const
Definition: SparseMatrix.h:431

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

vector< unsigned int > SparseMsg::getEntryPairs ( ) const

Definition at line 251 of file SparseMsg.cpp.

References SparseMatrix< T >::colIndex(), matrix_, SparseMatrix< T >::nRows(), and SparseMatrix< T >::rowStart().

Referenced by initCinfo().

252 {
253  vector< unsigned int > cols = matrix_.colIndex();
254  vector< unsigned int > y;
255  for ( unsigned int row = 0; row < matrix_.nRows(); ++row )
256  {
257  unsigned int begin = matrix_.rowStart()[row];
258  unsigned int end = matrix_.rowStart()[row+1];
259  for ( unsigned int j = begin; j < end; ++j )
260  y.push_back( row );
261  }
262  assert( cols.size() == y.size() );
263  y.insert( y.end(), cols.begin(), cols.end() );
264  return y;
265 }
unsigned int nRows() const
Definition: SparseMatrix.h:87
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
const vector< unsigned int > & colIndex() const
Definition: SparseMatrix.h:431
const vector< unsigned int > & rowStart() const
Definition: SparseMatrix.h:435

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SparseMatrix< unsigned int > & SparseMsg::getMatrix ( )

Returns the connection matrix

Definition at line 539 of file SparseMsg.cpp.

References matrix_.

540 {
541  return matrix_;
542 }
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
vector< unsigned int > SparseMsg::getMatrixEntry ( ) const

Definition at line 229 of file SparseMsg.cpp.

References matrix_, and SparseMatrix< T >::matrixEntry().

Referenced by initCinfo().

230 {
231  return matrix_.matrixEntry();
232 }
const vector< T > & matrixEntry() const
Here we expose the sparse matrix for MOOSE use.
Definition: SparseMatrix.h:427
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned int SparseMsg::getNumColumns ( ) const

Definition at line 219 of file SparseMsg.cpp.

References matrix_, and SparseMatrix< T >::nColumns().

Referenced by initCinfo().

220 {
221  return matrix_.nColumns();
222 }
unsigned int nColumns() const
Definition: SparseMatrix.h:92
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned int SparseMsg::getNumEntries ( ) const

Definition at line 224 of file SparseMsg.cpp.

References matrix_, and SparseMatrix< T >::nEntries().

Referenced by initCinfo().

225 {
226  return matrix_.nEntries();
227 }
unsigned int nEntries() const
Definition: SparseMatrix.h:97
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned int SparseMsg::getNumRows ( ) const

Definition at line 214 of file SparseMsg.cpp.

References matrix_, and SparseMatrix< T >::nRows().

Referenced by initCinfo().

215 {
216  return matrix_.nRows();
217 }
unsigned int nRows() const
Definition: SparseMatrix.h:87
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double SparseMsg::getProbability ( ) const

Definition at line 193 of file SparseMsg.cpp.

References p_.

Referenced by initCinfo().

194 {
195  return p_;
196 }
double p_
Definition: SparseMsg.h:147

+ Here is the caller graph for this function:

vector< unsigned int > SparseMsg::getRowStart ( ) const

Definition at line 239 of file SparseMsg.cpp.

References matrix_, and SparseMatrix< T >::rowStart().

Referenced by initCinfo().

240 {
241  return matrix_.rowStart();
242 }
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
const vector< unsigned int > & rowStart() const
Definition: SparseMatrix.h:435

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned long SparseMsg::getSeed ( ) const

Definition at line 209 of file SparseMsg.cpp.

References seed_.

Referenced by initCinfo().

210 {
211  return seed_;
212 }
unsigned long seed_
Definition: SparseMsg.h:152

+ Here is the caller graph for this function:

const Cinfo * SparseMsg::initCinfo ( )
static

Connection matrix entries to manipulate in Python.

connection matrix column indices to manipulate in Python.

connection matrix rowStart to manipulate in Python.

Definition at line 24 of file SparseMsg.cpp.

References clear(), getColIndex(), getEntryPairs(), getMatrixEntry(), getNumColumns(), getNumEntries(), getNumRows(), getProbability(), getRowStart(), getSeed(), Msg::initCinfo(), numEntries, pairFill(), setEntry(), setEntryPairs(), setProbability(), setRandomConnectivity(), setSeed(), sparseMsgCinfo, transpose(), tripletFill(), tripletFill1(), and unsetEntry().

Referenced by Msg::initMsgManagers().

25 {
27  // Field definitions.
30  "numRows",
31  "Number of rows in matrix.",
33  );
35  "numColumns",
36  "Number of columns in matrix.",
38  );
40  "numEntries",
41  "Number of Entries in matrix.",
43  );
44 
45  static ValueFinfo< SparseMsg, vector< unsigned int > > connectionList(
46  "connectionList",
47  "Pairwise specification of connection matrix where each x,y value "
48  "represents a connection from src[x] to dest[y]. "
49  "The (x,y) entries are ordered in a single vector as \n"
50  "(x0, x1,... x_n-1, y0, y1,... y_n-1)\n",
53  );
54 
57  matrixEntry(
58  "matrixEntry",
59  "The non-zero matrix entries in the sparse matrix. Their"
60  "column indices are in a separate vector and the row"
61  "informatino in a third",
63  );
66  columnIndex(
67  "columnIndex",
68  "Column Index of each matrix entry",
70  );
73  rowStart(
74  "rowStart",
75  "Row start for each block of entries and column indices",
77  );
78 
79  static ValueFinfo< SparseMsg, double > probability(
80  "probability",
81  "connection probability for random connectivity.",
84  );
85 
87  "seed",
88  "Random number seed for generating probabilistic connectivity.",
91  );
92 
94 // DestFinfos
96 
97  static DestFinfo setRandomConnectivity( "setRandomConnectivity",
98  "Assigns connectivity with specified probability and seed",
101 
102  static DestFinfo setEntry( "setEntry",
103  "Assigns single row,column value",
105  &SparseMsg::setEntry ) );
106 
107  static DestFinfo unsetEntry( "unsetEntry",
108  "Clears single row,column entry",
111 
112  static DestFinfo clear( "clear",
113  "Clears out the entire matrix",
115  &SparseMsg::clear ) );
116 
117  static DestFinfo transpose( "transpose",
118  "Transposes the sparse matrix",
121 
122  static DestFinfo pairFill( "pairFill",
123  "Fills entire matrix using pairs of (x,y) indices to indicate "
124  "presence of a connection. If the target is a FieldElement it"
125  "automagically assigns FieldIndices.",
126  new OpFunc2< SparseMsg,
127  vector< unsigned int >, vector< unsigned int> >(
128  &SparseMsg::pairFill ) );
129 
130  static DestFinfo tripletFill( "tripletFill",
131  "Fills entire matrix using triplets of (x,y,fieldIndex) to fully "
132  "specify every connection in the sparse matrix.",
133  new OpFunc3< SparseMsg,
134  vector< unsigned int >, vector< unsigned int>,
135  vector< unsigned int > >(
137 
138  static DestFinfo tripletFill1( "tripletFill1",
139  "Single contiguous array to fill entire connection matrix using "
140  "triplets of (x,y, fieldindex) ordered as \n"
141  "(x0, x1,... xn-1, y0, y1,... yn-1, fi0, fi1,... fi_n-1)\n",
142  new OpFunc1< SparseMsg, vector< unsigned int > >(
144 
146 // Assemble it all.
148 
149  static Finfo* sparseMsgFinfos[] =
150  {
151  &numRows, // readonly value
152  &numColumns, // readonly value
153  &numEntries, // readonly value
154  &connectionList, // value
155  &matrixEntry, // ReadOnlyValue
156  &columnIndex, // ReadOnlyValue
157  &rowStart, // ReadOnlyValue
158  &probability, // value
159  &seed, // value
160  &setRandomConnectivity, // dest
161  &setEntry, // dest
162  &unsetEntry, //dest
163  &clear, //dest
164  &transpose, //dest
165  &pairFill, //dest
166  &tripletFill, //dest
167  &tripletFill1, //dest
168  };
169 
170  static Dinfo< short > dinfo;
171  static Cinfo sparseMsgCinfo (
172  "SparseMsg", // name
173  Msg::initCinfo(), // base class
174  sparseMsgFinfos,
175  sizeof( sparseMsgFinfos ) / sizeof( Finfo* ), // num Fields
176  &dinfo
177  );
178 
179  return &sparseMsgCinfo;
180 }
vector< unsigned int > getEntryPairs() const
Definition: SparseMsg.cpp:251
static const Cinfo * sparseMsgCinfo
Definition: SparseMsg.cpp:182
Definition: Dinfo.h:60
Definition: OpFunc.h:56
void clear()
Definition: SparseMsg.cpp:289
void setEntryPairs(vector< unsigned int > entries)
Definition: SparseMsg.cpp:244
const int numEntries
Definition: proc.cpp:60
void tripletFill(vector< unsigned int > src, vector< unsigned int > dest, vector< unsigned int > field)
Definition: SparseMsg.cpp:366
unsigned int getNumColumns() const
Definition: SparseMsg.cpp:219
vector< unsigned int > getColIndex() const
Definition: SparseMsg.cpp:234
void setRandomConnectivity(double probability, long seed)
Definition: SparseMsg.cpp:271
Definition: OpFunc.h:40
unsigned int getNumRows() const
Definition: SparseMsg.cpp:214
void setProbability(double value)
Definition: SparseMsg.cpp:187
vector< unsigned int > getMatrixEntry() const
Definition: SparseMsg.cpp:229
void tripletFill1(vector< unsigned int > entries)
Definition: SparseMsg.cpp:375
Definition: OpFunc.h:27
void pairFill(vector< unsigned int > src, vector< unsigned int > dest)
Definition: SparseMsg.cpp:323
void unsetEntry(unsigned int row, unsigned int column)
Definition: SparseMsg.cpp:284
void setSeed(unsigned long value)
Definition: SparseMsg.cpp:198
void transpose()
Definition: SparseMsg.cpp:294
double getProbability() const
Definition: SparseMsg.cpp:193
void setEntry(unsigned int row, unsigned int column, unsigned int value)
Definition: SparseMsg.cpp:278
unsigned int getNumEntries() const
Definition: SparseMsg.cpp:224
Definition: OpFunc.h:13
vector< unsigned int > getRowStart() const
Definition: SparseMsg.cpp:239
Definition: Cinfo.h:18
static const Cinfo * initCinfo()
Definition: Msg.cpp:165
unsigned long getSeed() const
Definition: SparseMsg.cpp:209
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char * SparseMsg::lookupMsg ( unsigned int  index)
static

Static function for Msg access.

Definition at line 643 of file SparseMsg.cpp.

References msg_.

Referenced by Msg::clearAllMsgs(), and Msg::initMsgManagers().

644 {
645  assert( index < msg_.size() );
646  return reinterpret_cast< char* >( msg_[index] );
647 }
static vector< SparseMsg * > msg_
Definition: SparseMsg.h:149

+ Here is the caller graph for this function:

Id SparseMsg::managerId ( ) const

Definition at line 529 of file SparseMsg.cpp.

References managerId_.

530 {
531  return SparseMsg::managerId_;
532 }
static Id managerId_
Definition: SparseMsg.h:148
unsigned int SparseMsg::numMsg ( )
static

Msg lookup functions.

Static function for Msg access.

Definition at line 637 of file SparseMsg.cpp.

References msg_.

Referenced by Msg::clearAllMsgs(), and Msg::initMsgManagers().

638 {
639  return msg_.size();
640 }
static vector< SparseMsg * > msg_
Definition: SparseMsg.h:149

+ Here is the caller graph for this function:

void SparseMsg::pairFill ( vector< unsigned int >  src,
vector< unsigned int >  dest 
)

Fills up the entire message based on pairs of src,dest (i.e., row,column) values. All filled entries are set to zero.

We set retainSize flag to true since the # of src/dest objects doesn't change. We can explicitly assign it elsewhere if needed.

Definition at line 323 of file SparseMsg.cpp.

References Msg::e1(), Msg::e2(), matrix_, Element::numData(), SparseMatrix< T >::tripletFill(), and updateAfterFill().

Referenced by initCinfo(), and setEntryPairs().

325 {
326  // Sanity check
327  vector< unsigned int >::const_iterator i;
328  for ( i = src.begin(); i != src.end(); ++i )
329  {
330  if (*i >= e1()->numData() )
331  {
332  cout << "Warning: SparseMsg::pairFill: Src index " << *i <<
333  " exceeds Src array size " << e1()->numData() <<
334  ". Aborting\n";
335  return;
336  }
337  }
338  for ( i = dest.begin(); i != dest.end(); ++i )
339  {
340  if (*i >= e2()->numData() )
341  {
342  cout << "Warning: SparseMsg::pairFill: Dest index " << *i <<
343  " exceeds Dest array size " << e2()->numData() <<
344  ". Aborting\n";
345  return;
346  }
347  }
348 
349  vector< unsigned int > numAtDest( dest.size(), 0 );
350  vector< unsigned int > fieldIndex( dest.size(), 0 );
351  for ( unsigned int i = 0; i < dest.size(); ++i )
352  {
353  fieldIndex[i] = numAtDest[ dest[i] ];
354  // Could do on previous line, but clarity
355  ++numAtDest[ dest[i] ];
356  }
357 
362  matrix_.tripletFill( src, dest, fieldIndex, true );
363  updateAfterFill();
364 }
Element * e2() const
Definition: Msg.h:68
void tripletFill(const vector< unsigned int > &row, const vector< unsigned int > &col, const vector< T > &z, bool retainSize=false)
Definition: SparseMatrix.h:583
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
void updateAfterFill()
Definition: SparseMsg.cpp:301
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
Element * e1() const
Definition: Msg.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned int SparseMsg::randomConnect ( double  probability)

Returns number of synapses formed. Fills it in transpose form, because we need to count and index the number of synapses on the target, so we need to iterate over the sources in the inner loop. Once full, does the transpose. Should really have a seed argument for the random number. Later need a way to fast-forward mtrand to just the entries we need to fill.

Definition at line 465 of file SparseMsg.cpp.

References SparseMatrix< T >::addRow(), SparseMatrix< T >::clear(), dist_, Msg::e1(), Msg::e2(), Msg::e2_, Element::localDataStart(), Element::markRewired(), matrix_, SparseMatrix< T >::nColumns(), SparseMatrix< T >::nRows(), Element::numData(), Element::numLocalData(), Element::resizeField(), rng_, and SparseMatrix< T >::transpose().

Referenced by setProbability(), setRandomConnectivity(), setSeed(), and testSparseMsg().

466 {
467  unsigned int nRows = matrix_.nRows(); // Sources
468  unsigned int nCols = matrix_.nColumns(); // Destinations
469  matrix_.clear();
470  unsigned int totalSynapses = 0;
471  vector< unsigned int > sizes( nCols, 0 );
472  unsigned int totSynNum = 0;
473  Element* syn = e2_;
474  unsigned int startData = syn->localDataStart();
475  unsigned int endData = startData + syn->numLocalData();
476 
477  assert( nCols == syn->numData() );
478 
479  matrix_.transpose();
480  for ( unsigned int i = 0; i < nCols; ++i )
481  {
482  vector< unsigned int > synIndex;
483  // This needs to be obtained from current size of syn array.
484  // unsigned int synNum = sizes[ i ];
485  unsigned int synNum = 0;
486  for ( unsigned int j = 0; j < nRows; ++j )
487  {
488  double r = dist_( rng_ ); // Want to ensure it is called each time round the loop.
489  if ( r < probability )
490  {
491  synIndex.push_back( synNum );
492  ++synNum;
493  ++totSynNum;
494  }
495  else
496  {
497  synIndex.push_back( ~0 );
498  }
499  }
500 
501  if ( i >= startData && i < endData )
502  {
503  e2_->resizeField( i - startData, synNum );
504  }
505  totalSynapses += synNum;
506  matrix_.addRow( i, synIndex );
507  /*
508  * This is the correct form, but I need to implement something
509  * to check up for target nodes in order to use this.
510  if ( i >= startData && i < endData ) {
511  e2_->resizeField( i - startData, synNum );
512  totalSynapses += synNum;
513  matrix_.addRow( i, synIndex );
514  } else {
515  synIndex.resize( 0 );
516  synIndex.assign( nRows, ~0 );
517  matrix_.addRow( i, synIndex );
518  }
519  */
520  }
521 
522  matrix_.transpose();
523  // cout << Shell::myNode() << ": sizes.size() = " << sizes.size() << ", ncols = " << nCols << ", startSynapse = " << startSynapse << endl;
524  e1()->markRewired();
525  e2()->markRewired();
526  return totalSynapses;
527 }
void markRewired()
Definition: Element.cpp:706
Element * e2() const
Definition: Msg.h:68
unsigned int nColumns() const
Definition: SparseMatrix.h:92
moose::MOOSE_RNG_DEFAULT_ENGINE rng_
Definition: SparseMsg.h:154
unsigned int nRows() const
Definition: SparseMatrix.h:87
void transpose()
Definition: SparseMatrix.h:456
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
void addRow(unsigned int rowNum, const vector< T > &row)
Definition: SparseMatrix.h:387
moose::MOOSE_UNIFORM_DISTRIBUTION< double > dist_
Definition: SparseMsg.h:155
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
virtual unsigned int localDataStart() const =0
Returns index of first data entry on this node.
virtual unsigned int numLocalData() const =0
Returns number of local data entries on this node.
Element * e1() const
Definition: Msg.h:61
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181
virtual void resizeField(unsigned int rawIndex, unsigned int newNumField)=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::setEntry ( unsigned int  row,
unsigned int  column,
unsigned int  value 
)

Definition at line 278 of file SparseMsg.cpp.

References matrix_, and SparseMatrix< T >::set().

Referenced by initCinfo().

280 {
281  matrix_.set( row, column, value );
282 }
uint32_t value
Definition: moosemodule.h:42
void set(unsigned int row, unsigned int column, T value)
Definition: SparseMatrix.h:161
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::setEntryPairs ( vector< unsigned int >  entries)

Definition at line 244 of file SparseMsg.cpp.

References pairFill().

Referenced by initCinfo().

245 {
246  vector< unsigned int > src( v.begin(), v.begin() + v.size()/2 );
247  vector< unsigned int > dest( v.begin() + v.size()/2, v.end() );
248  pairFill( src, dest );
249 }
void pairFill(vector< unsigned int > src, vector< unsigned int > dest)
Definition: SparseMsg.cpp:323

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::setMatrix ( const SparseMatrix< unsigned int > &  m)

Assigns the whole connection matrix

Definition at line 534 of file SparseMsg.cpp.

References matrix_.

Referenced by copy().

535 {
536  matrix_ = m;
537 }
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144

+ Here is the caller graph for this function:

void SparseMsg::setProbability ( double  value)

Definition at line 187 of file SparseMsg.cpp.

References p_, and randomConnect().

Referenced by initCinfo().

188 {
189  p_ = probability;
190  randomConnect( probability );
191 }
unsigned int randomConnect(double probability)
Definition: SparseMsg.cpp:465
double p_
Definition: SparseMsg.h:147

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::setRandomConnectivity ( double  probability,
long  seed 
)

Definition at line 271 of file SparseMsg.cpp.

References p_, randomConnect(), and rng_.

Referenced by initCinfo().

272 {
273  p_ = probability;
274  rng_.seed( seed );
275  randomConnect( probability );
276 }
unsigned int randomConnect(double probability)
Definition: SparseMsg.cpp:465
double p_
Definition: SparseMsg.h:147
moose::MOOSE_RNG_DEFAULT_ENGINE rng_
Definition: SparseMsg.h:154

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::setSeed ( unsigned long  value)

Definition at line 198 of file SparseMsg.cpp.

References p_, randomConnect(), rd_, rng_, and seed_.

Referenced by initCinfo().

199 {
200  if( seed > 0 )
201  seed_ = seed;
202  else
203  seed_ = rd_();
204 
205  rng_.seed( seed_ );
206  randomConnect( p_ );
207 }
unsigned int randomConnect(double probability)
Definition: SparseMsg.cpp:465
double p_
Definition: SparseMsg.h:147
moose::MOOSE_RNG_DEFAULT_ENGINE rng_
Definition: SparseMsg.h:154
unsigned long seed_
Definition: SparseMsg.h:152
moose::MOOSE_RANDOM_DEVICE rd_
Definition: SparseMsg.h:153

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::sources ( vector< vector< Eref > > &  v) const

Definition at line 624 of file SparseMsg.cpp.

References Msg::e1_, Msg::e2_, fillErefsFromMatrix(), matrix_, and SparseMatrix< T >::transpose().

625 {
627  temp.transpose();
628  fillErefsFromMatrix( temp, v, e2_, e1_ );
629 }
void fillErefsFromMatrix(const SparseMatrix< unsigned int > &matrix, vector< vector< Eref > > &v, Element *e1, Element *e2)
Definition: SparseMsg.cpp:603
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
Element * e1_
Index of this Msg on the msg_ vector.
Definition: Msg.h:180
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181

+ Here is the call graph for this function:

void SparseMsg::targets ( vector< vector< Eref > > &  v) const

Definition at line 631 of file SparseMsg.cpp.

References Msg::e1_, Msg::e2_, fillErefsFromMatrix(), and matrix_.

632 {
634 }
void fillErefsFromMatrix(const SparseMatrix< unsigned int > &matrix, vector< vector< Eref > > &v, Element *e1, Element *e2)
Definition: SparseMsg.cpp:603
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
Element * e1_
Index of this Msg on the msg_ vector.
Definition: Msg.h:180
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181

+ Here is the call graph for this function:

void SparseMsg::transpose ( )

Definition at line 294 of file SparseMsg.cpp.

References Msg::e1(), Msg::e2(), Element::markRewired(), matrix_, and SparseMatrix< T >::transpose().

Referenced by initCinfo().

295 {
296  matrix_.transpose();
297  e1()->markRewired();
298  e2()->markRewired();
299 }
void markRewired()
Definition: Element.cpp:706
Element * e2() const
Definition: Msg.h:68
void transpose()
Definition: SparseMatrix.h:456
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
Element * e1() const
Definition: Msg.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::tripletFill ( vector< unsigned int >  src,
vector< unsigned int >  dest,
vector< unsigned int >  field 
)

Fills up the entire message based on triplets of src,destDataIndex,destFieldIndex

Definition at line 366 of file SparseMsg.cpp.

References matrix_, SparseMatrix< T >::tripletFill(), and updateAfterFill().

Referenced by initCinfo(), and tripletFill1().

369 {
370  // We set retainSize flag to true
371  matrix_.tripletFill( src, destDataIndex, destFieldIndex, true );
372  updateAfterFill();
373 }
void tripletFill(const vector< unsigned int > &row, const vector< unsigned int > &col, const vector< T > &z, bool retainSize=false)
Definition: SparseMatrix.h:583
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
void updateAfterFill()
Definition: SparseMsg.cpp:301

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::tripletFill1 ( vector< unsigned int >  entries)

Fills up the entire message based on triplets of src,destDataIndex,destFieldIndex, but catenates them all into a single long vector since PyMoose doesn't know how to handle multiple vectors.

Definition at line 375 of file SparseMsg.cpp.

References tripletFill().

Referenced by initCinfo().

376 {
377  unsigned int s3 = v.size() / 3;
378  vector< unsigned int > src( v.begin(), v.begin() + s3 );
379  vector< unsigned int > dest( v.begin() + s3, v.begin() + 2 * s3 );
380  vector< unsigned int > fieldIndex( v.begin() + 2 * s3, v.end() );
381  tripletFill( src, dest, fieldIndex );
382 }
void tripletFill(vector< unsigned int > src, vector< unsigned int > dest, vector< unsigned int > field)
Definition: SparseMsg.cpp:366

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::unsetEntry ( unsigned int  row,
unsigned int  column 
)

Definition at line 284 of file SparseMsg.cpp.

References matrix_, and SparseMatrix< T >::unset().

Referenced by initCinfo().

285 {
286  matrix_.unset( row, column );
287 }
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
void unset(unsigned int row, unsigned int column)
Definition: SparseMatrix.h:212

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SparseMsg::updateAfterFill ( )

Utility function to update all sorts of values after we've rebuilt the matrix.

Definition at line 301 of file SparseMsg.cpp.

References Msg::e1(), Msg::e2(), Msg::e2_, SparseMatrix< T >::getRow(), Element::localDataStart(), Element::markRewired(), matrix_, SparseMatrix< T >::nRows(), Element::numLocalData(), Element::resizeField(), and SparseMatrix< T >::transpose().

Referenced by pairFill(), and tripletFill().

302 {
303  unsigned int startData = e2_->localDataStart();
304  unsigned int endData = startData + e2_->numLocalData();
306  temp.transpose();
307  for ( unsigned int i = 0; i < temp.nRows(); ++ i )
308  {
309  const unsigned int* colIndex;
310  const unsigned int* entry;
311  unsigned int num = temp.getRow( i, &entry, &colIndex );
312  if ( i >= startData && i < endData )
313  {
314  // Inefficient. Better to do it in one pass after getting
315  // the max num
316  e2_->resizeField( i - startData, num + 1 );
317  }
318  }
319  e1()->markRewired();
320  e2()->markRewired();
321 }
void markRewired()
Definition: Element.cpp:706
Element * e2() const
Definition: Msg.h:68
SparseMatrix< unsigned int > matrix_
Definition: SparseMsg.h:144
virtual unsigned int localDataStart() const =0
Returns index of first data entry on this node.
virtual unsigned int numLocalData() const =0
Returns number of local data entries on this node.
Element * e1() const
Definition: Msg.h:61
Element * e2_
Element 1 attached to Msg.
Definition: Msg.h:181
virtual void resizeField(unsigned int rawIndex, unsigned int newNumField)=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

unsigned int Msg::initMsgManagers ( )
friend

Member Data Documentation

moose::MOOSE_UNIFORM_DISTRIBUTION<double> SparseMsg::dist_
private

Definition at line 155 of file SparseMsg.h.

Referenced by randomConnect().

Id SparseMsg::managerId_
staticprivate

Definition at line 148 of file SparseMsg.h.

Referenced by Msg::initMsgManagers(), and managerId().

vector< SparseMsg * > SparseMsg::msg_
staticprivate

Definition at line 149 of file SparseMsg.h.

Referenced by lookupMsg(), numMsg(), SparseMsg(), and ~SparseMsg().

unsigned int SparseMsg::nrows_
private

Definition at line 146 of file SparseMsg.h.

Referenced by copy().

unsigned int SparseMsg::numThreads_
private

Definition at line 145 of file SparseMsg.h.

double SparseMsg::p_
private

Definition at line 147 of file SparseMsg.h.

Referenced by getProbability(), setProbability(), setRandomConnectivity(), and setSeed().

moose::MOOSE_RANDOM_DEVICE SparseMsg::rd_
private

Definition at line 153 of file SparseMsg.h.

Referenced by setSeed(), and SparseMsg().

moose::MOOSE_RNG_DEFAULT_ENGINE SparseMsg::rng_
private

Definition at line 154 of file SparseMsg.h.

Referenced by randomConnect(), setRandomConnectivity(), setSeed(), and SparseMsg().

unsigned long SparseMsg::seed_
private

Definition at line 152 of file SparseMsg.h.

Referenced by getSeed(), setSeed(), and SparseMsg().


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