Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

schedAction.cpp 5.94 KB
Newer Older
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
1
#include "schedAction.h"
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
2
#include "util.h"
3
#include <iostream>
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
4

EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
5 6
using namespace std;

7 8 9
void ActionSequence::add(SchedAction* a) {
  actions.push_back(a);
}
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23

void ActionSequence::remove(SchedAction* a) {
  auto it = actions.begin(); 
  while(it != actions.end()) {
    if (a == *it) break; 
    ++it; 
  }
  if(it != actions.end())
    actions.erase(it);
  else {
    cerr << "Warning: unable to remove action " << a << " from list of actions" << endl; 
  }
}

24 25 26
void ActionSequence::onSchedule(int i, int w, double s, double f) {
  for (std::vector<SchedAction*>::iterator it = actions.begin() ; it != actions.end(); ++it) {
    (*it)->onSchedule(i, w, s, f);
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
27
  }
28 29 30 31 32
}
void ActionSequence::onTaskPush(int t) {
  for (std::vector<SchedAction*>::iterator it = actions.begin() ; it != actions.end(); ++it)
    (*it)->onTaskPush(t);
}
33
int ActionSequence::chooseTask(int wType, double now) {
34 35
  int tmp; 
  for (std::vector<SchedAction*>::iterator it = actions.begin() ; it != actions.end(); ++it)
36
    if( (tmp = (*it)->chooseTask(wType, now)) != SCHEDACTION_NONE) 
37
      return tmp; 
38
  return SCHEDACTION_NONE; 
39
}
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
40

EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
41 42 43 44 45 46 47 48
ExportSchedule::ExportSchedule(ostream *stream, Instance* ins, bool header, string name) : output(stream), instance(ins), name(name) { 
  if(header) outputHeader(); 
}
ExportSchedule::ExportSchedule(Instance* ins, string name) 
  : instance(ins), name(name) {
}


49
ExportToFile::ExportToFile(string filename, Instance* ins, bool header, string name): ExportSchedule(ins, name), f(new ofstream(filename, ios::app)) {
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
50 51 52 53 54 55 56 57 58 59 60
  output = f;
  if(header) outputHeader(); 
}

ExportToString::ExportToString(Instance* ins, bool header, string name)
  : ExportSchedule(ins, name), f(new ostringstream()) {
  output = f;
  if(header) outputHeader(); 
}

void ExportSchedule::outputHeader() {
61
  if(name != "") 
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
62 63 64 65 66
    *output << "sched ";
  *output << "Tid   worker taskType "; 
  if(instance->taskIDs.size() > 0) 
    *output << "JobId "; 
  *output << "start duration end" << endl;
67
}
68

EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
69
void ExportSchedule::changeName(string newName) {
70
  if((name == "" && newName != "")) {
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
71
    cerr << "ExportSchedule: Warning, adding a name after the start breaks the header" << endl;
72 73 74 75 76
  }
  if(name != "" && newName == "") newName = "NA";
  name = newName; 
}

EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
77
void ExportSchedule::onSchedule(int i, int w, double s, double f) {
78
  if(name != "")
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
79 80
    *output << name << " "; 
  *output << i << " " << w << " "; 
81
  if(instance->taskTypeNames.size() > 0) 
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
82
    *output << instance->taskTypeNames[instance->taskTypes[i]]; 
83
  else 
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
84
    *output << instance->taskTypes[i]; 
85
  if(instance->taskIDs.size() > 0) 
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
86 87
    *output << " " << instance->taskIDs[i]; 
  *output << " " << s << " " << (f - s) << " " << f << endl;
88
}
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
89

90
ExportToFile::~ExportToFile() {
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
91 92 93 94 95
  f->close();
}

