MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
testAsync.cpp File Reference
#include <stdio.h>
#include <iomanip>
#include "header.h"
#include "global.h"
#include "Dinfo.h"
#include "SparseMatrix.h"
#include "../msg/OneToOneMsg.h"
#include "../msg/SparseMsg.h"
#include "../msg/SingleMsg.h"
#include "../synapse/Synapse.h"
#include "../synapse/SynEvent.h"
#include "../synapse/SynHandlerBase.h"
#include "../synapse/SimpleSynHandler.h"
#include "../shell/Shell.h"
#include "../shell/Neutral.h"
#include "../mpi/PostMaster.h"
#include "../scheduling/Clock.h"
#include "../builtins/Arith.h"
#include "../biophysics/IntFire.h"
#include "../randnum/RNG.h"
#include <queue>
+ Include dependency graph for testAsync.cpp:

Go to the source code of this file.

Classes

class  Test
 
class  TestId
 

Functions

void printGrid (Element *e, const string &field, double min, double max)
 
void printSparseMatrix (const SparseMatrix< unsigned int > &m)
 
void showFields ()
 
void test2ArgSetVec ()
 
void testAsync ()
 
void testCinfoElements ()
 
void testCinfoFields ()
 
void testConvVector ()
 
void testConvVectorOfVectors ()
 
void testCreateMsg ()
 
void testFinfoFields ()
 
void testGet ()
 
void testHopFunc ()
 
void testIsA ()
 
void testLookupSetGet ()
 
void testMsgField ()
 
void testMsgSrcDestFields ()
 
void testSendMsg ()
 
void testSendSpike ()
 
void testSetGet ()
 
void testSetGetDouble ()
 
void testSetGetExtField ()
 
void testSetGetSynapse ()
 
void testSetGetVec ()
 
void testSetRepeat ()
 
void testSharedMsg ()
 
void testSparseMatrix ()
 
void testSparseMatrix2 ()
 
void testSparseMatrixFill ()
 
void testSparseMatrixReorder ()
 
void testSparseMsg ()
 
void testStrGet ()
 
void testStrSet ()
 

Variables

int _seed_ = 0
 
static SrcFinfo0 s0 ("s0","")
 

Function Documentation

void printGrid ( Element e,
const string &  field,
double  min,
double  max 
)

Definition at line 763 of file testAsync.cpp.

References Field< A >::get(), Element::id(), and Element::numData().

764 {
765  static string icon = " .oO@";
766  unsigned int yside = sqrt( double ( e->numData() ) );
767  unsigned int xside = e->numData() / yside;
768  if ( e->numData() % yside > 0 )
769  xside++;
770 
771  for ( unsigned int i = 0; i < e->numData(); ++i ) {
772  if ( ( i % xside ) == 0 )
773  cout << endl;
774  Eref er( e, i );
775  ObjId oid( e->id(), i );
776  double Vm = Field< double >::get( oid, field );
777  int shape = 5.0 * ( Vm - min ) / ( max - min );
778  if ( shape > 4 )
779  shape = 4;
780  if ( shape < 0 )
781  shape = 0;
782  cout << icon[ shape ];
783  }
784  cout << endl;
785 }
Definition: ObjId.h:20
Id id() const
Definition: Element.cpp:71
Definition: Eref.h:26
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

void printSparseMatrix ( const SparseMatrix< unsigned int > &  m)

Definition at line 485 of file testAsync.cpp.

References SparseMatrix< T >::get(), SparseMatrix< T >::getRow(), SparseMatrix< T >::nColumns(), and SparseMatrix< T >::nRows().

486 {
487  unsigned int nRows = m.nRows();
488  unsigned int nCols = m.nColumns();
489 
490  for ( unsigned int i = 0; i < nRows; ++i ) {
491  cout << "[ ";
492  for ( unsigned int j = 0; j < nCols; ++j ) {
493  cout << m.get( i, j ) << " ";
494  }
495  cout << "]\n";
496  }
497  const unsigned int *n;
498  const unsigned int *c;
499  for ( unsigned int i = 0; i < nRows; ++i ) {
500  unsigned int num = m.getRow( i, &n, &c );
501  for ( unsigned int j = 0; j < num; ++j )
502  cout << n[j] << " ";
503  }
504  cout << endl;
505 
506  for ( unsigned int i = 0; i < nRows; ++i ) {
507  unsigned int num = m.getRow( i, &n, &c );
508  for ( unsigned int j = 0; j < num; ++j )
509  cout << c[j] << " ";
510  }
511  cout << endl;
512  cout << endl;
513 }
unsigned int nColumns() const
Definition: SparseMatrix.h:92
T get(unsigned int row, unsigned int column) const
Definition: SparseMatrix.h:253
unsigned int getRow(unsigned int row, const T **entry, const unsigned int **colIndex) const
Definition: SparseMatrix.h:288
unsigned int nRows() const
Definition: SparseMatrix.h:87

+ Here is the call graph for this function:

void showFields ( )

Definition at line 39 of file testAsync.cpp.

References Id::element(), Neutral::initCinfo(), and Id::nextId().

Referenced by testAsync().

