DistributedOutgoingAnalogMsgDispatcher.cpp

Go to the documentation of this file.
00001 #include "DistributedOutgoingAnalogMsgDispatcher.h"
00002 
00003 DistributedOutgoingAnalogMsgDispatcher::DistributedOutgoingAnalogMsgDispatcher(engineid_t eng_id, delay_t minimumDelay, MPIOutputBuffer *mpiOutputBuffer)
00004         : engineID(eng_id), minDelay(minimumDelay), outputBuffer(mpiOutputBuffer)
00005 {
00006     initialized = false;
00007     outgoingSources = new OutgoingAnalogMPIBufferSourcesSet();
00008 }
00009 
00010 DistributedOutgoingAnalogMsgDispatcher::~DistributedOutgoingAnalogMsgDispatcher()
00011 {
00012         if (!initialized)
00013                 delete outgoingSources;
00014 }
00015 
00016 void DistributedOutgoingAnalogMsgDispatcher::addOutgoingAnalogMessage(SimObject *src, analog_port_id_t src_port)
00017 {
00018     if (outgoingSources->insert(src, src_port)) {
00019         port_msgs_buff_pos.push_back(outputBuffer->getAnalogMsgCounter(engineID)++);
00020         port_msgs.push_back(make_pair(src, src_port));
00021     }
00022 }
00023 
00024 void DistributedOutgoingAnalogMsgDispatcher::addOutgoingAnalogMessage(SimObject *src, string srcfield)
00025 {
00026         const Field * src_field = src->findField(srcfield);
00027     if (outgoingSources->insert(src, srcfield)) {
00028         field_msgs_buff_pos.push_back(outputBuffer->getAnalogMsgCounter(engineID)++);
00029         field_msgs.push_back( make_pair(src_field->getPtr(src), src_field->getType()));
00030     }
00031 }
00032 
00033 void DistributedOutgoingAnalogMsgDispatcher::dispatchMPIOutgoingAnalogMsgs(int step)
00034 {
00035         // dispatch port messages
00036         port_outgoing_analog_msgs_type::iterator port_msgs_it;
00037         vector< unsigned >::const_iterator port_msgs_buff_pos_iter = port_msgs_buff_pos.begin();
00038         for (port_msgs_it = port_msgs.begin(); port_msgs_it != port_msgs.end(); ++port_msgs_it)
00039         {
00040                 /*cerr << "Dispatching new value = " << port_msgs_it->first->getAnalogOutput(port_msgs_it->second) << endl;
00041                 cerr << " address = " << (mpiBuffer + minDelay * (*(port_msgs_buff_pos_iter++)) + step) << endl;
00042                 cerr << " buffer = " << mpiBuffer << " port_msgs_buff_pos_iter = " << *(port_msgs_buff_pos_iter) << " step=" << step << endl;*/
00043                 *(mpiBuffer + minDelay * (*(port_msgs_buff_pos_iter++)) + step) =
00044                                         port_msgs_it->first->getAnalogOutput(port_msgs_it->second);
00045         }
00046 
00047 
00048     // dispatch field messages
00049         field_outgoing_analog_msgs_type::iterator field_msgs_it;
00050         vector< unsigned >::const_iterator field_msgs_buff_pos_iter = field_msgs_buff_pos.begin();
00051         for (field_msgs_it = field_msgs.begin(); field_msgs_it != field_msgs.end(); ++field_msgs_it) {
00052                 *(mpiBuffer + minDelay * (*(field_msgs_buff_pos_iter++)) + step) = Field::getValue(field_msgs_it->first, field_msgs_it->second);
00053         }
00054 
00055 }
00056 
00057 void DistributedOutgoingAnalogMsgDispatcher::initialize()
00058 {
00059         mpiBuffer = outputBuffer->getAnalogBuffer() + minDelay * (engineID ? outputBuffer->getAnalogMsgCounter(engineID - 1) : 0);
00060         if (!initialized) {
00061         initialized = true;
00062         delete outgoingSources;
00063         }
00064 }

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