Statistics
| Branch: | Revision:

root / src / sim / parsim / cparsimsynchr.h @ e1750c09

History | View | Annotate | Download (3 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  CPARSIMSYNCHR.H - 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
#ifndef __CPARSIMSYNCHR_H__
22
#define __CPARSIMSYNCHR_H__
23
24
#include "cscheduler.h"
25
#include "simtime_t.h"
26
27
NAMESPACE_BEGIN
28
29
// forward declarations
30
class cSimulation;
31
class cMessage;
32
class cParsimPartition;
33
class cParsimCommunications;
34
35
/**
36
 * Abstract base class for parallel simulation algorithms.
37
 * Subclasses implement the "null message algorithm" and others.
38
 *
39
 * Task of this layer is to implement conservative synchronization, that is,
40
 * block the execution at time points where it is not safe to proceed
41
 * since events from other partitions will (may) arrive before the next
42
 * local event.
43
 *
44
 * Synchronizer integrates into the simulation kernel via the
45
 * getNextEvent() and processOutgoingMessage() functions:
46
 *
47
 * - getNextEvent() is the scheduler function (comes from cScheduler)
48
 *
49
 * - processOutgoingMessage() is invoked when messages are sent
50
 * out of the partition, from gates (see cProxyGate) of placeholder modules
51
 * (cPlaceholderModule) via cParsimPartition.
52
 *
53
 * @ingroup Parsim
54
 */
55
class SIM_API cParsimSynchronizer : public cScheduler
56
{
57
  protected:
58
    cParsimPartition *partition;
59
    cParsimCommunications *comm;
60
61
  public:
62
    /**
63
     * Constructor.
64
     */
65
    cParsimSynchronizer() : cScheduler()  {partition = NULL; comm = NULL;}
66
67
    /**
68
     * Destructor.
69
     */
70
    virtual ~cParsimSynchronizer() {}
71
72
    /**
73
     * Pass cParsimSynchronizer the objects it has to cooperate with.
74
     */
75
    virtual void setContext(cSimulation *sim, cParsimPartition *seg, cParsimCommunications *co)
76
       {setSimulation(sim); partition = seg; comm = co;}
77
78
    /**
79
     * Called at the beginning of a simulation run.
80
     */
81
    virtual void startRun() = 0;
82
83
    /**
84
     * Called at the end of a simulation run.
85
     */
86
    virtual void endRun() = 0;
87
88
    /**
89
     * Scheduler function -- it comes from cScheduler interface.
90
     */
91
    virtual cMessage *getNextEvent() =0;
92
93
    /**
94
     * Hook, called when a cMessage is sent out of the partition.
95
     * It is provided here so that the synchronizer can potentially
96
     * perform optimizations, such as piggybacking null messages
97
     * (see null message algorithm) on outgoing messages.
98
     */
99
    virtual void processOutgoingMessage(cMessage *msg, int procId, int moduleId, int gateId, void *data) = 0;
100
};
101
102
NAMESPACE_END
103
104
105
#endif