Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / parsim / cparsimpartition.h @ 81ad8b66

History | View | Annotate | Download (4.9 KB)

1
//=========================================================================
2
//  CPARSIMPARTITION.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 __CPARSIMPARTITION_H__
22
#define __CPARSIMPARTITION_H__
23

    
24
#include "simkerneldefs.h"
25
#include "cobject.h"
26
#include "simtime_t.h"
27

    
28
NAMESPACE_BEGIN
29

    
30
// forward declarations:
31
class cSimulation;
32
class cParsimSynchronizer;
33
class cParsimCommunications;
34
class cCommBuffer;
35
class cException;
36
class cTerminationException;
37

    
38

    
39
/**
40
 * Represents one partition in a parallel simulation. Knows about
41
 * partitions and the links between this partition and its neighbours.
42
 *
43
 * Interconnections are stored not directly inside this object,
44
 * but in cProxyGate's of cPlaceholderModule's. The remote address fields
45
 * of cProxyGate's are filled out here in the connectRemoteGates() method.
46
 *
47
 * This layer also handles generic (synchronization-independent part of)
48
 * communication with other partitions:
49
 *
50
 * - cMessages outgoing from this partition flow through here
51
 *   (processOutgoingMessage()), and
52
 *
53
 * - incoming messages are processed at here by processReceivedBuffer()
54
 *   (invoked from the synchronization layer, cParsimSynchronizer)
55
 *
56
 * This layer is communication library independent (i.e it contains
57
 * no MPI, PVM, etc. calls) -- it builds on the abstraction layer provided
58
 * by cParsimCommunications.
59
 *
60
 * @ingroup Parsim
61
 */
62
class SIM_API cParsimPartition : public cObject
63
{
64
  protected:
65
    cSimulation *sim;
66
    cParsimCommunications *comm;
67
    cParsimSynchronizer *synch;
68
    bool debug;
69

    
70
  protected:
71
    // internal: fills in remote gate addresses of all cProxyGate's in the current partition
72
    void connectRemoteGates();
73

    
74
  public:
75
    /**
76
     * Constructor.
77
     */
78
    cParsimPartition();
79

    
80
    /**
81
     * Virtual destructor.
82
     */
83
    virtual ~cParsimPartition();
84

    
85
    /**
86
     * Pass cParsimPartition the objects it has to cooperate with.
87
     */
88
    void setContext(cSimulation *sim, cParsimCommunications *comm, cParsimSynchronizer *synch);
89

    
90
    /**
91
     * Called at the beginning of a simulation run. Fills in remote gate addresses
92
     * of all cProxyGate's in the current partition.
93
     */
94
    void startRun();
95

    
96
    /**
97
     * Called at the end of a simulation run.
98
     */
99
    void endRun();
100

    
101
    /**
102
     * Shut down the parallel simulation system.
103
     */
104
    void shutdown();
105

    
106
    /**
107
     * A hook called from cProxyGate::deliver() when an outgoing cMessage
108
     * arrives at partition boundary. We just pass it up to the synchronization
109
     * layer (see similar method in cParsimSynchronizer).
110
     */
111
    virtual void processOutgoingMessage(cMessage *msg, int procId, int moduleId, int gateId, void *data);
112

    
113
    /**
114
     * Process messages coming from other partitions. This method is called from
115
     * the synchronization layer (see cParsimSynchronizer), after it has
116
     * processed all tags that it understands (namely, cMessages
117
     * (tag=TAG_CMESSAGE) and all tags used by the synchronization protocol).
118
     */
119
    virtual void processReceivedBuffer(cCommBuffer *buffer, int tag, int sourceProcId);
120

    
121
    /**
122
     * Process cMessages received from other partitions. This method is called from
123
     * the synchronization layer (see cParsimSynchronizer) when it received
124
     * a message from other partitions. This method checks that the destination
125
     * module/gate still exists, sets the source module/gate to the appropriate
126
     * placeholder module, and inserts the message into the FES.
127
     */
128
    virtual void processReceivedMessage(cMessage *msg, int destModuleId, int destGateId, int sourceProcId);
129

    
130
    /**
131
     * Called when a cTerminationException occurs (i.e. the simulation is
132
     * about to be finished normally), this methods notifies other partitions
133
     * about the exception.
134
     *
135
     * This methods "eats" exceptions that occur during broadcast. (We're
136
     * not interested in cascading exceptions.)
137
     */
138
    virtual void broadcastTerminationException(cTerminationException& e);
139

    
140
    /**
141
     * Called when an exception occurs (i.e. the simulation is about to be
142
     * stopped with an error), this methods notifies other partitions
143
     * about the exception.
144
     *
145
     * This methods "eats" exceptions that occur during broadcast. (We're
146
     * not interested in cascading exceptions.)
147
     */
148
    virtual void broadcastException(std::exception& e);
149
};
150

    
151
NAMESPACE_END
152

    
153

    
154
#endif
155