DistributedNetwork.h

Go to the documentation of this file.
00001 #ifndef DISTRIBUTEDNETWORK_H_
00002 #define DISTRIBUTEDNETWORK_H_
00003 
00004 
00005 #include "globaldefinitions.h"
00006 #include "SimNetwork.h"
00007 
00008 #include <iostream>
00009 using std::cerr;
00010 using std::endl;
00011 
00012 #include <mpi.h>
00013 
00014 class DistributedSimEngine;
00015 
00017 
00023 class DistributedNetwork : public SimNetwork
00024 {
00025 public:
00026 
00027 
00029     DistributedNetwork( int nThreads, SimParameter sp = SimParameter::Default );
00030 
00031 
00033     DistributedNetwork( int nThreads, MPI::Intracomm &mpiCommunicator, SimParameter sp = SimParameter::Default );
00034 
00035 
00037     virtual ~DistributedNetwork();
00038 
00039 
00041     inline MPI::Intracomm &getMpiComm() { return mpi_comm; };
00042 
00043 
00045 
00049     virtual void _addObject_( const SimObjectFactory &objFactory, const SimEngine::ID &loc, SimObject::ID &gid );
00050 
00052     virtual void _addObject_( const SimObjectFactory &objFactory, SimObject::ID &id )
00053     {
00054         return _addObject_( objFactory, (*distributionStrategy)( this ), id );
00055     }
00056 
00057     virtual void _addSpikeMessage_(const SimObject::ID &sender, const port_t out, const SimObject::ID &receiver, const port_t in, const Time &delay);
00058 
00059     //
00061 
00062 
00064     virtual gl_engineid_t getGlobalEngineID( const SimEngine::ID &eid ) const;
00065 
00067     virtual gl_engineid_t getGlobalEngineID( engineid_t eng ) const;
00068 
00070     virtual gl_engineid_t maxGlobalEngineID(void) const;
00071 
00073     virtual gl_engineid_t maxLocalEngineID(void) const;
00074 
00076     virtual const SimEngine::ID getLocation( gl_engineid_t gEID ) const;
00077 
00079 
00080 public:
00081 
00082     struct ConnectInfo
00083     {
00084         ConnectInfo(void) :
00085                 //                managed_delay(0),
00086                 first_spike_output_port_id(INVALID_SPIKE_PORT_ID),
00087                 nSpikeInputPorts(0),
00088                 nSpikeOutputPorts(0),
00089                 nAnalogInputPorts(0),
00090                 nAnalogOutputPorts(0)
00091         { /*NOOP*/ };
00092 
00093         ConnectInfo(int sp, int si, int so, int ai, int ao) :
00094                 //                managed_delay(md),
00095                 first_spike_output_port_id(sp),
00096                 nSpikeInputPorts(si),
00097                 nSpikeOutputPorts(so),
00098                 nAnalogInputPorts(ai),
00099                 nAnalogOutputPorts(ao)
00100         { /*NOOP*/ };
00101 
00102         //        int managed_delay;
00103         int first_spike_output_port_id;
00104         int nSpikeInputPorts;
00105         int nSpikeOutputPorts;
00106         int nAnalogInputPorts;
00107         int nAnalogOutputPorts;
00108 
00109         bool operator!=(const ConnectInfo& other) const
00110         {
00111             return // ( this->managed_delay != other.managed_delay ) ||
00112                 ( this->first_spike_output_port_id != other.first_spike_output_port_id ) ||
00113                 ( this->nSpikeInputPorts != other.nSpikeInputPorts ) ||
00114                 ( this->nSpikeOutputPorts != other.nSpikeOutputPorts ) ||
00115                 ( this->nAnalogInputPorts != other.nAnalogInputPorts ) ||
00116                 ( this->nAnalogOutputPorts != other.nAnalogOutputPorts ) ;
00117         };
00118 
00119         bool operator==(const ConnectInfo& other) const
00120         {
00121             return // ( this->managed_delay == other.managed_delay ) &&
00122                 ( this->first_spike_output_port_id == other.first_spike_output_port_id ) &&
00123                 ( this->nSpikeInputPorts == other.nSpikeInputPorts ) &&
00124                 ( this->nSpikeOutputPorts == other.nSpikeOutputPorts ) &&
00125                 ( this->nAnalogInputPorts == other.nAnalogInputPorts ) &&
00126                 ( this->nAnalogOutputPorts == other.nAnalogOutputPorts ) ;
00127         };
00128 
00129     };
00130 
00131 protected:
00132 
00133     friend class DistributedMultiThreadNetworkTest;
00134 
00135     virtual void _mount_( const SimObjectFactory &objFactory, const SimObject::ID &mountpoint, SimObject::ID &gid );
00136 
00138     virtual void _insert_( const SimObjectFactory &objFactory, const SimObject::ID &container, SimObject::ID &gid );
00139 
00140     virtual void _addSpikeMessage_(const SimObject::ID &sender, const port_t out, const spike_port_id_t sender_port, const SimObject::ID &receiver, const port_t port, const step_t delay)
00141     {
00142         cerr << "THIS MUST NEVER HAPPEN!!!!" << endl;
00143     };
00144 
00146     /* The type of connection (spike or analog) is determined (guessed) automatically.
00147      * If delay < 0 then the value returned by the destination objects getManagedDelay() method is used.
00148      * If a positive value is specified this value overwrites the dstobj.getManagedDelay() value.
00149      * */
00150     virtual void _connect_( SimObject::ID const& src, port_t out, const SimObject::ID &dst, port_t in, int delay );
00151 
00152     // void locallyGetConnectInfo( const SimObject::ID &oid, ConnectInfo &ci );
00153     // void getConnectInfo( const SimObject::ID &sender, const SimObject::ID &receiver, ConnectInfo &senderInfo, ConnectInfo &receiverInfo );
00154     // void conditionallyExchangeConnectInfo( const ConnectInfo &senderInfo, const SimObject::ID &receiver, ConnectInfo &receiverInfo );
00155 
00156     // void getPortInfo( const SimObject::ID &sender,  SimObject::PortInfo &senderInfo  );
00157     spike_port_id_t getFirstSenderSpikePort( const SimObject::ID &oid );
00158     /*  spike_port_id_t getFirstSenderSpikePort( const SimObject::ID &sender, const port_t out, const SimObject::ID &receiver );
00159       spike_port_id_t locallyGetFirstSenderSpikePort( const SimObject::ID &sender, const port_t out  );
00160       void transFirstSenderPort( spike_port_id_t first_sender_port, nodeid_t rec_node );
00161       spike_port_id_t recvFirstSenderPort( const SimObject::ID &sender );
00162 
00163       double getManagedDelay( const SimObject::ID &sender, const SimObject::ID &receiver );
00164       double locallyGetManagedDelay( const SimObject::ID &sender );
00165       void transManagedDelay( const SimObject::ID &receiver, double d );
00166       double recvManagedDelay( const SimObject::ID &sender ); */
00167 
00168     // virtual local_objectid_t addObjectLocally( SimObject *o, engineid_t eng = 0 ) = 0;
00169 
00171     MPI::Intracomm &mpi_comm;
00172 
00174     DistributedSimEngine *distEngine;
00175 
00177 
00180     SimEngine *localSimEngine;
00181 
00183     vector< vector< gl_engineid_t > > glengineids;
00184 
00186     vector<bool> incomingConnections;
00187     vector<bool> outgoingConnections;
00188 
00190 
00193     void setupGlEngineIDs(unsigned int numLocalEngines = 1);
00194 
00196     gl_engineid_t _max_global_engine_id;
00197 
00199     vector< SimEngine::ID > location;
00200 
00201 
00202     local_objectid_t getGhostID( gl_engineid_t gEID, SimObjectFactory const& objFactory  );
00203 
00205     vector< vector< local_objectid_t > > objectCounter;
00206 
00208     vector< spike_port_id_t > spikePortCounter;
00209     // vector< vector< vector< SimObject::PortInfo > > > ghostPortInfo;
00210     vector< vector< vector< spike_port_id_t > > > ghostFirstPortInfo;
00211 
00212 
00213     virtual void seed_noise_rng( uint32 noise_seed );
00214 
00215         virtual uint32 getUniqueSeedOverMpi( uint32 seed );
00216 
00217 private:
00218     void init();
00219     int _nThreads;
00220     DistributionStrategy::GlobalRoundRobin globalRoundRobin;
00221 
00222 };
00223 
00224 
00225 ostream& operator<<(ostream &s, const DistributedNetwork::ConnectInfo &ci);
00226 
00227 
00228 #endif /*DISTRIBUTEDNETWORK_H_*/

Generated on Wed Jul 9 16:34:37 2008 for PCSIM by  doxygen 1.5.5