Commit b9b5e854 authored by Millian Poquet's avatar Millian Poquet

New modelisation of the inter-process communication and of the process...

New modelisation of the inter-process communication and of the process creation (and parameters). A context has been created to avoid any global variable. Network is now implemented in C++. Network parsing is done in C++ too. The server socker is now BatSim's. To be continued.
parent 35611845
*.o
\ No newline at end of file
/**
* @file context.hpp The Batsim context
*/
#include "network.hpp"
#include "machines.hpp"
#include "jobs.hpp"
#include "profiles.hpp"
#include "export.hpp"
struct BatsimContext
{
UnixDomainSocket socket;
Machines machines;
Jobs jobs;
Profiles profiles;
long long microseconds_used_by_scheduler;
};
#include "ipp.hpp"
#include <simgrid/msg.h>
#include <map>
using namespace std;
XBT_LOG_NEW_DEFAULT_CATEGORY(ipp, "ipp");
void send_message(const std::string & destination_mailbox, IPMessageType type, void * data)
{
IPMessage * message = new IPMessage;
message->type = type;
message->data = data;
msg_task_t task_to_send = MSG_task_create(NULL, 0, 1e-6, message);
XBT_INFO("message from '%s' to '%s' of type '%s' with data %p",
MSG_process_get_name(MSG_process_self()), destination_mailbox.c_str(), ipMessageTypeToString(type).c_str(), data);
MSG_task_send(task_to_send, destination_mailbox.c_str());
}
std::string ipMessageTypeToString(IPMessageType type)
{
static map<IPMessageType, string> type_to_string =
{
{IPMessageType::JOB_SUBMITTED, "JOB_SUBMITTED"},
{IPMessageType::JOB_COMPLETED, "JOB_COMPLETED"},
{IPMessageType::SCHED_ALLOCATION, "SCHED_ALLOCATION"},
{IPMessageType::SCHED_NOP, "SCHED_NOP"},
{IPMessageType::SCHED_READY, "SCHED_READY"},
{IPMessageType::SUBMITTER_HELLO, "SUBMITTER_HELLO"},
{IPMessageType::SUBMITTER_BYE, "SUBMITTER_BYE"},
};
return type_to_string[type];
}
#pragma once
/**
* @file ipp.hpp Inter-Process Protocol
*/
#include <vector>
#include <string>
struct BatsimContext;
enum class IPMessageType
{
JOB_SUBMITTED //!< Submitter -> Server. The submitter tells the server a new job has been submitted.
,JOB_COMPLETED //!< Launcher/killer -> Server. The launcher tells the server a job has been completed.
,SCHED_ALLOCATION //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a job allocation).
,SCHED_NOP //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a NOP message).
,SCHED_READY //!< SchedulerHandler -> Server. The scheduler handler tells the server that the scheduler is ready (messages can be sent to it).
,SUBMITTER_HELLO //!< Submitter -> Server. The submitter tells it starts submitting to the server.
,SUBMITTER_BYE //!< Submitter -> Server. The submitter tells it stops submitting to the server.
};
struct JobSubmittedMessage
{
int job_id; //! The job ID
};
struct JobCompletedMessage
{
int job_id; //! The job ID
};
struct SchedulingAllocation
{
int job_id;
std::vector<int> machine_ids; //! The IDs of the machines on which the job should be allocated
};
struct SchedulingAllocationMessage
{
std::vector<SchedulingAllocation> allocations; //! Possibly several allocations
};
struct IPMessage
{
IPMessageType type; //! The message type
void * data; //! The message data (can be NULL if type is in [SCHED_NOP, SUBMITTER_HELLO, SUBMITTER_BYE, SUBMITTER_READY]). Otherwise, it is either a JobSubmittedMessage*, a JobCompletedMessage* or a SchedulingAllocationMessage* according to type.
};
struct RequestReplyProcessArguments
{
BatsimContext * context;
std::string send_buffer;
};
struct ServerProcessArguments
{
BatsimContext * context;
};
/**
* @brief Sends a message from the given process to the given mailbox
* @param[in] dst The destination mailbox
* @param[in] type The type of message to send
* @param[in] job_id The job the message is about
* @param[in] data The data associated to the message
*/
void send_message(const std::string & destination_mailbox, IPMessageType type, void * data = nullptr);
std::string ipMessageTypeToString(IPMessageType type);
/**
* @file jobs.cpp
*/
/**
* @file jobs.hpp
*/
#pragma once
#include <map>
enum class JobState
{
JOB_STATE_NOT_SUBMITTED //!< The job exists but cannot be scheduled yet.
,JOB_STATE_SUBMITTED //!< The job has been submitted, it can now be scheduled.
,JOB_STATE_RUNNING //!< The job has been scheduled and is currently being processed.
,JOB_STATE_COMPLETED_SUCCESSFULLY //!< The job execution finished before its walltime.
,JOB_STATE_COMPLETED_KILLED //!< The job execution time was longer than its walltime so the job had been killed.
};
struct Job
{
int id;
std::string profile;
double submission_time;
double walltime;
int required_nb_res;
double starting_time;
double runtime;
std::vector<int> allocation;
JobState state;
};
class Jobs
{
public:
Jobs();
~Jobs();
void load_from_json(const std::string & filename);
Job * operator[](int job_id);
const Job * operator[](int job_id) const;
bool exists(int job_id) const;
const std::map<int, Job> & jobs() const;
private:
std::map<int, Job> _jobs;
};
......@@ -2,6 +2,7 @@
#include <algorithm>
#include <iterator>
#include <map>
using namespace std;
......@@ -32,7 +33,7 @@ void Machines::createMachines(xbt_dynar_t hosts)
machine.name = MSG_host_get_name(host);
machine.host = host;
machine.jobs_being_computed = {};
machine.state = Machine::IDLE;
machine.state = MachineState::IDLE;
}
}
......@@ -51,7 +52,7 @@ void Machines::updateMachinesOnJobRun(int jobID, const std::vector<int> & usedMa
for (int machineID : usedMachines)
{
Machine & machine = _machines[machineID];
machine.state = Machine::COMPUTING;
machine.state = MachineState::COMPUTING;
// cout << machine;
machine.jobs_being_computed.insert(jobID);
......@@ -72,7 +73,7 @@ void Machines::updateMachinesOnJobEnd(int jobID, const std::vector<int> & usedMa
if (machine.jobs_being_computed.empty())
{
machine.state = Machine::IDLE;
machine.state = MachineState::IDLE;
// todo: handle the Pajé trace in this file, not directly in batsim.c
}
......@@ -87,7 +88,7 @@ ostream & operator<<(ostream & out, const Machine & machine)
"COMPUTING"};
out << "Machine " << machine.id << ", ";
out << "state = " << machineStateToStr[machine.state] << ", ";
out << "state = " << machineStateToString(machine.state) << ", ";
out << "jobs = [";
std::copy(machine.jobs_being_computed.begin(), machine.jobs_being_computed.end(),
std::ostream_iterator<char>(out, " "));
......@@ -95,3 +96,15 @@ ostream & operator<<(ostream & out, const Machine & machine)
return out;
}
string machineStateToString(MachineState state)
{
static const std::map<MachineState,std::string> conv =
{
{MachineState::SLEEPING, "sleeping"},
{MachineState::IDLE, "idle"},
{MachineState::COMPUTING, "computing"}
};
return conv.at(state);
}
......@@ -7,19 +7,19 @@
#include <simgrid/msg.h>
enum class MachineState
{
SLEEPING,
IDLE,
COMPUTING,
};
struct Machine
{
enum State
{
SLEEPING,
IDLE,
COMPUTING,
};
int id;
std::string name;
int id;
std::string name;
msg_host_t host;
State state;
MachineState state;
std::set<int> jobs_being_computed;
};
......@@ -28,19 +28,23 @@ std::ostream & operator<<(std::ostream & out, const Machine & machine);
class Machines
{
public:
Machines();
~Machines();
void createMachines(xbt_dynar_t hosts);
void updateMachinesOnJobRun(int jobID, const std::vector<int> & usedMachines);
void updateMachinesOnJobEnd(int jobID, const std::vector<int> & usedMachines);
Machines();
~Machines();
void createMachines(xbt_dynar_t hosts);
void updateMachinesOnJobRun(int jobID, const std::vector<int> & usedMachines);
void updateMachinesOnJobEnd(int jobID, const std::vector<int> & usedMachines);
const Machine & operator[](int machineID) const;
Machine & operator[](int machineID);
const Machine & operator[](int machineID) const;
Machine & operator[](int machineID);
bool exists(int machineID) const;
private:
std::vector<Machine> _machines;
std::vector<Machine> _machines;
};
std::string machineStateToString(MachineState state);
// The array of machines
extern int nb_machines;
extern Machine* machines;
......
This diff is collapsed.
#pragma once
#include <string>
struct BatsimContext;
enum NetworkStamp : char
{
STATIC_JOB_ALLOCATION = 'J',
JOB_REJECTION = 'R',
NOP = 'N',
STATIC_JOB_SUBMISSION = 'S',
STATIC_JOB_COMPLETION = 'C'
};
class UnixDomainSocket
{
public:
UnixDomainSocket();
UnixDomainSocket(const std::string & filename);
~UnixDomainSocket();
void create_socket(const std::string & filename);
void accept_pending_connection();
void close();
std::string receive();
void send(const std::string & message);
private:
int _server_socket;
int _client_socket;
};
int uds_server_process(int argc, char *argv[]);
int request_reply_scheduler_process(int argc, char *argv[]);
#include "profiles.hpp"
Profiles::Profiles()
{
}
#pragma once
#include <string>
#include <map>
#include <vector>
enum ProfileType
{
DELAY,
MSG_PARALLEL,
MSG_PARALLEL_HOMOGENEOUS,
SMPI,
SEQUENCE
};
struct Profile
{
ProfileType type;
void * data;
};
struct MsgParallelProfileData
{
int nb_res; //! The number of resources
double * cpu; //! The computation vector
double * com; //! The communication matrix
};
struct MsgParallelHomogeneousProfileData
{
double cpu; //! The computation amount on each node
double com; //! The communication amount between each pair of nodes
};
struct DelayProfileData
{
double delay; //! The time amount, in seconds, that the job is supposed to take
};
struct SmpiProfileData
{
std::vector<std::string> trace_filenames; //! all defined tracefiles
};
//! The structure used to store additional information about profiles of type composed
struct SequenceProfileData
{
int repeat; //! The number of times the sequence must be repeated
std::vector<std::string> sequence; //! The sequence of profile names
};
class Profiles
{
public:
Profiles();
private:
std::map<std::string, Profile> _profiles;
};
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