GreenCloud Simulator
taskalloc.cc
Go to the documentation of this file.
1 /*
2  * taskalloc.cc
3  *
4  * @date Sep 26, 2013
5  * @author Guzek:Mateusz
6  */
7 
8 #include "taskalloc.h"
9 #include "corescheduler.h"
10 
11 
13 
14 }
15 
16 TaskAlloc::TaskAlloc(CloudTask * ct, int rd, int cap) : core(NULL),executedSince_(0.0){
17  this->cloudTask = ct;
18  this->rd = rd;
19  this->cap = cap;
20 }
22  return cloudTask->getMIPS(rd,cap);
23 }
25  return cloudTask->getDeadline();
26 }
27 
29  this->core=cs;
30 }
32  return this->core;
33 }
34 
35 bool TaskAlloc::operator==(const TaskAlloc &other) const {
36  if(cloudTask==other.cloudTask && rd == other.rd && cap == other.cap){
37  return true;
38  } else {
39  return false;
40  }
41 }
42 
43 void TaskAlloc::setComputingRate(double rate)
44 {
45  /* update what has already been computed */
46  updateMIPS();
47  cloudTask->res_demands.at(rd)->current_performance.at(cap)= rate;
48 }
49 
51  std::cerr << "id "<< cloudTask->id_ << " "<< rd << " ,c: " << cap << " mips left: " << getMIPS() << "\texec since: " << executedSince_;
52 }
53 
55 {
56  ResDemand* res_dem = cloudTask->res_demands.at(rd);
57 
58  double operationsComputed = (res_dem)->current_performance.at(cap)*(Scheduler::instance().clock() - executedSince_);
59 
60  if((res_dem)->capacity.at(cap) > operationsComputed){
61  (res_dem)->capacity.at(cap) -= operationsComputed;
62  } else {
63  (res_dem)->capacity.at(cap) = 0;
64  }
65 // std::cout << "--\t Task: " << this->cloudTask->id_ << " MIPS: " << getMIPS() << "\n";
66 
67 
68  executedSince_ = Scheduler::instance().clock();
69 }
70 
71 
72 
74 {
75  if (cloudTask->res_demands.at(rd)->current_performance.at(cap)){
76  return ((double)(cloudTask->res_demands.at(rd)->capacity.at(cap))/cloudTask->res_demands.at(rd)->current_performance.at(cap));
77  }
78  else{
79  return DBL_MAX;
80  }
81 }
82 
double getMIPS(int rd, int cap)
Definition: cloudtask.cc:52
CoreScheduler * core
Definition: taskalloc.h:19
int rd
Definition: taskalloc.h:39
int cap
Definition: taskalloc.h:40
double getDeadline()
Definition: cloudtask.h:23
double getMIPS()
Definition: taskalloc.cc:21
bool operator==(const TaskAlloc &other) const
Definition: taskalloc.cc:35
virtual ~TaskAlloc()
Definition: taskalloc.cc:12
void setCoreScheduler(CoreScheduler *cs)
Definition: taskalloc.cc:28
std::vector< ResDemand * > res_demands
int id_
Definition: cloudtask.h:51
void updateMIPS()
Definition: taskalloc.cc:54
TaskAlloc(CloudTask *ct, int rd, int cap)
Definition: taskalloc.cc:16
double executedSince_
Definition: taskalloc.h:20
CloudTask * cloudTask
Definition: taskalloc.h:17
void print()
Definition: taskalloc.cc:50
double execTime()
Definition: taskalloc.cc:73
CoreScheduler * getCoreScheduler()
Definition: taskalloc.cc:31
void setComputingRate(double rate)
Definition: taskalloc.cc:43
double getDeadline()
Definition: taskalloc.cc:24