DistributionStrategy.h

Go to the documentation of this file.
00001 #ifndef DistributionStrategy_H_
00002 #define DistributionStrategy_H_
00003 
00004 #include "SimEngine.h"
00005 #include "SimpleRandomNumberGenerator.h"
00006 #include "RandomDistribution.h"
00007 
00008 #include <mpi.h>
00009 
00010 #include <vector>
00011 using std::vector;
00012 
00013 #include <list>
00014 using std::list;
00015 
00016 #include <functional>
00017 using std::unary_function;
00018 
00019 class SimNetwork;
00020 class DistributedNetwork;
00021 
00022 class DistributionStrategy
00023 {
00024 
00025 public:
00026 
00027 class DistributionFunction : public unary_function<SimNetwork*, SimEngine::ID>
00028     {
00029     public:
00030         virtual SimEngine::ID operator()( SimNetwork* dn ) = 0;
00031         virtual SimEngine::ID operator()( DistributedNetwork* dn ) = 0;
00032         virtual ~DistributionFunction()
00033         { /*NOOP*/
00034         };
00035     };
00036 
00037 
00038 class ModuloOverGlobalEngines : public DistributionFunction
00039     {
00040     public:
00041         ModuloOverGlobalEngines(void)
00042         {
00043             e = 0;
00044         };
00045         virtual ~ModuloOverGlobalEngines()
00046         { /*NOOP*/
00047         };
00048         virtual SimEngine::ID operator()( SimNetwork* net );
00049         virtual SimEngine::ID operator()( DistributedNetwork* dn );
00050 
00051     private:
00052         int e;
00053     };
00054 
00055 
00056 class ModuloOverLocalEngines : public DistributionFunction
00057     {
00058     public:
00059         ModuloOverLocalEngines()
00060         {
00061             e = 0;
00062         };
00063         virtual ~ModuloOverLocalEngines()
00064         { /*NOOP*/
00065         };
00066         virtual SimEngine::ID operator()( SimNetwork* net );
00067         virtual SimEngine::ID operator()( DistributedNetwork* dn );
00068 
00069     private:
00070         int e;
00071     };
00072 
00073     typedef ModuloOverGlobalEngines GlobalRoundRobin;
00074     typedef ModuloOverLocalEngines LocalRoundRobin;
00075 
00076 class ModuloOverLocalEnginesOnOneNode : public DistributionFunction
00077     {
00078     public:
00079         ModuloOverLocalEnginesOnOneNode(nodeid_t node)
00080                 : node(node)
00081         {
00082             e = 0;
00083         };
00084         virtual ~ModuloOverLocalEnginesOnOneNode()
00085         { /*NOOP*/
00086         };
00087         virtual SimEngine::ID operator()( SimNetwork* net );
00088         virtual SimEngine::ID operator()( DistributedNetwork* dn );
00089 
00090     private:
00091         int e;
00092         nodeid_t node;
00093 
00094     };
00095 
00096 class RandomOverGlobalEngines : public DistributionFunction
00097     {
00098     public:
00099         RandomOverGlobalEngines( const MPI::Intracomm &mpiCommunicator )
00100         {
00101             // uni = new UniformDistribution<  >( 0, 1, mpiCommunicator );
00102         };
00103 
00104 
00105         virtual ~RandomOverGlobalEngines()
00106         {
00107             // delete uni;
00108         };
00109 
00110         virtual SimEngine::ID operator()( SimNetwork* net )
00111         {
00112             return SimEngine::ID::Invalid;
00113         };
00114         virtual SimEngine::ID operator()( DistributedNetwork* dn );
00115 
00116     private:
00117         // UniformDistribution< > *uni;
00118     };
00119 
00120 
00121 class RandomOverLocalEngines : public DistributionFunction
00122     {
00123     public:
00124         RandomOverLocalEngines(void)
00125         {
00126             // uni = new UniformDistribution< >( 0, 1 );
00127         };
00128 
00129 
00130         virtual ~RandomOverLocalEngines()
00131         {
00132             // delete uni;
00133         };
00134 
00135         virtual SimEngine::ID operator()( SimNetwork* net );
00136         virtual SimEngine::ID operator()( DistributedNetwork* dn );
00137 
00138     private:
00139         // UniformDistribution< > *uni;
00140     };
00141 
00142     typedef RandomOverGlobalEngines GlobalRandom;
00143     typedef RandomOverLocalEngines LocalRandom;
00144 
00145 
00146 
00147 class EngineListStrategy: public DistributionFunction
00148     {
00149     public:
00150         EngineListStrategy(void)
00151         {
00152         };
00153 
00154         void setEngineList(const list<int> &the_engine_list)
00155         {
00156             engine_list = the_engine_list;
00157         };
00158 
00159         void addEngineList(const int e)
00160         {
00161             engine_list.push_back( e );
00162         };
00163 
00164         virtual ~EngineListStrategy()
00165         {
00166         };
00167 
00168         virtual SimEngine::ID operator()( SimNetwork* net );
00169         virtual SimEngine::ID operator()( DistributedNetwork* dn );
00170 
00171     protected:
00172         list<int> engine_list;
00173 
00174     };
00175 
00176 
00177 class RankListStrategy: public DistributionFunction
00178     {
00179     public:
00180         RankListStrategy(void)
00181         {
00182             e = 0;
00183         };
00184 
00185         void setRankList(const list<int> &the_rank_list)
00186         {
00187             rank_list = the_rank_list;
00188         };
00189 
00190         void addEngineList(const int e)
00191         {
00192             rank_list.push_back( e );
00193         };
00194 
00195         virtual ~RankListStrategy()
00196         {
00197         };
00198 
00199         virtual SimEngine::ID operator()( SimNetwork* net );
00200         virtual SimEngine::ID operator()( DistributedNetwork* dn );
00201 
00202     protected:
00203         list<int> rank_list;
00204         int e;
00205 
00206     };
00207 
00208 };
00209 
00210 #endif /* DistributionStrategy_H_ */

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