Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a doc error about actors (Tutorial_algorithms)
[simgrid.git] / src / msg / msg_private.hpp
1 /* Copyright (c) 2004-2019. 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
14 #include <cmath>
15
16 /**************** datatypes **********************************/
17 namespace simgrid {
18 namespace msg {
19 class Task {
20   std::string name_             = "";
21   std::string tracing_category_ = "";
22   void* userdata_               = nullptr;
23   long long int id_;
24
25   double timeout_  = 0.0;
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 */
30
31   explicit Task(const std::string& name, double flops_amount, double bytes_amount, void* data);
32   explicit Task(const std::string& name, std::vector<s4u::Host*>&& hosts, std::vector<double>&& flops_amount,
33                 std::vector<double>&& bytes_amount, void* data);
34
35   void report_multiple_use() const;
36
37 public:
38   static Task* create(const std::string& name, double flops_amount, double bytes_amount, void* data);
39   static Task* create_parallel(const 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();
42   msg_error_t send(const std::string& alias, double timeout);
43   s4u::CommPtr send_async(const std::string& alias, void_f_pvoid_t cleanup, bool detached);
44
45   void cancel();
46
47   Task(const Task&) = delete;
48   Task& operator=(const Task&) = delete;
49   ~Task()                      = default;
50
51   bool is_used() { return is_used_; }
52   bool is_parallel() { return parallel_; }
53
54   void set_used();
55   void set_not_used() { this->is_used_ = false; }
56   const std::string& get_name() const { return name_; }
57   const char* get_cname() { return name_.c_str(); }
58   void set_name(const char* new_name) { name_ = std::string(new_name); }
59   void set_tracing_category(const char* category) { tracing_category_ = category ? std::string(category) : ""; }
60   const std::string& get_tracing_category() { return tracing_category_; }
61   bool has_tracing_category() { return not tracing_category_.empty(); }
62   void* get_user_data() { return userdata_; }
63   void set_user_data(void* data) { userdata_ = data; }
64   long long int get_id() { return id_; }
65   double get_priority() { return priority_; }
66   void set_priority(double priority);
67   void set_bound(double bound) { bound_ = bound; }
68   double get_bound() { return bound_; }
69   void set_rate(double rate) { rate_ = rate; }
70   double get_rate() { return rate_; }
71   void set_timeout(double timeout) { timeout_ = timeout; }
72
73   s4u::Actor* get_sender();
74   s4u::Host* get_source();
75
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 */
80
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;
86 };
87
88 class Comm {
89   msg_error_t status_ = MSG_OK; /* status of the communication once finished */
90 public:
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))
96   {
97   }
98   bool test();
99   msg_error_t wait_for(double timeout);
100   void set_status(msg_error_t status) { status_ = status; }
101   msg_error_t get_status() { return status_; }
102 };
103
104 class ActorUserData {
105   void* userdata_      = nullptr;
106
107 public:
108   static xbt::Extension<simgrid::s4u::Actor, ActorUserData> EXTENSION_ID;
109
110   void set_user_data(void* data) { userdata_ = data; }
111   void* get_user_data() { return userdata_; }
112 };
113
114 } // namespace msg
115 } // namespace simgrid
116
117 /************************** Global variables ********************************/
118 struct MSG_Global_t {
119   static bool debug_multiple_use;    /* whether we want an error message when reusing the same Task for 2 things */
120   std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
121   void (*task_copy_callback)(msg_task_t task, msg_process_t src, msg_process_t dst);
122   void_f_pvoid_t process_data_cleanup;
123 };
124
125 XBT_PUBLIC_DATA MSG_Global_t* msg_global;
126
127 /*************************************************************/
128 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size);
129
130 #endif