Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / parsim / clinkdelaylookahead.cc @ 81ad8b66

History | View | Annotate | Download (3.73 KB)

1
//=========================================================================
2
//  CLINKDELAYLOOKAHEAD.CC - part of
3
//
4
//                  OMNeT++/OMNEST
5
//           Discrete System Simulation in C++
6
//
7
//  Author: Andras Varga, 2003
8
//          Dept. of Electrical and Computer Systems Engineering,
9
//          Monash University, Melbourne, Australia
10
//
11
//=========================================================================
12

    
13
/*--------------------------------------------------------------*
14
  Copyright (C) 2003-2008 Andras Varga
15
  Copyright (C) 2006-2008 OpenSim Ltd.
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20

    
21

    
22
#include "clinkdelaylookahead.h"
23
#include "csimulation.h"
24
#include "cmessage.h"
25
#include "cenvir.h"
26
#include "cnullmessageprot.h"
27
#include "cparsimcomm.h"
28
#include "cparsimpartition.h"
29
#include "cplaceholdermod.h"
30
#include "cproxygate.h"
31
#include "cdataratechannel.h"
32
#include "globals.h"
33
#include "regmacros.h"
34

    
35
USING_NAMESPACE
36

    
37

    
38
Register_Class(cLinkDelayLookahead);
39

    
40

    
41
cLinkDelayLookahead::cLinkDelayLookahead()
42
{
43
    numSeg = 0;
44
    segInfo = NULL;
45
}
46

    
47
cLinkDelayLookahead::~cLinkDelayLookahead()
48
{
49
    delete [] segInfo;
50
}
51

    
52
void cLinkDelayLookahead::startRun()
53
{
54
    ev << "starting Link Delay Lookahead...\n";
55

    
56
    delete [] segInfo;
57

    
58
    numSeg = comm->getNumPartitions();
59
    segInfo = new PartitionInfo[numSeg];
60
    int myProcId = comm->getProcId();
61

    
62
    // temporarily initialize everything to zero.
63
    for (int i=0; i<numSeg; i++)
64
        segInfo[i].minDelay = -1;
65

    
66
    // fill in minDelays
67
    ev << "  calculating minimum link delays...\n";
68
    for (int modId=0; modId<=sim->getLastModuleId(); modId++)
69
    {
70
        cPlaceholderModule *mod = dynamic_cast<cPlaceholderModule *>(sim->getModule(modId));
71
        if (mod)
72
        {
73
            for (cModule::GateIterator i(mod); !i.end(); i++)
74
            {
75
                // if this is a properly connected proxygate, process it
76
                // FIXME leave out gates from other cPlaceholderModules
77
                cGate *g = i();
78
                cProxyGate *pg  = dynamic_cast<cProxyGate *>(g);
79
                if (pg && pg->getPreviousGate() && pg->getRemoteProcId()>=0)
80
                {
81
                    // check we have a delay on this link (it gives us lookahead)
82
                    cGate *fromg  = pg->getPreviousGate();
83
                    cChannel *chan = fromg->getChannel();
84
                    simtime_t linkDelay = chan->hasPar("delay") ? chan->par("delay").doubleValue() : 0.0;
85
                    if (linkDelay<=0.0)
86
                        throw cRuntimeError("cLinkDelayLookahead: zero delay on link from gate `%s', no lookahead for parallel simulation", fromg->getFullPath().c_str());
87

    
88
                    // store
89
                    int procId = pg->getRemoteProcId();
90
                    if (segInfo[procId].minDelay==-1 || segInfo[procId].minDelay > linkDelay)
91
                        segInfo[procId].minDelay = linkDelay;
92
                }
93
            }
94
        }
95
    }
96

    
97
    // if two partitions are not connected, the lookeahead is "infinity"
98
    for (int i=0; i<numSeg; i++)
99
        if (i!=myProcId && segInfo[i].minDelay==-1)
100
            segInfo[i].minDelay = MAXTIME;
101

    
102
    for (int i=0; i<numSeg; i++)
103
        if (i!=myProcId)
104
            ev << "    lookahead to procId=" << i << " is " << segInfo[i].minDelay << "\n";
105

    
106
    ev << "  setup done.\n";
107
}
108

    
109
void cLinkDelayLookahead::endRun()
110
{
111
    delete [] segInfo;
112
    segInfo = NULL;
113
}
114

    
115
simtime_t cLinkDelayLookahead::getCurrentLookahead(cMessage *, int procId, void *)
116
{
117
    return segInfo[procId].minDelay;
118
}
119

    
120
simtime_t cLinkDelayLookahead::getCurrentLookahead(int procId)
121
{
122
    return segInfo[procId].minDelay;
123
}
124

    
125

    
126