40 {
41  const Cinfo* nc = Neutral::initCinfo();
42  Id i1 = Id::nextId();
43  Element* ret = new GlobalDataElement( i1, nc, "test1", 1 );
44  assert( ret );
45  // i1.eref().element()->showFields();
46  cout << "." << flush;
47 
48  delete i1.element();
49 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
static Id nextId()
Definition: Id.cpp:132
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void test2ArgSetVec ( )

Definition at line 878 of file testAsync.cpp.

References ObjId::data(), doubleEq(), Id::element(), Arith::initCinfo(), Id::nextId(), and SetGet2< A1, A2 >::setVec().

Referenced by testAsync().

879 {
880  const Cinfo* ac = Arith::initCinfo();
881  unsigned int size = 100;
882 
883  string arg;
884  Id i2 = Id::nextId();
885  Element* ret = new GlobalDataElement( i2, ac, "test2", size );
886  assert( ret );
887 
888  vector< double > arg1( size );
889  vector< double > arg2( size );
890  for ( unsigned int i = 0; i < size; ++i ) {
891  arg1[i] = i;
892  arg2[i] = 100 * ( 100 - i );
893  }
894 
895  SetGet2< double, double >::setVec( i2, "arg1x2", arg1, arg2 );
896 
897  for ( unsigned int i = 0; i < size; ++i ) {
898  ObjId oid( i2, i );
899  double x = i * 100 * ( 100 - i );
900  double val = reinterpret_cast< Arith* >(oid.data())->getOutput();
901  assert( doubleEq( val, x ) );
902  }
903  cout << "." << flush;
904  delete i2.element();
905 }
static bool setVec(Id destId, const string &field, const vector< A1 > &arg1, const vector< A2 > &arg2)
Definition: SetGet.h:404
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
Definition: ObjId.h:20
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testAsync ( )

Definition at line 1813 of file testAsync.cpp.

References showFields(), test2ArgSetVec(), testCinfoElements(), testCinfoFields(), testConvVector(), testConvVectorOfVectors(), testCreateMsg(), testFinfoFields(), testHopFunc(), testIsA(), testLookupSetGet(), testMsgField(), testMsgSrcDestFields(), testSendMsg(), testSetGet(), testSetGetDouble(), testSetGetSynapse(), testSetGetVec(), testSetRepeat(), testSharedMsg(), testSparseMatrix(), testSparseMatrix2(), testSparseMatrixFill(), testSparseMatrixReorder(), testSparseMsg(), testStrGet(), and testStrSet().

Referenced by nonMpiTests().

1814 {
1815  showFields();
1816 #ifdef DO_UNIT_TESTS
1817  testSendMsg();
1818  testCreateMsg();
1819  testSetGet();
1820  testSetGetDouble();
1822  testSetGetVec();
1823  test2ArgSetVec();
1824  testSetRepeat();
1825  testStrSet();
1826  testStrGet();
1827  testLookupSetGet();
1828 // testSendSpike();
1829  testSparseMatrix();
1833  testSparseMsg();
1834  testSharedMsg();
1835  testConvVector();
1837  testMsgField();
1838  // testSetGetExtField(); Unsure if we're keeping ext fields.
1839  testIsA();
1840  testFinfoFields();
1841  testCinfoFields();
1844  testHopFunc();
1845 #endif
1846 }
void testIsA()
Definition: testAsync.cpp:1444
void testStrSet()
Definition: testAsync.cpp:188
void testSparseMatrix2()
Definition: testAsync.cpp:591
void testSendMsg()
Definition: testAsync.cpp:51
void testSetRepeat()
Definition: testAsync.cpp:941
void testSparseMatrixReorder()
Definition: testAsync.cpp:665
void testFinfoFields()
Definition: testAsync.cpp:1457
void testMsgField()
Definition: testAsync.cpp:1234
void testLookupSetGet()
Definition: testAsync.cpp:1397
void testSetGetSynapse()
Definition: testAsync.cpp:344
void testSparseMatrix()
Definition: testAsync.cpp:515
void testSetGetDouble()
Definition: testAsync.cpp:310
void testSparseMsg()
Definition: testAsync.cpp:787
void testCreateMsg()
Definition: testAsync.cpp:112
void testSharedMsg()
Definition: testAsync.cpp:1042
void testConvVector()
Definition: testAsync.cpp:1132
void testSparseMatrixFill()
Definition: testAsync.cpp:727
void testCinfoFields()
Definition: testAsync.cpp:1518
void testCinfoElements()
Definition: testAsync.cpp:1582
void testSetGet()
Definition: testAsync.cpp:156
void testConvVectorOfVectors()
Definition: testAsync.cpp:1183
void testStrGet()
Definition: testAsync.cpp:267
void showFields()
Definition: testAsync.cpp:39
void test2ArgSetVec()
Definition: testAsync.cpp:878
void testHopFunc()
Definition: testAsync.cpp:1774
void testSetGetVec()
Definition: testAsync.cpp:394
void testMsgSrcDestFields()
Definition: testAsync.cpp:1627

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testCinfoElements ( )

Definition at line 1582 of file testAsync.cpp.

References Field< A >::get().

Referenced by testAsync().

1583 {
1584  Id intFireCinfoId( "/classes/IntFire" );
1585  // const Cinfo *neutralCinfo = Neutral::initCinfo();
1586  // unsigned int nvf = neutralCinfo->getNumValueFinfo();
1587  // unsigned int nsf = neutralCinfo->getNumSrcFinfo();
1588  // unsigned int ndf = neutralCinfo->getNumDestFinfo();
1589  //unsigned int sdf = SynHandler::initCinfo()->getNumDestFinfo();
1590 
1591  assert( intFireCinfoId != Id() );
1592  assert( Field< string >::get( intFireCinfoId, "name" ) == "IntFire" );
1593  assert( Field< string >::get( intFireCinfoId, "baseClass" ) ==
1594  "Neutral" );
1595  Id intFireValueFinfoId( "/classes/IntFire/valueFinfo" );
1596  unsigned int n = Field< unsigned int >::get(
1597  intFireValueFinfoId, "numData" );
1598  assert( n == 4 );
1599  Id intFireSrcFinfoId( "/classes/IntFire/srcFinfo" );
1600  assert( intFireSrcFinfoId != Id() );
1601  n = Field< unsigned int >::get( intFireSrcFinfoId, "numData" );
1602  assert( n == 1 );
1603  Id intFireDestFinfoId( "/classes/IntFire/destFinfo" );
1604  assert( intFireDestFinfoId != Id() );
1605  n = Field< unsigned int >::get( intFireDestFinfoId, "numData" );
1606  assert( n == 11 );
1607 
1608  ObjId temp( intFireSrcFinfoId, 0 );
1609  string foo = Field< string >::get( temp, "fieldName" );
1610  assert( foo == "spikeOut" );
1611 
1612  foo = Field< string >::get( temp, "type" );
1613  assert( foo == "double" );
1614 
1615  n = Field< unsigned int >::get( intFireDestFinfoId, "numField" );
1616  assert( n == 1 );
1617 
1618  temp = ObjId( intFireDestFinfoId, 7 );
1619  string str = Field< string >::get( temp, "fieldName" );
1620  assert( str == "getRefractoryPeriod");
1621  temp = ObjId( intFireDestFinfoId, 10 );
1622  str = Field< string >::get( temp, "fieldName" );
1623  assert( str == "reinit" );
1624  cout << "." << flush;
1625 }
Definition: SetGet.h:236
Definition: ObjId.h:20
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testCinfoFields ( )

Definition at line 1518 of file testAsync.cpp.

References getBaseClass(), Cinfo::getNumDestFinfo(), Cinfo::getNumLookupFinfo(), Cinfo::getNumSharedFinfo(), Cinfo::getNumSrcFinfo(), Cinfo::getNumValueFinfo(), IntFire::initCinfo(), SimpleSynHandler::initCinfo(), Neutral::initCinfo(), and neutralCinfo.

Referenced by testAsync().

1519 {
1520  assert( IntFire::initCinfo()->getDocs() == "" );
1521  assert( SimpleSynHandler::initCinfo()->getBaseClass() == "SynHandlerBase" );
1522 
1523  // We have a little bit of a hack here to cast away
1524  // constness, due to the way the FieldElementFinfos
1525  // are set up.
1526  Cinfo *neutralCinfo = const_cast< Cinfo* >( Neutral::initCinfo() );
1527  assert( neutralCinfo->getNumSrcFinfo() == 1 );
1528 
1529  Cinfo *cinfo = const_cast< Cinfo* >( IntFire::initCinfo() );
1530  unsigned int nsf = neutralCinfo->getNumSrcFinfo();
1531  assert( nsf == 1 );
1532  assert( cinfo->getNumSrcFinfo() == 1 + nsf );
1533  assert( cinfo->getSrcFinfo( 0 + nsf ) == cinfo->findFinfo( "spikeOut" ) );
1534 
1535  unsigned int ndf = neutralCinfo->getNumDestFinfo();
1536  assert( ndf == 29 );
1537  unsigned int sdf = IntFire::initCinfo()->getNumDestFinfo();
1538  assert( sdf == 40 );
1539 
1540  /*
1541  assert( cinfo->getDestFinfo( 0+ndf )->name() == "setNumSynapses" );
1542  assert( cinfo->getDestFinfo( 1+ndf )->name() == "getNumSynapses" );
1543  assert( cinfo->getDestFinfo( 2+ndf )->name() == "setNumSynapse" );
1544  assert( cinfo->getDestFinfo( 3+ndf )->name() == "getNumSynapse" );
1545  */
1546 
1547  assert( cinfo->getDestFinfo( 0+ndf ) == cinfo->findFinfo( "setVm" ) );
1548  assert( cinfo->getDestFinfo( 1+ndf ) == cinfo->findFinfo( "getVm" ) );
1549  assert( cinfo->getDestFinfo( 2+ndf ) == cinfo->findFinfo( "setTau" ) );
1550  assert( cinfo->getDestFinfo( 3+ndf ) == cinfo->findFinfo( "getTau" ) );
1551 
1552  assert( cinfo->getDestFinfo( 4+ndf ) == cinfo->findFinfo( "setThresh" ) );
1553  assert( cinfo->getDestFinfo( 5+ndf ) == cinfo->findFinfo( "getThresh" ) );
1554  assert( cinfo->getDestFinfo( 6+ndf ) == cinfo->findFinfo( "setRefractoryPeriod" ) );
1555  assert( cinfo->getDestFinfo( 7+ndf ) == cinfo->findFinfo( "getRefractoryPeriod" ) );
1556  assert( cinfo->getDestFinfo( 8+ndf ) == cinfo->findFinfo( "activation" ) );
1557  assert( cinfo->getDestFinfo( 9+ndf ) == cinfo->findFinfo( "process" ) );
1558  assert( cinfo->getDestFinfo( 10+ndf ) == cinfo->findFinfo( "reinit" ) );
1559 
1560 
1561  unsigned int nvf = neutralCinfo->getNumValueFinfo();
1562  assert( nvf == 19 );
1563  assert( cinfo->getNumValueFinfo() == 4 + nvf );
1564  assert( cinfo->getValueFinfo( 0 + nvf ) == cinfo->findFinfo( "Vm" ) );
1565  assert( cinfo->getValueFinfo( 1 + nvf ) == cinfo->findFinfo( "tau" ) );
1566  assert( cinfo->getValueFinfo( 2 + nvf ) == cinfo->findFinfo( "thresh" ) );
1567  assert( cinfo->getValueFinfo( 3 + nvf ) == cinfo->findFinfo( "refractoryPeriod" ) );
1568 
1569  unsigned int nlf = neutralCinfo->getNumLookupFinfo();
1570  assert( nlf == 4 ); // Neutral inserts a lookup field for neighbors
1571  assert( cinfo->getNumLookupFinfo() == 0 + nlf );
1572  assert( cinfo->getLookupFinfo( 0 + nlf )->name() == "dummy");
1573 
1574  unsigned int nshf = neutralCinfo->getNumSharedFinfo();
1575  assert( nshf == 0 );
1576  assert( cinfo->getNumSharedFinfo() == 1 + nshf );
1577  assert( cinfo->getSharedFinfo( 0 + nshf ) == cinfo->findFinfo( "proc" ) );
1578 
1579  cout << "." << flush;
1580 }
unsigned int getNumSrcFinfo() const
Definition: Cinfo.cpp:421
unsigned int getNumDestFinfo() const
Definition: Cinfo.cpp:444
unsigned int getNumValueFinfo() const
Definition: Cinfo.cpp:467
static const Cinfo * neutralCinfo
Definition: Neutral.cpp:270
static const Cinfo * initCinfo()
Definition: IntFire.cpp:23
unsigned int getNumSharedFinfo() const
Definition: Cinfo.cpp:514
static const Cinfo * initCinfo()
PyTypeObject * getBaseClass(PyObject *self)
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
unsigned int getNumLookupFinfo() const
Definition: Cinfo.cpp:491
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testConvVector ( )

Definition at line 1132 of file testAsync.cpp.

References Conv< T >::buf2val(), Conv< T >::size(), and Conv< T >::val2buf().

Referenced by testAsync().

1133 {
1134  vector< unsigned int > intVec;
1135  for ( unsigned int i = 0; i < 5; ++i )
1136  intVec.push_back( i * i );
1137 
1138  double buf[500];
1139  double* tempBuf = buf;
1140 
1141  Conv< vector< unsigned int > > intConv;
1142  assert( intConv.size( intVec ) == 1 + intVec.size() );
1143  intConv.val2buf( intVec, &tempBuf );
1144  assert( tempBuf == buf + 6 );
1145  assert( buf[0] == intVec.size() );
1146  assert( static_cast< unsigned int >( buf[1] ) == intVec[0] );
1147  assert( static_cast< unsigned int >( buf[2] ) == intVec[1] );
1148  assert( static_cast< unsigned int >( buf[3] ) == intVec[2] );
1149  assert( static_cast< unsigned int >( buf[4] ) == intVec[3] );
1150  assert( static_cast< unsigned int >( buf[5] ) == intVec[4] );
1151 
1152  tempBuf = buf;
1153  const vector< unsigned int >& testIntVec = intConv.buf2val( &tempBuf );
1154 
1155  assert( intVec.size() == testIntVec.size() );
1156  for ( unsigned int i = 0; i < intVec.size(); ++i ) {
1157  assert( intVec[ i ] == testIntVec[i] );
1158  }
1159 
1160  vector< string > strVec;
1161  strVec.push_back( "one" );
1162  strVec.push_back( "two" );
1163  strVec.push_back( "three and more and more and more" );
1164  strVec.push_back( "four and yet more" );
1165 
1166  tempBuf = buf;
1167  Conv< vector< string > >::val2buf( strVec, &tempBuf );
1168  unsigned int sz = Conv< vector< string > >::size( strVec );
1169  assert( sz == 1 + 2 + ( strVec[2].length() + 8) /8 + ( strVec[3].length() + 8 )/8 );
1170  assert( buf[0] == 4 );
1171  assert( strcmp( reinterpret_cast< char* >( buf + 1 ), "one" ) == 0 );
1172 
1173  tempBuf = buf;
1174  const vector< string >& tgtStr =
1175  Conv< vector< string > >::buf2val( &tempBuf );
1176  assert( tgtStr.size() == 4 );
1177  for ( unsigned int i = 0; i < 4; ++i )
1178  assert( tgtStr[i] == strVec[i] );
1179 
1180  cout << "." << flush;
1181 }
static void val2buf(const T &val, double **buf)
Definition: Conv.h:56
Definition: Conv.h:30
static unsigned int size(const T &val)
Definition: Conv.h:38
static const T & buf2val(double **buf)
Definition: Conv.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testConvVectorOfVectors ( )

Definition at line 1183 of file testAsync.cpp.

References Conv< T >::buf2val(), doubleEq(), Conv< T >::size(), and Conv< T >::val2buf().

Referenced by testAsync().

1184 {
1185  short *row0 = 0;
1186  short row1[] = { 1 };
1187  short row2[] = { 2, 3 };
1188  short row3[] = { 4, 5, 6 };
1189  short row4[] = { 7, 8, 9, 10 };
1190  short row5[] = { 11, 12, 13, 14, 15 };
1191 
1192  vector< vector < short > > vec( 6 );
1193  vec[0].insert( vec[0].end(), row0, row0 + 0 );
1194  vec[1].insert( vec[1].end(), row1, row1 + 1 );
1195  vec[2].insert( vec[2].end(), row2, row2 + 2 );
1196  vec[3].insert( vec[3].end(), row3, row3 + 3 );
1197  vec[4].insert( vec[4].end(), row4, row4 + 4 );
1198  vec[5].insert( vec[5].end(), row5, row5 + 5 );
1199 
1200  double expected[] = {
1201  6, // Number of sub-vectors
1202  0, // No entries on first sub-vec
1203  1, 1,
1204  2, 2,3,
1205  3, 4,5,6,
1206  4, 7,8,9,10,
1207  5, 11,12,13,14,15
1208  };
1209 
1210  double origBuf[500];
1211  double* buf = origBuf;
1212 
1214 
1215  assert( conv.size( vec ) == 1 + 6 + 0 + 1 + 2 + 3 + 4 + 5 ); // 21
1216  conv.val2buf( vec, &buf );
1217  assert( buf == 22 + origBuf );
1218  for ( unsigned int i = 0; i < 22; ++i )
1219  assert( doubleEq( origBuf[i], expected[i] ) );
1220 
1221  double* buf2 = origBuf;
1222  const vector< vector< short > >& rc = conv.buf2val( &buf2 );
1223 
1224  assert( rc.size() == 6 );
1225  for ( unsigned int i = 0; i < 6; ++i ) {
1226  assert( rc[i].size() == i );
1227  for ( unsigned int j = 0; j < i; ++j )
1228  assert( rc[i][j] == vec[i][j] );
1229  }
1230 
1231  cout << "." << flush;
1232 }
static void val2buf(const T &val, double **buf)
Definition: Conv.h:56
Definition: Conv.h:30
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static unsigned int size(const T &val)
Definition: Conv.h:38
static const T & buf2val(double **buf)
Definition: Conv.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testCreateMsg ( )

Definition at line 112 of file testAsync.cpp.

References Finfo::addMsg(), Element::data(), doubleEq(), Eref::element(), Id::element(), Id::eref(), Cinfo::findFinfo(), Arith::initCinfo(), Msg::mid(), Id::nextId(), and SrcFinfo1< T >::send().

Referenced by testAsync().

113 {
114  const Cinfo* ac = Arith::initCinfo();
115  unsigned int size = 100;
116  Id i1 = Id::nextId();
117  Id i2 = Id::nextId();
118  Element* temp = new GlobalDataElement( i1, ac, "test1", size );
119  // bool ret = nc->create( i1, "test1", size );
120  assert( temp );
121  temp = new GlobalDataElement( i2, ac, "test2", size );
122  assert( temp );
123 
124  Eref e1 = i1.eref();
125  Eref e2 = i2.eref();
126 
127  OneToOneMsg *m = new OneToOneMsg( e1, e2, 0 );
128  assert( m );
129  const Finfo* f1 = ac->findFinfo( "output" );
130  assert( f1 );
131  const Finfo* f2 = ac->findFinfo( "arg1" );
132  assert( f2 );
133  bool ret = f1->addMsg( f2, m->mid(), e1.element() );
134 
135  assert( ret );
136  // e1.element()->digestMessages();
137 
138  for ( unsigned int i = 0; i < size; ++i ) {
139  const SrcFinfo1< double >* sf = dynamic_cast< const SrcFinfo1< double >* >( f1 );
140  assert( sf != 0 );
141  sf->send( Eref( e1.element(), i ), double( i ) );
142  double val = reinterpret_cast< Arith* >(e2.element()->data( i ) )->getArg1();
143  assert( doubleEq( val, i ) );
144  }
145 
146  /*
147  for ( unsigned int i = 0; i < size; ++i )
148  cout << i << " " << reinterpret_cast< Neutral* >(e2.element()->data( i ))->getName() << endl;
149 
150 */
151  cout << "." << flush;
152  delete i1.element();
153  delete i2.element();
154 }
ObjId mid() const
Definition: Msg.h:106
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
Eref eref() const
Definition: Id.cpp:125
Element * element() const
Definition: Eref.h:42
void send(const Eref &er, T arg) const
Definition: SrcFinfo.h:106
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
virtual bool addMsg(const Finfo *target, ObjId mid, Element *src) const
Definition: Finfo.h:92
Definition: Eref.h:26
virtual char * data(unsigned int rawIndex, unsigned int fieldIndex=0) const =0
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
Definition: Cinfo.h:18
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testFinfoFields ( )

Definition at line 1457 of file testAsync.cpp.

References FinfoWrapper::dest(), FinfoWrapper::docs(), Cinfo::findFinfo(), FinfoWrapper::getName(), IntFire::initCinfo(), SimpleSynHandler::initCinfo(), Neutral::initCinfo(), name, processFinfo, FinfoWrapper::src(), and FinfoWrapper::type().

Referenced by testAsync().

1458 {
1459  const FinfoWrapper vmFinfo = IntFire::initCinfo()->findFinfo( "Vm" );
1460  const FinfoWrapper synFinfo = SimpleSynHandler::initCinfo()->findFinfo( "synapse" );
1461  const FinfoWrapper procFinfo = IntFire::initCinfo()->findFinfo( "proc" );
1462  const FinfoWrapper processFinfo = IntFire::initCinfo()->findFinfo( "process" );
1463  const FinfoWrapper reinitFinfo = IntFire::initCinfo()->findFinfo( "reinit" );
1464  const FinfoWrapper spikeFinfo = IntFire::initCinfo()->findFinfo( "spikeOut" );
1465  const FinfoWrapper classNameFinfo = Neutral::initCinfo()->findFinfo( "className" );
1466 
1467  assert( vmFinfo.getName() == "Vm" );
1468  assert( vmFinfo.docs() == "Membrane potential" );
1469  assert( vmFinfo.src().size() == 0 );
1470  assert( vmFinfo.dest().size() == 2 );
1471  assert( vmFinfo.dest()[0] == "setVm" );
1472  assert( vmFinfo.dest()[1] == "getVm" );
1473  assert( vmFinfo.type() == "double" );
1474 
1475  assert( synFinfo.getName() == "synapse" );
1476  assert( synFinfo.docs() == "Sets up field Elements for synapse" );
1477  assert( synFinfo.src().size() == 0 );
1478  assert( synFinfo.dest().size() == 0 );
1479  // cout << synFinfo->type() << endl;
1480  assert( synFinfo.type() == typeid(Synapse).name() );
1481 
1482  assert( procFinfo.getName() == "proc" );
1483  assert( procFinfo.docs() == "Shared message for process and reinit" );
1484  assert( procFinfo.src().size() == 0 );
1485  assert( procFinfo.dest().size() == 2 );
1486  assert( procFinfo.dest()[0] == "process" );
1487  assert( procFinfo.dest()[1] == "reinit" );
1488  // cout << "proc " << procFinfo.type() << endl;
1489  assert( procFinfo.type() == "void" );
1490 
1491  assert( processFinfo.getName() == "process" );
1492  assert( processFinfo.docs() == "Handles process call" );
1493  assert( processFinfo.src().size() == 0 );
1494  assert( processFinfo.dest().size() == 0 );
1495  // cout << "process " << processFinfo.type() << endl;
1496  assert( processFinfo.type() == "const ProcInfo*" );
1497 
1498  assert( reinitFinfo.getName() == "reinit" );
1499  assert( reinitFinfo.docs() == "Handles reinit call" );
1500  assert( reinitFinfo.src().size() == 0 );
1501  assert( reinitFinfo.dest().size() == 0 );
1502  // cout << "reinit " << reinitFinfo.type() << endl;
1503  assert( reinitFinfo.type() == "const ProcInfo*" );
1504 
1505  assert( spikeFinfo.getName() == "spikeOut" );
1506  assert( spikeFinfo.docs() == "Sends out spike events. The argument is the timestamp of the spike. " );
1507  assert( spikeFinfo.src().size() == 0 );
1508  assert( spikeFinfo.dest().size() == 0 );
1509  // cout << spikeFinfo->type() << endl;
1510  assert( spikeFinfo.type() == "double" );
1511 
1512  assert( classNameFinfo.getName() == "className" );
1513  assert( classNameFinfo.type() == "string" );
1514 
1515  cout << "." << flush;
1516 }
string getName() const
Definition: Finfo.cpp:92
static DestFinfo processFinfo("process","handles process call", new EpFunc1< TestSched, ProcPtr >(&TestSched::process))
vector< string > dest() const
Definition: Finfo.cpp:113
static const Cinfo * initCinfo()
Definition: IntFire.cpp:23
vector< string > src() const
Definition: Finfo.cpp:108
string docs() const
Definition: Finfo.cpp:97
static char name[]
Definition: mfield.cpp:401
string type() const
Definition: Finfo.cpp:103
static const Cinfo * initCinfo()
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testGet ( )

Definition at line 230 of file testAsync.cpp.

References Element::data(), doubleEq(), ObjId::element(), Id::element(), Field< A >::get(), Arith::initCinfo(), Id::nextId(), and Element::setName().

231 {
232  const Cinfo* ac = Arith::initCinfo();
233  unsigned int size = 100;
234  string arg;
235  Id i2 = Id::nextId();
236 
237  Element* ret = new GlobalDataElement( i2, ac, "test2", size );
238  assert( ret );
239  ProcInfo p;
240 
241  ObjId oid( i2, 0 );
242 
243  string val = Field< string >::get( oid, "name" );
244  assert( val == "test2" );
245  ret->setName( "HupTwoThree" );
246  val = Field< string >::get( oid, "name" );
247  assert( val == "HupTwoThree" );
248 
249  for ( unsigned int i = 0; i < size; ++i ) {
250  double temp = i * 3;
251  reinterpret_cast< Arith* >(oid.element()->data( i ))->setOutput( temp );
252  }
253 
254  for ( unsigned int i = 0; i < size; ++i ) {
255  // Eref dest( e2.element(), i );
256  ObjId dest( i2, i );
257 
258  double val = Field< double >::get( dest, "outputValue" );
259  double temp = i * 3;
260  assert( doubleEq( val, temp ) );
261  }
262 
263  cout << "." << flush;
264  delete i2.element();
265 }
void setName(const string &val)
Definition: Element.cpp:61
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
Definition: ObjId.h:20
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Cinfo.h:18

+ Here is the call graph for this function:

void testHopFunc ( )

Definition at line 1774 of file testAsync.cpp.

References TgtInfo::bindIndex(), checkHopFuncTestBuffer(), TgtInfo::dataSize(), doubleEq(), TgtInfo::headerSize, MooseTestHop, HopFunc2< A1, A2 >::op(), and HopFunc3< A1, A2, A3 >::op().

Referenced by testAsync().

1775 {
1776  extern const double* checkHopFuncTestBuffer();
1777 
1778  HopIndex hop2( 1234, MooseTestHop );
1779  HopFunc2< string, double > two( hop2 );
1780 
1781  two.op( Id(3).eref(), "two", 2468.0 );
1782  const double* buf = checkHopFuncTestBuffer();
1783  const TgtInfo* tgt = reinterpret_cast< const TgtInfo* >( buf );
1784  assert( tgt->bindIndex() == 1234 );
1785  assert( tgt->dataSize() == 2 );
1786  const char* c = reinterpret_cast< const char* >(
1787  buf + TgtInfo::headerSize );
1788  assert( strcmp( c, "two" ) == 0 );
1789  assert( doubleEq( buf[TgtInfo::headerSize + 1], 2468.0 ) );
1790 
1791  HopIndex hop3( 36912, MooseTestHop );
1793  vector< double > temp( 3 );
1794  temp[0] = 11222;
1795  temp[1] = 24332;
1796  temp[2] = 234232342;
1797  three.op( Id(3).eref(), "three", 3333, temp );
1798 
1799  assert( tgt->bindIndex() == 36912 );
1800  assert( tgt->dataSize() == 6 );
1801  c = reinterpret_cast< const char* >( buf + TgtInfo::headerSize );
1802  assert( strcmp( c, "three" ) == 0 );
1803  int i = TgtInfo::headerSize + 1;
1804  assert( doubleEq( buf[i++], 3333.0 ) );
1805  assert( doubleEq( buf[i++], 3.0 ) ); // Size of array.
1806  assert( doubleEq( buf[i++], temp[0] ) );
1807  assert( doubleEq( buf[i++], temp[1] ) );
1808  assert( doubleEq( buf[i++], temp[2] ) );
1809 
1810  cout << "." << flush;
1811 }
unsigned int bindIndex() const
Definition: PostMaster.h:93
unsigned int dataSize() const
Definition: PostMaster.h:89
static const unsigned int headerSize
Definition: PostMaster.h:97
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
const double * checkHopFuncTestBuffer()
Definition: HopFunc.cpp:23
Definition: Id.h:17
const unsigned char MooseTestHop
Definition: OpFuncBase.cpp:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testIsA ( )

Definition at line 1444 of file testAsync.cpp.

References Arith::initCinfo(), Neutral::initCinfo(), and Cinfo::isA().

Referenced by testAsync().

1445 {
1446  const Cinfo* n = Neutral::initCinfo();
1447  const Cinfo* a = Arith::initCinfo();
1448  assert( a->isA( "Arith" ) );
1449  assert( a->isA( "Neutral" ) );
1450  assert( !a->isA( "Fish" ) );
1451  assert( !a->isA( "Synapse" ) );
1452  assert( !n->isA( "Arith" ) );
1453  assert( n->isA( "Neutral" ) );
1454  cout << "." << flush;
1455 }
bool isA(const string &ancestor) const
Definition: Cinfo.cpp:280
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testLookupSetGet ( )

Definition at line 1397 of file testAsync.cpp.

References ObjId::data(), Id::destroy(), doubleEq(), LookupField< L, A >::get(), Arith::getArg1(), Arith::getIdentifiedArg(), Arith::getOutput(), Arith::initCinfo(), Id::nextId(), LookupField< L, A >::set(), and Arith::setIdentifiedArg().

Referenced by testAsync().

1398 {
1399  const Cinfo* ac = Arith::initCinfo();
1400  unsigned int size = 100;
1401  string arg;
1402  Id i2 = Id::nextId();
1403 
1404  Element* elm = new GlobalDataElement( i2, ac, "test2", size );
1405  assert( elm );
1406  ObjId obj( i2, 0 );
1407 
1408  Arith* arith = reinterpret_cast< Arith* >(obj.data() );
1409  for ( unsigned int i = 0; i < 4; ++i )
1410  arith->setIdentifiedArg( i, 0 );
1411  for ( unsigned int i = 0; i < 4; ++i )
1412  assert( doubleEq( 0, arith->getIdentifiedArg( i ) ) );
1413 
1414  LookupField< unsigned int, double >::set( obj, "anyValue", 0, 100 );
1415  LookupField< unsigned int, double >::set( obj, "anyValue", 1, 101 );
1416  LookupField< unsigned int, double >::set( obj, "anyValue", 2, 102 );
1417  LookupField< unsigned int, double >::set( obj, "anyValue", 3, 103 );
1418 
1419  assert( doubleEq( arith->getOutput(), 100 ) );
1420  assert( doubleEq( arith->getArg1(), 101 ) );
1421  assert( doubleEq( arith->getIdentifiedArg( 2 ), 102 ) );
1422  assert( doubleEq( arith->getIdentifiedArg( 3 ), 103 ) );
1423 
1424  for ( unsigned int i = 0; i < 4; ++i )
1425  arith->setIdentifiedArg( i, 17 * i + 3 );
1426 
1428  obj, "anyValue", 0 );
1429  assert( doubleEq( ret, 3 ) );
1430 
1431  ret = LookupField< unsigned int, double >::get( obj, "anyValue", 1 );
1432  assert( doubleEq( ret, 20 ) );
1433 
1434  ret = LookupField< unsigned int, double >::get( obj, "anyValue", 2 );
1435  assert( doubleEq( ret, 37 ) );
1436 
1437  ret = LookupField< unsigned int, double >::get( obj, "anyValue", 3 );
1438  assert( doubleEq( ret, 54 ) );
1439 
1440  cout << "." << flush;
1441  i2.destroy();
1442 }
double getIdentifiedArg(unsigned int i) const
Definition: Arith.cpp:195
static bool set(const ObjId &dest, const string &field, L index, A arg)
Definition: SetGet.h:467
static A get(const ObjId &dest, const string &field, L index)
Definition: SetGet.h:532
Definition: Arith.h:12
Definition: ObjId.h:20
void destroy() const
Definition: Id.cpp:176
double getOutput() const
Definition: Arith.cpp:185
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
void setIdentifiedArg(unsigned int i, double val)
Definition: Arith.cpp:208
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
double getArg1() const
Definition: Arith.cpp:190
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testMsgField ( )

