Commit 9cbf589b authored by Millian Poquet's avatar Millian Poquet
Browse files

[code] cosmetics

parent efa8e190
......@@ -761,7 +761,8 @@ void export_schedule_to_csv(const std::string &filename, const BatsimContext *co
map<string, string> output_map;
map<int, Rational> machines_utilisation;
for (int i=0; i<context->machines.nb_machines(); i++) {
for (int i=0; i<context->machines.nb_machines(); i++)
{
machines_utilisation[i] = 0;
}
......@@ -833,7 +834,8 @@ void export_schedule_to_csv(const std::string &filename, const BatsimContext *co
MachineRange & allocation = job->allocation;
auto size = allocation.size();
for (size_t i=0; i<size; i++) {
for (size_t i=0; i < size; i++)
{
int machine_idx = allocation[i];
machines_utilisation[machine_idx] += job->runtime;
}
......@@ -844,9 +846,11 @@ void export_schedule_to_csv(const std::string &filename, const BatsimContext *co
double sum_time_running = 0;
double max_time_running = 0;
for (auto const & entry: machines_utilisation) {
for (auto const & entry : machines_utilisation)
{
sum_time_running += (double) entry.second;
if ((double) entry.second > max_time_running) {
if ((double) entry.second > max_time_running)
{
max_time_running = (double) entry.second;
}
}
......
......@@ -334,7 +334,8 @@ string job_state_to_string(JobState state)
{
string job_state("UNKNOWN");
switch (state) {
switch (state)
{
case JobState::JOB_STATE_NOT_SUBMITTED:
job_state = "NOT_SUBMITTED";
break;
......
......@@ -122,7 +122,8 @@ int execute_profile(BatsimContext *context,
int pfs_id = nb_res - 1;
// Add the pfs_machine
switch(data->host) {
switch(data->host)
{
case MsgParallelHomogeneousPFSMultipleTiersProfileData::Host::HPST:
hosts_to_use.push_back(context->machines.hpst_machine()->host);
break;
......@@ -150,7 +151,8 @@ int execute_profile(BatsimContext *context,
{
for (int x = 0; x < nb_res; ++x)
{
switch(data->direction) {
switch(data->direction)
{
case MsgParallelHomogeneousPFSMultipleTiersProfileData::Direction::TO_STORAGE:
// Communications are done towards the PFS host, which is the last resource (to the storage)
if (x != pfs_id)
......@@ -195,7 +197,8 @@ int execute_profile(BatsimContext *context,
hosts_to_use = std::vector<msg_host_t>();
// Add the pfs_machine
switch(data->direction) {
switch(data->direction)
{
case MsgDataStagingProfileData::Direction::LCST_TO_HPST:
hosts_to_use.push_back(context->machines.pfs_machine()->host);
hosts_to_use.push_back(context->machines.hpst_machine()->host);
......
......@@ -252,7 +252,7 @@ void Machines::create_machines(xbt_dynar_t hosts,
machine->id = -3;
_hpst_machine = machine;
}
else
else
{
xbt_die("Invalid machine found");
}
......
......@@ -62,7 +62,7 @@ struct Machine
Rational last_state_change_date = 0; //!< The time at which the last state change has been done
std::map<MachineState, Rational> time_spent_in_each_state; //!< The cumulated time of the machine in each MachineState
std::map<std::string, std::string> properties; //!< Properties defined in the platform file
/**
......@@ -278,9 +278,9 @@ public:
private:
std::vector<Machine *> _machines; //!< The vector of computing machines
Machine * _master_machine = nullptr; //!< The Master host
Machine * _pfs_machine = nullptr; //!< The Master host
Machine * _hpst_machine = nullptr; //!< The Master host
Machine * _master_machine = nullptr; //!< The master machine
Machine * _pfs_machine = nullptr; //!< The PFS machine
Machine * _hpst_machine = nullptr; //!< The HPST machine
PajeTracer * _tracer = nullptr; //!< The PajeTracer
std::map<MachineState, int> _nb_machines_in_each_state; //!< Counts how many machines are in each state
};
......
......@@ -375,6 +375,9 @@ Profile *Profile::from_json(const std::string & profile_name,
if (json_desc.HasMember("host"))
{
xbt_assert(json_desc["host"].IsString(),
"%s: profile '%s' has a non-string 'host' field",
error_prefix.c_str(), profile_name.c_str());
string host = json_desc["host"].GetString();
if (host == "HPST")
{
......
#include "protocol.hpp"
#include <boost/algorithm/string/join.hpp>
#include <xbt.h>
#include <rapidjson/stringbuffer.h>
......@@ -101,7 +103,8 @@ Value JsonProtocolWriter::machine_to_json_value(const Machine & machine)
machine_doc.AddMember("state", Value().SetString(machine_state_to_string(machine.state).c_str(), _alloc), _alloc);
Value properties(rapidjson::kObjectType);
for(auto const &entry : machine.properties) {
for(auto const &entry : machine.properties)
{
rapidjson::Value key(entry.first.c_str(), _alloc);
rapidjson::Value value(entry.second.c_str(), _alloc);
properties.AddMember(key, value, _alloc);
......@@ -714,22 +717,29 @@ void JsonProtocolReader::handle_change_job_state(int event_number,
xbt_assert(job_state_value.IsString(), "Invalid JSON message: in event %d (CHANGE_JOB_STATE): ['data']['job_state'] should be a string", event_number);
string job_state = job_state_value.GetString();
if (job_state != "NOT_SUBMITTED"
&& job_state != "SUBMITTED"
&& job_state != "RUNNING"
&& job_state != "COMPLETED_SUCCESSFULLY"
&& job_state != "COMPLETED_KILLED"
&& job_state != "REJECTED") {
xbt_assert(false, "Invalid JSON message: in event %d (CHANGE_JOB_STATE): ['data']['job_state'] must be one of: NOT_SUBMITTED, SUBMITTED, RUNNING, COMPLETED_SUCCESSFULLY, COMPLETED_KILLED, REJECTED", event_number);
set<string> allowed_states = {"NOT_SUBMITTED",
"RUNNING",
"COMPLETED_SUCCESSFULLY",
"COMPLETED_KILLED",
"REJECTED"};
if (allowed_states.count(job_state) != 1)
{
xbt_assert(false, "Invalid JSON message: in event %d (CHANGE_JOB_STATE): "
"['data']['job_state'] must be one of: {%s}", event_number,
boost::algorithm::join(allowed_states, ", ").c_str());
}
string kill_reason;
if (data_object.HasMember("kill_reason")) {
if (data_object.HasMember("kill_reason"))
{
const Value & kill_reason_value = data_object["kill_reason"];
xbt_assert(kill_reason_value.IsString(), "Invalid JSON message: in event %d (CHANGE_kill_reason): ['data']['kill_reason'] should be a string", event_number);
kill_reason = kill_reason_value.GetString();
if (kill_reason != "" && job_state != "COMPLETED_KILLED") {
if (kill_reason != "" && job_state != "COMPLETED_KILLED")
{
xbt_assert(false, "Invalid JSON message: in event %d (CHANGE_JOB_STATE): ['data']['kill_reason'] is only allowed if the job_state is COMPLETED_KILLED", event_number);
}
}
......
......@@ -171,9 +171,9 @@ bool CurrentSwitches::mark_switch_as_done(int machine_id,
}
all_machines = s->all_machines;
if (context->energy_used) {
if (context->energy_used)
{
context->pstate_tracer.add_pstate_change(MSG_get_clock(), s->all_machines, s->target_pstate);
context->energy_tracer.add_pstate_change(MSG_get_clock(), s->all_machines, s->target_pstate);
}
......
......@@ -281,9 +281,10 @@ void server_on_pstate_modification(ServerData * data,
data->context->current_switches.add_switch(message->machine_ids, message->new_pstate);
if (data->context->energy_used) {
if (data->context->energy_used)
{
data->context->energy_tracer.add_pstate_change(MSG_get_clock(), message->machine_ids,
message->new_pstate);
message->new_pstate);
}
// Let's quickly check whether this is a switchON or a switchOFF
......@@ -299,10 +300,11 @@ void server_on_pstate_modification(ServerData * data,
transition_state = -2; // means we are switching to a SLEEP_PSTATE
}
if (data->context->energy_used) {
if (data->context->energy_used)
{
// The pstate is set to an invalid one to know the machines are in transition.
data->context->pstate_tracer.add_pstate_change(MSG_get_clock(), message->machine_ids,
transition_state);
transition_state);
}
// Let's mark that some switches have been requested
......@@ -614,7 +616,7 @@ void server_on_submit_job(ServerData * data,
}
void server_on_change_job_state(ServerData * data,
IPMessage * task_data)
IPMessage * task_data)
{
xbt_assert(task_data->data != nullptr);
ChangeJobStateMessage * message = (ChangeJobStateMessage *) task_data->data;
......@@ -622,14 +624,16 @@ void server_on_change_job_state(ServerData * data,
Job * job = data->context->workloads.job_at(message->job_id);
XBT_INFO("Change job state: Job %d (workload=%s) to state %s (kill_Reason=%s)",
job->number, job->workload->name.c_str(),
message->job_state.c_str(), message->kill_reason.c_str());
job->number, job->workload->name.c_str(),
message->job_state.c_str(), message->kill_reason.c_str());
JobState new_state = job_state_from_string(message->job_state);
switch (job->state) {
switch (job->state)
{
case JobState::JOB_STATE_SUBMITTED:
switch (new_state) {
switch (new_state)
{
case JobState::JOB_STATE_RUNNING:
job->starting_time = MSG_get_clock();
data->nb_running_jobs++;
......@@ -644,7 +648,8 @@ void server_on_change_job_state(ServerData * data,
}
break;
case JobState::JOB_STATE_RUNNING:
switch (new_state) {
switch (new_state)
{
case JobState::JOB_STATE_COMPLETED_SUCCESSFULLY:
case JobState::JOB_STATE_COMPLETED_KILLED:
job->runtime = MSG_get_clock() - job->starting_time;
......@@ -660,11 +665,12 @@ void server_on_change_job_state(ServerData * data,
default:
xbt_assert(false, "Can only change the state of a submitted or running job.");
}
job->state = new_state;
job->kill_reason = message->kill_reason;
XBT_INFO("Job state changed: Job %d (workload=%s)",
job->number, job->workload->name.c_str());
job->number, job->workload->name.c_str());
check_submitted_and_completed(data);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment