Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e675c367405091b0deea2c85c1ceab7e7ef3a0e5
[simgrid.git] / src / msg / msg_private.h
1 /* Copyright (c) 2004-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef METASIMGRID_PRIVATE_H
8 #define METASIMGRID_PRIVATE_H
9
10 #include "simgrid/msg.h"
11
12 #include "src/kernel/activity/SynchroExec.hpp"
13 #include "src/kernel/activity/SynchroComm.hpp"
14
15 #include <xbt/Extendable.hpp>
16
17 SG_BEGIN_DECL()
18
19 /**************** datatypes **********************************/
20 /**************************** Host Extension *********************************/
21 namespace simgrid {
22 class MsgHostExt {
23 public:
24   static simgrid::xbt::Extension<s4u::Host, MsgHostExt> EXTENSION_ID;
25
26   ~MsgHostExt() {
27     delete file_descriptor_table;
28   }
29   std::vector<int>* file_descriptor_table = nullptr; // Created lazily on need
30 };
31 }
32 /********************************* Task **************************************/
33
34 typedef struct simdata_task {
35   ~simdata_task()
36   {
37     if (this->compute)
38       this->compute->unref();
39
40     /* parallel tasks only */
41     xbt_free(this->host_list);
42   }
43   void setUsed();
44   void setNotUsed()
45   {
46     this->isused = false;
47   }
48
49   simgrid::kernel::activity::Exec *compute = nullptr; /* SIMIX modeling of computation */
50   simgrid::kernel::activity::Comm *comm = nullptr;    /* SIMIX modeling of communication */
51   double bytes_amount = 0.0; /* Data size */
52   double flops_amount = 0.0; /* Computation size */
53   msg_process_t sender = nullptr;
54   msg_process_t receiver = nullptr;
55   msg_host_t source = nullptr;
56   double priority = 0.0;
57   double bound = 0.0; /* Capping for CPU resource */
58   double rate = 0.0;  /* Capping for network resource */
59
60   bool isused = false;  /* Indicates whether the task is used in SIMIX currently */
61   int host_nb = 0;      /* ==0 if sequential task; parallel task if not */
62   /*******  Parallel Tasks Only !!!! *******/
63   sg_host_t *host_list = nullptr;
64   double *flops_parallel_amount = nullptr;
65   double *bytes_parallel_amount = nullptr;
66
67 private:
68   void reportMultipleUse() const;
69 } s_simdata_task_t;
70
71 /********************************* File **************************************/
72 typedef struct simdata_file {
73   smx_file_t smx_file;
74 } s_simdata_file_t;
75
76 XBT_PRIVATE int __MSG_host_get_file_descriptor_id(msg_host_t host);
77 XBT_PRIVATE void __MSG_host_release_file_descriptor_id(msg_host_t host, int id);
78
79 /******************************* Process *************************************/
80
81 typedef struct simdata_process {
82   msg_host_t m_host;              /* the host on which the process is running */
83   msg_host_t put_host;            /* used for debugging purposes */
84   smx_activity_t waiting_action;
85   msg_task_t waiting_task;
86   msg_error_t last_errno;       /* the last value returned by a MSG_function */
87
88   void* data;                   /* user data */
89 } s_simdata_process_t, *simdata_process_t;
90
91 typedef struct process_arg {
92   const char *name;
93   xbt_main_func_t code;
94   void *data;
95   msg_host_t m_host;
96   int argc;
97   char **argv;
98   double kill_time;
99 } s_process_arg_t, *process_arg_t;
100
101 typedef struct msg_comm {
102   smx_activity_t s_comm;          /* SIMIX communication object encapsulated (the same for both processes) */
103   msg_task_t task_sent;           /* task sent (NULL for the receiver) */
104   msg_task_t *task_received;      /* where the task will be received (NULL for the sender) */
105   msg_error_t status;           /* status of the communication once finished */
106 } s_msg_comm_t;
107
108 /************************** Global variables ********************************/
109 typedef struct MSG_Global {
110   int debug_multiple_use;       /* whether we want an error message when reusing the same Task for 2 things */
111   unsigned long int 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 } s_MSG_Global_t, *MSG_Global_t;
115
116 /*extern MSG_Global_t msg_global;*/
117 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
118
119 /*************************************************************/
120 XBT_PRIVATE msg_host_t __MSG_host_create(sg_host_t host);
121 XBT_PRIVATE msg_storage_t __MSG_storage_create(smx_storage_t storage);
122 XBT_PRIVATE void __MSG_storage_destroy(msg_storage_priv_t host);
123 XBT_PRIVATE void __MSG_file_destroy(msg_file_priv_t host);
124
125 XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc);
126 XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char *name,
127                                    std::function<void()> code, void *data,
128                                    sg_host_t host, double kill_time,
129                                    xbt_dict_t properties, int auto_restart,
130                                    smx_actor_t parent_process);
131 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
132
133 XBT_PRIVATE void MSG_post_create_environment();
134
135 XBT_PRIVATE void MSG_host_add_task(msg_host_t host, msg_task_t task);
136 XBT_PRIVATE void MSG_host_del_task(msg_host_t host, msg_task_t task);
137
138 /********** Tracing **********/
139 /* declaration of instrumentation functions from msg_task_instr.c */
140 XBT_PRIVATE void TRACE_msg_set_task_category(msg_task_t task, const char *category);
141 XBT_PRIVATE void TRACE_msg_task_create(msg_task_t task);
142 XBT_PRIVATE void TRACE_msg_task_execute_start(msg_task_t task);
143 XBT_PRIVATE void TRACE_msg_task_execute_end(msg_task_t task);
144 XBT_PRIVATE void TRACE_msg_task_destroy(msg_task_t task);
145 XBT_PRIVATE void TRACE_msg_task_get_end(double start_time, msg_task_t task);
146 XBT_PRIVATE void TRACE_msg_task_get_start();
147 XBT_PRIVATE int TRACE_msg_task_put_start(msg_task_t task);    //returns TRUE if the task_put_end must be called
148 XBT_PRIVATE void TRACE_msg_task_put_end();
149
150 /* declaration of instrumentation functions from msg_process_instr.c */
151 XBT_PRIVATE char *instr_process_id (msg_process_t proc, char *str, int len);
152 XBT_PRIVATE char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
153 XBT_PRIVATE void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host);
154 XBT_PRIVATE void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
155 XBT_PRIVATE void TRACE_msg_process_destroy (const char *process_name, int process_pid);
156 XBT_PRIVATE void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process);
157 XBT_PRIVATE void TRACE_msg_process_suspend(msg_process_t process);
158 XBT_PRIVATE void TRACE_msg_process_resume(msg_process_t process);
159 XBT_PRIVATE void TRACE_msg_process_sleep_in(msg_process_t process);   //called from msg/gos.c
160 XBT_PRIVATE void TRACE_msg_process_sleep_out(msg_process_t process);
161
162 SG_END_DECL()
163
164 XBT_PUBLIC(msg_process_t) MSG_process_create_with_environment(
165   const char *name, std::function<void()> code, void *data,
166   msg_host_t host, xbt_dict_t properties);
167
168 inline void simdata_task::setUsed()
169 {
170   if (this->isused)
171     this->reportMultipleUse();
172   if (msg_global->debug_multiple_use) {
173     // TODO, backtrace
174   }
175   this->isused = true;
176 }
177
178 #endif