string ExportToString::getResult() {
  return f->str(); 
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
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
ExportAlloc::ExportAlloc(string filename, Instance* ins) : output(filename), instance(ins) {
}

void ExportAlloc::onSchedule(int i, int w, double s, double f) {
  if(instance->taskIDs.size() > 0) {
    output << "JobId: " << instance->taskIDs[i] << endl; 
  } else {
    output << "TaskId: " << i << endl; 
  }
  if(instance->taskTypeNames.size() > 0) {
    output << "TaskType: " << instance->taskTypeNames[instance->taskTypes[i]] << endl; 
  }
  if(instance->workerNames.size() > 0) {
    output << "Architecture: "  << instance->workerNames[instance->getType(w)] << endl; 
  } else {
    output << "WorkerType: " << instance->getType(w) << endl; 
  }
  output << endl; 
}

ExportAlloc::~ExportAlloc() {
  output.close();
}


EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
123 124 125
UtilAnalysis::UtilAnalysis(Instance* _ins, string saveFile) :
  ins(_ins), repartition(_ins->nbWorkerTypes, 
			 std::vector<int>(ins->nbTaskTypes, 0)), 
126
  output(saveFile, ios::app) {
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
127 128 129 130 131 132 133
  
  }
UtilAnalysis::~UtilAnalysis(){
  output.close(); 
}

void UtilAnalysis::onSchedule(int i, int w, double s, double f) {
134
  repartition[ins->getType(w)][ins->taskTypes[i]] += 1; 
EYRAUD-DUBOIS Lionel's avatar
EYRAUD-DUBOIS Lionel committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
}

std::vector<std::vector<int> > UtilAnalysis::getRepartition() {
  return repartition; 
}

void UtilAnalysis::reset() {
  for(auto &v: repartition)
    for(auto &n: v)
      n = 0; 
}

void UtilAnalysis::write(string prefix) {
  for(int i = 0; i < (int) repartition.size(); i++) {
    for(int j = 0; j < (int) repartition[i].size(); j++) {
      output << prefix << " " << i << " " << j << " " 
	     << repartition[i][j] << " " 
	     << repartition[i][j] * ins->execTimes[i][j] << endl;
    }
  }
  reset(); 
}
157 158 159


InternalShare::InternalShare(string name, Instance* ins) : 
160 161 162 163
  shareName(name), instance(ins), allocation(ins->nbTasks, -1),
  worker(ins->nbTasks, -1), 
  startTimes(ins->nbTasks, -1),
  endTimes(ins->nbTasks, -1) {
164 165 166
}

void InternalShare::onSchedule(int i, int w, double s, double f) {
167 168 169
  allocation[i] = instance->getType(w);
  worker[i] = w; 
  startTimes[i] = s;
170
  endTimes[i] = f;
171 172 173
}

void InternalShare::finish() {
174 175 176 177
  instance->extraData.insert(shareName + "[worker]", new vector<int>(worker)); 
  instance->extraData.insert(shareName + "[alloc]", new vector<int>(allocation)); 
  instance->extraData.insert(shareName + "[start]", new vector<double>(startTimes)); 
  instance->extraData.insert(shareName + "[end]", new vector<double>(endTimes)); 
178
}
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

ExportBubble::ExportBubble(string filename, Instance* ins, int btt) : 
  InternalShare(filename, ins), output(filename), bubbleTaskType(btt) {
}

void ExportBubble::finish() {
  vector<double> bubbleStarts; 
  vector<int> topOrder = instance->getTopOrder(); 
  int nbBubbles; 
  for(int i = 0; i < instance->nbTasks; i++) {
    if(instance->taskTypes[topOrder[i]] == bubbleTaskType) 
      bubbleStarts.push_back(startTimes[topOrder[i]]);  
  }
  nbBubbles = bubbleStarts.size(); 
  for(int i = 0; i < instance->nbTasks; i++) {
    double s = startTimes[i], e = startTimes[i] + instance->execType(allocation[i], i);
    int firstBubble = -1, lastBubble = -1; 
    for(int j = 0; j < nbBubbles; j++) {
      if(s >= bubbleStarts[j]) firstBubble = j; 
      if(e >= bubbleStarts[j]) lastBubble = j; 
      else break; 
    }
    output << firstBubble << " " << lastBubble << " " << allocation[i] << endl; 
  }
  output.close(); 
}