1 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef MSG_PRIVATE_HPP
7 #define MSG_PRIVATE_HPP
9 #include "simgrid/Exception.hpp"
10 #include "simgrid/msg.h"
11 #include "src/kernel/activity/CommImpl.hpp"
12 #include <simgrid/modelchecker.h>
13 #include <xbt/Extendable.hpp>
17 /**************** datatypes **********************************/
20 extern template class XBT_PUBLIC xbt::Extendable<msg::Task>;
23 class Task : public xbt::Extendable<Task> {
24 std::string name_ = "";
25 std::string tracing_category_ = "";
28 double timeout_ = -1; /* Default timeout is infinite */
29 double priority_ = 1.0;
30 double bound_ = 0.0; /* Capping for CPU resource, or 0 for no capping */
31 double rate_ = -1; /* Capping for network resource, or -1 for no capping*/
32 bool is_used_ = false; /* Indicates whether the task is used in SIMIX currently */
34 explicit Task(const std::string& name, double flops_amount, double bytes_amount, void* data);
35 explicit Task(const std::string& name, std::vector<s4u::Host*>&& hosts, std::vector<double>&& flops_amount,
36 std::vector<double>&& bytes_amount, void* data);
38 void report_multiple_use() const;
41 static Task* create(const std::string& name, double flops_amount, double bytes_amount, void* data);
42 static Task* create_parallel(const std::string& name, int host_nb, const msg_host_t* host_list, double* flops_amount,
43 double* bytes_amount, void* data);
44 msg_error_t execute();
45 msg_error_t send(const std::string& alias, double timeout);
46 s4u::CommPtr send_async(const std::string& alias, void_f_pvoid_t cleanup, bool detached);
50 Task(const Task&) = delete;
51 Task& operator=(const Task&) = delete;
53 bool is_used() const { return is_used_; }
54 bool is_parallel() const { return parallel_; }
57 void set_not_used() { this->is_used_ = false; }
58 const std::string& get_name() const { return name_; }
59 const char* get_cname() const { return name_.c_str(); }
60 void set_name(const char* new_name) { name_ = std::string(new_name); }
61 void set_tracing_category(const char* category) { tracing_category_ = category ? category : ""; }
62 const std::string& get_tracing_category() const { return tracing_category_; }
63 bool has_tracing_category() { return not tracing_category_.empty(); }
64 long long int get_id() const { return id_; }
65 double get_priority() const { return priority_; }
66 void set_priority(double priority);
67 void set_bound(double bound) { bound_ = bound; }
68 double get_bound() const { return bound_; }
69 void set_rate(double rate) { rate_ = rate; }
70 double get_rate() const { return rate_; }
71 void set_timeout(double timeout) { timeout_ = timeout; }
73 s4u::Actor* get_sender() const;
74 s4u::Host* get_source() const;
76 s4u::ExecPtr compute = nullptr; /* S4U modeling of computation */
77 s4u::CommPtr comm = nullptr; /* S4U modeling of communication */
78 double flops_amount = 0.0; /* Computation size */
79 double bytes_amount = 0.0; /* Data size */
81 /******* Parallel Tasks Only !!!! *******/
82 bool parallel_ = false;
83 std::vector<s4u::Host*> hosts_;
84 std::vector<double> flops_parallel_amount;
85 std::vector<double> bytes_parallel_amount;
89 msg_error_t status_ = MSG_OK; /* status of the communication once finished */
91 Task* task_sent; /* task sent (NULL for the receiver) */
92 Task** task_received; /* where the task will be received (NULL for the sender) */
93 s4u::CommPtr s_comm; /* SIMIX communication object encapsulated (the same for both processes) */
94 Comm(msg_task_t sent, msg_task_t* received, s4u::CommPtr comm)
95 : task_sent(sent), task_received(received), s_comm(std::move(comm))
99 msg_error_t wait_for(double timeout);
100 void set_status(msg_error_t status) { status_ = status; }
101 msg_error_t get_status() const { return status_; }
105 } // namespace simgrid
107 /************************** Global variables ********************************/
108 struct MSG_Global_t {
109 static bool debug_multiple_use; /* whether we want an error message when reusing the same Task for 2 things */
110 std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
111 void (*task_copy_callback)(msg_task_t task, msg_process_t src, msg_process_t dst);
112 void_f_pvoid_t process_data_cleanup;
115 XBT_PUBLIC_DATA MSG_Global_t* msg_global;
117 /*************************************************************/