meric.h 4.66 KB
Newer Older
Ondrej Meca's avatar
Ondrej Meca committed
1
2
3
4

#ifndef SRC_MERIC_DISTRIBUTED_DISTRIBUTEDMERIC_H_
#define SRC_MERIC_DISTRIBUTED_DISTRIBUTEDMERIC_H_

Ondrej Vysocky's avatar
Ondrej Vysocky committed
5
#include <mpi.h>
Ondrej Meca's avatar
Ondrej Meca committed
6
7

#include "../meric.h"
8
9

#include "../../store/aggregated/aggregatestore.h"
Ondrej Meca's avatar
Ondrej Meca committed
10
#include "../../store/aggregated/detailedaggregatestore.h"
Ondrej Meca's avatar
Ondrej Meca committed
11
#include "../../store/aggregated/debugaggregatestore.h"
12
#include "../../store/aggregated/countersaggregatestore.h"
13
#include "../../store/aggregated/infoaggregatestore.h"
Ondrej Meca's avatar
Ondrej Meca committed
14
15
16
17
18
19
20

namespace meric {

class DistributedMeric: public Meric {

public:
	DistributedMeric();
Ondrej Meca's avatar
Ondrej Meca committed
21
	~DistributedMeric();
Ondrej Meca's avatar
Ondrej Meca committed
22

Ondrej Meca's avatar
Ondrej Meca committed
23
24
	void start(const std::string &region)
	{
25
26
27
28
		if (OMPbarriers)
		{
			#pragma omp barrier
		}
29
		#pragma omp single nowait
30
		{
Ondrej Vysocky's avatar
Ondrej Vysocky committed
31
32
			if (_storeList[0]->getMPIWrite())
				MERIC_INFO << "region '" << region << "' starting\n";
Ondrej Vysocky's avatar
Ondrej Vysocky committed
33
			SocketsRegionParameters change = regionValue(currentState, region, _nodeId);
34
35
			if (MPIbarriers)
				MPI_Barrier(_currentNode);
Ondrej Vysocky's avatar
Ondrej Vysocky committed
36
			setRegionEnvironment(change, !_MPInodeRank);
37
		}
Ondrej Vysocky's avatar
Ondrej Vysocky committed
38
39
		if (Meric::IGNORE)
			return;
40
		#pragma omp single nowait
41
		{
42
43
44
			if (!ignoreRegion(region))
				Meric::start(region);
			_stack.push_back(getRegionID(region));
45
		}
46
47
48
49
		if (OMPbarriers)
		{
			#pragma omp barrier
		}
Ondrej Meca's avatar
Ondrej Meca committed
50
	}
xvysoc01's avatar
xvysoc01 committed
51
	
52
	double stop()
Ondrej Meca's avatar
Ondrej Meca committed
53
	{
54
		double regionRuntime = 0.0;
55
		if (OMPbarriers)
56
		{
57
58
			#pragma omp barrier
		}
59
		#pragma omp single nowait
60
		{
Ondrej Vysocky's avatar
Ondrej Vysocky committed
61
62
			if (_storeList[0]->getMPIWrite())
				MERIC_INFO << "region '" << getRegionName(_stack.size(), _stack.back()) << "' stopping\n";
63
			SocketsRegionParameters change = regionValue(currentState, getRegionName(_stack.size()-1, _stack.back()-1), _nodeId);
64
65
			if (MPIbarriers)
				MPI_Barrier(_currentNode);
Ondrej Vysocky's avatar
Ondrej Vysocky committed
66
			setRegionEnvironment(change, !_MPInodeRank);
67
		}
Ondrej Vysocky's avatar
Ondrej Vysocky committed
68
		if (Meric::IGNORE)
69
			return 0.0;
70
		#pragma omp single nowait
71
		{
72
			if (!ignoreRegion(getRegionName(_stack.size(), _stack.back())))
73
			{
74
75
76
				if (!_stack.size())
				{
					std::cerr << "MERIC ERROR: Incorrect regions. There are more 'ends' than 'starts'!\n";
77
					regionRuntime = -1.0;
78
				}
Ondrej Vysocky's avatar
Ondrej Vysocky committed
79
80
				else
				{
81
					regionRuntime = Meric::stop();
Ondrej Vysocky's avatar
Ondrej Vysocky committed
82
83
					_stack.pop_back();
				}
84
			}
Ondrej Vysocky's avatar
Ondrej Vysocky committed
85
86
			else
				_stack.pop_back();
87
		}
88
89
90
91
		if (OMPbarriers)
		{
			#pragma omp barrier
		}
92
		return regionRuntime;
Ondrej Meca's avatar
Ondrej Meca committed
93
	}
94

95
	double stopStart(const std::string &region)
96
	{
97
		double regionRuntime = 0.0;
98
99
100
101
		if (OMPbarriers)
		{
			#pragma omp barrier
		}
102
		#pragma omp single nowait
Ondrej Vysocky's avatar
Ondrej Vysocky committed
103
		{
104
			MERIC_INFO << "region '" << getRegionName(_stack.size(), _stack.back()) << "' stopping and staring region'"  << region << "'\n";
Ondrej Vysocky's avatar
Ondrej Vysocky committed
105
			SocketsRegionParameters change = regionValue(currentState, region, _nodeId);
106
107
			if (MPIbarriers)
				MPI_Barrier(_currentNode);
Ondrej Vysocky's avatar
Ondrej Vysocky committed
108
109
			setRegionEnvironment(change, !_MPInodeRank);
		}
110
111
		
		if (Meric::IGNORE)
112
			return 0.0;
113
114
		if (!_stack.size())
		{
115
			#pragma omp single nowait
116
			std::cerr << "MERIC ERROR: Incorrect regions. There are more 'ends' than 'starts'!\n";
117
			return -1.0;
118
		}
119
		#pragma omp single nowait
120
121
		{
			if (!ignoreRegion(getRegionName(_stack.size(), _stack.back())))
122
				regionRuntime = Meric::stop();
123
124
125
126
127
128
			_stack.pop_back();

			if (!ignoreRegion(region))
				Meric::start(region);
			_stack.push_back(getRegionID(region));
		}
129
130
131
132
		if (OMPbarriers)
		{
			#pragma omp barrier
		}
133
		return regionRuntime;
134
135
	}

136
137
138
139
	void startIgnore()
	{
		Meric::startIgnore();
	}
xvysoc01's avatar
xvysoc01 committed
140
	
141
142
143
144
145
	void stopIgnore()
	{
		Meric::stopIgnore();
	}	

Ondrej Meca's avatar
Ondrej Meca committed
146
147
	void save()
	{
148
149
		stop(); //applicationMainRegion
		
150
151
		if (MPIbarriers)
			MPI_Barrier(_currentNode);
152

153
		if (!_MPInodeRank)
154
		{
155
156
157
158
159
160
161
162
			if (Meric::MODE == MODE_HDEEM || Meric::MODE == MODE_BOTH)
			{
				HDEEM::stop(_stopTime);
			}
			else if (Meric::MODE == MODE_DAVIDE && Meric::CONTINUAL)
			{
				DAVIDE::stop(_stopTime);
			}
163
		}
164
	
165
		Meric::close();
166
167
168
		
		if (!_MPInodeRank)
		{
169
			Environment::setDefaultFrequencies();
170
171
		}
		
172
173
174
		if (_stack.size() != 0)
		{
			if (!_MPInodeRank)
175
			{
176
				std::cerr << "MERIC ERROR: not all regions were stopped before the MERIC_Close()\n";
177
178
				MPI_Abort(MPI_COMM_WORLD, -1);
			}
179
		}
180

181
182
		for(int i=0; i<_storeList.size(); i++)
		{
Ondrej Vysocky's avatar
Ondrej Vysocky committed
183
			if (!_MPInodeRank)
184
			{
185
				_storeList[i]->initStore(Meric::ITERATION, Meric::OUTPUT_DIR, Meric::OUTPUT_FILENAME, Meric::outputFilenameInfo, _nodeName);
Ondrej Vysocky's avatar
Ondrej Vysocky committed
186
187
188
			}
			if (_storeList[i]->getMPIWrite())
			{
189
190
191
192
193
194
				try
				{
					_storeList[i]->save(Meric::OUTPUT_DIR, Meric::OUTPUT_FILENAME, _name, _nodeName);
				}
				catch (int &e)
				{
195
					//exception for timeenergystore(HDEEM), timestore<HDEEM>, timestore<DAVIDE> store when there are no power samples
196
197
					MPI_Abort(MPI_COMM_WORLD, 1);
				}
198
199
			}
		}
200
201
		if (MPIbarriers)
			MPI_Barrier(_currentNode);
Ondrej Meca's avatar
Ondrej Meca committed
202
	}
Ondrej Meca's avatar
Ondrej Meca committed
203
204

protected:
Ondrej Meca's avatar
Ondrej Meca committed
205
206
207
208
	int _MPIglobalRank;
	int _MPIglobalSize;
	int _MPInodeRank;
	int _MPInodeSize;
209
	int _nodeId;
Ondrej Meca's avatar
Ondrej Meca committed
210
	std::string _nodeName;
Ondrej Meca's avatar
Ondrej Meca committed
211
	MPI_Comm _currentNode;
Ondrej Meca's avatar
Ondrej Meca committed
212
	MPI_Comm _storingProcs;
213
	MPI_Comm _supportComm;
214
	MPI_Comm _worldCopy;
215
216
217

private:

Ondrej Meca's avatar
Ondrej Meca committed
218
219
220
221
222
};

}

#endif /* SRC_MERIC_DISTRIBUTED_DISTRIBUTEDMERIC_H_ */