Project

General

Profile

Statistics
| Branch: | Revision:

root / include / cparsimcomm.h @ 2f5cc443

History | View | Annotate | Download (3.42 KB)

1
//=========================================================================
2
//  CPARSIMCOMM.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

    
22
#ifndef __CPARSIMCOMM_H__
23
#define __CPARSIMCOMM_H__
24

    
25
#include "cobject.h"
26

    
27
NAMESPACE_BEGIN
28

    
29
// forward declaration:
30
class cCommBuffer;
31

    
32
#define PARSIM_ANY_TAG  -1
33

    
34

    
35
/**
36
 * Basic communications layer for parallel simulation. It provides an
37
 * abstraction layer above MPI, PVM, shared-memory communications, etc.
38
 *
39
 * This is an interface: functionality is added by specific subclasses
40
 * for MPI, PVM, etc.
41
 *
42
 * @ingroup ParsimBrief
43
 * @ingroup Parsim
44
 */
45
class SIM_API cParsimCommunications : public cObject
46
{
47
  public:
48
    /**
49
     * Virtual destructor.
50
     */
51
    virtual ~cParsimCommunications() {}
52

    
53
    /** @name Lifecycle of communications library */
54
    //@{
55
    /**
56
     * Init the library -- parameters (if there are any) should have
57
     * been passed in constructor.
58
     *
59
     * This process may also include starting the program on all
60
     * processors needed for the current simulation run, if
61
     * it is not handled by the parallel runtime system (e.g. MPI
62
     * handles it via mpirun).
63
     */
64
    virtual void init() = 0;
65

    
66
    /**
67
     * Shutdown the communications library.
68
     */
69
    virtual void shutdown() = 0;
70
    //@}
71

    
72
    //@{
73
    /**
74
     * Returns total number of partitions.
75
     */
76
    virtual int getNumPartitions() const = 0;
77

    
78
    /**
79
     * Returns id of this partition, an integer in the range 0..getNumPartitions()-1.
80
     */
81
    virtual int getProcId() const = 0;
82

    
83
    /** @name Buffers, send, receive */
84
    //@{
85
    /**
86
     * Creates an empty buffer that can be used to send/receive data
87
     */
88
    virtual cCommBuffer *createCommBuffer() = 0;
89

    
90
    /**
91
     * Recycle communication buffer after use. May be used to implement pooling, etc.
92
     */
93
    virtual void recycleCommBuffer(cCommBuffer *buffer) = 0;
94

    
95
    /**
96
     * Sends packed data with given tag to destination.
97
     */
98
    virtual void send(cCommBuffer *buffer, int tag, int destination) = 0;
99

    
100
    /**
101
     * Broadcasts packed data with given tag to all partitions. This default
102
     * implementation just simply sends the data to every other partition.
103
     */
104
    virtual void broadcast(cCommBuffer *buffer, int tag);
105

    
106
    /**
107
     * Receives packed data with given tag from given destination.
108
     * Normally returns true; false is returned if blocking was interrupted by the user.
109
     */
110
    virtual bool receiveBlocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId) = 0;
111

    
112
    /**
113
     * Receives packed data with given tag from given destination.
114
     * Call is non-blocking -- it returns true if something has been
115
     * received, false otherwise.
116
     */
117
    virtual bool receiveNonblocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId) = 0;
118
    //@}
119
};
120

    
121
NAMESPACE_END
122

    
123

    
124
#endif
125