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 priority_ = 1.0;
27 double bound_ = 0.0; /* Capping for CPU resource, or 0 for no capping */
28 double rate_ = -1; /* Capping for network resource, or -1 for no capping*/
29 bool is_used_ = false; /* Indicates whether the task is used in SIMIX currently */
31 explicit Task(std::string name, double flops_amount, double bytes_amount, void* data);
32 explicit Task(std::string name, std::vector<s4u::Host*> hosts, std::vector<double> flops_amount,
33 std::vector<double> bytes_amount, void* data);
35 void report_multiple_use() const;
38 static Task* create(std::string name, double flops_amount, double bytes_amount, void* data);
39 static Task* create_parallel(std::string name, int host_nb, const msg_host_t* host_list, double* flops_amount,
40 double* bytes_amount, void* data);
41 msg_error_t execute();
44 Task(const Task&) = delete;
45 Task& operator=(const Task&) = delete;
48 bool is_used() { return is_used_; }
49 bool is_parallel() { return parallel_; }
52 void set_not_used() { this->is_used_ = false; }
53 const std::string& get_name() const { return name_; }
54 const char* get_cname() { return name_.c_str(); }
55 void set_name(const char* new_name) { name_ = std::string(new_name); }
56 void set_tracing_category(const char* category) { tracing_category_ = category ? std::string(category) : ""; }
57 const std::string& get_tracing_category() { return tracing_category_; }
58 bool has_tracing_category() { return not tracing_category_.empty(); }
59 void* get_user_data() { return userdata_; }
60 void set_user_data(void* data) { userdata_ = data; }
61 long long int get_id() { return id_; }
62 double get_priority() { return priority_; }
63 void set_priority(double priority);
64 void set_bound(double bound) { bound_ = bound; }
65 double get_bound() { return bound_; }
66 void set_rate(double rate) { rate_ = rate; }
67 double get_rate() { return rate_; }
69 s4u::Actor* get_sender();
70 s4u::Host* get_source();
72 kernel::activity::ExecImplPtr compute = nullptr; /* SIMIX modeling of computation */
73 s4u::CommPtr comm = nullptr; /* S4U modeling of communication */
74 double flops_amount = 0.0; /* Computation size */
75 double bytes_amount = 0.0; /* Data size */
78 /******* Parallel Tasks Only !!!! *******/
79 bool parallel_ = false;
80 std::vector<s4u::Host*> hosts_;
81 std::vector<double> flops_parallel_amount;
82 std::vector<double> bytes_parallel_amount;
87 msg_task_t task_sent; /* task sent (NULL for the receiver) */
88 msg_task_t* task_received; /* where the task will be received (NULL for the sender) */
89 s4u::CommPtr s_comm; /* SIMIX communication object encapsulated (the same for both processes) */
90 msg_error_t status = MSG_OK; /* status of the communication once finished */
91 Comm(msg_task_t sent, msg_task_t* received, s4u::CommPtr comm)
92 : task_sent(sent), task_received(received), s_comm(std::move(comm))
98 } // namespace simgrid
100 /************************** Global variables ********************************/
101 struct s_MSG_Global_t {
102 bool debug_multiple_use; /* whether we want an error message when reusing the same Task for 2 things */
103 std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
104 void (*task_copy_callback)(msg_task_t task, msg_process_t src, msg_process_t dst);
105 void_f_pvoid_t process_data_cleanup;
107 typedef s_MSG_Global_t* MSG_Global_t;
109 XBT_PUBLIC_DATA MSG_Global_t msg_global;
111 /*************************************************************/
112 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size);
114 /********** Tracing **********/
115 /* declaration of instrumentation functions from msg_task_instr.c */
116 XBT_PRIVATE void TRACE_msg_task_put_start(msg_task_t task);