ipp.hpp 6.99 KB
Newer Older
1
/**
Millian Poquet's avatar
Millian Poquet committed
2
 * @file ipp.hpp
Millian Poquet's avatar
Millian Poquet committed
3
 * @brief Inter-Process Protocol (within Batsim, not with the Decision real process)
4 5
 */

Millian Poquet's avatar
Millian Poquet committed
6 7
#pragma once

8 9 10
#include <vector>
#include <string>

11 12
#include <simgrid/msg.h>

13 14
#include "machine_range.hpp"

15 16
struct BatsimContext;

Millian Poquet's avatar
Millian Poquet committed
17 18 19
/**
 * @brief Stores the different types of inter-process messages
 */
20 21
enum class IPMessageType
{
22 23 24 25 26 27 28 29 30 31 32 33 34 35
    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.
    ,PSTATE_MODIFICATION    //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a pstate modification).
    ,SCHED_ALLOCATION       //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a job allocation).
    ,SCHED_REJECTION        //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a job rejection).
    ,SCHED_NOP              //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a NOP message).
    ,SCHED_NOP_ME_LATER     //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a NOP_ME_LATTER message).
    ,SCHED_TELL_ME_ENERGY   //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a TELL_ME_CONSUMED_ENERGY message).
    ,SCHED_READY            //!< SchedulerHandler -> Server. The scheduler handler tells the server that the scheduler is ready (messages can be sent to it).
    ,WAITING_DONE           //!< Waiter -> server. The waiter tells the server that the target time has been reached.
    ,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.
    ,SWITCHED_ON            //!< SwitcherON -> Server. The switcherON process tells the server the machine pstate has been changed
    ,SWITCHED_OFF           //!< SwitcherOFF -> Server. The switcherOFF process tells the server the machine pstate has been changed.
36 37
};

Millian Poquet's avatar
Millian Poquet committed
38 39 40
/**
 * @brief The content of the JobSubmitted message
 */
41 42
struct JobSubmittedMessage
{
Millian Poquet's avatar
Millian Poquet committed
43
    int job_id; //!< The job ID
44 45
};

Millian Poquet's avatar
Millian Poquet committed
46 47 48
/**
 * @brief The content of the JobCompleted message
 */
49 50
struct JobCompletedMessage
{
Millian Poquet's avatar
Millian Poquet committed
51
    int job_id; //!< The job ID
52 53
};

Millian Poquet's avatar
Millian Poquet committed
54 55 56
/**
 * @brief The content of the JobRejected message
 */
57 58
struct JobRejectedMessage
{
Millian Poquet's avatar
Millian Poquet committed
59
    int job_id; //!< The job ID
60 61
};

Millian Poquet's avatar
Millian Poquet committed
62 63 64
/**
 * @brief A subpart of the SchedulingAllocation message
 */
65 66
struct SchedulingAllocation
{
Millian Poquet's avatar
Millian Poquet committed
67 68 69
    int job_id; //!< The job unique number
    MachineRange machine_ids; //!< The IDs of the machines on which the job should be allocated
    std::vector<msg_host_t> hosts;  //!< The corresponding SimGrid hosts
70 71
};

Millian Poquet's avatar
Millian Poquet committed
72 73 74
/**
 * @brief The content of the JobSubmitted message
 */
75 76
struct SchedulingAllocationMessage
{
Millian Poquet's avatar
Millian Poquet committed
77
    std::vector<SchedulingAllocation *> allocations;  //!< Possibly several allocations
78 79
};

Millian Poquet's avatar
Millian Poquet committed
80 81 82
/**
 * @brief The content of the PstateModification message
 */
83 84
struct PStateModificationMessage
{
Millian Poquet's avatar
Millian Poquet committed
85 86
    MachineRange machine_ids; //!< The IDs of the machines on which the pstate should be changed
    int new_pstate; //!< The power state into which the machines should be put
87 88
};

Millian Poquet's avatar
Millian Poquet committed
89 90 91
/**
 * @brief The content of the NOPMeLater message
 */
92 93
struct NOPMeLaterMessage
{
Millian Poquet's avatar
Millian Poquet committed
94
    double target_time; //!< The time at which Batsim should send a NOP message to the decision real process
95 96
};

Millian Poquet's avatar
Millian Poquet committed
97 98 99
/**
 * @brief The content of the SwitchON message
 */
100 101
struct SwitchONMessage
{
Millian Poquet's avatar
Millian Poquet committed
102 103
    int machine_id; //!< The unique number of the machine which should be switched ON
    int new_pstate; //!< The power state the machine should be put into
104 105
};

