Project

General

Profile

Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.92 KB)

1
//=========================================================================
2
//  CMPICOMM.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
#ifdef WITH_MPI
22

    
23
#ifndef __CMPICOMM_H__
24
#define __CMPICOMM_H__
25

    
26
#include "cparsimcomm.h"
27

    
28
NAMESPACE_BEGIN
29

    
30
class cMPICommBuffer;
31

    
32
/**
33
 * MPI implementation of the basic parallel simulation communications layer.
34
 *
35
 * @ingroup Parsim
36
 */
37
class SIM_API cMPICommunications : public cParsimCommunications
38
{
39
  protected:
40
    cMPICommBuffer *recycledBuffer;
41
    int numPartitions;
42
    int myRank;
43

    
44
  protected:
45
    /**
46
     * Factory method behind createCommBuffer()
47
     */
48
    virtual cMPICommBuffer *doCreateCommBuffer();
49

    
50
  public:
51
    /**
52
     * Constructor.
53
     */
54
    cMPICommunications();
55

    
56
    /**
57
     * Destructor calls MPI_Finalize()
58
     */
59
    virtual ~cMPICommunications();
60

    
61
    /** @name Redefined methods from cParsimCommunications */
62
    //@{
63
    /**
64
     * Init the library.
65
     */
66
    virtual void init();
67

    
68
    /**
69
     * Shutdown the communications library.
70
     */
71
    virtual void shutdown();
72

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

    
78
    /**
79
     * Returns the MPI rank of this partition.
80
     */
81
    virtual int getProcId() const;
82

    
83
    /**
84
     * Creates an empty buffer of type cMPICommBuffer.
85
     */
86
    virtual cCommBuffer *createCommBuffer();
87

    
88
    /**
89
     * Recycle communication buffer after use.
90
     */
91
    virtual void recycleCommBuffer(cCommBuffer *buffer);
92

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

    
98
    /**
99
     * Sends packed data with given tag to all partitions.
100
     */
101
    virtual void broadcast(cCommBuffer *buffer, int tag);
102

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

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

    
118
NAMESPACE_END
119

    
120

    
121
#endif
122

    
123
#endif