DistributedSyncWiringMethod.cpp

Go to the documentation of this file.
00001 
00011 #include "DistributedSyncWiringMethod.h"
00012 
00013 SimObject::ID::Vector DistributedSyncWiringMethod::connect(
00014     const SimObjectPopulation &srcPopulation,
00015     const SimObjectPopulation &destPopulation,
00016     const SimObjectFactory &connector,
00017     ConnectionIterator &decider,
00018     bool collectIDs,
00019     bool collectPairs,
00020     WiringMethod::ConnectPairsVector connectPairs )
00021 {
00022     decider.init(srcPopulation, destPopulation);
00023     SimObject::ID::SortedVector src_vec(srcPopulation.idVector(),net->mpi_rank());
00024     SimObject::ID::SortedVector dest_vec(destPopulation.idVector(),net->mpi_rank());
00025 
00026     SimObject::ID::Vector collids(new vector<SimObject::ID::Packed>(0));
00027     unsigned cnt = 0;
00028     SimObject::ID id;
00029 
00030     // create incoming connections
00031     src_vec.startBlockIteration();
00032     while (src_vec.hasNextBlock()) {
00033         nodeid_t curr_node = src_vec.nextBlock();
00034         RandomEngine *re = net->getIncomingConstructRNGEngines()[curr_node];
00035         //re->seed( curr_node );
00036         //cerr << "----------" << curr_node << "=>" << net->mpi_rank() << " : " << (*re)() << endl;
00037         decider.setRNDEngine(re );
00038         if ( (src_vec.beginBlock() != src_vec.endBlock() )
00039                 && (dest_vec.localIDsBegin() != dest_vec.localIDsEnd() )) {
00040             decider.reset(src_vec.beginBlock(),
00041                                             src_vec.endBlock(), dest_vec.localIDsBegin(),
00042                                             dest_vec.localIDsEnd());
00043             pair<SimObject::ID, SimObject::ID> connect_pair;
00044             while (decider.next( connect_pair ) ) {
00045 
00046                 net->connect( connect_pair.first, connect_pair.second, connector, id );
00047 
00048                 if (collectIDs) {
00049                     collids->push_back(id.packed() );
00050                 }
00051                 if (collectPairs) {
00052                     connectPairs->push_back(connect_pair);
00053                 }
00054                 cnt++;
00055             }
00056         }
00057     }
00058 
00059     // create outgoing connections
00060     dest_vec.startBlockIteration();
00061     while (dest_vec.hasNextBlock()) {
00062         nodeid_t curr_node = dest_vec.nextBlock();
00063         if (curr_node != net->mpi_rank()) {
00064             RandomEngine *re = net->getOutgoingConstructRNGEngines()[curr_node];
00065             //re->seed( net->mpi_rank() );
00066             //cerr << "----------" << curr_node << "<=" << net->mpi_rank() << " : " << (*re)() << endl;
00067             decider.setRNDEngine(re );
00068             if ( (src_vec.localIDsBegin() != src_vec.localIDsEnd() )
00069                     && (dest_vec.beginBlock() != dest_vec.endBlock() )) {
00070                 decider.reset (src_vec.localIDsBegin(), src_vec.localIDsEnd(),
00071                                dest_vec.beginBlock(), dest_vec.endBlock());
00072 
00073                 pair<SimObject::ID, SimObject::ID> connect_pair;
00074 
00075                 while( decider.next( connect_pair ) ) {
00076 
00077                     net->connect(connect_pair.first, connect_pair.second,
00078                                  connector, id );
00079                     //                    pcp
00080                     if (collectIDs) {
00081                         collids->push_back(id.packed() );
00082                     }
00083                     if (collectPairs) {
00084                         connectPairs->push_back(connect_pair);
00085                     }
00086                     cnt++;
00087                 }
00088             }
00089         }
00090     }
00091 
00092     if (!collectIDs)
00093         collids->push_back((SimObject::ID::Packed)cnt);
00094 
00095     return collids;
00096 }
00097 
00098 unsigned DistributedSyncWiringMethod::connect(
00099     const SimObjectPopulation &srcPopulation,
00100     const SimObjectPopulation &destPopulation,
00101     ConnectionIterator &decider,
00102     bool collectPairs,
00103     WiringMethod::ConnectPairsVector connectPairs)
00104 {
00105   
00106     decider.init(srcPopulation, destPopulation);
00107     
00108     SimObject::ID::SortedVector src_vec( srcPopulation.idVector(), net->mpi_rank() );
00109     SimObject::ID::SortedVector dest_vec( destPopulation.idVector(), net->mpi_rank() );
00110 
00111     unsigned cnt = 0;
00112 
00113     // create incoming connections
00114     src_vec.startBlockIteration();
00115     while (src_vec.hasNextBlock()) {
00116         nodeid_t curr_node = src_vec.nextBlock();
00117         decider.setRNDEngine(net->getIncomingConstructRNGEngines()[curr_node]);
00118         if ( (src_vec.beginBlock() != src_vec.endBlock() )
00119                 && (dest_vec.localIDsBegin() != dest_vec.localIDsEnd() )) {
00120             decider.reset(src_vec.beginBlock(), src_vec.endBlock(),
00121                           dest_vec.localIDsBegin(), dest_vec.localIDsEnd());
00122 
00123             pair<SimObject::ID, SimObject::ID> connect_pair;
00124 
00125             while (decider.next(connect_pair)) {
00126 
00127                 net->connect(connect_pair.first, connect_pair.second);
00128                 //                pcp
00129                 if (collectPairs) {
00130                     connectPairs->push_back(connect_pair);
00131                 }
00132                 cnt++;
00133             }
00134         }
00135     }
00136 
00137     // create outgoing connections
00138     dest_vec.startBlockIteration();
00139     while (dest_vec.hasNextBlock()) {
00140         nodeid_t curr_node = dest_vec.nextBlock();
00141         if (curr_node != net->mpi_rank()) {
00142             decider.setRNDEngine(net->getOutgoingConstructRNGEngines()[curr_node]);
00143             if ( (src_vec.localIDsBegin() != src_vec.localIDsEnd() )
00144                     && (dest_vec.beginBlock() != dest_vec.endBlock() )) {
00145                 decider.reset(src_vec.localIDsBegin(), src_vec.localIDsEnd(),
00146                               dest_vec.beginBlock(),dest_vec.endBlock());
00147 
00148                  pair<SimObject::ID, SimObject::ID> connect_pair;
00149 
00150                 while (decider.next(connect_pair)) {
00151 
00152                     net->connect(connect_pair.first, connect_pair.second);
00153                     //                    pcp
00154                     if (collectPairs) {
00155                         connectPairs->push_back(connect_pair);
00156                     }
00157                     cnt++;
00158                 }
00159             }
00160         }
00161     }
00162 
00163     return cnt;
00164 }
00165 
00166 
00167 SimObject::ID::Vector DistributedSyncWiringMethod::connect(
00168     const SimObjectPopulation &srcPopulation,
00169     const SimObjectPopulation &destPopulation,
00170     ConnObjectFactory &connector,
00171     ConnectionIterator &decider,
00172     bool collectIDs,
00173     bool collectPairs,
00174     WiringMethod::ConnectPairsVector connectPairs )
00175 {
00176     decider.init(srcPopulation, destPopulation);
00177     SimObject::ID::SortedVector src_vec(srcPopulation.idVector(),net->mpi_rank());
00178     SimObject::ID::SortedVector dest_vec(destPopulation.idVector(),net->mpi_rank());
00179 
00180     SimObject::ID::Vector collids(new vector<SimObject::ID::Packed>(0));
00181     unsigned cnt = 0;
00182     SimObject::ID id;
00183 
00184     // create incoming connections
00185     src_vec.startBlockIteration();
00186     while (src_vec.hasNextBlock()) {
00187         nodeid_t curr_node = src_vec.nextBlock();
00188         RandomEngine *re = net->getIncomingConstructRNGEngines()[curr_node];
00189         //re->seed( curr_node );
00190         //cerr << "----------" << curr_node << "=>" << net->mpi_rank() << " : " << (*re)() << endl;
00191         decider.setRNDEngine(re );
00192         if ( (src_vec.beginBlock() != src_vec.endBlock() )
00193                 && (dest_vec.localIDsBegin() != dest_vec.localIDsEnd() )) {
00194             decider.reset(src_vec.beginBlock(),
00195                                             src_vec.endBlock(), dest_vec.localIDsBegin(),
00196                                             dest_vec.localIDsEnd());
00197             pair<SimObject::ID, SimObject::ID> connect_pair;
00198             while (decider.next( connect_pair ) )
00199             {
00200                 size_t src_idx, dst_idx;
00201                 decider.getIdx(src_idx, dst_idx);
00202                 connector.init(srcPopulation, src_idx, destPopulation, dst_idx);
00203 
00204                 net->connect( connect_pair.first, connect_pair.second, connector, id );
00205 
00206                 if (collectIDs) {
00207                     collids->push_back(id.packed() );
00208                 }
00209                 if (collectPairs) {
00210                     connectPairs->push_back(connect_pair);
00211                 }
00212                 cnt++;
00213             }
00214         }
00215     }
00216 
00217     // create outgoing connections
00218     dest_vec.startBlockIteration();
00219     while (dest_vec.hasNextBlock()) {
00220         nodeid_t curr_node = dest_vec.nextBlock();
00221         if (curr_node != net->mpi_rank()) {
00222             RandomEngine *re = net->getOutgoingConstructRNGEngines()[curr_node];
00223             //re->seed( net->mpi_rank() );
00224             //cerr << "----------" << curr_node << "<=" << net->mpi_rank() << " : " << (*re)() << endl;
00225             decider.setRNDEngine(re );
00226             if ( (src_vec.localIDsBegin() != src_vec.localIDsEnd() )
00227                     && (dest_vec.beginBlock() != dest_vec.endBlock() )) {
00228                 decider.reset (src_vec.localIDsBegin(), src_vec.localIDsEnd(),
00229                                dest_vec.beginBlock(), dest_vec.endBlock());
00230 
00231                 pair<SimObject::ID, SimObject::ID> connect_pair;
00232 
00233                 while( decider.next( connect_pair ) ) {
00234 
00235                     net->connect(connect_pair.first, connect_pair.second,
00236                                  connector, id );
00237                     //                    pcp
00238                     if (collectIDs) {
00239                         collids->push_back(id.packed() );
00240                     }
00241                     if (collectPairs) {
00242                         connectPairs->push_back(connect_pair);
00243                     }
00244                     cnt++;
00245                 }
00246             }
00247         }
00248     }
00249 
00250     if (!collectIDs)
00251         collids->push_back((SimObject::ID::Packed)cnt);
00252 
00253     return collids;
00254 }

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