1 /* Copyright (c) 2004-2019. 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 "src/kernel/activity/ExecImpl.hpp"
13 #include <simgrid/modelchecker.h>
17 /**************** datatypes **********************************/
21 std::string name_ = "";
22 std::string tracing_category_ = "";
23 void* userdata_ = nullptr;
26 double timeout_ = 0.0;
27 double priority_ = 1.0;
28 double bound_ = 0.0; /* Capping for CPU resource, or 0 for no capping */
29 double rate_ = -1; /* Capping for network resource, or -1 for no capping*/
30 bool is_used_ = false; /* Indicates whether the task is used in SIMIX currently */
32 explicit Task(std::string name, double flops_amount, double bytes_amount, void* data);
33 explicit Task(std::string name, std::vector<s4u::Host*> hosts, std::vector<double> flops_amount,
34 std::vector<double> bytes_amount, void* data);
36 void report_multiple_use() const;
39 static Task* create(std::string name, double flops_amount, double bytes_amount, void* data);
40 static Task* create_parallel(std::string name, int host_nb, const msg_host_t* host_list, double* flops_amount,
41 double* bytes_amount, void* data);
42 msg_error_t execute();
43 s4u::CommPtr send_async(std::string alias, void_f_pvoid_t cleanup, bool detached);
46 Task(const Task&) = delete;
47 Task& operator=(const Task&) = delete;
50 bool is_used() { return is_used_; }
51 bool is_parallel() { return parallel_; }
54 void set_not_used() { this->is_used_ = false; }
55 const std::string& get_name() const { return name_; }
56 const char* get_cname() { return name_.c_str(); }
57 void set_name(const char* new_name) { name_ = std::string(new_name); }
58 void set_tracing_category(const char* category) { tracing_category_ = category ? std::string(category) : ""; }
59 const std::string& get_tracing_category() { return tracing_category_; }
60 bool has_tracing_category() { return not tracing_category_.empty(); }
61 void* get_user_data() { return userdata_; }
62 void set_user_data(void* data) { userdata_ = data; }
63 long long int get_id() { return id_; }
64 double get_priority() { return priority_; }
65 void set_priority(double priority);
66 void set_bound(double bound) { bound_ = bound; }
67 double get_bound() { return bound_; }
68 void set_rate(double rate) { rate_ = rate; }
69 double get_rate() { return rate_; }
70 void set_timeout(double timeout) { timeout_ = timeout; }
72 s4u::Actor* get_sender();
73 s4u::Host* get_source();
75 s4u::ExecPtr compute = nullptr; /* S4U modeling of computation */
76 s4u::CommPtr comm = nullptr; /* S4U modeling of communication */
77 double flops_amount = 0.0; /* Computation size */
78 double bytes_amount = 0.0; /* Data size */
80 /******* Parallel Tasks Only !!!! *******/
81 bool parallel_ = false;
82 std::vector<s4u::Host*> hosts_;
83 std::vector<double> flops_parallel_amount;
84 std::vector<double> bytes_parallel_amount;
89 Task* task_sent; /* task sent (NULL for the receiver) */
90 Task** task_received; /* where the task will be received (NULL for the sender) */
91 s4u::CommPtr s_comm; /* SIMIX communication object encapsulated (the same for both processes) */
92 msg_error_t status = MSG_OK; /* status of the communication once finished */
93 Comm(msg_task_t sent, msg_task_t* received, s4u::CommPtr comm)
94 : task_sent(sent), task_received(received), s_comm(std::move(comm))
100 } // namespace simgrid
102 /************************** Global variables ********************************/
103 struct s_MSG_Global_t {
104 bool debug_multiple_use; /* whether we want an error message when reusing the same Task for 2 things */
105 std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
106 void (*task_copy_callback)(msg_task_t task, msg_process_t src, msg_process_t dst);
107 void_f_pvoid_t process_data_cleanup;
109 typedef s_MSG_Global_t* MSG_Global_t;
111 XBT_PUBLIC_DATA MSG_Global_t msg_global;
113 /*************************************************************/
114 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size);