Definition at line 1234 of file testAsync.cpp.

References Element::addMsgAndFunc(), ObjId::data(), doubleEq(), Eref::element(), ObjId::element(), Id::element(), Id::eref(), Cinfo::findFinfo(), DestFinfo::getFid(), Element::getName(), Arith::initCinfo(), Msg::mid(), and Id::nextId().

Referenced by testAsync().

1235 {
1236  const Cinfo* ac = Arith::initCinfo();
1237  unsigned int size = 10;
1238 
1239  const DestFinfo* df = dynamic_cast< const DestFinfo* >(
1240  ac->findFinfo( "setOutputValue" ) );
1241  assert( df != 0 );
1242  FuncId fid = df->getFid();
1243 
1244  Id i1 = Id::nextId();
1245  Id i2 = Id::nextId();
1246  Element* ret = new GlobalDataElement( i1, ac, "test1", size );
1247  assert( ret );
1248  ret = new GlobalDataElement( i2, ac, "test2", size );
1249  assert( ret );
1250 
1251  Eref e1 = i1.eref();
1252 
1253  Msg* m = new SingleMsg( Eref( i1.element(), 5 ), Eref( i2.element(), 3 ), 0 );
1254  ProcInfo p;
1255 
1256  assert( m->mid().element()->getName() == "singleMsg" );
1257 
1258  SingleMsg* sm = reinterpret_cast< SingleMsg* >( m->mid().data() );
1259  assert( sm );
1260  assert ( sm == m );
1261  assert( sm->getI1() == 5 );
1262  assert( sm->getI2() == 3 );
1263 
1264  SrcFinfo1<double> s( "test", "" );
1265  s.setBindIndex( 0 );
1266  e1.element()->addMsgAndFunc( m->mid(), fid, s.getBindIndex() );
1267 
1268  for ( unsigned int i = 0; i < size; ++i ) {
1269  double x = i * 42;
1270  s.send( Eref( e1.element(), i ), x );
1271  }
1272 
1273  // Check that regular msgs go through.
1274  Eref tgt3( i2.element(), 3 );
1275  Eref tgt8( i2.element(), 8 );
1276  double val = reinterpret_cast< Arith* >( tgt3.data() )->getOutput();
1277  assert( doubleEq( val, 5 * 42 ) );
1278  val = reinterpret_cast< Arith* >( tgt8.data() )->getOutput();
1279  assert( doubleEq( val, 0 ) );
1280 
1281  // Now change I1 and I2, rerun, and check.
1282  sm->setI1( 9 );
1283  sm->setI2( 8 );
1284  for ( unsigned int i = 0; i < size; ++i ) {
1285  double x = i * 1000;
1286  s.send( Eref( e1.element(), i ), x );
1287  }
1288  val = reinterpret_cast< Arith* >( tgt3.data() )->getOutput();
1289  assert( doubleEq( val, 5 * 42 ) );
1290  val = reinterpret_cast< Arith* >( tgt8.data() )->getOutput();
1291  assert( doubleEq( val, 9000 ) );
1292 
1293  cout << "." << flush;
1294 
1295  delete i1.element();
1296  delete i2.element();
1297 }
ObjId mid() const
Definition: Msg.h:106
char * data() const
Definition: ObjId.cpp:113
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Definition: Element.cpp:128
Eref eref() const
Definition: Id.cpp:125
Element * element() const
Definition: Eref.h:42
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
FuncId getFid() const
Definition: DestFinfo.cpp:45
Definition: Eref.h:26
Definition: Msg.h:18
Element * element() const
Definition: ObjId.cpp:124
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
unsigned int FuncId
Definition: header.h:42
const string & getName() const
Definition: Element.cpp:56
Definition: Cinfo.h:18
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testMsgSrcDestFields ( )

