00001 #include "DistributionStrategy.h"
00002 #include "DistributedNetwork.h"
00003
00004 #include <iostream>
00005
00006 using std::cerr;
00007 using std::endl;
00008
00009 SimEngine::ID DistributionStrategy::ModuloOverGlobalEngines::operator()( DistributedNetwork* net )
00010 {
00011 e = e % (net->maxGlobalEngineID() + 1);
00012 return net->getLocation( e++ );
00013 }
00014
00015 SimEngine::ID DistributionStrategy::ModuloOverGlobalEngines::operator()( SimNetwork* net )
00016 {
00017 e = e % (net->maxLocalEngineID() + 1);
00018 return SimEngine::ID( net->mpi_rank(), e );
00019 }
00020
00021 SimEngine::ID DistributionStrategy::ModuloOverLocalEngines::operator()( DistributedNetwork* net )
00022 {
00023 e = e % (net->maxLocalEngineID() + 1);
00024
00025 return SimEngine::ID( net->mpi_rank() , e++ );
00026 }
00027
00028 SimEngine::ID DistributionStrategy::ModuloOverLocalEngines::operator()( SimNetwork* net )
00029 {
00030 e = e % (net->maxLocalEngineID() + 1);
00031
00032 return SimEngine::ID( net->mpi_rank() , e++ );
00033 }
00034
00035 SimEngine::ID DistributionStrategy::ModuloOverLocalEnginesOnOneNode::operator()( DistributedNetwork* net )
00036 {
00037 e = e % (net->maxLocalEngineID() + 1);
00038 return SimEngine::ID( node , e++ );
00039 }
00040
00041 SimEngine::ID DistributionStrategy::ModuloOverLocalEnginesOnOneNode::operator()( SimNetwork* net )
00042 {
00043 e = e % (net->maxLocalEngineID() + 1);
00044 return SimEngine::ID( node , e++ );
00045 }
00046
00047
00048 SimEngine::ID DistributionStrategy::RandomOverGlobalEngines::operator()( DistributedNetwork* net )
00049 {
00050 gl_engineid_t gEID = (gl_engineid_t)( (int)( (*(net->getMainConstructRNGEngine()))() * net->maxGlobalEngineID() + 0.5 ) );
00051 return net->getLocation( gEID );
00052 }
00053
00054
00055
00056
00057
00058
00059
00060 SimEngine::ID DistributionStrategy::RandomOverLocalEngines::operator()( SimNetwork* net )
00061 {
00062 engineid_t gEID = (engineid_t)( (int)( (*(net->getMainConstructRNGEngine()))() * net->maxLocalEngineID() + 0.5 ) );
00063 return SimEngine::ID( net->mpi_rank() , gEID );
00064 }
00065
00066 SimEngine::ID DistributionStrategy::RandomOverLocalEngines::operator()( DistributedNetwork* net )
00067 {
00068 engineid_t gEID = (engineid_t)( (int)( (*(net->getMainConstructRNGEngine()))() * net->maxLocalEngineID() + 0.5 ) );
00069 return SimEngine::ID( net->mpi_rank() , gEID );
00070 }
00071
00072
00073
00074 SimEngine::ID DistributionStrategy::EngineListStrategy::operator()( SimNetwork* net )
00075 {
00076 if(engine_list.empty()) {
00077 cerr << "engine_list empty!!!" << endl;
00078 engineid_t gEID = (engineid_t)( (int)( (*(net->getMainConstructRNGEngine()))() * net->maxLocalEngineID() + 0.5 ) );
00079 return SimEngine::ID( net->mpi_rank() , gEID );
00080 }
00081
00082 engineid_t gEID = (engineid_t) engine_list.front();
00083 engine_list.pop_front();
00084
00085 return SimEngine::ID( net->mpi_rank() , gEID );
00086 }
00087
00088
00089 SimEngine::ID DistributionStrategy::EngineListStrategy::operator()( DistributedNetwork* net )
00090 {
00091 if(engine_list.empty()) {
00092 cerr << "engine_list empty!!!" << endl;
00093 gl_engineid_t gEID = (gl_engineid_t)( (int)( (*(net->getMainConstructRNGEngine()))() * net->maxGlobalEngineID() + 0.5 ) );
00094 return net->getLocation( gEID );
00095 }
00096
00097 gl_engineid_t gEID = (gl_engineid_t) engine_list.front();
00098 engine_list.pop_front();
00099
00100 return net->getLocation( gEID );
00101 }
00102
00103
00104
00105 SimEngine::ID DistributionStrategy::RankListStrategy::operator()( SimNetwork* net )
00106 {
00107 if(rank_list.empty()) {
00108 cerr << "rank_list empty!!!" << endl;
00109 engineid_t gEID = (engineid_t)( (int)( (*(net->getMainConstructRNGEngine()))() * net->maxLocalEngineID() + 0.5 ) );
00110 return SimEngine::ID( net->mpi_rank() , gEID );
00111 }
00112
00113 e = e % (net->maxLocalEngineID() + 1);
00114 int rank = (int) rank_list.front();
00115 rank_list.pop_front();
00116
00117 return SimEngine::ID( rank, e );
00118 }
00119
00120
00121
00122 SimEngine::ID DistributionStrategy::RankListStrategy::operator()( DistributedNetwork* net )
00123 {
00124 if(rank_list.empty()) {
00125 cerr << "rank_list empty!!!" << endl;
00126 gl_engineid_t gEID = (gl_engineid_t)( (int)( (*(net->getMainConstructRNGEngine()))() * net->maxGlobalEngineID() + 0.5 ) );
00127 return net->getLocation( gEID );
00128 }
00129
00130 e = e % (net->maxLocalEngineID() + 1);
00131 int rank = (int) rank_list.front();
00132 rank_list.pop_front();
00133
00134 return SimEngine::ID(rank, e++ );
00135 }