Skip to content
Snippets Groups Projects
Commit 4a70f7e1 authored by Mael Madon's avatar Mael Madon
Browse files

fix wrong condition in assert book_job_id. Bin_packing_energy seems to work

parent 71a21d71
Branches
Tags
No related merge requests found
Pipeline #500 failed
......@@ -19,6 +19,7 @@ BinPackingEnergy::SortableHost::SortableHost(
, pstate_soff(soff_pst)
{
nb_available_cores = nb_cores;
this->booked_jobs_id = new std::list<std::string>();
}
void BinPackingEnergy::SortableHost::update_available_cores(int nb_cores_available)
......@@ -28,7 +29,8 @@ void BinPackingEnergy::SortableHost::update_available_cores(int nb_cores_availab
void BinPackingEnergy::SortableHost::book(std::string job_id)
{
booked_jobs_id.push_back(job_id);
this->booked_jobs_id->push_back(job_id);
PPK_ASSERT_ERROR(!this->booked_jobs_id->empty(), "Lists of booked jobs is empty after adding job %s", job_id.c_str());
}
bool BinPackingEnergy::SortableHost::is_idle()
......@@ -143,126 +145,127 @@ void BinPackingEnergy::on_requested_call(double date)
void BinPackingEnergy::make_decisions(
double date, SortableJobOrder::UpdateInformation *update_info, SortableJobOrder::CompareInformation *compare_info)
{
/* SIMULATION_BEGIN is sent in a dedicated message buffer at t=0 even
/* SIMULATION_BEGIN is sent in a dedicated message buffer at t=0 even
if other messages are also sent at t=0. We wait for these potential other
messages to be read by calling back the scheduler at time t+epsilon. */
if (on_simulation_begin){
if (on_simulation_begin)
{
_decision->add_call_me_later(date + 1, date);
on_simulation_begin = false;
}
else{
/***************************************************************************
* Handle recently ended jobs and update the available machines
**************************************************************************/
for (const std::string &ended_job_id : _jobs_ended_recently)
else
{
SortableHost *host = current_allocations[ended_job_id];
/***************************************************************************
* Handle recently ended jobs and update the available machines
**************************************************************************/
for (const std::string &ended_job_id : _jobs_ended_recently)
{
SortableHost *host = current_allocations[ended_job_id];
const Job *ended_job = (*_workload)[ended_job_id];
host->nb_available_cores += ended_job->nb_requested_resources;
PPK_ASSERT_ERROR(host->nb_available_cores <= host->nb_cores);
const Job *ended_job = (*_workload)[ended_job_id];
host->nb_available_cores += ended_job->nb_requested_resources;
PPK_ASSERT_ERROR(host->nb_available_cores <= host->nb_cores);
current_allocations.erase(ended_job_id);
}
/***************************************************************************
* Handle recently released jobs from worklaod: put them in the queue
**************************************************************************/
for (const std::string &new_job_id : _jobs_released_recently)
{
const Job *new_job = (*_workload)[new_job_id];
current_allocations.erase(ended_job_id);
}
if (new_job->nb_requested_resources > max_nb_core)
_decision->add_reject_job(new_job_id, date);
else
_queue->append_job(new_job, update_info);
}
/***************************************************************************
* Handle recently released jobs from worklaod: put them in the queue
**************************************************************************/
for (const std::string &new_job_id : _jobs_released_recently)
{
const Job *new_job = (*_workload)[new_job_id];
/***************************************************************************
* Binpacking scheduling decision:
* Sort jobs in decreasing number of requested cores (DescendingSizeOrder)
* and hosts in our custom order (~ increasing available core)
**************************************************************************/
_queue->sort_queue(update_info, compare_info);
listofHosts.sort(HostComparator());
if (new_job->nb_requested_resources > max_nb_core)
_decision->add_reject_job(new_job_id, date);
else
_queue->append_job(new_job, update_info);
}
/* Go through the job queue and try to schedule the jobs */
for (auto job_it = _queue->begin(); job_it != _queue->end();)
{
const Job *job = (*job_it)->job;
/***************************************************************************
* Binpacking scheduling decision:
* Sort jobs in decreasing number of requested cores (DescendingSizeOrder)
* and hosts in our custom order (~ increasing available core)
**************************************************************************/
_queue->sort_queue(update_info, compare_info);
listofHosts.sort(HostComparator());
/* Find the smallest host where it fits */
bool host_found = false;
for (auto host : listofHosts)
/* Go through the job queue and try to schedule the jobs */
for (auto job_it = _queue->begin(); job_it != _queue->end();)
{
if (host->machine_state == SWITCHING_OFF)
{
/* We don't prebook jobs on switching off machines: we let them
complete their shut down. Consequently, we've reached the end
of the queue of potentially useful hosts. */
break;
}
const Job *job = (*job_it)->job;
if (host->nb_available_cores >= job->nb_requested_resources)
/* Find the smallest host where it fits */
bool host_found = false;
for (auto host : listofHosts)
{
host_found = true;
execute_or_book(job, host, date);
/* Even if the jobs are not executed straight away (booked) we
update the available cores to avoid double booking */
host->nb_available_cores -= job->nb_requested_resources;
PPK_ASSERT_ERROR(host->nb_available_cores >= 0);
listofHosts.sort(HostComparator());
if (_debug)
LOG_F(1, "makedecisions, list of hosts=%s", hosts_to_string(listofHosts).c_str());
break;
if (host->machine_state == SWITCHING_OFF)
{
/* We don't prebook jobs on switching off machines: we let them
complete their shut down. Consequently, we've reached the end
of the queue of potentially useful hosts. */
break;
}
if (host->nb_available_cores >= job->nb_requested_resources)
{
host_found = true;
execute_or_book(job, host, date);
/* Even if the jobs are not executed straight away (booked) we
update the available cores to avoid double booking */
host->nb_available_cores -= job->nb_requested_resources;
PPK_ASSERT_ERROR(host->nb_available_cores >= 0);
listofHosts.sort(HostComparator());
if (_debug)
LOG_F(1, "makedecisions, list of hosts=%s", hosts_to_string(listofHosts).c_str());
break;
}
}
}
if (host_found)
job_it = _queue->remove_job(job);
else
job_it++;
}
if (host_found)
job_it = _queue->remove_job(job);
else
job_it++;
}
/* Check end of simulation */
// TODO: make sure it's the good condition
if (_no_more_static_job_to_submit_received)
{
// Check if all hosts are either idle or asleep
reached_end_of_simulation = true;
for (auto host : vectorofHosts)
/* Check end of simulation */
// TODO: make sure it's the good condition
if (_no_more_static_job_to_submit_received)
{
if (!(host->is_idle() || host->machine_state == ASLEEP))
// Check if all hosts are either idle or asleep
reached_end_of_simulation = true;
for (auto host : vectorofHosts)
{
reached_end_of_simulation = false;
break;
if (!(host->is_idle() || host->machine_state == ASLEEP))
{
reached_end_of_simulation = false;
break;
}
}
}
}
/***************************************************************************
* Switch off the idle machines
**************************************************************************/
if (!reached_end_of_simulation)
for (auto host : vectorofHosts)
{
if (host->is_idle())
/***************************************************************************
* Switch off the idle machines
**************************************************************************/
if (!reached_end_of_simulation)
for (auto host : vectorofHosts)
{
add_state_to_switch(host->id, host->pstate_asleep);
host->machine_state = SWITCHING_OFF;
if (host->is_idle())
{
add_state_to_switch(host->id, host->pstate_asleep);
host->machine_state = SWITCHING_OFF;
}
}
}
/***************************************************************************
* Tell to batsim to update the machine states
**************************************************************************/
update_machine_states(date);
/***************************************************************************
* Tell to batsim to update the machine states
**************************************************************************/
update_machine_states(date);
}
}
......@@ -290,11 +293,11 @@ void BinPackingEnergy::on_machine_state_changed(double date, IntervalSet machine
{
current_host->machine_state = AWAKE;
PPK_ASSERT_ERROR(current_host->booked_jobs_id.empty(),
PPK_ASSERT_ERROR(!current_host->booked_jobs_id->empty(),
"Machine %d just became awake but has no job booked.", current_host->id);
int check_cores = 0;
for (auto it = current_host->booked_jobs_id.begin(); it != current_host->booked_jobs_id.end();
it = current_host->booked_jobs_id.erase(it))
for (auto it = current_host->booked_jobs_id->begin(); it != current_host->booked_jobs_id->end();
it = current_host->booked_jobs_id->erase(it))
{
const Job *booked_job = (*_workload)[*it];
check_cores += booked_job->nb_requested_resources;
......
......@@ -44,17 +44,20 @@ public:
* If the machine is asleep or switching on, the host keeps a list of jobs
* to execute as soon as the machine is awake.
*/
struct SortableHost
class SortableHost
{
public:
const int id;
const int nb_cores;
int nb_available_cores;
MachineState machine_state;
std::list<std::string> booked_jobs_id = std::list<std::string>();
std::list<std::string> *booked_jobs_id;
const int pstate_awake, pstate_son, pstate_asleep, pstate_soff;
// TODO remove pstate_son / pstate_soff
SortableHost(
int id_host, int cores, MachineState state, int awake_pst, int son_pst, int asleep_pst, int soff_pst);
public:
void update_available_cores(int nb_cores_available);
void book(std::string job_id);
bool is_idle();
......@@ -87,7 +90,6 @@ protected:
Job *start_switch_off_job(SortableHost *host, double date);
Job *start_fakejob(std::string type_of_fakejob, SortableHost *host, double date);
private:
int max_nb_core;
// list of hosts, to be sorted with listofHosts.sort(HostComparator())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment