00001 #ifndef MULTITHREADNETWORK_H_
00002 #define MULTITHREADNETWORK_H_
00003
00004 #include <string>
00005 using std::string;
00006
00007 #include <boost/format.hpp>
00008
00009
00010
00011
00012 #include "SimObject.h"
00013 #include "SimNetwork.h"
00014
00015 #include "PropagatedSpikeBuffer.h"
00016 #include "MultiThreadSpikeScheduler.h"
00017 #include "MultiThreadSimEngine.h"
00018 #include "AnalogDelayObjectMap.h"
00019 #include "STAnalogMessageCreator.h"
00020 #include "MTAnalogMessageCreator.h"
00021
00022
00023
00025
00032 class MultiThreadNetwork : public SimNetwork {
00033
00034 public:
00036
00042 MultiThreadNetwork(int nThreads, SimParameter sp = SimParameter::Default );
00043
00044 MultiThreadNetwork(int nThreads, MPI::Intracomm &comm, SimParameter sp = SimParameter::Default );
00045
00046
00047
00048
00049
00050
00051
00052
00053 virtual ~MultiThreadNetwork();
00054
00055
00057
00058
00060
00073
00074
00076
00080 virtual void _addObject_( const SimObjectFactory &objFactory, const SimEngine::ID &loc, SimObject::ID &gid );
00081
00083 virtual void _addObject_( const SimObjectFactory &objFactory, SimObject::ID &gid );
00084
00086
00088
00089
00091
00092 virtual void _addSpikeMessage_(const SimObject::ID &sender, const port_t out, const SimObject::ID &receiver, const port_t in, const Time &delay);
00093
00095 virtual void _addAnalogMessage_(const SimObject::ID &sender, int sender_port, const SimObject::ID &receiver, int recv_port, const Time &delay);
00096
00097 virtual void _addAnalogMessage_(const SimObject::ID &sender, int sender_port, const SimObject::ID &receiver, string destfield, const Time &delay);
00098
00099 virtual void _addAnalogMessage_(const SimObject::ID &sender, string srcfield, const SimObject::ID &receiver, int recv_port, const Time &delay);
00100
00101 virtual void _addAnalogMessage_(const SimObject::ID &sender, string srcfield, const SimObject::ID &receiver, string destfield, const Time &delay);
00102
00104
00105
00107
00108
00110 virtual gl_engineid_t maxLocalEngineID(void) const;
00111
00113
00114 protected:
00115
00116 friend class DistributedSingleThreadNetwork;
00117 friend class DistributedMultiThreadNetwork;
00118
00120
00123 virtual void _reset_();
00124
00126
00133 virtual void _advance_( int nSteps = 1 );
00134
00136 virtual void _initialize_();
00137
00138 static void addLocalSpikeMessage(
00139 MTSpikeRoutingTables *arg_tables, SimEngine *arg_simEngine, const SimParameter &SP,
00140 const SimObject::ID &sender, spike_port_id_t sender_port, const SimObject::ID &receiver, const port_t in_port, step_t delay
00141 );
00142
00144 virtual void _mount_( const SimObjectFactory &objFactory, const SimObject::ID &mountpoint, SimObject::ID &gid );
00145
00147 virtual void _insert_( const SimObjectFactory &objFactory, const SimObject::ID &container, SimObject::ID &gid );
00148
00150
00151
00152
00153
00154 virtual void _connect_( SimObject::ID const& src, port_t out, const SimObject::ID &dst, port_t in, int delay );
00155
00157
00168 virtual SimObject * _getObject_(const SimObject::ID &id);
00169
00171
00198 template<typename srcType, typename destType>
00199 int addGenericAnalogMessage(const SimObject::ID &sender,
00200 srcType senderPortOrField,
00201 const SimObject::ID &receiver,
00202 destType recvPortOrField, delay_t delay) {
00203 if (sender.eng == receiver.eng) {
00204 return stAnalogMsgCreators[sender.eng]->addAnalogMessage(sender,
00205 senderPortOrField,
00206 receiver,
00207 recvPortOrField,
00208 delay);
00209 } else {
00210 if( delay < simParam.minDelay.in_steps( simParam.dt ) || delay > simParam.maxDelay.in_steps( simParam.dt ) ) {
00211 throw(
00212 PCSIM::ConstructionException(
00213 "MultiThreadNetwork::addGenericAnalogMessage",
00214 str( boost::format("Specified delay (%1% ms) out of range (min=%2% ms, max=%3% ms).") %
00215 (delay * simParam.dt.in_ms()) % simParam.minDelay.in_ms() % simParam.maxDelay.in_ms() )
00216 )
00217 );
00218 }
00219 return mtAnalogMsgCreator->addAnalogMessage(sender,
00220 senderPortOrField,
00221 receiver,
00222 recvPortOrField,
00223 delay);
00224 }
00225
00226 }
00227
00229 int nThreads;
00230
00232 MTSpikeRoutingTables *tables;
00233
00235 ThreadPool thrPool;
00236
00238 vector<PropagatedSpikeBuffer*> STBuffers;
00239
00241 MultiThreadSpikeScheduler *spikeScheduler;
00242
00244
00247 MultiThreadSimEngine *simEngine;
00248
00249 vector<MultiThreadAnalogMsgDispatcher*> analogMsgDispatchers;
00250
00251 vector< STAnalogMessageCreator *> stAnalogMsgCreators;
00252
00253 MTAnalogMessageCreator *mtAnalogMsgCreator;
00254
00255 AnalogDelayObjectMap *analogDelayObjectsMap;
00256
00257 virtual void seed_noise_rng( uint32 noise_seed );
00258
00259 private:
00260 void init();
00261 DistributionStrategy::LocalRoundRobin localRoundRobin;
00262 };
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 #endif