Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reindent
[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 /**************** 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     if (this->compute)
36       this->compute->unref();
37
38     /* parallel tasks only */
39     xbt_free(this->host_list);
40   }
41   void setUsed();
42   void setNotUsed()
43   {
44     this->isused = false;
45   }
46
47   simgrid::kernel::activity::Exec *compute = nullptr; /* SIMIX modeling of computation */
48   simgrid::kernel::activity::Comm *comm = nullptr;    /* SIMIX modeling of communication */
49   double bytes_amount = 0.0; /* Data size */
50   double flops_amount = 0.0; /* Computation size */
51   msg_process_t sender = nullptr;
52   msg_process_t receiver = nullptr;
53   msg_host_t source = nullptr;
54   double priority = 0.0;
55   double bound = 0.0; /* Capping for CPU resource */
56   double rate = 0.0;  /* Capping for network resource */
57
58   bool isused = false;  /* Indicates whether the task is used in SIMIX currently */
59   int host_nb = 0;      /* ==0 if sequential task; parallel task if not */
60   /*******  Parallel Tasks Only !!!! *******/
61   sg_host_t *host_list = nullptr;
62   double *flops_parallel_amount = nullptr;
63   double *bytes_parallel_amount = nullptr;
64
65 private:
66   void reportMultipleUse() const;
67 } s_simdata_task_t;
68
69 /********************************* File **************************************/
70 typedef struct simdata_file {
71   smx_file_t smx_file;
72 } s_simdata_file_t;
73
74 /******************************* Process *************************************/
75
76 namespace simgrid {
77 class MsgActorExt {
78 public:
79   explicit MsgActorExt(void* d) : data(d) {}
80   msg_error_t errno_ = MSG_OK;  /* the last value returned by a MSG_function */
81   void* data = nullptr; /* user data */
82 };
83 }
84
85 typedef struct process_arg {
86   const char *name;
87   xbt_main_func_t code;
88   void *data;
89   msg_host_t m_host;
90   int argc;
91   char **argv;
92   double kill_time;
93 } s_process_arg_t, *process_arg_t;
94
95 typedef struct msg_comm {
96   smx_activity_t s_comm;          /* SIMIX communication object encapsulated (the same for both processes) */
97   msg_task_t task_sent;           /* task sent (NULL for the receiver) */
98   msg_task_t *task_received;      /* where the task will be received (NULL for the sender) */
99   msg_error_t status;           /* status of the communication once finished */
100 } s_msg_comm_t;
101
102 /************************** Global variables ********************************/
103 typedef struct MSG_Global {
104   int debug_multiple_use;       /* whether we want an error message when reusing the same Task for 2 things */
105   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
106   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
107   void_f_pvoid_t process_data_cleanup;
108 } s_MSG_Global_t, *MSG_Global_t;
109
110 SG_BEGIN_DECL()
111
112 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
113
114 /*************************************************************/
115
116 XBT_PRIVATE msg_host_t __MSG_host_create(sg_host_t host);
117 XBT_PRIVATE msg_storage_t __MSG_storage_create(smx_storage_t storage);
118 XBT_PRIVATE void __MSG_storage_destroy(msg_storage_priv_t host);
119 XBT_PRIVATE void __MSG_file_destroy(msg_file_priv_t host);
120
121 XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc);
122 XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function<void()> code, void* data,
123                                                       sg_host_t host, xbt_dict_t properties,
124                                                       smx_actor_t parent_process);
125 XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
126
127 XBT_PRIVATE void MSG_post_create_environment();
128
129 XBT_PRIVATE void MSG_host_add_task(msg_host_t host, msg_task_t task);
130 XBT_PRIVATE void MSG_host_del_task(msg_host_t host, msg_task_t task);
131
132 /********** Tracing **********/
133 /* declaration of instrumentation functions from msg_task_instr.c */
134 XBT_PRIVATE void TRACE_msg_set_task_category(msg_task_t task, const char *category);
135 XBT_PRIVATE void TRACE_msg_task_create(msg_task_t task);
136 XBT_PRIVATE void TRACE_msg_task_execute_start(msg_task_t task);
137 XBT_PRIVATE void TRACE_msg_task_execute_end(msg_task_t task);
138 XBT_PRIVATE void TRACE_msg_task_destroy(msg_task_t task);
139 XBT_PRIVATE void TRACE_msg_task_get_end(double start_time, msg_task_t task);
140 XBT_PRIVATE void TRACE_msg_task_get_start();
141 XBT_PRIVATE int TRACE_msg_task_put_start(msg_task_t task);    //returns TRUE if the task_put_end must be called
142 XBT_PRIVATE void TRACE_msg_task_put_end();
143
144 /* declaration of instrumentation functions from msg_process_instr.c */
145 XBT_PRIVATE char *instr_process_id (msg_process_t proc, char *str, int len);
146 XBT_PRIVATE char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
147 XBT_PRIVATE void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host);
148 XBT_PRIVATE void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
149 XBT_PRIVATE void TRACE_msg_process_destroy (const char *process_name, int process_pid);
150 XBT_PRIVATE void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process);
151 XBT_PRIVATE void TRACE_msg_process_suspend(msg_process_t process);
152 XBT_PRIVATE void TRACE_msg_process_resume(msg_process_t process);
153 XBT_PRIVATE void TRACE_msg_process_sleep_in(msg_process_t process);   //called from msg/gos.c
154 XBT_PRIVATE void TRACE_msg_process_sleep_out(msg_process_t process);
155
156 SG_END_DECL()
157
158 XBT_PUBLIC(msg_process_t)
159 MSG_process_create_from_stdfunc(const char* name, std::function<void()> code, void* data, msg_host_t host,
160                                 xbt_dict_t properties);
161
162 inline void simdata_task::setUsed()
163 {
164   if (this->isused)
165     this->reportMultipleUse();
166   if (msg_global->debug_multiple_use) {
167     // TODO, backtrace
168   }
169   this->isused = true;
170 }
171
172 #endif