Millian Poquet's avatar
Millian Poquet committed
106 107 108
/**
 * @brief The content of the SwitchOFF message
 */
109 110
struct SwitchOFFMessage
{
Millian Poquet's avatar
Millian Poquet committed
111 112
    int machine_id; //!< The unique number of the machine which should be switched OFF
    int new_pstate; //!< The power state the machine should be put into
113 114
};

Millian Poquet's avatar
Millian Poquet committed
115 116 117
/**
 * @brief The base struct sent in inter-process messages
 */
118 119
struct IPMessage
{
Millian Poquet's avatar
Millian Poquet committed
120 121 122 123
    /**
     * @brief Destroys a IPMessage
     * @details This method deletes the message data according to its type
     */
124
    ~IPMessage();
Millian Poquet's avatar
Millian Poquet committed
125 126
    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.
127 128
};

Millian Poquet's avatar
Millian Poquet committed
129 130 131
/**
 * @brief The arguments of the request_reply_scheduler_process process
 */
132 133
struct RequestReplyProcessArguments
{
Millian Poquet's avatar
Millian Poquet committed
134 135
    BatsimContext * context;    //!< The BatsimContext
    std::string send_buffer;    //!< The message to send to the Decision real process
136 137
};

Millian Poquet's avatar
Millian Poquet committed
138 139 140
/**
 * @brief The arguments of the uds_server_process process
 */
141 142
struct ServerProcessArguments
{
Millian Poquet's avatar
Millian Poquet committed
143
    BatsimContext * context;    //!< The BatsimContext
144 145
};

Millian Poquet's avatar
Millian Poquet committed
146 147 148
/**
 * @brief The arguments of the execute_job_process process
 */
149 150
struct ExecuteJobProcessArguments
{
Millian Poquet's avatar
Millian Poquet committed
151 152
    BatsimContext * context;            //!< The BatsimContext
    SchedulingAllocation * allocation;  //!< The SchedulingAllocation
153 154
};

Millian Poquet's avatar
Millian Poquet committed
155 156 157
/**
 * @brief The arguments of the killer_process process
 */
158 159
struct KillerProcessArguments
{
Millian Poquet's avatar
Millian Poquet committed
160 161
    msg_task_t task; //!< The task that will be cancelled if the walltime is reached
    double walltime; //!< The number of seconds to wait before cancelling the task
162 163
};

Millian Poquet's avatar
Millian Poquet committed
164 165 166
/**
 * @brief The arguments of the switch_on_machine_process and switch_off_machine_process processes
 */
167 168
struct SwitchPStateProcessArguments
{
Millian Poquet's avatar
Millian Poquet committed
169 170 171
    BatsimContext * context;    //!< The BatsimContext
    int machine_id;             //!< The unique number of the machine whose power state should be switched
    int new_pstate;             //!< The power state into which the machine should be put
172
};
173

Millian Poquet's avatar
Millian Poquet committed
174 175 176
/**
 * @brief The arguments of the job_submitter_process process
 */
177 178
struct JobSubmitterProcessArguments
{
Millian Poquet's avatar
Millian Poquet committed
179
    BatsimContext * context;    //!< The BatsimContext
180 181
};

Millian Poquet's avatar
Millian Poquet committed
182 183 184
/**
 * @brief The arguments of the waiter_process process
 */
185 186
struct WaiterProcessArguments
{
Millian Poquet's avatar
Millian Poquet committed
187
    double target_time; //!< The time at which the waiter should stop waiting
188 189
};

190 191
/**
 * @brief Sends a message from the given process to the given mailbox
192
 * @param[in] destination_mailbox The destination mailbox
193 194 195 196
 * @param[in] type The type of message to send
 * @param[in] data The data associated to the message
 */
void send_message(const std::string & destination_mailbox, IPMessageType type, void * data = nullptr);
Millian Poquet's avatar
Millian Poquet committed
197 198 199

/**
 * @brief Sends a message from the given process to the given mailbox
200
 * @param[in] destination_mailbox The destination mailbox
Millian Poquet's avatar
Millian Poquet committed
201 202 203
 * @param[in] type The type of message to send
 * @param[in] data The data associated to the message
 */
204
void send_message(const char * destination_mailbox, IPMessageType type, void * data = nullptr);
205

Millian Poquet's avatar
Millian Poquet committed
206 207 208 209 210
/**
 * @brief Transforms a IPMessageType into a std::string
 * @param[in] type The IPMessageType
 * @return The std::string corresponding to the type
 */
211
std::string ipMessageTypeToString(IPMessageType type);