Logo AND Algorithmique Numérique Distribuée

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