Definition at line 1627 of file testAsync.cpp.

References Id::destroy(), Id::element(), Id::eref(), Cinfo::findFinfo(), Msg::getDestFieldsOnE1(), Msg::getDestFieldsOnE2(), Element::getFieldsOfOutgoingMsg(), Element::getMsgSourceAndSender(), Element::getMsgTargetAndFunctions(), Msg::getSrcFieldsOnE1(), Msg::getSrcFieldsOnE2(), Test::initCinfo(), Msg::mid(), name, and Id::nextId().

Referenced by testAsync().

1628 {
1630  // Setup
1632  /* This is initialized in testSharedMsg()
1633  static SrcFinfo1< string > s1( "s1", "" );
1634  static SrcFinfo2< int, int > s2( "s2", "" );
1635  static DestFinfo d0( "d0", "",
1636  new OpFunc0< Test >( & Test::handleS0 ) );
1637  static DestFinfo d1( "d1", "",
1638  new EpFunc1< Test, string >( &Test::handleS1 ) );
1639  static DestFinfo d2( "d2", "",
1640  new EpFunc2< Test, int, int >( &Test::handleS2 ) );
1641 
1642  Test::sharedVec[0] = &s0;
1643  Test::sharedVec[1] = &d0;
1644  Test::sharedVec[2] = &s1;
1645  Test::sharedVec[3] = &d1;
1646  Test::sharedVec[4] = &s2;
1647  Test::sharedVec[5] = &d2;
1648  */
1649 
1650  Id t1 = Id::nextId();
1651  Id t2 = Id::nextId();
1652  // bool ret = Test::initCinfo()->create( t1, "test1", 1 );
1653  Element* e1 = new GlobalDataElement( t1, Test::initCinfo(), "test1" );
1654  assert( e1 );
1655  assert( e1 == t1.element() );
1656  Element* e2 = new GlobalDataElement( t2, Test::initCinfo(), "test2", 1 );
1657  // ret = Test::initCinfo()->create( t2, "test2", 1 );
1658  assert( e2 );
1659  assert( e2 == t2.element() );
1660 
1661  // Set up message. The actual routine is in Shell.cpp, but here we
1662  // do it independently.
1663  const Finfo* shareFinfo = Test::initCinfo()->findFinfo( "shared" );
1664  assert( shareFinfo != 0 );
1665  Msg* m = new OneToOneMsg( t1.eref(), t2.eref(), 0 );
1666  assert( m != 0 );
1667  bool ret = shareFinfo->addMsg( shareFinfo, m->mid(), t1.element() );
1668  assert( ret );
1669 
1671  // Test Element::getFieldsOfOutgoingMsg
1673  vector< pair< BindIndex, FuncId > > pairs;
1674  e1->getFieldsOfOutgoingMsg( m->mid(), pairs );
1675  assert( pairs.size() == 3 );
1676  assert( pairs[0].first == dynamic_cast< SrcFinfo* >(Test::sharedVec[0])->getBindIndex() );
1677  assert( pairs[0].second == dynamic_cast< DestFinfo* >(Test::sharedVec[1])->getFid() );
1678 
1679  assert( pairs[1].first == dynamic_cast< SrcFinfo* >(Test::sharedVec[2])->getBindIndex() );
1680  assert( pairs[1].second == dynamic_cast< DestFinfo* >(Test::sharedVec[3])->getFid() );
1681 
1682  assert( pairs[2].first == dynamic_cast< SrcFinfo* >(Test::sharedVec[4])->getBindIndex() );
1683  assert( pairs[2].second == dynamic_cast< DestFinfo* >(Test::sharedVec[5])->getFid() );
1684 
1685  e2->getFieldsOfOutgoingMsg( m->mid(), pairs );
1686  assert( pairs.size() == 3 );
1687 
1689  // Test Cinfo::srcFinfoName
1691  assert( Test::initCinfo()->srcFinfoName( pairs[0].first ) == "s0" );
1692  assert( Test::initCinfo()->srcFinfoName( pairs[1].first ) == "s1" );
1693  assert( Test::initCinfo()->srcFinfoName( pairs[2].first ) == "s2" );
1694 
1696  // Test Cinfo::destFinfoName
1698  assert( Test::initCinfo()->destFinfoName( pairs[0].second ) == "d0" );
1699  assert( Test::initCinfo()->destFinfoName( pairs[1].second ) == "d1" );
1700  assert( Test::initCinfo()->destFinfoName( pairs[2].second ) == "d2" );
1702  // Test Msg::getSrcFieldsOnE1 and family
1704  vector< string > fieldNames;
1705  fieldNames = m->getSrcFieldsOnE1();
1706  assert( fieldNames.size() == 3 );
1707  assert( fieldNames[0] == "s0" );
1708  assert( fieldNames[1] == "s1" );
1709  assert( fieldNames[2] == "s2" );
1710 
1711  fieldNames = m->getDestFieldsOnE2();
1712  assert( fieldNames.size() == 3 );
1713  assert( fieldNames[0] == "d0" );
1714  assert( fieldNames[1] == "d1" );
1715  assert( fieldNames[2] == "d2" );
1716 
1717  fieldNames = m->getSrcFieldsOnE2();
1718  assert( fieldNames.size() == 3 );
1719  assert( fieldNames[0] == "s0" );
1720  assert( fieldNames[1] == "s1" );
1721  assert( fieldNames[2] == "s2" );
1722 
1723  fieldNames = m->getDestFieldsOnE1();
1724  assert( fieldNames.size() == 3 );
1725  assert( fieldNames[0] == "d0" );
1726  assert( fieldNames[1] == "d1" );
1727  assert( fieldNames[2] == "d2" );
1728 
1730  // getMsgTargetAndFunctions
1732  vector< ObjId > tgt;
1733  vector< string > func;
1734  unsigned int numTgt = e1->getMsgTargetAndFunctions( 0,
1735  dynamic_cast< SrcFinfo* >(Test::sharedVec[0] ),
1736  tgt, func );
1737  assert( numTgt == tgt.size() );
1738  assert( tgt.size() == 1 );
1739  assert( tgt[0] == ObjId( t2, 0 ) );
1740  assert( func[0] == "d0" );
1741 
1742  // Note that the srcFinfo #2 is in sharedVec[4]
1743  numTgt = e2->getMsgTargetAndFunctions( 0,
1744  dynamic_cast< SrcFinfo* >(Test::sharedVec[4] ),
1745  tgt, func );
1746  assert( numTgt == tgt.size() );
1747  assert( tgt.size() == 1 );
1748  assert( tgt[0] == ObjId( t1, 0 ) );
1749  assert( func[0] == "d2" );
1750 
1752  // getMsgSourceAndSender
1754  vector< ObjId > source;
1755  vector< string > sender;
1756  FuncId fid =
1757  static_cast< const DestFinfo* >( Test::sharedVec[5] )->getFid();
1758  unsigned int numSrc = t2.element()->getMsgSourceAndSender(
1759  fid, source, sender );
1760  assert( numSrc == 1 );
1761  assert( source.size() == 1 );
1762  assert( source[0] == tgt[0] );
1763  assert( sender[0] == Test::sharedVec[4]->name() );
1764  cout << "." << flush;
1765 
1767  // Clean up.
1769  t1.destroy();
1770  t2.destroy();
1771  cout << "." << flush;
1772 }
static const Cinfo * initCinfo()
Definition: testAsync.cpp:1014
ObjId mid() const
Definition: Msg.h:106
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
static Finfo * sharedVec[6]
Definition: testAsync.cpp:1012
vector< string > getDestFieldsOnE2() const
Definition: Msg.cpp:99
unsigned int getMsgTargetAndFunctions(DataId srcDataId, const SrcFinfo *finfo, vector< ObjId > &tgt, vector< string > &func) const
Definition: Element.cpp:772
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
unsigned int getMsgSourceAndSender(FuncId fid, vector< ObjId > &src, vector< string > &sender) const
Definition: Element.cpp:828
void destroy() const
Definition: Id.cpp:176
unsigned int getFieldsOfOutgoingMsg(ObjId mid, vector< pair< BindIndex, FuncId > > &ret) const
Definition: Element.cpp:1009
static Id nextId()
Definition: Id.cpp:132
Definition: Msg.h:18
static char name[]
Definition: mfield.cpp:401
vector< string > getSrcFieldsOnE1() const
Definition: Msg.cpp:80
vector< string > getSrcFieldsOnE2() const
Definition: Msg.cpp:118
Definition: Id.h:17
vector< string > getDestFieldsOnE1() const
Definition: Msg.cpp:137
unsigned int FuncId
Definition: header.h:42
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSendMsg ( )

