Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d87469cb3a15adc16b53f4a9a7dff558e48a0861
[simgrid.git] / src / msg / msg_private.hpp
1 /* Copyright (c) 2004-2021. 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_  = -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 */
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   long long int get_id() const { return id_; }
66   double get_priority() const { return priority_; }
67   void set_priority(double priority);
68   void set_bound(double bound) { bound_ = bound; }
69   double get_bound() const { return bound_; }
70   void set_rate(double rate) { rate_ = rate; }
71   double get_rate() const { return rate_; }
72   void set_timeout(double timeout) { timeout_ = timeout; }
73
74   s4u::Actor* get_sender() const;
75   s4u::Host* get_source() const;
76
77   s4u::ExecPtr compute = nullptr; /* S4U modeling of computation */
78   s4u::CommPtr comm    = nullptr; /* S4U modeling of communication */
79   double flops_amount  = 0.0;     /* Computation size */
80   double bytes_amount  = 0.0;     /* Data size */
81
82   /*******  Parallel Tasks Only !!!! *******/
83   bool parallel_ = false;
84   std::vector<s4u::Host*> hosts_;
85   std::vector<double> flops_parallel_amount;
86   std::vector<double> bytes_parallel_amount;
87 };
88
89 class Comm {
90   msg_error_t status_ = MSG_OK; /* status of the communication once finished */
91 public:
92   Task* task_sent;             /* task sent (NULL for the receiver) */
93   Task** task_received;        /* where the task will be received (NULL for the sender) */
94   s4u::CommPtr s_comm;         /* SIMIX communication object encapsulated (the same for both processes) */
95   Comm(msg_task_t sent, msg_task_t* received, s4u::CommPtr comm)
96       : task_sent(sent), task_received(received), s_comm(std::move(comm))
97   {
98   }
99   bool test();
100   msg_error_t wait_for(double timeout);
101   void set_status(msg_error_t status) { status_ = status; }
102   msg_error_t get_status() const { return status_; }
103 };
104
105 } // namespace msg
106 } // namespace simgrid
107
108 /************************** Global variables ********************************/
109 struct MSG_Global_t {
110   static bool debug_multiple_use;    /* whether we want an error message when reusing the same Task for 2 things */
111   std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
112   void (*task_copy_callback)(msg_task_t task, msg_process_t src, msg_process_t dst);
113   void_f_pvoid_t process_data_cleanup;
114 };
115
116 XBT_PUBLIC_DATA MSG_Global_t* msg_global;
117
118 /*************************************************************/
119
120 #endif