}
}
typedef simgrid::msg::Comm sg_msg_Comm;
-/** @brief Task datatype.
- *
- * Since most scheduling algorithms rely on a concept of task that can be either <em>computed</em> locally or
- * <em>transferred</em> on another processor, it seems to be the right level of abstraction for our purposes.
- * A <em>task</em> may then be defined by a <em>computing amount</em>, a <em>message size</em> and
- * some <em>private data</em>.
- */
-typedef simgrid::msg::Task* msg_task_t;
+typedef simgrid::msg::Task sg_msg_Task;
#else
typedef struct msg_Comm sg_msg_Comm;
-typedef struct msg_Task* msg_task_t;
+typedef struct msg_Task sg_msg_Task;
#endif
#ifdef __cplusplus
* \endrst
*/
typedef sg_msg_Comm* msg_comm_t;
+typedef const sg_msg_Comm* const_msg_comm_t;
+
+/** @brief Task datatype.
+ *
+ * Since most scheduling algorithms rely on a concept of task that can be either <em>computed</em> locally or
+ * <em>transferred</em> on another processor, it seems to be the right level of abstraction for our purposes.
+ * A <em>task</em> may then be defined by a <em>computing amount</em>, a <em>message size</em> and
+ * some <em>private data</em>.
+ */
+typedef sg_msg_Task* msg_task_t;
+typedef const sg_msg_Task* const_msg_task_t;
/* ******************************** Task ************************************ */
XBT_PUBLIC xbt_dynar_t MSG_processes_as_dynar();
XBT_PUBLIC int MSG_process_get_number();
-XBT_PUBLIC void* MSG_process_get_data(msg_process_t process);
+XBT_PUBLIC void* MSG_process_get_data(const_sg_actor_t process);
XBT_PUBLIC msg_error_t MSG_process_set_data(msg_process_t process, void* data);
XBT_PUBLIC void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data);
XBT_PUBLIC msg_task_t MSG_task_create(const char* name, double flops_amount, double bytes_amount, void* data);
XBT_PUBLIC msg_task_t MSG_parallel_task_create(const char* name, int host_nb, const msg_host_t* host_list,
double* flops_amount, double* bytes_amount, void* data);
-XBT_PUBLIC void* MSG_task_get_data(msg_task_t task);
+XBT_PUBLIC void* MSG_task_get_data(const_msg_task_t task);
XBT_PUBLIC void MSG_task_set_data(msg_task_t task, void* data);
-XBT_PUBLIC msg_process_t MSG_task_get_sender(msg_task_t task);
-XBT_PUBLIC msg_host_t MSG_task_get_source(msg_task_t task);
-XBT_PUBLIC const char* MSG_task_get_name(msg_task_t task);
+XBT_PUBLIC msg_process_t MSG_task_get_sender(const_msg_task_t task);
+XBT_PUBLIC msg_host_t MSG_task_get_source(const_msg_task_t task);
+XBT_PUBLIC const char* MSG_task_get_name(const_msg_task_t task);
XBT_PUBLIC void MSG_task_set_name(msg_task_t task, const char* name);
XBT_PUBLIC msg_error_t MSG_task_cancel(msg_task_t task);
XBT_PUBLIC msg_error_t MSG_task_destroy(msg_task_t task);
XBT_PUBLIC void MSG_task_set_bound(msg_task_t task, double bound);
XBT_PUBLIC void MSG_task_set_flops_amount(msg_task_t task, double flops_amount);
-XBT_PUBLIC double MSG_task_get_flops_amount(msg_task_t task);
-XBT_PUBLIC double MSG_task_get_remaining_work_ratio(msg_task_t task);
+XBT_PUBLIC double MSG_task_get_flops_amount(const_msg_task_t task);
+XBT_PUBLIC double MSG_task_get_remaining_work_ratio(const_msg_task_t task);
XBT_PUBLIC void MSG_task_set_bytes_amount(msg_task_t task, double bytes_amount);
-XBT_PUBLIC double MSG_task_get_remaining_communication(msg_task_t task);
-XBT_PUBLIC double MSG_task_get_bytes_amount(msg_task_t task);
+XBT_PUBLIC double MSG_task_get_remaining_communication(const_msg_task_t task);
+XBT_PUBLIC double MSG_task_get_bytes_amount(const_msg_task_t task);
XBT_PUBLIC msg_error_t MSG_task_receive_with_timeout(msg_task_t* task, const char* alias, double timeout);
XBT_PUBLIC msg_comm_t MSG_task_irecv_bounded(msg_task_t* task, const char* alias, double rate);
XBT_PUBLIC int MSG_comm_test(msg_comm_t comm);
XBT_PUBLIC int MSG_comm_testany(xbt_dynar_t comms);
-XBT_PUBLIC void MSG_comm_destroy(msg_comm_t comm);
+XBT_PUBLIC void MSG_comm_destroy(const_msg_comm_t comm);
XBT_PUBLIC msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout);
XBT_PUBLIC void MSG_comm_waitall(msg_comm_t* comm, int nb_elem, double timeout);
XBT_PUBLIC int MSG_comm_waitany(xbt_dynar_t comms);
-XBT_PUBLIC msg_task_t MSG_comm_get_task(msg_comm_t comm);
-XBT_PUBLIC msg_error_t MSG_comm_get_status(msg_comm_t comm);
+XBT_PUBLIC msg_task_t MSG_comm_get_task(const_msg_comm_t comm);
+XBT_PUBLIC msg_error_t MSG_comm_get_status(const_msg_comm_t comm);
/** @brief Check if there is a communication going on in a mailbox.
*
XBT_PUBLIC msg_error_t MSG_task_send_bounded(msg_task_t task, const char* alias, double rate);
XBT_PUBLIC int MSG_task_listen_from(const char* alias);
XBT_PUBLIC void MSG_task_set_category(msg_task_t task, const char* category);
-XBT_PUBLIC const char* MSG_task_get_category(msg_task_t task);
+XBT_PUBLIC const char* MSG_task_get_category(const_msg_task_t task);
/************************** Mailbox handling ************************************/
static jfieldID jcomm_field_Comm_taskBind;
void jcomm_bind_task(JNIEnv *env, jobject jcomm) {
- msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
+ const_msg_comm_t comm = (msg_comm_t)(uintptr_t)env->GetLongField(jcomm, jcomm_field_Comm_bind);
//test if we are receiving or sending a task.
jboolean jreceiving = env->GetBooleanField(jcomm, jcomm_field_Comm_receiving);
if (jreceiving == JNI_TRUE) {
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm) {
- msg_comm_t comm;
msg_task_t *task_received;
task_received = (msg_task_t*) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_taskBind);
delete task_received;
- comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
+ const_msg_comm_t comm = (msg_comm_t)(uintptr_t)env->GetLongField(jcomm, jcomm_field_Comm_bind);
MSG_comm_destroy(comm);
}
}
JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobject jtask) {
- msg_task_t task = jtask_to_native(jtask, env);
+ const_msg_task_t task = jtask_to_native(jtask, env);
if (not task) {
jxbt_throw_notbound(env, "task", jtask);
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobject jtask) {
- msg_task_t task = jtask_to_native(jtask, env);
+ const_msg_task_t task = jtask_to_native(jtask, env);
if (not task) {
jxbt_throw_notbound(env, "task", jtask);
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource(JNIEnv * env, jobject jtask)
{
- msg_task_t task = jtask_to_native(jtask, env);
+ const_msg_task_t task = jtask_to_native(jtask, env);
if (not task) {
jxbt_throw_notbound(env, "task", jtask);
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Task_getFlopsAmount(JNIEnv * env, jobject jtask)
{
- msg_task_t ptask = jtask_to_native(jtask, env);
+ const_msg_task_t ptask = jtask_to_native(jtask, env);
if (not ptask) {
jxbt_throw_notbound(env, "task", jtask);
}
/** @brief Destroys the provided communication. */
-void MSG_comm_destroy(msg_comm_t comm)
+void MSG_comm_destroy(const_msg_comm_t comm)
{
delete comm;
}
* @param comm a finished communication
* @return the status of the communication, or #MSG_OK if no error occurred during the communication
*/
-msg_error_t MSG_comm_get_status(msg_comm_t comm)
+msg_error_t MSG_comm_get_status(const_msg_comm_t comm)
{
return comm->get_status();
}
* @param comm the communication where to get the task
* @return the task from the communication
*/
-msg_task_t MSG_comm_get_task(msg_comm_t comm)
+msg_task_t MSG_comm_get_task(const_msg_comm_t comm)
{
xbt_assert(comm, "Invalid parameter");
*
* This function checks whether @a process is a valid pointer and returns the user data associated to this process.
*/
-void* MSG_process_get_data(msg_process_t process)
+void* MSG_process_get_data(const_sg_actor_t process)
{
xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
Task& operator=(const Task&) = delete;
~Task() = default;
- bool is_used() { return is_used_; }
- bool is_parallel() { return parallel_; }
+ bool is_used() const { return is_used_; }
+ bool is_parallel() const { return parallel_; }
void set_used();
void set_not_used() { this->is_used_ = false; }
const std::string& get_name() const { return name_; }
- const char* get_cname() { return name_.c_str(); }
+ const char* get_cname() const { return name_.c_str(); }
void set_name(const char* new_name) { name_ = std::string(new_name); }
void set_tracing_category(const char* category) { tracing_category_ = category ? std::string(category) : ""; }
- const std::string& get_tracing_category() { return tracing_category_; }
+ const std::string& get_tracing_category() const { return tracing_category_; }
bool has_tracing_category() { return not tracing_category_.empty(); }
XBT_ATTRIB_DEPRECATED_v329("Please use set_data()") void* get_user_data() { return get_data(); }
XBT_ATTRIB_DEPRECATED_v329("Please use get_data()") void set_user_data(void* data) { set_data(data); }
- long long int get_id() { return id_; }
- double get_priority() { return priority_; }
+ long long int get_id() const { return id_; }
+ double get_priority() const { return priority_; }
void set_priority(double priority);
void set_bound(double bound) { bound_ = bound; }
- double get_bound() { return bound_; }
+ double get_bound() const { return bound_; }
void set_rate(double rate) { rate_ = rate; }
- double get_rate() { return rate_; }
+ double get_rate() const { return rate_; }
void set_timeout(double timeout) { timeout_ = timeout; }
- s4u::Actor* get_sender();
- s4u::Host* get_source();
+ s4u::Actor* get_sender() const;
+ s4u::Host* get_source() const;
s4u::ExecPtr compute = nullptr; /* S4U modeling of computation */
s4u::CommPtr comm = nullptr; /* S4U modeling of communication */
bool test();
msg_error_t wait_for(double timeout);
void set_status(msg_error_t status) { status_ = status; }
- msg_error_t get_status() { return status_; }
+ msg_error_t get_status() const { return status_; }
};
} // namespace msg
priority_ = 1.0 / priority;
}
-s4u::Actor* Task::get_sender()
+s4u::Actor* Task::get_sender() const
{
return comm ? comm->get_sender() : nullptr;
}
-s4u::Host* Task::get_source()
+s4u::Host* Task::get_source() const
{
return comm ? comm->get_sender()->get_host() : nullptr;
}
}
/** @brief Return the user data of the given task */
-void* MSG_task_get_data(msg_task_t task)
+void* MSG_task_get_data(const_msg_task_t task)
{
return task->get_data();
}
}
/** @brief Returns the sender of the given task */
-msg_process_t MSG_task_get_sender(msg_task_t task)
+msg_process_t MSG_task_get_sender(const_msg_task_t task)
{
return task->get_sender();
}
/** @brief Returns the source (the sender's host) of the given task */
-msg_host_t MSG_task_get_source(msg_task_t task)
+msg_host_t MSG_task_get_source(const_msg_task_t task)
{
return task->get_source();
}
/** @brief Returns the name of the given task. */
-const char *MSG_task_get_name(msg_task_t task)
+const char* MSG_task_get_name(const_msg_task_t task)
{
return task->get_cname();
}
*
* It works for either parallel or sequential tasks.
*/
-double MSG_task_get_remaining_work_ratio(msg_task_t task)
+double MSG_task_get_remaining_work_ratio(const_msg_task_t task)
{
xbt_assert((task != nullptr), "Cannot get information from a nullptr task");
if (task->compute) {
* It works for sequential tasks, but the remaining amount of work is not a scalar value for parallel tasks.
* So you will get an exception if you call this function on parallel tasks. Just don't do it.
*/
-double MSG_task_get_flops_amount(msg_task_t task) {
+double MSG_task_get_flops_amount(const_msg_task_t task)
+{
if (task->compute != nullptr) {
return task->compute->get_remaining();
} else {
* If the communication does not exist it will return 0.
* So, if the communication has FINISHED or FAILED it returns zero.
*/
-double MSG_task_get_remaining_communication(msg_task_t task)
+double MSG_task_get_remaining_communication(const_msg_task_t task)
{
XBT_DEBUG("calling simcall_communication_get_remains(%p)", task->comm.get());
return task->comm->get_remaining();
}
/** @brief Returns the size of the data attached to the given task. */
-double MSG_task_get_bytes_amount(msg_task_t task)
+double MSG_task_get_bytes_amount(const_msg_task_t task)
{
xbt_assert(task != nullptr, "Invalid parameter");
return task->bytes_amount;
* @param task the task to be considered
* @return Returns the name of the tracing category of the given task, "" otherwise
*/
-const char* MSG_task_get_category(msg_task_t task)
+const char* MSG_task_get_category(const_msg_task_t task)
{
return task->get_tracing_category().c_str();
}