Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename C++ only header files from .h to .hpp.
[simgrid.git] / src / msg / msg_private.hpp
1 /* Copyright (c) 2004-2017. 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/msg.h"
10
11 #include "src/kernel/activity/CommImpl.hpp"
12 #include "src/kernel/activity/ExecImpl.hpp"
13 #include "xbt/Extendable.hpp"
14
15 #include <atomic>
16
17 /**************** datatypes **********************************/
18 /**************************** Host Extension *********************************/
19 namespace simgrid {
20 class MsgHostExt {
21 public:
22   static simgrid::xbt::Extension<s4u::Host, MsgHostExt> EXTENSION_ID;
23
24   ~MsgHostExt() {
25     delete file_descriptor_table;
26   }
27   std::vector<int>* file_descriptor_table = nullptr; // Created lazily on need
28 };
29 }
30 /********************************* Task **************************************/
31
32 typedef struct simdata_task {
33   ~simdata_task()
34   {
35     /* parallel tasks only */
36     xbt_free(this->host_list);
37   }
38   void setUsed();
39   void setNotUsed()
40   {
41     this->isused = false;
42   }
43
44   simgrid::kernel::activity::ExecImplPtr compute = nullptr; /* SIMIX modeling of computation */
45   simgrid::kernel::activity::CommImplPtr comm    = nullptr; /* SIMIX modeling of communication */
46   double bytes_amount = 0.0; /* Data size */
47   double flops_amount = 0.0; /* Computation size */
48   msg_process_t sender = nullptr;
49   msg_process_t receiver = nullptr;
50   msg_host_t source = nullptr;
51
52   double priority = 1.0;
53   double bound    = 0.0; /* Capping for CPU resource, or 0 for no capping */
54   double rate     = -1;  /* Capping for network resource, or -1 for no capping*/
55
56   bool isused = false;  /* Indicates whether the task is used in SIMIX currently */
57   int host_nb = 0;      /* ==0 if sequential task; parallel task if not */
58   /*******  Parallel Tasks Only !!!! *******/
59   sg_host_t *host_list = nullptr;
60   double *flops_parallel_amount = nullptr;
61   double *bytes_parallel_amount = nullptr;
62
63 private:
64   void reportMultipleUse() const;
65 } s_simdata_task_t;
66
67 /******************************* Process *************************************/
68
69 namespace simgrid {
70 namespace msg {
71 class ActorExt {
72 public:
73   explicit ActorExt(void* d) : data(d) {}
74   msg_error_t errno_ = MSG_OK;  /* the last value returned by a MSG_function */
75   void* data = nullptr; /* user data */
76 };
77
78 class Comm {
79 public:
80   msg_task_t task_sent;           /* task sent (NULL for the receiver) */
81   msg_task_t *task_received;      /* where the task will be received (NULL for the sender) */
82   smx_activity_t s_comm;          /* SIMIX communication object encapsulated (the same for both processes) */
83   msg_error_t status = MSG_OK;    /* status of the communication once finished */
84   Comm(msg_task_t sent, msg_task_t* received, smx_activity_t comm)
85       : task_sent(sent), task_received(received), s_comm(std::move(comm))
86   {
87   }
88 };
89 }
90 }
91
92 /************************** Global variables ********************************/
93 typedef struct MSG_Global {
94   int debug_multiple_use;       /* whether we want an error message when reusing the same Task for 2 things */
95   std::atomic_int_fast32_t sent_msg; /* Total amount of messages sent during the simulation */
96   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
97   void_f_pvoid_t process_data_cleanup;
98 } s_MSG_Global_t;
99 typedef s_MSG_Global_t* MSG_Global_t;
100
101 SG_BEGIN_DECL()
102
103 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
104
105 /*************************************************************/
106 XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc);
107 XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function<void()> code, void* data,
108                                                       sg_host_t host, std::map<std::string, std::string>* properties,
109                                                       smx_actor_t parent_process);
110 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
111
112 XBT_PRIVATE void MSG_host_add_task(msg_host_t host, msg_task_t task);
113 XBT_PRIVATE void MSG_host_del_task(msg_host_t host, msg_task_t task);
114
115 /********** Tracing **********/
116 /* declaration of instrumentation functions from msg_task_instr.c */
117 XBT_PRIVATE void TRACE_msg_set_task_category(msg_task_t task, const char *category);
118 XBT_PRIVATE void TRACE_msg_task_create(msg_task_t task);
119 XBT_PRIVATE void TRACE_msg_task_execute_start(msg_task_t task);
120 XBT_PRIVATE void TRACE_msg_task_execute_end(msg_task_t task);
121 XBT_PRIVATE void TRACE_msg_task_destroy(msg_task_t task);
122 XBT_PRIVATE void TRACE_msg_task_get_end(double start_time, msg_task_t task);
123 XBT_PRIVATE void TRACE_msg_task_get_start();
124 XBT_PRIVATE int TRACE_msg_task_put_start(msg_task_t task);    //returns TRUE if the task_put_end must be called
125 XBT_PRIVATE void TRACE_msg_task_put_end();
126
127 /* declaration of instrumentation functions from msg_process_instr.c */
128 XBT_PRIVATE char *instr_process_id (msg_process_t proc, char *str, int len);
129 XBT_PRIVATE char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
130 XBT_PRIVATE void TRACE_msg_process_change_host(msg_process_t process, msg_host_t new_host);
131 XBT_PRIVATE void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
132 XBT_PRIVATE void TRACE_msg_process_destroy (const char *process_name, int process_pid);
133 XBT_PRIVATE void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process);
134 XBT_PRIVATE void TRACE_msg_process_suspend(msg_process_t process);
135 XBT_PRIVATE void TRACE_msg_process_resume(msg_process_t process);
136 XBT_PRIVATE void TRACE_msg_process_sleep_in(msg_process_t process);   //called from msg/gos.c
137 XBT_PRIVATE void TRACE_msg_process_sleep_out(msg_process_t process);
138
139 SG_END_DECL()
140
141 inline void simdata_task::setUsed()
142 {
143   if (this->isused)
144     this->reportMultipleUse();
145   if (msg_global->debug_multiple_use) {
146     // TODO, backtrace
147   }
148   this->isused = true;
149 }
150
151 #endif