Definition at line 51 of file testAsync.cpp.

References Element::addMsgAndFunc(), Element::data(), Eref::dataIndex(), dataIndex, doubleEq(), Eref::element(), Id::element(), Id::eref(), Cinfo::findFinfo(), SrcFinfo::getBindIndex(), DestFinfo::getFid(), Arith::initCinfo(), Msg::mid(), Element::msgDigest(), Id::nextId(), SrcFinfo1< T >::send(), SrcFinfo::setBindIndex(), and Msg::targets().

Referenced by testAsync().

52 {
53  const Cinfo* ac = Arith::initCinfo();
54  unsigned int size = 100;
55 
56  const DestFinfo* df = dynamic_cast< const DestFinfo* >(
57  ac->findFinfo( "setOutputValue" ) );
58  assert( df != 0 );
59  FuncId fid = df->getFid();
60 
61  Id i1 = Id::nextId();
62  Id i2 = Id::nextId();
63  Element* ret = new GlobalDataElement( i1, ac, "test1", size );
64  // bool ret = nc->create( i1, "test1", size );
65  assert( ret );
66  // ret = nc->create( i2, "test2", size );
67  ret = new GlobalDataElement( i2, ac, "test2", size );
68  assert( ret );
69 
70  Eref e1 = i1.eref();
71  Eref e2 = i2.eref();
72 
73  Msg* m = new OneToOneMsg( e1, e2, 0 );
74  vector< vector< Eref > > ver;
75  m->targets( ver );
76  assert( ver.size() == size );
77  assert( ver[0].size() == 1 );
78  assert( ver[0][0].element() == e2.element() );
79  assert( ver[0][0].dataIndex() == e2.dataIndex() );
80  assert( ver[55].size() == 1 );
81  assert( ver[55][0].element() == e2.element() );
82  assert( ver[55][0].dataIndex() == 55 );
83 
84  SrcFinfo1<double> s( "test", "" );
85  s.setBindIndex( 0 );
86  e1.element()->addMsgAndFunc( m->mid(), fid, s.getBindIndex() );
87  // e1.element()->digestMessages();
88  const vector< MsgDigest >& md = e1.element()->msgDigest( 0 );
89  assert( md.size() == 1 );
90  assert( md[0].targets.size() == 1 );
91  assert( md[0].targets[0].element() == e2.element() );
92  assert( md[0].targets[0].dataIndex() == e2.dataIndex() );
93 
94  for ( unsigned int i = 0; i < size; ++i ) {
95  double x = i + i * i;
96  s.send( Eref( e1.element(), i ), x );
97  }
98 
99  for ( unsigned int i = 0; i < size; ++i ) {
100  double temp = i + i * i;
101  double val = reinterpret_cast< Arith* >(e2.element()->data( i ) )->getOutput();
102  assert( doubleEq( val, temp ) );
103  }
104  cout << "." << flush;
105 
106  delete i1.element();
107  delete i2.element();
108 }
ObjId mid() const
Definition: Msg.h:106
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
unsigned int dataIndex() const
Definition: Eref.h:50
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Definition: Element.cpp:128
Eref eref() const
Definition: Id.cpp:125
Element * element() const
Definition: Eref.h:42
virtual void targets(vector< vector< Eref > > &v) const =0
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
const vector< MsgDigest > & msgDigest(unsigned int index)
Definition: Element.cpp:289
static char dataIndex[]
Definition: mfield.cpp:406
FuncId getFid() const
Definition: DestFinfo.cpp:45
Definition: Eref.h:26
Definition: Msg.h:18
virtual char * data(unsigned int rawIndex, unsigned int fieldIndex=0) const =0
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
unsigned int FuncId
Definition: header.h:42
Definition: Cinfo.h:18
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSendSpike ( )

Definition at line 431 of file testAsync.cpp.

References Finfo::addMsg(), Eref::data(), ObjId::data(), doubleEq(), ProcInfo::dt, ObjId::element(), Id::element(), ObjId::eref(), Id::eref(), Cinfo::findFinfo(), Field< A >::get(), Synapse::initCinfo(), IntFire::initCinfo(), Msg::mid(), Id::nextId(), Field< A >::set(), and Id::value().

432 {
433  static const double WEIGHT = -1.0;
434  static const double TAU = 1.0;
435  static const double DT = 0.1;
436  const Cinfo* ic = IntFire::initCinfo();
437  const Cinfo* sc = Synapse::initCinfo();
438  unsigned int size = 100;
439 
440  string arg;
441  Id i2 = Id::nextId();
442  Element* temp = new GlobalDataElement( i2, ic, "test2", size );
443  assert( temp );
444  Id i3 = Id::nextId();
445  Element* temp2 = new GlobalDataElement( i3, sc, "syns", size );
446  assert( temp2 );
447  Eref e2 = i2.eref();
448  for ( unsigned int i = 0; i < size; ++i ) {
449  ObjId oid( i3, i );
450  bool ret = Field< unsigned int >::set( oid, "numSynapses", i );
451  assert( ret );
452  }
453 
454  Id synId( i3.value() + 1 );
455  ObjId target( synId , 1 );
456 
457  reinterpret_cast< Synapse* >(target.data())->setWeight( WEIGHT );
458  reinterpret_cast< Synapse* >(target.data())->setDelay( 0.01 );
459  SingleMsg *m = new SingleMsg( e2, target.eref(), 0 );
460  const Finfo* f1 = ic->findFinfo( "spikeOut" );
461  const Finfo* f2 = sc->findFinfo( "addSpike" );
462  bool ret = f1->addMsg( f2, m->mid(), synId.element() );
463  assert( ret );
464 
465  reinterpret_cast< IntFire* >(e2.data())->setVm( 1.0 );
466  // ret = SetGet1< double >::set( e2, "Vm", 1.0 );
467  ProcInfo p;
468  p.dt = DT;
469  reinterpret_cast< IntFire* >(e2.data())->process( e2, &p );
470  // At this stage we have sent the spike, so e2.data::Vm should be -1e-7.
471  double Vm = reinterpret_cast< IntFire* >(e2.data())->getVm();
472  assert( doubleEq( Vm, -1e-7 ) );
473  ObjId targetCell( i2, 1 );
474  reinterpret_cast< IntFire* >(targetCell.data())->setTau( TAU );
475 
476  reinterpret_cast< IntFire* >(targetCell.data())->process( targetCell.eref(), &p );
477  Vm = Field< double >::get( targetCell, "Vm" );
478  assert( doubleEq( Vm , WEIGHT * ( 1.0 - DT / TAU ) ) );
479  delete i2.element();
480  delete i3.element();
481  delete synId.element();
482  cout << "." << flush;
483 }
ObjId mid() const
Definition: Msg.h:106
char * data() const
Definition: Eref.cpp:41
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
unsigned int value() const
Definition: Id.cpp:197
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
static const Cinfo * initCinfo()
Definition: IntFire.cpp:23
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static const Cinfo * initCinfo()
Definition: Synapse.cpp:15
static Id nextId()
Definition: Id.cpp:132
virtual bool addMsg(const Finfo *target, ObjId mid, Element *src) const
Definition: Finfo.h:92
double dt
Definition: ProcInfo.h:18
Definition: Eref.h:26
Element * element() const
Definition: ObjId.cpp:124
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Cinfo.h:18
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12

+ Here is the call graph for this function:

void testSetGet ( )

Definition at line 156 of file testAsync.cpp.

References ObjId::data(), doubleEq(), Id::element(), Field< A >::get(), Arith::initCinfo(), Id::nextId(), and Field< A >::set().

Referenced by testAsync().

