MOOSE - Multiscale Object Oriented Simulation Environment
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SrcFinfo.h
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 #ifndef _SRC_FINFO_H
10 #define _SRC_FINFO_H
11 
12 #ifdef CYMOOSE
13 
14 #include "../basecode/Finfo.h"
15 #include "../basecode/header.h"
16 
17 #endif /* ----- CYMOOSE ----- */
18 
24 class SrcFinfo: public Finfo
25 {
26  public:
27  SrcFinfo( const string& name, const string& doc );
28 
29  ~SrcFinfo() {;}
30 
31  void registerFinfo( Cinfo* c );
32 
34 
35  bool strSet( const Eref& tgt, const string& field,
36  const string& arg ) const {
37  return 0; // always fails
38  }
39 
40  bool strGet( const Eref& tgt, const string& field,
41  string& returnValue ) const {
42  return 0; // always fails
43  }
44 
45  BindIndex getBindIndex() const;
46  void setBindIndex( BindIndex b );
47 
51  bool checkTarget( const Finfo* target ) const;
52 
56  bool addMsg( const Finfo* target, ObjId mid, Element* src ) const;
57 
62  virtual void sendBuffer( const Eref& e, double* buf )
63  const = 0;
64 
65  static const BindIndex BadBindIndex;
66  private:
70  unsigned short bindIndex_;
71 };
72 
76 class SrcFinfo0: public SrcFinfo
77 {
78  public:
79 
80  SrcFinfo0( const string& name, const string& doc );
81  ~SrcFinfo0() {;}
82 
83  void send( const Eref& e ) const;
84 
85  void sendBuffer( const Eref& e, double* buf ) const;
86 
87  string rttiType() const {
88  return "void";
89  }
90 
91  private:
92 };
93 
94 template< class A > class OpFunc1Base;
95 // Should specialize for major cases like doubles.
96 
97 template < class T > class SrcFinfo1: public SrcFinfo
98 {
99  public:
101 
102  SrcFinfo1( const string& name, const string& doc )
103  : SrcFinfo( name, doc )
104  { ; }
105 
106  void send( const Eref& er, T arg ) const
107  {
108  const vector< MsgDigest >& md = er.msgDigest( getBindIndex() );
109  for ( vector< MsgDigest >::const_iterator
110  i = md.begin(); i != md.end(); ++i ) {
111  const OpFunc1Base< T >* f =
112  dynamic_cast< const OpFunc1Base< T >* >( i->func );
113  assert( f );
114  for ( vector< Eref >::const_iterator
115  j = i->targets.begin(); j != i->targets.end(); ++j ) {
116  if ( j->dataIndex() == ALLDATA ) {
117  Element* e = j->element();
118  unsigned int start = e->localDataStart();
119  unsigned int end = start + e->numLocalData();
120  for ( unsigned int k = start; k < end; ++k )
121  f->op( Eref( e, k ), arg );
122  } else {
123  f->op( *j, arg );
124  // Need to send stuff offnode too here. The
125  // target in this case is just the src Element.
126  // Its ObjId gets stuffed into the send buf.
127  // On the other node it will execute
128  // its own send command with the passed in args.
129  }
130  }
131  }
132  }
133 
134  void sendTo( const Eref& er, Id tgt, T arg ) const
135  {
136  const vector< MsgDigest >& md = er.msgDigest( getBindIndex() );
137  for ( vector< MsgDigest >::const_iterator
138  i = md.begin(); i != md.end(); ++i ) {
139  const OpFunc1Base< T >* f =
140  dynamic_cast< const OpFunc1Base< T >* >( i->func );
141  assert( f );
142  for ( vector< Eref >::const_iterator
143  j = i->targets.begin(); j != i->targets.end(); ++j ) {
144  if ( j->element() != tgt.element() )
145  continue; // Wasteful unless very few dests.
146  if ( j->dataIndex() == ALLDATA ) {
147  Element* e = j->element();
148  unsigned int start = e->localDataStart();
149  unsigned int end = start + e->numLocalData();
150  for ( unsigned int k = start; k < end; ++k )
151  f->op( Eref( e, k ), arg );
152  } else {
153  f->op( *j, arg );
154  // Need to send stuff offnode too here. The
155  // target in this case is just the src Element.
156  // Its ObjId gets stuffed into the send buf.
157  // On the other node it will execute
158  // its own send command with the passed in args.
159  }
160  }
161  }
162  }
163 
169  void sendVec( const Eref& er, const vector< T >& arg ) const
170  {
171  if ( arg.size() == 0 )
172  return;
173  const vector< MsgDigest >& md = er.msgDigest( getBindIndex() );
174  unsigned int argPos = 0;
175  for ( vector< MsgDigest >::const_iterator
176  i = md.begin(); i != md.end(); ++i ) {
177  const OpFunc1Base< T >* f =
178  dynamic_cast< const OpFunc1Base< T >* >( i->func );
179  assert( f );
180  for ( vector< Eref >::const_iterator
181  j = i->targets.begin(); j != i->targets.end(); ++j ) {
182  if ( j->dataIndex() == ALLDATA ) {
183  Element* e = j->element();
184  unsigned int start = e->localDataStart();
185  unsigned int end = start + e->numLocalData();
186  for ( unsigned int k = start; k < end; ++k ) {
187  f->op( Eref( e, k ), arg[ argPos++ ] );
188  if ( argPos >= arg.size() )
189  argPos = 0;
190  }
191  } else {
192  f->op( *j, arg[ argPos++ ] );
193  if ( argPos >= arg.size() )
194  argPos = 0;
195  // Need to send stuff offnode too here. The
196  // target in this case is just the src Element.
197  // Its ObjId gets stuffed into the send buf.
198  // On the other node it will execute
199  // its own send command with the passed in args.
200  }
201  }
202  }
203  }
204 
205  void sendBuffer( const Eref& e, double* buf ) const
206  {
207  send( e, Conv< T >::buf2val( &buf ) );
208  }
209 
210  string rttiType() const {
211  return Conv<T>::rttiType();
212  }
213  private:
214 };
215 
216 
217 template< class A1, class A2 > class OpFunc2Base;
218 // Specialize for doubles.
219 template < class T1, class T2 > class SrcFinfo2: public SrcFinfo
220 {
221  public:
223 
224  SrcFinfo2( const string& name, const string& doc )
225  : SrcFinfo( name, doc )
226  { ; }
227 
228  void send( const Eref& e, const T1& arg1, const T2& arg2 ) const
229  {
230  const vector< MsgDigest >& md = e.msgDigest( getBindIndex() );
231  for ( vector< MsgDigest >::const_iterator
232  i = md.begin(); i != md.end(); ++i ) {
233  const OpFunc2Base< T1, T2 >* f =
234  dynamic_cast< const OpFunc2Base< T1, T2 >* >( i->func );
235  assert( f );
236  for ( vector< Eref >::const_iterator
237  j = i->targets.begin(); j != i->targets.end(); ++j ) {
238  if ( j->dataIndex() == ALLDATA ) {
239  Element* e = j->element();
240  unsigned int start = e->localDataStart();
241  unsigned int end = start + e->numData();
242  for ( unsigned int k = start; k < end; ++k )
243  f->op( Eref( e, k ), arg1, arg2 );
244  } else {
245  f->op( *j, arg1, arg2 );
246  }
247  }
248  }
249  }
250 
251  void sendTo( const Eref& e, Id tgt,
252  const T1& arg1, const T2& arg2 ) const
253  {
254  const vector< MsgDigest >& md = e.msgDigest( getBindIndex() );
255  for ( vector< MsgDigest >::const_iterator
256  i = md.begin(); i != md.end(); ++i ) {
257  const OpFunc2Base< T1, T2 >* f =
258  dynamic_cast< const OpFunc2Base< T1, T2 >* >( i->func );
259  assert( f );
260  for ( vector< Eref >::const_iterator
261  j = i->targets.begin(); j != i->targets.end(); ++j ) {
262  if ( j->element() != tgt.element() )
263  continue; // Wasteful unless very few dests.
264  if ( j->dataIndex() == ALLDATA ) {
265  Element* e = j->element();
266  unsigned int start = e->localDataStart();
267  unsigned int end = start + e->numData();
268  for ( unsigned int k = start; k < end; ++k )
269  f->op( Eref( e, k ), arg1, arg2 );
270  } else {
271  f->op( *j, arg1, arg2 );
272  }
273  }
274  }
275  }
276 
277  void sendBuffer( const Eref& e, double* buf ) const
278  {
279  // Note that buf2val alters the buf ptr as a side-effect, in
280  // order to advance to the next argument. However, the order
281  // in which argument evaluation is called within a multi-
282  // argument function is undefined. So we have to explicitly
283  // ensure the ordering of argument calls.
284  const T1& arg1 = Conv< T1 >::buf2val( &buf );
285  send( e, arg1, Conv< T2 >::buf2val( &buf ) );
286  }
287 
288  string rttiType() const {
289  return Conv<T1>::rttiType() + "," + Conv< T2 >::rttiType();
290  }
291 
292  private:
293 };
294 
295 template< class A1, class A2, class A3 > class OpFunc3Base;
296 template < class T1, class T2, class T3 > class SrcFinfo3: public SrcFinfo
297 {
298  public:
300 
301  SrcFinfo3( const string& name, const string& doc )
302  : SrcFinfo( name, doc )
303  { ; }
304 
305  void send( const Eref& e,
306  const T1& arg1, const T2& arg2, const T3& arg3 ) const
307  {
308  const vector< MsgDigest >& md = e.msgDigest( getBindIndex() );
309  for ( vector< MsgDigest >::const_iterator
310  i = md.begin(); i != md.end(); ++i ) {
311  const OpFunc3Base< T1, T2, T3 >* f =
312  dynamic_cast< const OpFunc3Base< T1, T2, T3 >* >(
313  i->func );
314  assert( f );
315  for ( vector< Eref >::const_iterator
316  j = i->targets.begin(); j != i->targets.end(); ++j ) {
317  if ( j->dataIndex() == ALLDATA ) {
318  Element* e = j->element();
319  unsigned int start = e->localDataStart();
320  unsigned int end = start + e->numData();
321  for ( unsigned int k = start; k < end; ++k )
322  f->op( Eref( e, k ), arg1, arg2, arg3 );
323  } else {
324  f->op( *j, arg1, arg2, arg3 );
325  }
326  }
327  }
328  }
329 
330  void sendBuffer( const Eref& e, double* buf ) const
331  {
332  const T1& arg1 = Conv< T1 >::buf2val( &buf );
333  const T2& arg2 = Conv< T2 >::buf2val( &buf );
334  send( e, arg1, arg2, Conv< T3 >::buf2val( &buf ) );
335  }
336 
337  string rttiType() const {
338  return Conv<T1>::rttiType() + "," + Conv< T2 >::rttiType() +
339  "," + Conv<T3>::rttiType();
340  }
341 
342  private:
343 };
344 
345 template< class A1, class A2, class A3, class A4 > class OpFunc4Base;
346 template < class T1, class T2, class T3, class T4 > class SrcFinfo4: public SrcFinfo
347 {
348  public:
350 
351  SrcFinfo4( const string& name, const string& doc )
352  : SrcFinfo( name, doc )
353  { ; }
354 
355  // Will need to specialize for strings etc.
356  void send( const Eref& e,
357  const T1& arg1, const T2& arg2,
358  const T3& arg3, const T4& arg4 ) const
359  {
360  const vector< MsgDigest >& md = e.msgDigest( getBindIndex() );
361  for ( vector< MsgDigest >::const_iterator
362  i = md.begin(); i != md.end(); ++i ) {
364  dynamic_cast< const OpFunc4Base< T1, T2, T3, T4 >* >(
365  i->func );
366  assert( f );
367  for ( vector< Eref >::const_iterator
368  j = i->targets.begin(); j != i->targets.end(); ++j ) {
369  if ( j->dataIndex() == ALLDATA ) {
370  Element* e = j->element();
371  unsigned int start = e->localDataStart();
372  unsigned int end = start + e->numData();
373  for ( unsigned int k = start; k < end; ++k )
374  f->op( Eref( e, k ), arg1, arg2, arg3, arg4 );
375  } else {
376  f->op( *j, arg1, arg2, arg3, arg4 );
377  }
378  }
379  }
380  }
381 
382  void sendBuffer( const Eref& e, double* buf ) const
383  {
384  const T1& arg1 = Conv< T1 >::buf2val( &buf );
385  const T2& arg2 = Conv< T2 >::buf2val( &buf );
386  const T3& arg3 = Conv< T3 >::buf2val( &buf );
387  send( e, arg1, arg2, arg3, Conv< T4 >::buf2val( &buf ) );
388  }
389 
390  string rttiType() const {
391  return Conv<T1>::rttiType() + "," + Conv< T2 >::rttiType() +
392  "," + Conv<T3>::rttiType() + "," + Conv< T4 >::rttiType();
393  }
394 
395  private:
396 };
397 
398 template< class A1, class A2, class A3, class A4, class A5 >
399  class OpFunc5Base;
400 template < class T1, class T2, class T3, class T4, class T5 > class SrcFinfo5: public SrcFinfo
401 {
402  public:
404 
405  SrcFinfo5( const string& name, const string& doc )
406  : SrcFinfo( name, doc )
407  { ; }
408 
409  // Will need to specialize for strings etc.
410  void send( const Eref& e,
411  const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
412  const T5& arg5 ) const
413  {
414  const vector< MsgDigest >& md = e.msgDigest( getBindIndex() );
415  for ( vector< MsgDigest >::const_iterator
416  i = md.begin(); i != md.end(); ++i ) {
418  dynamic_cast<
419  const OpFunc5Base< T1, T2, T3, T4, T5 >* >( i->func );
420  assert( f );
421  for ( vector< Eref >::const_iterator
422  j = i->targets.begin(); j != i->targets.end(); ++j ) {
423  if ( j->dataIndex() == ALLDATA ) {
424  Element* e = j->element();
425  unsigned int start = e->localDataStart();
426  unsigned int end = start + e->numData();
427  for ( unsigned int k = start; k < end; ++k )
428  f->op( Eref( e, k ),
429  arg1, arg2, arg3, arg4, arg5 );
430  } else {
431  f->op( *j, arg1, arg2, arg3, arg4, arg5 );
432  }
433  }
434  }
435  }
436 
437  void sendBuffer( const Eref& e, double* buf ) const
438  {
439  const T1& arg1 = Conv< T1 >::buf2val( &buf );
440  const T2& arg2 = Conv< T2 >::buf2val( &buf );
441  const T3& arg3 = Conv< T3 >::buf2val( &buf );
442  const T4& arg4 = Conv< T4 >::buf2val( &buf );
443  send( e, arg1, arg2, arg3, arg4, Conv< T5 >::buf2val( &buf ) );
444  }
445 
446  string rttiType() const {
447  return Conv<T1>::rttiType() + "," + Conv< T2 >::rttiType() +
448  "," + Conv<T3>::rttiType() + "," + Conv< T4 >::rttiType() +
449  "," + Conv<T5>::rttiType();
450  }
451 
452  private:
453 };
454 
455 
456 template< class A1, class A2, class A3, class A4, class A5, class A6 >
457  class OpFunc6Base;
458 template < class T1, class T2, class T3, class T4, class T5, class T6 > class SrcFinfo6: public SrcFinfo
459 {
460  public:
462 
463  SrcFinfo6( const string& name, const string& doc )
464  : SrcFinfo( name, doc )
465  { ; }
466 
467  void send( const Eref& e,
468  const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
469  const T5& arg5, const T6& arg6 ) const
470  {
471  const vector< MsgDigest >& md = e.msgDigest( getBindIndex() );
472  for ( vector< MsgDigest >::const_iterator
473  i = md.begin(); i != md.end(); ++i ) {
475  dynamic_cast<
477  i->func );
478  assert( f );
479  for ( vector< Eref >::const_iterator
480  j = i->targets.begin(); j != i->targets.end(); ++j ) {
481  if ( j->dataIndex() == ALLDATA ) {
482  Element* e = j->element();
483  unsigned int start = e->localDataStart();
484  unsigned int end = start + e->numData();
485  for ( unsigned int k = start; k < end; ++k )
486  f->op( Eref( e, k ),
487  arg1, arg2, arg3, arg4, arg5, arg6 );
488  } else {
489  f->op( *j, arg1, arg2, arg3, arg4, arg5, arg6 );
490  }
491  }
492  }
493  }
494 
495  void sendBuffer( const Eref& e, double* buf ) const
496  {
497  const T1& arg1 = Conv< T1 >::buf2val( &buf );
498  const T2& arg2 = Conv< T2 >::buf2val( &buf );
499  const T3& arg3 = Conv< T3 >::buf2val( &buf );
500  const T4& arg4 = Conv< T4 >::buf2val( &buf );
501  const T5& arg5 = Conv< T5 >::buf2val( &buf );
502  send( e, arg1, arg2, arg3, arg4, arg5, Conv< T6 >::buf2val( &buf ) );
503  }
504 
505  string rttiType() const {
506  return Conv<T1>::rttiType() + "," + Conv< T2 >::rttiType() +
507  "," + Conv<T3>::rttiType() + "," + Conv< T4 >::rttiType() +
508  "," + Conv<T5>::rttiType() + "," + Conv< T6 >::rttiType();
509  }
510 
511  private:
512 };
513 
514 #endif // _SRC_FINFO_H
void sendBuffer(const Eref &e, double *buf) const
Definition: SrcFinfo.h:495
virtual void op(const Eref &e, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6) const =0
string rttiType() const
Definition: SrcFinfo.h:505
virtual void op(const Eref &e, A1 arg1, A2 arg2, A3 arg3, A4 arg4) const =0
SrcFinfo(const string &name, const string &doc)
Definition: SrcFinfo.cpp:18
SrcFinfo5(const string &name, const string &doc)
Definition: SrcFinfo.h:405
SrcFinfo1(const string &name, const string &doc)
Definition: SrcFinfo.h:102
virtual void op(const Eref &e, A arg) const =0
string rttiType() const
Definition: SrcFinfo.h:337
void sendBuffer(const Eref &e, double *buf) const
Definition: SrcFinfo.h:437
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
unsigned short BindIndex
Definition: header.h:62
BindIndex getBindIndex() const
Definition: SrcFinfo.cpp:28
bool addMsg(const Finfo *target, ObjId mid, Element *src) const
Definition: SrcFinfo.cpp:50
void sendTo(const Eref &er, Id tgt, T arg) const
Definition: SrcFinfo.h:134
virtual void sendBuffer(const Eref &e, double *buf) const =0
~SrcFinfo4()
Definition: SrcFinfo.h:349
~SrcFinfo2()
Definition: SrcFinfo.h:222
Definition: ObjId.h:20
const string & name() const
Definition: Finfo.cpp:80
Element * element() const
Definition: Eref.h:42
virtual void op(const Eref &e, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) const =0
void send(const Eref &e, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5) const
Definition: SrcFinfo.h:410
void send(const Eref &er, T arg) const
Definition: SrcFinfo.h:106
SrcFinfo2(const string &name, const string &doc)
Definition: SrcFinfo.h:224
~SrcFinfo3()
Definition: SrcFinfo.h:299
SrcFinfo4(const string &name, const string &doc)
Definition: SrcFinfo.h:351
~SrcFinfo0()
Definition: SrcFinfo.h:81
Definition: Conv.h:30
const unsigned int ALLDATA
Used by ObjId and Eref.
Definition: consts.cpp:22
const vector< MsgDigest > & msgDigest(unsigned int bindIndex) const
Definition: Eref.cpp:67
void send(const Eref &e, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4) const
Definition: SrcFinfo.h:356
void sendBuffer(const Eref &e, double *buf) const
Definition: SrcFinfo.cpp:92
unsigned short bindIndex_
Definition: SrcFinfo.h:70
~SrcFinfo()
Definition: SrcFinfo.h:29
void send(const Eref &e, const T1 &arg1, const T2 &arg2) const
Definition: SrcFinfo.h:228
void setBindIndex(BindIndex b)
Definition: SrcFinfo.cpp:36
~SrcFinfo6()
Definition: SrcFinfo.h:461
bool checkTarget(const Finfo *target) const
Definition: SrcFinfo.cpp:41
virtual void op(const Eref &e, A1 arg1, A2 arg2) const =0
void sendVec(const Eref &er, const vector< T > &arg) const
Definition: SrcFinfo.h:169
void sendTo(const Eref &e, Id tgt, const T1 &arg1, const T2 &arg2) const
Definition: SrcFinfo.h:251
Definition: Eref.h:26
virtual void op(const Eref &e, A1 arg1, A2 arg2, A3 arg3) const =0
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
bool strGet(const Eref &tgt, const string &field, string &returnValue) const
Definition: SrcFinfo.h:40
virtual unsigned int localDataStart() const =0
Returns index of first data entry on this node.
bool strSet(const Eref &tgt, const string &field, const string &arg) const
Definition: SrcFinfo.h:35
virtual unsigned int numLocalData() const =0
Returns number of local data entries on this node.
SrcFinfo3(const string &name, const string &doc)
Definition: SrcFinfo.h:301
string rttiType() const
Definition: SrcFinfo.h:390
void send(const Eref &e, const T1 &arg1, const T2 &arg2, const T3 &arg3) const
Definition: SrcFinfo.h:305
string rttiType() const
Definition: SrcFinfo.h:288
~SrcFinfo5()
Definition: SrcFinfo.h:403
void send(const Eref &e, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5, const T6 &arg6) const
Definition: SrcFinfo.h:467
static const T & buf2val(double **buf)
Definition: Conv.h:44
void send(const Eref &e) const
Definition: SrcFinfo.cpp:70
static string rttiType()
Definition: Conv.h:82
Definition: Id.h:17
void sendBuffer(const Eref &e, double *buf) const
Definition: SrcFinfo.h:277
void sendBuffer(const Eref &e, double *buf) const
Definition: SrcFinfo.h:205
string rttiType() const
Definition: SrcFinfo.h:446
string rttiType() const
Definition: SrcFinfo.h:87
string rttiType() const
Definition: SrcFinfo.h:210
void sendBuffer(const Eref &e, double *buf) const
Definition: SrcFinfo.h:330
static const BindIndex BadBindIndex
Definition: SrcFinfo.h:65
SrcFinfo0(const string &name, const string &doc)
Definition: SrcFinfo.cpp:65
Definition: Cinfo.h:18
SrcFinfo6(const string &name, const string &doc)
Definition: SrcFinfo.h:463
void sendBuffer(const Eref &e, double *buf) const
Definition: SrcFinfo.h:382
~SrcFinfo1()
Definition: SrcFinfo.h:100
Definition: Finfo.h:12
void registerFinfo(Cinfo *c)
Definition: SrcFinfo.cpp:22