MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Shell.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 
10 #ifndef _SHELL_H
11 #define _SHELL_H
12 
13 #include <string>
14 
15 using namespace std;
16 
17 
18 class DestFinfo;
19 
21 
22 // These Finfo objects are exposed to other classes for convenience in test cases and other functions.
23 // NOTE: These should never be re-registered in an initCinfo of another class.
24 //extern SrcFinfo4< Id, DataId, FuncId, unsigned int >* requestGet(); // Not available
25 extern DestFinfo* receiveGet();
26 //extern SrcFinfo2< unsigned int, unsigned int >* ack(); // Not currently used.
27 
30 {
31 public:
32  NodeBalance( unsigned int nd, NodePolicy np, unsigned int node )
33  : numData( nd ), policy( np ), preferredNode( node )
34  {
35  ;
36  }
37 
38  unsigned int numData;
40  unsigned int preferredNode;
41 };
42 
43 class Shell
44 {
45 public:
46  Shell();
47  ~Shell();
48 
49 #ifdef CYMOOSE
50 
60  Shell* initShell();
61 
62 
78  Id create( string type, string name, unsigned int numData,
79  NodePolicy nodePolicy = MooseBlockBalance,
80  unsigned int preferredNode = 1 );
81 
82 
83 #endif /* ----- CYMOOSE ----- */
84  // Field functions
87 
90  string doVersion();
91 
95  void setCwe( ObjId cwe );
96 
100  ObjId getCwe() const;
101 
105  bool isRunning() const;
106 
108  // Parser functions
110 
118  Id doCreate( string type, ObjId parent, string name,
119  unsigned int numData,
120  NodePolicy nodePolicy = MooseBlockBalance,
121  unsigned int preferredNode = 1 );
122 
130  bool doDelete( ObjId oid );
131 
138  ObjId doAddMsg( const string& msgType,
139  ObjId src, const string& srcField,
140  ObjId dest, const string& destField );
141 
145  void doQuit( );
146 
153  void doStart( double runtime, bool notify = false );
154 
164  void doNonBlockingStart( double runtime );
165 
171  void doReinit();
172 
177  void doStop();
178 
184  void doTerminate();
185 
190  void doMove( Id orig, ObjId newParent );
191 
198  Id doCopy( Id orig, ObjId newParent, string newName,
199  unsigned int n, bool toGlobal, bool copyExtMsgs );
200 
206  ObjId doFind( const string& path ) const;
207 
215  void doUseClock( string path, string field, unsigned int tick );
216 
224  Id doLoadModel( const string& fname, const string& modelpath,
225  const string& solverClass = "" );
226 
239  void doSaveModel( Id model, const string& fileName, bool qflag = 0 ) const;
240 
247  void doSyncDataHandler( Id tgt );
248 
256  void doReacDiffMesh( Id baseCompartment );
257 
265  void doSetParserIdleFlag( bool isParserIdle );
266 
273  static void clearRestructuringQ();
275  // DestFinfo functions
277 
282  void start( double runTime );
283 
290  void initAck();
291 
296  void waitForAck();
297 
302  void handleAck( unsigned int ackNode, unsigned int status );
303 
307  bool isAckPending() const;
308 
313  void handleQuit();
314 
315  void handleCreate( const Eref& e,
316  string type, ObjId parent, Id newElm, string name,
317  NodeBalance nb, unsigned int parentMsgIndex );
318  void destroy( const Eref& e, ObjId oid);
319 
328  void innerCreate( string type, ObjId parent, Id newElm, string name,
329  const NodeBalance& nb, unsigned int parentMsgIndex );
330 
332  bool innerCopy( const vector< ObjId >& args, const string& newName,
333  unsigned int n, bool toGlobal, bool copyExtMsgs );
334 
341  const Msg* innerAddMsg( string msgType, ObjId src, string srcField,
342  ObjId dest, string destField, unsigned int msgIndex );
343 
349  void handleAddMsg( const Eref& e,
350  string msgType,
351  ObjId src, string srcField,
352  ObjId dest, string destField,
353  unsigned int msgIndex );
354 
358  bool innerMove( Id orig, ObjId newParent );
359 
363  void handleMove( const Eref& e,
364  Id orig, ObjId newParent );
365 
369  void handleSync( const Eref& e, Id elm, FuncId fid);
370 
380  void handleCopy( const Eref& e,
381  vector< ObjId > args, string newName, unsigned int n,
382  bool toGlobal, bool copyExtMsgs );
383 
387  bool innerUseClock( string path, string field,
388  unsigned int tick, unsigned int msgIndex);
389 
390  void handleUseClock( const Eref& e,
391  string path, string field, unsigned int tick,
392  unsigned int msgIndex );
393 
398  void addClockMsgs( const vector< ObjId >& list,
399  const string& field, unsigned int tick, unsigned int msgIndex );
400 
405  static void dropClockMsgs(
406  const vector< ObjId >& list, const string& field );
407 
409  // Thread and MPI handling functions
411 
416  static void setHardware(
417  unsigned int numCores, unsigned int numNodes,
418  unsigned int myNode );
419 
420  static unsigned int myNode();
421  static unsigned int numNodes();
422  static unsigned int numCores();
423  static unsigned int numProcessThreads();
424 
429  static void loadBalance();
430 
431  static void launchParser();
432 
437  static bool inBlockingParserCall();
438 
448  static bool isSingleThreaded();
449 
453  static bool keepLooping();
454 
459  static bool isParserIdle();
460 
466  static void launchThreads();
467 
471  static unsigned int reduceInt( unsigned int val );
472 
474  // Sets up clock ticks. Essentially is a call into the
475  // Clock::setupTick function, but may be needed to be called from
476  // the parser so it is a Shell function too.
477  void doSetClock( unsigned int tickNum, double dt );
478 
479  // Should set these up as streams so that we can build error
480  // messages similar to cout.
481  void warning( const string& text );
482  void error( const string& text );
483 
484  static const Cinfo* initCinfo();
485 
487  // Utility functions
489  static bool adopt( ObjId parent, Id child, unsigned int msgIndex );
490  static bool adopt( Id parent, Id child, unsigned int msgIndex );
491 
492  static const unsigned int OkStatus;
493  static const unsigned int ErrorStatus;
494 
495  // Initialization function, used only in main.cpp:init()
496  void setShellElement( Element* shelle );
497 
499  static const ProcInfo* procInfo();
500 
501  const ProcInfo* getProcInfo( unsigned int index ) const;
502 
509  static bool chopString( const string& path, vector< string >& ret,
510  char separator = '/' );
511 
516  static bool isNameValid( const string& name );
517 
532  static bool chopPath( const string& path, vector< string >& ret,
533  vector< unsigned int >& index );
534 
535  // static void wildcard( const string& path, vector< Id >& list );
536 
543  static void cleanSimulation();
544 
548  void expectVector( bool flag );
549 
550 private:
551  Element* shelle_; // It is useful for the Shell to have this.
552 
558  vector< double* > getBuf_;
559 
565 
570  unsigned int numGetVecReturns_;
571 
577  static bool isBlockedOnParser_;
578 
583  static bool keepLooping_;
584 
588  static unsigned int numCores_;
589 
595  static unsigned int numProcessThreads_;
596 
601  static unsigned int numNodes_;
602 
606  static unsigned int myNode_;
607 
613  static ProcInfo p_;
614 
615  static vector< ProcInfo > threadProcs_;
616 
621  static unsigned int numAcks_;
622  static vector< unsigned int > acked_;
623 
624 
629  static bool doReinit_;
630 
634  static double runtime_;
635 
636  static bool isParserIdle_;
637 
640 };
641 
642 /*
643 extern bool set( Eref& dest, const string& destField, const string& val );
644 
645 extern bool get( const Eref& dest, const string& destField );
646 */
647 
648 #endif // _SHELL_H
static unsigned int numCores
NodePolicy policy
Definition: Shell.h:39
static ProcInfo p_
Definition: Shell.h:613
static double runtime_
Definition: Shell.h:634
static unsigned int myNode_
Definition: Shell.h:606
static bool keepLooping_
Definition: Shell.h:583
static bool isParserIdle_
Definition: Shell.h:636
static unsigned int numAcks_
Definition: Shell.h:621
DestFinfo * receiveGet()
static const unsigned int OkStatus
Definition: Shell.h:492
Definition: ObjId.h:20
ObjId cwe_
Current working Element.
Definition: Shell.h:639
static vector< ProcInfo > threadProcs_
Definition: Shell.h:615
NodePolicy
Definition: Shell.h:28
static unsigned int numNodes_
Definition: Shell.h:601
static unsigned int numProcessThreads_
Definition: Shell.h:595
static bool isBlockedOnParser_
Definition: Shell.h:577
Definition: Shell.h:20
vector< double * > getBuf_
Definition: Shell.h:558
static unsigned int myNode
unsigned int numData
Definition: Shell.h:38
static unsigned int numCores_
Definition: Shell.h:588
Definition: Eref.h:26
NodeBalance(unsigned int nd, NodePolicy np, unsigned int node)
Definition: Shell.h:32
Definition: Msg.h:18
Definition: Shell.h:20
static unsigned int numNodes
static char name[]
Definition: mfield.cpp:401
bool gettingVector_
Definition: Shell.h:564
unsigned int numGetVecReturns_
Definition: Shell.h:570
static const unsigned int ErrorStatus
Definition: Shell.h:493
Definition: Id.h:17
static vector< unsigned int > acked_
Definition: Shell.h:622
Element * shelle_
Definition: Shell.h:551
unsigned int FuncId
Definition: header.h:42
unsigned int preferredNode
Definition: Shell.h:40
AssignmentType
Definition: Shell.h:20
Definition: Cinfo.h:18
static char path[]
Definition: mfield.cpp:403
static bool doReinit_
Definition: Shell.h:629
Definition: Shell.h:20
Definition: Shell.h:43