-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharedCommunicator.hpp
86 lines (69 loc) · 1.38 KB
/
SharedCommunicator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef SHAREDCOMMUNICATOR_HPP_
#define SHAREDCOMMUNICATOR_HPP_
#include "Communicator.hpp"
#include <mpi.h>
#include <vector>
#include <limits>
#include <atomic>
template<typename T>
class SharedCommunicator : public Communicator<T>
{
typedef Communicator<T> Parent;
public:
SharedCommunicator(const unsigned & sizeBuffer)
: Parent(sizeBuffer),
_numComms(0)
{
}
virtual ~SharedCommunicator()
{
}
unsigned getNumDoneCommunications() const
{
return _numComms;
}
void addBuffer() override
{
_reqs.push_back(false);
Parent::addBuffer();
}
void openConnection(const unsigned & pos) override
{
_reqs[pos] = false;
}
bool checkIfRecvCompleted(const unsigned & pos) override
{
if (_reqs[pos])
{
++_numComms;
return true;
}
else
return false;
}
bool checkIfFreeForSend(const unsigned & pos) override
{
if (!_reqs[pos])
{
Parent::getIndicatorOfWin(pos).clear();
return true;
}
else
return false;
}
void sendData(const unsigned & pos, const int & num) override
{
_reqs[pos] = true;
++_numComms;
}
void finishReceiver() override
{
}
void finishSender() override
{
}
private:
std::atomic<unsigned> _numComms;
std::vector<bool> _reqs;
};
#endif