Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv the internal isend function to the class
[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 "src/kernel/activity/ExecImpl.hpp"
13 #include <simgrid/modelchecker.h>
14
15 #include <cmath>
16
17 /**************** datatypes **********************************/
18 namespace simgrid {
19 namespace msg {
20 class Task {
21   std::string name_             = "";
22   std::string tracing_category_ = "";
23   void* userdata_               = nullptr;
24   long long int id_;
25
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(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);
34
35   void report_multiple_use() const;
36
37 public:
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();
42   Comm* send_async(std::string alias, void_f_pvoid_t cleanup, bool detached);
43   void cancel();
44
45   Task(const Task&) = delete;
46   Task& operator=(const Task&) = delete;
47   ~Task()                      = default;
48
49   bool is_used() { return is_used_; }
50   bool is_parallel() { return parallel_; }
51
52   void set_used();
53   void set_not_used() { this->is_used_ = false; }
54   const std::string& get_name() const { return name_; }
55   const char* get_cname() { return name_.c_str(); }
56   void set_name(const char* new_name) { name_ = std::string(new_name); }
57   void set_tracing_category(const char* category) { tracing_category_ = category ? std::string(category) : ""; }
58   const std::string& get_tracing_category() { return tracing_category_; }
59   bool has_tracing_category() { return not tracing_category_.empty(); }
60   void* get_user_data() { return userdata_; }
61   void set_user_data(void* data) { userdata_ = data; }
62   long long int get_id() { return id_; }
63   double get_priority() { return priority_; }
64   void set_priority(double priority);
65   void set_bound(double bound) { bound_ = bound; }
66   double get_bound() { return bound_; }
67   void set_rate(double rate) { rate_ = rate; }
68   double get_rate() { return rate_; }
69
70   s4u::Actor* get_sender();
71   s4u::Host* get_source();
72
73   kernel::activity::ExecImplPtr compute          = nullptr; /* SIMIX modeling of computation */
74   s4u::CommPtr comm                              = nullptr; /* S4U modeling of communication */
75   double flops_amount                            = 0.0;     /* Computation size */
76   double bytes_amount                            = 0.0;     /* Data size */
77
78
79   /*******  Parallel Tasks Only !!!! *******/
80   bool parallel_ = false;
81   std::vector<s4u::Host*> hosts_;
82   std::vector<double> flops_parallel_amount;
83   std::vector<double> bytes_parallel_amount;
84 };
85
86 class Comm {
87 public:
88   Task* task_sent;             /* task sent (NULL for the receiver) */
89   Task** task_received;        /* where the task will be received (NULL for the sender) */
90   s4u::CommPtr s_comm;         /* SIMIX communication object encapsulated (the same for both processes) */
91   msg_error_t status = MSG_OK; /* status of the communication once finished */
92   Comm(msg_task_t sent, msg_task_t* received, s4u::CommPtr comm)
93       : task_sent(sent), task_received(received), s_comm(std::move(comm))
94   {
95   }
96 };
97
98 } // namespace msg
99 } // namespace simgrid
100
101 /************************** Global variables ********************************/
102 struct s_MSG_Global_t {
103   bool debug_multiple_use;           /* whether we want an error message when reusing the same Task for 2 things */
104   std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
105   void (*task_copy_callback)(msg_task_t task, msg_process_t src, msg_process_t dst);
106   void_f_pvoid_t process_data_cleanup;
107 };
108 typedef s_MSG_Global_t* MSG_Global_t;
109
110 XBT_PUBLIC_DATA MSG_Global_t msg_global;
111
112 /*************************************************************/
113 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size);
114
115 /********** Tracing **********/
116 /* declaration of instrumentation functions from msg_task_instr.c */
117 XBT_PRIVATE void TRACE_msg_task_put_start(msg_task_t task);
118
119
120 #endif