Logo AND Algorithmique Numérique Distribuée

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