This repository has been archived by the owner on Mar 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ElasticTask.hpp
143 lines (118 loc) · 3.97 KB
/
ElasticTask.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef ELASTICTASK_HPP
#define ELASTICTASK_HPP
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <fstream>
#include <iostream>
#include <xbt/base.h>
#include <xbt/string.hpp>
#include <xbt/signal.hpp>
#include <xbt/Extendable.hpp>
#include "simgrid/msg.h"
#include <simgrid/simix.h>
#include <simgrid/datatypes.h>
#include <simgrid/s4u/forward.hpp>
#include <simgrid/s4u/actor.hpp>
class EvntQ {
public:
double date;
EvntQ(double date_) : date(date_) {}
virtual ~EvntQ() {}
};
typedef struct streamET {
size_t destET;
double ratioLoad;
//streamET() = default;
streamET(size_t destET_, double ratioLoad_)
: destET(destET_), ratioLoad(ratioLoad_) {}
} streamET;
class RatioChange : public EvntQ {
public:
size_t id;
double visitsPerSec;
//RatioChange() = default;
RatioChange(size_t id_, double date_, double visitsPerSec_)
: EvntQ(date_), id(id_), visitsPerSec(visitsPerSec_) {}
RatioChange(size_t id_, double visitsPerSec_) // for the event queue as the date is already known
: EvntQ(0.0), id(id_), visitsPerSec(visitsPerSec_) {}
RatioChange(double date_, double visitsPerSec_) // for the user that doesn't know the ID of the ET
: EvntQ(date_), visitsPerSec(visitsPerSec_) {}
};
class TaskDescription : public EvntQ {
public:
size_t id;
double flops;
double interSpawnDelay;
size_t nextHost;
std::vector<simgrid::s4u::Host*> hosts; // TODO, use hosts
bool repeat = true;
std::function<void()> outputFunction = []() {};
bool hasTimestamps = false;
std::ifstream *ts_file;
//TaskDescription() = default;
TaskDescription(double flops_, double interSpawnDelay_, simgrid::s4u::Host *host_, double date_)
: EvntQ(date_), flops(flops_), interSpawnDelay(interSpawnDelay_) {
hosts.push_back(host_);
nextHost = 0;
ts_file = new std::ifstream;
}
TaskDescription(double flops_, double interSpawnDelay_, simgrid::s4u::Host *host_)
: TaskDescription(flops_, interSpawnDelay_, host_, 0.0) {}
//~TaskDescription() {
// delete ts_file;
//}
};
struct Comparator {
bool operator()(const EvntQ* lhs, const EvntQ* rhs) {
return lhs->date > rhs->date;
}
};
namespace simgrid {
namespace s4u {
/** @brief */
XBT_PUBLIC_CLASS ElasticTaskManager {
private:
std::vector<TaskDescription> tasks;
std::priority_queue<EvntQ*, std::vector<EvntQ*>, Comparator> nextEvtQueue;
msg_sem_t sleep_sem;
bool keepGoing;
public:
ElasticTaskManager();
//~ElasticTaskManager();
size_t addElasticTask(s4u::Host *host, double flopsTask, double interSpawnDelay);
void addRatioChange(size_t id, double date, double visitsPerSec);
void addHost(size_t id, Host *host);
void changeRatio(size_t id, double visitsPerSec);
void changeTask(size_t id, double flops);
void simpleChangeTask(size_t id);
void removeTask(size_t id);
void removeRatioChanges(size_t id);
void triggerOneTimeTask(size_t id);
void triggerOneTimeTask(size_t id, double ratioLoad);
void setOutputFunction(size_t id, std::function<void()> code);
void setTimestampsFile(size_t id, std::string filename);
void kill();
void run();
};
XBT_PUBLIC_CLASS ElasticTask {
private:
size_t id;
ElasticTaskManager *etm;
public:
ElasticTask(Host *host, double flopsTask, double interSpawnDelay, ElasticTaskManager *etm_);
ElasticTask(Host *host, double flopsTask, ElasticTaskManager *etm_);
ElasticTask(Host *host, double flopsTask, std::vector<RatioChange> fluctuations, ElasticTaskManager *etm_);
~ElasticTask();
void setTriggerRatioVariation(std::vector<RatioChange> fluctuations);
void setRatioVariation(double interSpawnDelay);
void modifyTask(double flops);
void triggerOneTime();
void triggerOneTime(double ratioLoad);
void setOutputFunction(std::function<void()> code);
void addHost(Host *host);
void setTimestampsFile(std::string filename);
};
}}
#endif //ELASTICTASK_HPP