157 {
158  const Cinfo* ac = Arith::initCinfo();
159  unsigned int size = 100;
160 
161  string arg;
162  Id i2 = Id::nextId();
163  Element* ret = new GlobalDataElement( i2, ac, "test2", size );
164  assert( ret );
165  ProcInfo p;
166 
167  for ( unsigned int i = 0; i < size; ++i ) {
168  ObjId oid( i2, i );
169  double x = i * 3.14;
170  bool ret = Field< double >::set( oid, "outputValue", x );
171  assert( ret );
172  double val = reinterpret_cast< Arith* >(oid.data())->getOutput();
173  assert( doubleEq( val, x ) );
174  }
175 
176  for ( unsigned int i = 0; i < size; ++i ) {
177  ObjId oid( i2, i );
178  double x = i * 3.14;
179  double ret = Field< double >::get( oid, "outputValue" );
180  ProcInfo p;
181  assert( doubleEq( ret, x ) );
182  }
183 
184  cout << "." << flush;
185  delete i2.element();
186 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
Definition: ObjId.h:20
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSetGetDouble ( )

Definition at line 310 of file testAsync.cpp.

References ObjId::data(), doubleEq(), Id::element(), Field< A >::get(), IntFire::initCinfo(), Id::nextId(), and Field< A >::set().

Referenced by testAsync().

311 {
312  const Cinfo* ic = IntFire::initCinfo();
313  unsigned int size = 100;
314 
315  string arg;
316  Id i2 = Id::nextId();
317  // Id i3( i2.value() + 1 );
318  Element* ret = new GlobalDataElement( i2, ic, "test2", size );
319  assert( ret );
320  ProcInfo p;
321 
322  for ( unsigned int i = 0; i < size; ++i ) {
323  // Eref e2( i2(), i );
324  ObjId oid( i2, i );
325  double temp = i;
326  bool ret = Field< double >::set( oid, "Vm", temp );
327  assert( ret );
328  assert(
329  doubleEq ( reinterpret_cast< IntFire* >(oid.data())->getVm() , temp ) );
330  }
331 
332  for ( unsigned int i = 0; i < size; ++i ) {
333  ObjId oid( i2, i );
334  double temp = i;
335  double ret = Field< double >::get( oid, "Vm" );
336  assert( doubleEq( temp, ret ) );
337  }
338 
339  cout << "." << flush;
340  delete i2.element();
341  // delete i3.element();
342 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: ObjId.h:20
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
static const Cinfo * initCinfo()
Definition: IntFire.cpp:23
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSetGetExtField ( )

Definition at line 1299 of file testAsync.cpp.

References Shell::adopt(), ObjId::data(), Id::destroy(), doubleEq(), Field< A >::get(), Arith::initCinfo(), Neutral::initCinfo(), Id::nextId(), Field< A >::set(), Field< A >::setVec(), and Id::value().

1300 {
1301  const Cinfo* nc = Neutral::initCinfo();
1302  const Cinfo* rc = Arith::initCinfo();
1303  unsigned int size = 100;
1304 
1305  string arg;
1306  Id i1 = Id::nextId();
1307  Id i2( i1.value() + 1 );
1308  Id i3( i2.value() + 1 );
1309  Id i4( i3.value() + 1 );
1310  Element* e1 = new GlobalDataElement( i1, nc, "test", size );
1311  assert( e1 );
1312  Shell::adopt( Id(), i1, 0 );
1313  Element* e2 = new GlobalDataElement( i2, rc, "x", size );
1314  assert( e2 );
1315  Shell::adopt( i1, i2, 0 );
1316  Element* e3 = new GlobalDataElement( i3, rc, "y", size );
1317  assert( e3 );
1318  Shell::adopt( i1, i3, 0 );
1319  Element* e4 = new GlobalDataElement( i4, rc, "z", size );
1320  assert( e4 );
1321  Shell::adopt( i1, i4, 0 );
1322  bool ret;
1323 
1324  vector< double > vec;
1325  for ( unsigned int i = 0; i < size; ++i ) {
1326  ObjId a( i1, i );
1327  ObjId b( i1, size - i - 1);
1328  // Eref a( e1, i );
1329  // Eref b( e1, size - i - 1 );
1330  double temp = i;
1331  ret = Field< double >::set( a, "x", temp );
1332  assert( ret );
1333  double temp2 = temp * temp;
1334  ret = Field< double >::set( b, "y", temp2 );
1335  assert( ret );
1336  vec.push_back( temp2 - temp );
1337  }
1338 
1339  ret = Field< double >::setVec( i1, "z", vec );
1340  assert( ret );
1341 
1342  for ( unsigned int i = 0; i < size; ++i ) {
1343  /*
1344  Eref a( e2, i );
1345  Eref b( e3, size - i - 1 );
1346  Eref c( e4, i );
1347  */
1348  ObjId a( i2, i );
1349  ObjId b( i3, size - i - 1 );
1350  ObjId c( i4, i );
1351  double temp = i;
1352  double temp2 = temp * temp;
1353 
1354  double v = reinterpret_cast< Arith* >(a.data() )->getOutput();
1355  assert( doubleEq( v, temp ) );
1356 
1357  v = reinterpret_cast< Arith* >(b.data() )->getOutput();
1358  assert( doubleEq( v, temp2 ) );
1359 
1360  v = reinterpret_cast< Arith* >( c.data() )->getOutput();
1361  assert( doubleEq( v, temp2 - temp ) );
1362  }
1363 
1364  for ( unsigned int i = 0; i < size; ++i ) {
1365  // Eref a( e1, i );
1366  // Eref b( e1, size - i - 1 );
1367  ObjId a( i1, i );
1368  ObjId b( i1, size - i - 1 );
1369 
1370  double temp = i;
1371  double temp2 = temp * temp;
1372  double ret = Field< double >::get( a, "x" );
1373  assert( doubleEq( temp, ret ) );
1374 
1375  ret = Field< double >::get( b, "y" );
1376  assert( doubleEq( temp2, ret ) );
1377 
1378  ret = Field< double >::get( a, "z" );
1379  assert( doubleEq( temp2 - temp, ret ) );
1380  // cout << i << " " << ret << " temp2 = " << temp2 << endl;
1381  }
1382 
1383  cout << "." << flush;
1384 
1385  /*
1386  * This works, but I want to avoid calling the Shell specific ops here
1387  *
1388  * Shell* s = reinterpret_cast< Shell* >( Id().eref().data() );
1389  * s->doDelete( i1 );
1390  */
1391  i4.destroy();
1392  i3.destroy();
1393  i2.destroy();
1394  i1.destroy();
1395 }
Definition: Arith.h:12
unsigned int value() const
Definition: Id.cpp:197
Definition: ObjId.h:20
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
void destroy() const
Definition: Id.cpp:176
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:252
static bool adopt(ObjId parent, Id child, unsigned int msgIndex)
Definition: Shell.cpp:654
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
Definition: Cinfo.h:18

+ Here is the call graph for this function:

void testSetGetSynapse ( )

Definition at line 344 of file testAsync.cpp.

References Element::data(), doubleEq(), Field< A >::get(), SimpleSynHandler::initCinfo(), Id::nextId(), Element::numData(), Field< A >::setVec(), and Id::value().

Referenced by testAsync().

345 {
346  const Cinfo* ssh = SimpleSynHandler::initCinfo();
347  unsigned int size = 100;
348 
349  string arg;
350  Id handler = Id::nextId();
351  Element* temp = new GlobalDataElement( handler, ssh, "test2", size );
352  assert( temp );
353  vector< unsigned int > ns( size );
354  vector< vector< double > > delay( size );
355  for ( unsigned int i = 0; i < size; ++i ) {
356  ns[i] = i;
357  for ( unsigned int j = 0; j < i; ++j ) {
358  double temp = i * 1000 + j;
359  delay[i].push_back( temp );
360  }
361  }
362 
363  bool ret = Field< unsigned int >::setVec( handler, "numSynapse", ns );
364  assert( ret );
365  assert( temp->numData() == size );
366  Id syns( handler.value() + 1 );
367  for ( unsigned int i = 0; i < size; ++i ) {
368  ret = Field< double >::
369  setVec( ObjId( syns, i ), "delay", delay[i] );
370  if ( i > 0 )
371  assert( ret );
372  }
373 
374  for ( unsigned int i = 0; i < size; ++i ) {
375  assert( syns.element()->numField( i ) == i );
376  SimpleSynHandler* s =
377  reinterpret_cast< SimpleSynHandler* >( temp->data( i ) );
378  assert( s->getNumSynapses() == i );
379  for ( unsigned int j = 0; j < i; ++j ) {
380  // ObjId oid( syns, i, j );
381  ObjId oid( syns, i, j );
382  double x = i * 1000 + j ;
383  double d = Field< double >::get( oid, "delay" );
384  double d2 = s->getSynapse( j )->getDelay();
385  assert( doubleEq( d, x ) );
386  assert( doubleEq( d2, x ) );
387  }
388  }
389  delete syns.element();
390  delete temp;
391  cout << "." << flush;
392 }
unsigned int value() const
Definition: Id.cpp:197
Definition: ObjId.h:20
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:252
virtual char * data(unsigned int rawIndex, unsigned int fieldIndex=0) const =0
Definition: Id.h:17
static const Cinfo * initCinfo()
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSetGetVec ( )

Definition at line 394 of file testAsync.cpp.

References Element::data(), Id::element(), SynHandlerBase::getNumSynapses(), Field< A >::getVec(), SimpleSynHandler::initCinfo(), Id::nextId(), Field< A >::setVec(), and Id::value().

Referenced by testAsync().

395 {
396  const Cinfo* sc = SimpleSynHandler::initCinfo();
397  unsigned int size = 100;
398 
399  string arg;
400  Id i2 = Id::nextId();
401  Element* temp = new GlobalDataElement( i2, sc, "test2", size );
402  assert( temp );
403 
404  vector< unsigned int > numSyn( size, 0 );
405  for ( unsigned int i = 0; i < size; ++i )
406  numSyn[i] = i;
407 
408  Eref e2( i2.element(), 0 );
409  // Here we test setting a 1-D vector
410  bool ret = Field< unsigned int >::setVec( i2, "numSynapse", numSyn );
411  assert( ret );
412 
413  for ( unsigned int i = 0; i < size; ++i ) {
414  SimpleSynHandler* ssh = reinterpret_cast< SimpleSynHandler* >( i2.element()->data( i ) );
415  assert( ssh->getNumSynapses() == i );
416  }
417 
418  vector< unsigned int > getSyn;
419 
420  Field< unsigned int >::getVec( i2, "numSynapse", getSyn );
421  assert (getSyn.size() == size );
422  for ( unsigned int i = 0; i < size; ++i )
423  assert( getSyn[i] == i );
424 
425  Id synapse( i2.value() + 1 );
426  delete synapse.element();
427  delete temp;
428  cout << "." << flush;
429 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
unsigned int value() const
Definition: Id.cpp:197
unsigned int getNumSynapses() const
static Id nextId()
Definition: Id.cpp:132
Definition: Eref.h:26
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:252
virtual char * data(unsigned int rawIndex, unsigned int fieldIndex=0) const =0
Definition: Id.h:17
static const Cinfo * initCinfo()
static void getVec(ObjId dest, const string &field, vector< A > &vec)
Definition: SetGet.h:317
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSetRepeat ( )

Definition at line 941 of file testAsync.cpp.

References doubleEq(), Field< A >::getVec(), SimpleSynHandler::initCinfo(), Id::nextId(), Field< A >::setRepeat(), Field< A >::setVec(), and Id::value().

Referenced by testAsync().

942 {
943  const Cinfo* sc = SimpleSynHandler::initCinfo();
944  unsigned int size = 100;
945 
946  string arg;
947  Id cell = Id::nextId();
948  Element* temp = new GlobalDataElement( cell, sc, "cell", size );
949  assert( temp );
950  vector< unsigned int > numSyn( size, 0 );
951  for ( unsigned int i = 0; i < size; ++i )
952  numSyn[i] = i;
953 
954  // Here we test setting a 1-D vector
955  bool ret = Field< unsigned int >::setVec( cell, "numSynapse", numSyn);
956  assert( ret );
957 
958  Id synapse( cell.value() + 1 );
959  // Here we test setting a 2-D array with different dims on each axis.
960  for ( unsigned int i = 0; i < size; ++i ) {
961  ret = Field< double >::
962  setRepeat( ObjId( synapse, i ), "delay", 123.0 );
963  assert( ret );
964  }
965  for ( unsigned int i = 0; i < size; ++i ) {
966  vector< double > delay;
967  Field< double >::getVec( ObjId( synapse, i ), "delay", delay );
968  assert( delay.size() == i );
969  for ( unsigned int j = 0; j < i; ++j ) {
970  assert( doubleEq( delay[j], 123.0 ) );
971  }
972  }
973 
974  delete synapse.element();
975  delete temp;
976  cout << "." << flush;
977 }
unsigned int value() const
Definition: Id.cpp:197
static bool setRepeat(ObjId destId, const string &field, A arg)
Definition: SetGet.h:260
Definition: ObjId.h:20
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:252
Definition: Id.h:17
static const Cinfo * initCinfo()
static void getVec(ObjId dest, const string &field, vector< A > &vec)
Definition: SetGet.h:317
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSharedMsg ( )

Definition at line 1042 of file testAsync.cpp.

References Finfo::addMsg(), Eref::data(), Id::destroy(), Id::element(), Id::eref(), Cinfo::findFinfo(), Test::handleS0(), Test::handleS1(), Test::handleS2(), Test::i1_, Test::i2_, Test::initCinfo(), Msg::mid(), Id::nextId(), Test::numAcks_, s0, Test::s_, SrcFinfo1< T >::send(), and SrcFinfo2< T1, T2 >::send().

Referenced by testAsync().

1043 {
1044  static SrcFinfo1< string > s1( "s1", "" );
1045  static SrcFinfo2< int, int > s2( "s2", "" );
1046  static DestFinfo d0( "d0", "",
1047  new OpFunc0< Test >( & Test::handleS0 ) );
1048  static DestFinfo d1( "d1", "",
1050  static DestFinfo d2( "d2", "",
1052 
1053  Test::sharedVec[0] = &s0;
1054  Test::sharedVec[1] = &d0;
1055  Test::sharedVec[2] = &s1;
1056  Test::sharedVec[3] = &d1;
1057  Test::sharedVec[4] = &s2;
1058  Test::sharedVec[5] = &d2;
1059 
1060  Id t1 = Id::nextId();
1061  Id t2 = Id::nextId();
1062  // bool ret = Test::initCinfo()->create( t1, "test1", 1 );
1063 
1064  Element* temp = new GlobalDataElement( t1, Test::initCinfo(), "test1", 1 );
1065  assert( temp );
1066  temp = new GlobalDataElement( t2, Test::initCinfo(), "test2", 1 );
1067  // ret = Test::initCinfo()->create( t2, "test2", 1 );
1068  assert( temp );
1069 
1070  // Assign initial values
1071  Test* tdata1 = reinterpret_cast< Test* >( t1.eref().data() );
1072  tdata1->s_ = "tdata1";
1073  tdata1->i1_ = 1;
1074  tdata1->i2_ = 2;
1075 
1076  Test* tdata2 = reinterpret_cast< Test* >( t2.eref().data() );
1077  tdata2->s_ = "TDATA2";
1078  tdata2->i1_ = 5;
1079  tdata2->i2_ = 6;
1080 
1081  // Set up message. The actual routine is in Shell.cpp, but here we
1082  // do it independently.
1083 
1084  const Finfo* shareFinfo = Test::initCinfo()->findFinfo( "shared" );
1085  assert( shareFinfo != 0 );
1086  Msg* m = new OneToOneMsg( t1.eref(), t2.eref(), 0 );
1087  assert( m != 0 );
1088  bool ret = shareFinfo->addMsg( shareFinfo, m->mid(), t1.element() );
1089  assert( ret );
1090 
1091  // t1.element()->digestMessages();
1092  // t2.element()->digestMessages();
1093  // Display stuff. Need to figure out how to unit test this.
1094  // t1()->showMsg();
1095  // t2()->showMsg();
1096 
1097  // Send messages
1098  ProcInfo p;
1099  string arg1 = " hello ";
1100  s1.send( t1.eref(), arg1 );
1101  s2.send( t1.eref(), 100, 200 );
1102 
1103  string arg2 = " goodbye ";
1104  s1.send( t2.eref(), arg2 );
1105  s2.send( t2.eref(), 500, 600 );
1106 
1107  /*
1108  cout << "data1: s=" << tdata1->s_ <<
1109  ", i1=" << tdata1->i1_ << ", i2=" << tdata1->i2_ <<
1110  ", numAcks=" << tdata1->numAcks_ << endl;
1111  cout << "data2: s=" << tdata2->s_ <<
1112  ", i1=" << tdata2->i1_ << ", i2=" << tdata2->i2_ <<
1113  ", numAcks=" << tdata2->numAcks_ << endl;
1114  */
1115  // Check results
1116 
1117  assert( tdata1->s_ == " goodbye tdata1" );
1118  assert( tdata2->s_ == " hello TDATA2" );
1119  assert( tdata1->i1_ == 5001 );
1120  assert( tdata1->i2_ == 6002 );
1121  assert( tdata2->i1_ == 1005 );
1122  assert( tdata2->i2_ == 2006 );
1123  assert( tdata1->numAcks_ == 2 );
1124  assert( tdata2->numAcks_ == 2 );
1125 
1126  t1.destroy();
1127  t2.destroy();
1128 
1129  cout << "." << flush;
1130 }
static const Cinfo * initCinfo()
Definition: testAsync.cpp:1014
void handleS1(const Eref &e, string s)
Definition: testAsync.cpp:1001
ObjId mid() const
Definition: Msg.h:106
char * data() const
Definition: Eref.cpp:41
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
static Finfo * sharedVec[6]
Definition: testAsync.cpp:1012
Definition: EpFunc.h:64
string s_
Definition: testAsync.cpp:1034
Eref eref() const
Definition: Id.cpp:125
void destroy() const
Definition: Id.cpp:176
void handleS0()
Definition: testAsync.cpp:997
static Id nextId()
Definition: Id.cpp:132
static SrcFinfo0 s0("s0","")
virtual bool addMsg(const Finfo *target, ObjId mid, Element *src) const
Definition: Finfo.h:92
int i1_
Definition: testAsync.cpp:1035
Definition: Msg.h:18
Definition: Id.h:17
int numAcks_
Definition: testAsync.cpp:1037
Definition: OpFunc.h:13
Definition: EpFunc.h:79
void handleS2(const Eref &e, int i1, int i2)
Definition: testAsync.cpp:1006
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
int i2_
Definition: testAsync.cpp:1036
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSparseMatrix ( )

Definition at line 515 of file testAsync.cpp.

References SparseMatrix< T >::getRow(), SparseMatrix< T >::nColumns(), SparseMatrix< T >::nRows(), SparseMatrix< T >::reorderColumns(), SparseMatrix< T >::set(), and SparseMatrix< T >::transpose().

Referenced by testAsync().

516 {
517  static unsigned int preN[] = { 1, 2, 3, 4, 5, 6, 7 };
518  static unsigned int postN[] = { 1, 3, 4, 5, 6, 2, 7 };
519  static unsigned int preColIndex[] = { 0, 4, 0, 1, 2, 3, 4 };
520  static unsigned int postColIndex[] = { 0, 1, 1, 1, 2, 0, 2 };
521 
522  static unsigned int dropN[] = { 1, 6, 2, 7 };
523  static unsigned int dropColIndex[] = { 0, 1, 0, 1 };
524 
526  unsigned int nRows = m.nRows();
527  unsigned int nCols = m.nColumns();
528 
529  m.set( 0, 0, 1 );
530  m.set( 0, 4, 2 );
531  m.set( 1, 0, 3 );
532  m.set( 1, 1, 4 );
533  m.set( 1, 2, 5 );
534  m.set( 2, 3, 6 );
535  m.set( 2, 4, 7 );
536 
537  const unsigned int *n;
538  const unsigned int *c;
539  unsigned int k = 0;
540  for ( unsigned int i = 0; i < nRows; ++i ) {
541  unsigned int num = m.getRow( i, &n, &c );
542  for ( unsigned int j = 0; j < num; ++j ) {
543  assert( n[j] == preN[ k ] );
544  assert( c[j] == preColIndex[ k ] );
545  k++;
546  }
547  }
548  assert( k == 7 );
549 
550  // printSparseMatrix( m );
551 
552  m.transpose();
553  assert( m.nRows() == nCols );
554  assert( m.nColumns() == nRows );
555 
556  k = 0;
557  for ( unsigned int i = 0; i < nCols; ++i ) {
558  unsigned int num = m.getRow( i, &n, &c );
559  for ( unsigned int j = 0; j < num; ++j ) {
560  assert( n[j] == postN[ k ] );
561  assert( c[j] == postColIndex[ k ] );
562  k++;
563  }
564  }
565  assert( k == 7 );
566 
567  // Drop column 1.
568  vector< unsigned int > keepCols( 2 );
569  keepCols[0] = 0;
570  keepCols[1] = 2;
571  // cout << endl; m.print();
572  m.reorderColumns( keepCols );
573  // cout << endl; m.print();
574  assert( m.nRows() == nCols );
575  assert( m.nColumns() == 2 );
576 
577  k = 0;
578  for ( unsigned int i = 0; i < nCols; ++i ) {
579  unsigned int num = m.getRow( i, &n, &c );
580  for ( unsigned int j = 0; j < num; ++j ) {
581  assert( n[j] == dropN[ k ] );
582  assert( c[j] == dropColIndex[ k ] );
583  k++;
584  }
585  }
586  assert( k == 4 );
587 
588  cout << "." << flush;
589 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSparseMatrix2 ( )

Definition at line 591 of file testAsync.cpp.

References SparseMatrix< T >::clear(), SparseMatrix< T >::get(), init(), SparseMatrix< T >::reorderColumns(), resize(), SparseMatrix< T >::set(), SparseMatrix< T >::setSize(), and SparseMatrix< T >::transpose().

Referenced by testAsync().

592 {
593  // Here zeroes mean no entry, not an entry of zero.
594  // Rows 0 to 4 are totally empty
595  static unsigned int row5[] = { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0 };
596  static unsigned int row6[] = { 0, 0, 3, 4, 0, 0, 0, 0, 0, 0 };
597  static unsigned int row7[] = { 0, 0, 0, 0, 5, 0, 0, 0, 0, 6 };
598  static unsigned int row8[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
599  static unsigned int row9[] = { 0, 0, 7, 0, 0, 0, 0, 8, 0, 0 };
600 
601  vector< vector < unsigned int > > m( 10 );
602  for ( unsigned int i = 0; i < 10; ++i )
603  m[i].resize( 10, 0 );
604 
605  for ( unsigned int i = 0; i < 10; ++i ) m[5][i] = row5[i];
606  for ( unsigned int i = 0; i < 10; ++i ) m[6][i] = row6[i];
607  for ( unsigned int i = 0; i < 10; ++i ) m[7][i] = row7[i];
608  for ( unsigned int i = 0; i < 10; ++i ) m[8][i] = row8[i];
609  for ( unsigned int i = 0; i < 10; ++i ) m[9][i] = row9[i];
610 
611  SparseMatrix< unsigned int > n( 10, 10 );
612  for ( unsigned int i = 0; i < 10; ++i )
613  for ( unsigned int j = 0; j < 10; ++j )
614  if ( m[i][j] != 0 )
615  n.set( i, j, m[i][j] );
616 
617  n.transpose();
618  for ( unsigned int i = 0; i < 10; ++i )
619  for ( unsigned int j = 0; j < 10; ++j )
620  assert (n.get( j, i ) == m[i][j] );
621  n.transpose();
622  for ( unsigned int i = 0; i < 10; ++i )
623  for ( unsigned int j = 0; j < 10; ++j )
624  assert (n.get( i, j ) == m[i][j] );
625 
627  // Drop columns 2 and 7.
629  static unsigned int init[] = {0, 1, 3, 4, 5, 6, 8, 9};
630  vector< unsigned int > keepCols(
631  init, init + sizeof( init ) / sizeof( unsigned int ) );
632  n.reorderColumns( keepCols );
633  for ( unsigned int i = 0; i < 10; ++i ) {
634  for ( unsigned int j = 0; j < 8; ++j ) {
635  unsigned int k = keepCols[j];
636  assert (n.get( i, j ) == m[i][k] );
637  }
638  }
639  n.clear();
640  n.setSize( 1, 100 );
641  for ( unsigned int i = 0; i < 100; ++i )
642  n.set( 0, i, 10 * i );
643  n.transpose();
644  for ( unsigned int i = 0; i < 100; ++i )
645  assert( n.get( i, 0 ) == 10 * i );
646  n.transpose();
647  for ( unsigned int i = 0; i < 100; ++i )
648  assert( n.get( 0, i ) == 10 * i );
649 
650  /*
651  n.printInternal();
652  cout << "before transpose\n";
653  n.print();
654  n.transpose();
655  cout << "after transpose\n";
656  n.print();
657  n.transpose();
658  cout << "after transpose back\n";
659  n.print();
660  */
661 
662  cout << "." << flush;
663 }
Id init(int argc, char **argv, bool &doUnitTests, bool &doRegressionTests, unsigned int &benchmark)
Definition: main.cpp:150
vector< vector< T > > resize(vector< vector< T > >table, unsigned int n, T init)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSparseMatrixFill ( )

Definition at line 727 of file testAsync.cpp.

References SparseMatrix< T >::get(), SparseMatrix< T >::nColumns(), SparseMatrix< T >::nEntries(), SparseMatrix< T >::nRows(), and SparseMatrix< T >::tripletFill().

Referenced by testAsync().

728 {
730  unsigned int nrow = 5;
731  unsigned int ncol = 7;
732  vector< unsigned int > row;
733  vector< unsigned int > col;
734  vector< int > val;
735  unsigned int num = 0;
736  for ( unsigned int i = 0; i < nrow; ++i ) {
737  for ( unsigned int j = 0; j < ncol; ++j ) {
738  if ( j == 0 || i + j == 6 || ( j - i) == 2 ) {
739  row.push_back( i );
740  col.push_back( j );
741  val.push_back( 100 + i * 10 + j );
742  ++num;
743  }
744  }
745  }
746  n.tripletFill( row, col, val );
747  // n.print();
748  assert( n.nRows() == nrow );
749  assert( n.nColumns() == ncol );
750  assert( n.nEntries() == num );
751  for ( unsigned int i = 0; i < nrow; ++i ) {
752  for ( unsigned int j = 0; j < ncol; ++j ) {
753  int val = n.get( i, j );
754  if ( j == 0 || i + j == 6 || ( j - i) == 2 )
755  assert( static_cast< unsigned int >( val ) == 100 + i * 10 + j );
756  else
757  assert( val == 0 );
758  }
759  }
760  cout << "." << flush;
761 }
unsigned int nEntries() const
Definition: SparseMatrix.h:97
void tripletFill(const vector< unsigned int > &row, const vector< unsigned int > &col, const vector< T > &z, bool retainSize=false)
Definition: SparseMatrix.h:583
unsigned int nColumns() const
Definition: SparseMatrix.h:92
T get(unsigned int row, unsigned int column) const
Definition: SparseMatrix.h:253
unsigned int nRows() const
Definition: SparseMatrix.h:87

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSparseMatrixReorder ( )

Definition at line 665 of file testAsync.cpp.

References SparseMatrix< T >::get(), SparseMatrix< T >::nColumns(), SparseMatrix< T >::nRows(), SparseMatrix< T >::reorderColumns(), SparseMatrix< T >::set(), and SparseMatrix< T >::setSize().

Referenced by testAsync().

666 {
667  SparseMatrix< int > n( 2, 1 );
668  n.set( 0, 0, -1 );
669  n.set( 1, 0, 1 );
670  vector< unsigned int > colOrder( 1, 0 ); // Keep the original as is
671  n.reorderColumns( colOrder ); // This case failed in an earlier version
672  assert( n.get( 0, 0 ) == -1 );
673  assert( n.get( 1, 0 ) == 1 );
674 
675  unsigned int nrows = 4;
676  unsigned int ncolumns = 5;
677 
679  // Test a reordering
681  n.setSize( nrows, ncolumns );
682  for ( unsigned int i = 0; i < nrows; ++i ) {
683  for ( unsigned int j = 0; j < ncolumns; ++j ) {
684  int x = i * 10 + j;
685  n.set( i, j, x );
686  }
687  }
688  colOrder.resize( ncolumns );
689  colOrder[0] = 3;
690  colOrder[1] = 2;
691  colOrder[2] = 0;
692  colOrder[3] = 4;
693  colOrder[4] = 1;
694  n.reorderColumns( colOrder );
695  assert( n.nRows() == nrows );
696  assert( n.nColumns() == ncolumns );
697  for ( unsigned int i = 0; i < nrows; ++i ) {
698  for ( unsigned int j = 0; j < ncolumns; ++j ) {
699  int x = i * 10 + colOrder[j];
700  assert( n.get( i, j ) == x );
701  }
702  }
703 
705  // Test reordering + eliminating some columns
707  // Put back in original config
708  for ( unsigned int i = 0; i < nrows; ++i ) {
709  for ( unsigned int j = 0; j < ncolumns; ++j ) {
710  unsigned int x = i * 10 + j;
711  n.set( i, j, x );
712  }
713  }
714  colOrder.resize( 2 );
715  colOrder[0] = 3;
716  colOrder[1] = 2;
717  n.reorderColumns( colOrder );
718  assert( n.nRows() == nrows );
719  assert( n.nColumns() == 2 );
720  for ( unsigned int i = 0; i < nrows; ++i ) {
721  assert( n.get( i, 0 ) == static_cast< int >( i * 10 + 3 ) );
722  assert( n.get( i, 1 ) == static_cast< int >( i * 10 + 2 ) );
723  }
724  cout << "." << flush;
725 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testSparseMsg ( )

Definition at line 787 of file testAsync.cpp.

References Finfo::addMsg(), ProcInfo::currTime, ProcInfo::dt, Cinfo::findFinfo(), Field< A >::get(), id, Synapse::initCinfo(), IntFire::initCinfo(), SimpleSynHandler::initCinfo(), Msg::mid(), moose::mtrand(), Id::nextId(), SparseMsg::randomConnect(), moose::setGlobalSeed(), SetGet1< A >::setRepeat(), Field< A >::setVec(), and Id::value().

Referenced by testAsync().

788 {
789  // static const unsigned int NUMSYN = 104576;
790  static const double thresh = 0.2;
791  static const double Vmax = 1.0;
792  static const double refractoryPeriod = 0.4;
793  static const double weightMax = 0.02;
794  static const double delayMax = 4;
795  static const double timestep = 0.2;
796  static const double connectionProbability = 0.1;
797  static const unsigned int runsteps = 5;
798  const Cinfo* ic = IntFire::initCinfo();
799  const Cinfo* sshc = SimpleSynHandler::initCinfo();
800  const Cinfo* sc = Synapse::initCinfo();
801  const Finfo* procFinfo = sshc->findFinfo( "process" );
802  assert( procFinfo );
803  const DestFinfo* df = dynamic_cast< const DestFinfo* >( procFinfo );
804  assert( df );
805  // const Cinfo* sc = Synapse::initCinfo();
806  unsigned int size = 1024;
807 
808  string arg;
809 
810  // The default value, but better to be explicit.
811  moose::setGlobalSeed( 5489UL );
812 
813  Id sshid = Id::nextId();
814  Element* t2 = new GlobalDataElement( sshid, sshc, "test2", size );
815  assert( t2 );
816  Id syns( sshid.value() + 1 );
817  Id cells = Id::nextId();
818  Element* t3 = new GlobalDataElement( cells, ic, "intFire", size );
819  assert( t3 );
820 
821  SparseMsg* sm = new SparseMsg( t3, syns.element(), 0 );
822  assert( sm );
823  const Finfo* f1 = ic->findFinfo( "spikeOut" );
824  const Finfo* f2 = sc->findFinfo( "addSpike" );
825  assert( f1 && f2 );
826  f1->addMsg( f2, sm->mid(), t3 );
827  sm->randomConnect( connectionProbability );
828 
829  vector< double > temp( size, 0.0 );
830  for ( unsigned int i = 0; i < size; ++i )
831  temp[i] = moose::mtrand() * Vmax;
832 
833  bool ret = Field< double >::setVec( cells, "Vm", temp );
834  assert( ret );
835  temp.clear();
836  temp.resize( size, thresh );
837  ret = Field< double >::setVec( cells, "thresh", temp );
838  assert( ret );
839  temp.clear();
840  temp.resize( size, refractoryPeriod );
841  ret = Field< double >::setVec( cells, "refractoryPeriod", temp );
842  assert( ret );
843 
844  unsigned int fieldSize = 5000;
845  vector< double > weight( size * fieldSize, 0.0 );
846  vector< double > delay( size * fieldSize, 0.0 );
847  for ( unsigned int i = 0; i < size; ++i ) {
848  ObjId id( sshid, i );
849  unsigned int numSyn =
850  Field< unsigned int >::get( id, "numSynapse" );
851  unsigned int k = i * fieldSize;
852  for ( unsigned int j = 0; j < numSyn; ++j ) {
853  weight[ k + j ] = moose::mtrand() * weightMax;
854  delay[ k + j ] = moose::mtrand() * delayMax;
855  }
856  }
857  ret = Field< double >::setVec( syns, "weight", weight );
858  assert( ret );
859  ret = Field< double >::setVec( syns, "delay", delay );
860  assert( ret );
861 
862  // printGrid( cells(), "Vm", 0, thresh );
863 
864  ProcInfo p;
865  p.dt = timestep;
866  for ( unsigned int i = 0; i < runsteps; ++i ) {
867  p.currTime += p.dt;
868  SetGet1< ProcInfo* >::setRepeat( sshid, "process", &p );
869  SetGet1< ProcInfo* >::setRepeat( cells, "process", &p );
870  // cells()->process( &p, df->getFid() );
871  }
872 
873  delete t2;
874  delete t3;
875  cout << "." << flush;
876 }
unsigned int randomConnect(double probability)
Definition: SparseMsg.cpp:465
ObjId mid() const
Definition: Msg.h:106
double currTime
Definition: ProcInfo.h:19
unsigned int value() const
Definition: Id.cpp:197
Definition: ObjId.h:20
static const Cinfo * initCinfo()
Definition: IntFire.cpp:23
void setGlobalSeed(int seed)
Definition: global.cpp:211
static const Cinfo * initCinfo()
Definition: Synapse.cpp:15
static Id nextId()
Definition: Id.cpp:132
virtual bool addMsg(const Finfo *target, ObjId mid, Element *src) const
Definition: Finfo.h:92
double dt
Definition: ProcInfo.h:18
static bool setVec(ObjId destId, const string &field, const vector< A > &arg)
Definition: SetGet.h:252
double mtrand(void)
Generate a random double between 0 and 1.
Definition: global.cpp:97
Definition: Id.h:17
static const Cinfo * initCinfo()
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static char id[]
Definition: mfield.cpp:404
static bool setRepeat(ObjId destId, const string &field, const A &arg)
Definition: SetGet.h:213
Definition: Cinfo.h:18
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testStrGet ( )

Definition at line 267 of file testAsync.cpp.

References ObjId::data(), Id::element(), Arith::initCinfo(), Id::nextId(), Element::setName(), and SetGet::strGet().

Referenced by testAsync().

268 {
269  const Cinfo* ac = Arith::initCinfo();
270  unsigned int size = 100;
271  string arg;
272  Id i2 = Id::nextId();
273 
274  Element* ret = new GlobalDataElement( i2, ac, "test2", size );
275  assert( ret );
276  ProcInfo p;
277 
278  ObjId oid( i2, 0 );
279 
280  string val;
281  bool ok = SetGet::strGet( oid, "name", val );
282  assert( ok );
283  assert( val == "test2" );
284  ret->setName( "HupTwoThree" );
285  ok = SetGet::strGet( oid, "name", val );
286  assert( ok );
287  assert( val == "HupTwoThree" );
288 
289  for ( unsigned int i = 0; i < size; ++i ) {
290  double temp = i * 3;
291  reinterpret_cast< Arith* >( ObjId( i2, i ).data() )->setOutput( temp );
292  }
293 
294  for ( unsigned int i = 0; i < size; ++i ) {
295  // Eref dest( e2.element(), i );
296  ObjId dest( i2, i );
297  ok = SetGet::strGet( dest, "outputValue", val );
298  assert( ok );
299  double conv = atof( val.c_str() );
300  double temp = i * 3;
301  assert( fabs( conv - temp ) < 1e-5 );
302  // DoubleEq won't work here because string is truncated.
303  }
304 
305  cout << "." << flush;
306  delete i2.element();
307 }
char * data() const
Definition: ObjId.cpp:113
void setName(const string &val)
Definition: Element.cpp:61
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
Definition: ObjId.h:20
static Id nextId()
Definition: Id.cpp:132
static bool strGet(const ObjId &tgt, const string &field, string &ret)
Definition: SetGet.cpp:72
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void testStrSet ( )

Definition at line 188 of file testAsync.cpp.

References Shell::adopt(), Id::element(), Element::getName(), Arith::initCinfo(), Id::nextId(), and SetGet::strSet().

Referenced by testAsync().

189 {
190  const Cinfo* ac = Arith::initCinfo();
191  unsigned int size = 100;
192 
193  string arg;
194  Id i2 = Id::nextId();
195  Element* ret = new GlobalDataElement( i2, ac, "test2", size );
196  assert( ret );
197  ProcInfo p;
198 
199  Shell::adopt( Id(), i2, 0 );
200 
201  assert( ret->getName() == "test2" );
202  bool ok = SetGet::strSet( ObjId( i2, 0 ), "name", "NewImprovedTest" );
203  assert( ok );
204  assert( ret->getName() == "NewImprovedTest" );
205 
206  for ( unsigned int i = 0; i < size; ++i ) {
207  double x = sqrt((double) i );
208  // Eref dest( e2.element(), i );
209  ObjId dest( i2, i );
210  stringstream ss;
211  ss << setw( 10 ) << x;
212  ok = SetGet::strSet( dest, "outputValue", ss.str() );
213  assert( ok );
214  // SetGet1< double >::set( dest, "setOutputValue", x );
215  }
216 
217  for ( unsigned int i = 0; i < size; ++i ) {
218  double temp = sqrt((double) i );
219  double val = reinterpret_cast< Arith* >(
220  Eref( i2.element(), i ).data() )->getOutput();
221  assert( fabs( val - temp ) < 1e-5 );
222  // DoubleEq won't work here because string is truncated.
223  }
224 
225  cout << "." << flush;
226 
227  delete i2.element();
228 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
Definition: Arith.h:12
Definition: ObjId.h:20
static bool strSet(const ObjId &dest, const string &field, const string &val)
Definition: SetGet.cpp:84
static Id nextId()
Definition: Id.cpp:132
Definition: Eref.h:26
static bool adopt(ObjId parent, Id child, unsigned int msgIndex)
Definition: Shell.cpp:654
Definition: Id.h:17
static const Cinfo * initCinfo()
Definition: Arith.cpp:22
const string & getName() const
Definition: Element.cpp:56
Definition: Cinfo.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

int _seed_ = 0

Definition at line 37 of file testAsync.cpp.

SrcFinfo0 s0("s0","")
static

This sets up a reciprocal shared Msg in which the incoming value gets appended onto the corresponding value of the target. Also, as soon as any of the s1 or s2 are received, the target sends out an s0 call. All this is tallied for validating the unit test.

Referenced by estT(), Test::handleS1(), Test::handleS2(), testSharedMsg(), and CylBase::voxelVolume().