Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use implicit string conversion.
[simgrid.git] / src / msg / msg_private.hpp
1 /* Copyright (c) 2004-2020. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef MSG_PRIVATE_HPP
7 #define MSG_PRIVATE_HPP
8
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>
14
15 #include <cmath>
16
17 /**************** datatypes **********************************/
18 namespace simgrid {
19
20 extern template class XBT_PUBLIC xbt::Extendable<msg::Task>;
21
22 namespace msg {
23 class Task : public xbt::Extendable<Task> {
24   std::string name_             = "";
25   std::string tracing_category_ = "";
26   long long int id_;
27
28   double timeout_  = 0.0;
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 */
33
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);
37
38   void report_multiple_use() const;
39
40 public:
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);
47
48   void cancel();
49
50   Task(const Task&) = delete;
51   Task& operator=(const Task&) = delete;
52   ~Task()                      = default;
53
54   bool is_used() const { return is_used_; }
55   bool is_parallel() const { return parallel_; }
56
57   void set_used();
58   void set_not_used() { this->is_used_ = false; }
59   const std::string& get_name() const { return name_; }
60   const char* get_cname() const { return name_.c_str(); }
61   void set_name(const char* new_name) { name_ = std::string(new_name); }
62   void set_tracing_category(const char* category) { tracing_category_ = category ? category : ""; }
63   const std::string& get_tracing_category() const { return tracing_category_; }
64   bool has_tracing_category() { return not tracing_category_.empty(); }
65   XBT_ATTRIB_DEPRECATED_v329("Please use set_data()") void* get_user_data() { return get_data(); }
66   XBT_ATTRIB_DEPRECATED_v329("Please use get_data()") void set_user_data(void* data) { set_data(data); }
67   long long int get_id() const { return id_; }
68   double get_priority() const { return priority_; }
69   void set_priority(double priority);
70   void set_bound(double bound) { bound_ = bound; }
71   double get_bound() const { return bound_; }
72   void set_rate(double rate) { rate_ = rate; }
73   double get_rate() const { return rate_; }
74   void set_timeout(double timeout) { timeout_ = timeout; }
75
76   s4u::Actor* get_sender() const;
77   s4u::Host* get_source() const;
78
79   s4u::ExecPtr compute = nullptr; /* S4U modeling of computation */
80   s4u::CommPtr comm    = nullptr; /* S4U modeling of communication */
81   double flops_amount  = 0.0;     /* Computation size */
82   double bytes_amount  = 0.0;     /* Data size */
83
84   /*******  Parallel Tasks Only !!!! *******/
85   bool parallel_ = false;
86   std::vector<s4u::Host*> hosts_;
87   std::vector<double> flops_parallel_amount;
88   std::vector<double> bytes_parallel_amount;
89 };
90
91 class Comm {
92   msg_error_t status_ = MSG_OK; /* status of the communication once finished */
93 public:
94   Task* task_sent;             /* task sent (NULL for the receiver) */
95   Task** task_received;        /* where the task will be received (NULL for the sender) */
96   s4u::CommPtr s_comm;         /* SIMIX communication object encapsulated (the same for both processes) */
97   Comm(msg_task_t sent, msg_task_t* received, s4u::CommPtr comm)
98       : task_sent(sent), task_received(received), s_comm(std::move(comm))
99   {
100   }
101   bool test();
102   msg_error_t wait_for(double timeout);
103   void set_status(msg_error_t status) { status_ = status; }
104   msg_error_t get_status() const { return status_; }
105 };
106
107 } // namespace msg
108 } // namespace simgrid
109
110 /************************** Global variables ********************************/
111 struct MSG_Global_t {
112   static bool debug_multiple_use;    /* whether we want an error message when reusing the same Task for 2 things */
113   std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
114   void (*task_copy_callback)(msg_task_t task, msg_process_t src, msg_process_t dst);
115   void_f_pvoid_t process_data_cleanup;
116 };
117
118 XBT_PUBLIC_DATA MSG_Global_t* msg_global;
119
120 /*************************************************************/
121
122 #endif