MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
testScheduling.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2009 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #include "header.h"
11 #include "testScheduling.h"
12 #include "Clock.h"
13 
14 #include "SparseMatrix.h"
15 #include "SparseMsg.h"
16 #include "SingleMsg.h"
17 #include "../builtins/Arith.h"
18 #include "../shell/Shell.h"
19 
20 
22 // Setting up a class for testing scheduling.
24 
26 bool TestSched::isInitPending_ = true;
27 
28 static DestFinfo processFinfo( "process",
29  "handles process call",
31 );
32 
34 {
35 
36  static Finfo* testSchedFinfos[] = {
38  };
39 
40  static Dinfo< TestSched > dinfo;
41  static Cinfo testSchedCinfo (
42  "testSched",
43  0,
44  testSchedFinfos,
45  sizeof ( testSchedFinfos ) / sizeof( Finfo* ),
46  &dinfo
47  );
48 
49  return &testSchedCinfo;
50 }
51 
53 
54 void TestSched::process( const Eref& e, ProcPtr p )
55 {
56  static const int timings[] = { 1, 2, 2, 2, 3, 3, 4, 4, 4,
57  5, 5, 5, 6, 6, 6, 6, 7, 8, 8, 8, 9, 9, 10, 10, 10, 10, 10,
58  11, 12, 12, 12, 12, 13, 14, 14, 14, 15, 15, 15, 15,
59  16, 16, 16, 17, 18, 18, 18, 18, 19, 20, 20, 20, 20, 20,
60  21, 21, 22, 22, 22, 23, 24, 24, 24, 24, 25, 25, 25 };
61  // unsigned int max = sizeof( timings ) / sizeof( int );
62  // cout << Shell::myNode() << " : timing[ " << index_ << " ] = " << timings[ index_ ] << ", time = " << p->currTime << endl;
63  if ( static_cast< int >( p->currTime ) != timings[ index_ ] ) {
64  cout << Shell::myNode() << ":testSchedElement::process: index= " << index_ << ", currTime = " << p->currTime << endl;
65  }
66 
67  assert( static_cast< int >( p->currTime ) == timings[ index_ ] );
68  ++index_;
69 
70  // Check that everything remains in sync
71  assert( ( globalIndex_ - index_ )*( globalIndex_ - index_ ) <= 1 );
73 }
74 
76 
80 void testClock()
81 {
82  const double runtime = 20.0;
83  Id clock(1);
84 
85  bool ret = Field< double >::set( clock, "baseDt", 1.0);
86  assert( ret );
87  ret = LookupField< unsigned int, double >::set( clock, "tickDt", 0, 2.0);
88  assert( ret );
89  ret = LookupField< unsigned int, double >::set( clock, "tickDt", 3, 1.0);
90  assert( ret );
91  ret = LookupField< unsigned int, double >::set( clock, "tickDt", 1, 2.0);
92  assert( ret );
93  ret = LookupField< unsigned int, double >::set( clock, "tickDt", 2, 5.0);
94  assert( ret );
95  ret = LookupField< unsigned int, double >::set( clock, "tickDt", 4, 3.0);
96  assert( ret );
97  ret = LookupField< unsigned int, double >::set( clock, "tickDt", 7, 5.0);
98  assert( ret );
99 
100  /*
101  Id tabid = Id::nextId();
102  Element* tse = new Element( tsid, testSchedCinfo, "tse", 1 );
103 
104  Eref ts( tse, 0 );
105 
106  FuncId f( processFinfo.getFid() );
107  const Finfo* proc0 = clock.element()->cinfo()->findFinfo( "process0" );
108  assert( proc0 );
109  const SrcFinfo* sproc0 = dynamic_cast< const SrcFinfo* >( proc0 );
110  assert( sproc0 );
111  unsigned int b0 = sproc0->getBindIndex();
112  SingleMsg *m0 = new SingleMsg( er0.eref(), ts );
113  er0.element()->addMsgAndFunc( m0->mid(), f, er0.dataId.value()*2 + b0);
114  SingleMsg *m1 = new SingleMsg( er1.eref(), ts );
115  er1.element()->addMsgAndFunc( m1->mid(), f, er1.dataId.value()*2 + b0);
116  SingleMsg *m2 = new SingleMsg( er2.eref(), ts );
117  er2.element()->addMsgAndFunc( m2->mid(), f, er2.dataId.value()*2 + b0);
118  SingleMsg *m3 = new SingleMsg( er3.eref(), ts );
119  er3.element()->addMsgAndFunc( m3->mid(), f, er3.dataId.value()*2 + b0);
120  SingleMsg *m4 = new SingleMsg( er4.eref(), ts );
121  er4.element()->addMsgAndFunc( m4->mid(), f, er4.dataId.value()*2 + b0);
122  SingleMsg *m5 = new SingleMsg( er5.eref(), ts );
123  er5.element()->addMsgAndFunc( m5->mid(), f, er5.dataId.value()*2 + b0);
124 
125 
126 
127  assert( cdata->tickPtr_[0].mgr()->ticks_[0] == reinterpret_cast< const Tick* >( er3.data() ) );
128  assert( cdata->tickPtr_[1].mgr()->ticks_[0] == reinterpret_cast< const Tick* >( er2.data() ) );
129  assert( cdata->tickPtr_[1].mgr()->ticks_[1] == reinterpret_cast< const Tick* >( er1.data() ) );
130  assert( cdata->tickPtr_[2].mgr()->ticks_[0] == reinterpret_cast< const Tick* >( er4.data() ) );
131  assert( cdata->tickPtr_[3].mgr()->ticks_[0] == reinterpret_cast< const Tick* >( er0.data() ) );
132  assert( cdata->tickPtr_[3].mgr()->ticks_[1] == reinterpret_cast< const Tick* >( er5.data() ) );
133  */
134 
135  Eref clocker = clock.eref();
136  Clock* cdata = reinterpret_cast< Clock* >( clocker.data() );
137  assert ( cdata->ticks_.size() == Clock::numTicks );
138  cdata->buildTicks( clocker );
139  assert( cdata->activeTicks_.size() == 0 ); // No messages
140 
141  // Now put in the scheduling tester and messages.
142  Id test = Id::nextId();
143  Element* teste = new GlobalDataElement( test, testSchedCinfo, "test", 1 );
144  assert( teste );
145  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
146 
147  shell->doAddMsg( "oneToAll", clock, "process0", test, "process" );
148  shell->doAddMsg( "oneToAll", clock, "process1", test, "process" );
149  shell->doAddMsg( "oneToAll", clock, "process2", test, "process" );
150  shell->doAddMsg( "oneToAll", clock, "process3", test, "process" );
151  shell->doAddMsg( "oneToAll", clock, "process4", test, "process" );
152  shell->doAddMsg( "oneToAll", clock, "process7", test, "process" );
153  // clock.element()->digestMessages();
154  cdata->handleReinit( clocker );
155  assert( cdata->activeTicks_.size() == 6 ); // No messages
156  assert( cdata->activeTicks_[0] == 2 );
157  assert( cdata->activeTicks_[1] == 2 );
158  assert( cdata->activeTicks_[2] == 5 );
159  assert( cdata->activeTicks_[3] == 1 );
160  assert( cdata->activeTicks_[4] == 3 );
161  assert( cdata->activeTicks_[5] == 5 );
162  cdata->handleStart( clocker, runtime, false );
163  assert( doubleEq( cdata->getCurrentTime(), runtime ) );
164  test.destroy();
165  for ( unsigned int i = 0; i < Clock::numTicks; ++i )
166  cdata->ticks_[i] = 0;
167  cdata->buildTicks( clocker );
168  cout << "." << flush;
169 }
170 
172 {
173  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
174  // Clock* cdata = reinterpret_cast< Clock* >( Id(1).eref().data() );
175  Id syns = shell->doCreate( "SimpleSynHandler", Id(), "syns0", 10 );
176  Id fire = shell->doCreate( "IntFire", Id(), "fire0", 10 );
177 
178  shell->doDelete( syns );
179  shell->doDelete( fire );
180  cout << "." << flush;
181 }
182 
184 {
186  testClock();
187 }
188 
190 {
191 }
192 
194 {
195 }
char * data() const
Definition: Eref.cpp:41
void testClockMessaging()
static bool set(const ObjId &dest, const string &field, L index, A arg)
Definition: SetGet.h:467
static const unsigned int numTicks
Definition: Clock.h:121
void handleReinit(const Eref &e)
dest function for message to trigger reinit.
Definition: Clock.cpp:808
Definition: Clock.h:25
double getCurrentTime() const
Definition: Clock.cpp:512
double currTime
Definition: ProcInfo.h:19
static DestFinfo processFinfo("process","handles process call", new EpFunc1< TestSched, ProcPtr >(&TestSched::process))
Definition: Dinfo.h:60
Definition: EpFunc.h:64
void testClock()
Eref eref() const
Definition: Id.cpp:125
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
void handleStart(const Eref &e, double runtime, bool notify)
dest function for message to run simulation for specified time
Definition: Clock.cpp:699
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
vector< unsigned int > activeTicks_
Definition: Clock.h:158
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
static Id nextId()
Definition: Id.cpp:132
static const Cinfo * testSchedCinfo
void process(const Eref &e, ProcPtr p)
void testSchedulingProcess()
void testMpiScheduling()
void buildTicks(const Eref &e)
Definition: Clock.cpp:675
vector< unsigned int > ticks_
Definition: Clock.h:152
Definition: Eref.h:26
void testScheduling()
static bool isInitPending_
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
static unsigned int myNode()
static const Cinfo * initCinfo()
static int globalIndex_
Definition: Cinfo.h:18
Definition: Shell.h:43
Definition: Finfo.h:12