Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
input sanitization continued.
[simgrid.git] / include / simgrid / simix.h
1 /* Copyright (c) 2007-2019. 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 SIMGRID_SIMIX_H
7 #define SIMGRID_SIMIX_H
8
9 #include <simgrid/forward.h>
10 #include <simgrid/host.h>
11 #include <xbt/ex.h>
12 #include <xbt/parmap.h>
13 #ifdef __cplusplus
14 #include <functional>
15 #include <string>
16 #include <unordered_map>
17 #include <vector>
18 #endif
19
20 /******************************* Networking ***********************************/
21 extern unsigned smx_context_stack_size;
22 extern unsigned smx_context_guard_size;
23
24 SG_BEGIN_DECL
25
26 XBT_PUBLIC smx_actor_t SIMIX_process_from_PID(aid_t PID);
27
28 /* parallelism */
29 XBT_PUBLIC int SIMIX_context_is_parallel();
30 XBT_PUBLIC int SIMIX_context_get_nthreads();
31 XBT_PUBLIC void SIMIX_context_set_nthreads(int nb_threads);
32 XBT_PUBLIC int SIMIX_context_get_parallel_threshold();
33 XBT_PUBLIC void SIMIX_context_set_parallel_threshold(int threshold);
34 XBT_PUBLIC e_xbt_parmap_mode_t SIMIX_context_get_parallel_mode();
35 XBT_PUBLIC void SIMIX_context_set_parallel_mode(e_xbt_parmap_mode_t mode);
36 XBT_PUBLIC int SIMIX_is_maestro();
37
38 /********************************** Global ************************************/
39 /* Initialization and exit */
40 XBT_PUBLIC void SIMIX_global_init(int* argc, char** argv);
41
42 /* Set to execute in the maestro
43  *
44  * If no maestro code is registered (the default), the main thread
45  * is assumed to be the maestro. */
46 XBT_PUBLIC void SIMIX_set_maestro(void (*code)(void*), void* data);
47
48 /* Simulation execution */
49 XBT_PUBLIC void SIMIX_run();
50 XBT_PUBLIC double SIMIX_get_clock();
51
52 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::set()") XBT_PUBLIC smx_timer_t
53     SIMIX_timer_set(double date, void (*function)(void*), void* arg);
54 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::remove()") XBT_PUBLIC
55     void SIMIX_timer_remove(smx_timer_t timer);
56 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::next()") XBT_PUBLIC double SIMIX_timer_next();
57 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::get_date()") XBT_PUBLIC
58     double SIMIX_timer_get_date(smx_timer_t timer);
59
60 XBT_PUBLIC void SIMIX_display_process_status();
61 SG_END_DECL
62
63 /******************************** Deployment **********************************/
64 SG_BEGIN_DECL
65 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_default() or Engine::register_default()") XBT_PUBLIC
66     void SIMIX_function_register_default(xbt_main_func_t code);
67 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC void SIMIX_init_application();
68
69 XBT_PUBLIC void SIMIX_process_set_function(const char* process_host, const char* process_function,
70                                            xbt_dynar_t arguments, double process_start_time, double process_kill_time);
71 SG_END_DECL
72
73 #ifdef __cplusplus
74 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_function() or Engine::register_function()") XBT_PUBLIC
75     void SIMIX_function_register(const std::string& name, void (*code)(std::vector<std::string>));
76 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_function() or Engine::register_function()") XBT_PUBLIC
77     void SIMIX_function_register(const std::string& name, xbt_main_func_t code);
78 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_load_deployment() or Engine::load_deployment()") XBT_PUBLIC
79     void SIMIX_launch_application(const std::string& file);
80 #endif
81
82 /********************************* Process ************************************/
83 SG_BEGIN_DECL
84 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_get_actor_count()") XBT_PUBLIC int SIMIX_process_count();
85 XBT_PUBLIC smx_actor_t SIMIX_process_self();
86 XBT_PUBLIC const char* SIMIX_process_self_get_name();
87 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC
88     void SIMIX_process_self_set_data(void* data);
89 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC void* SIMIX_process_self_get_data();
90 SG_END_DECL
91
92 #ifdef __cplusplus
93 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC
94     void SIMIX_process_on_exit(smx_actor_t process, const std::function<void(bool /*failed*/)>& fun);
95 #endif
96
97 /****************************** Communication *********************************/
98 #ifdef __cplusplus
99 XBT_PUBLIC void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*,
100                                                                    size_t));
101 XBT_PUBLIC void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
102                                                  size_t buff_size);
103 XBT_PUBLIC void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
104                                                 size_t buff_size);
105 #endif
106
107 /******************************************************************************/
108 /*                            SIMIX simcalls                                  */
109 /******************************************************************************/
110 /* These functions are a system call-like interface to the simulation kernel. */
111 /* They can also be called from maestro's context, and they are thread safe.  */
112 /******************************************************************************/
113
114 /******************************* Host simcalls ********************************/
115 #ifdef __cplusplus
116 XBT_PUBLIC e_smx_state_t simcall_execution_wait(const smx_activity_t& execution);
117 XBT_PUBLIC unsigned int simcall_execution_waitany_for(simgrid::kernel::activity::ExecImpl* execs[], size_t count,
118                                                       double timeout);
119 XBT_PUBLIC bool simcall_execution_test(const smx_activity_t& execution);
120 #endif
121
122 /**************************** Process simcalls ********************************/
123 SG_BEGIN_DECL
124 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") void simcall_process_set_data(smx_actor_t process,
125                                                                                                   void* data);
126 XBT_ATTRIB_DEPRECATED_v328("Please use Actor::suspend()") XBT_PUBLIC void simcall_process_suspend(smx_actor_t process);
127
128 XBT_ATTRIB_DEPRECATED_v328("Please use Actor::join()") XBT_PUBLIC
129     void simcall_process_join(smx_actor_t process, double timeout);
130
131 XBT_ATTRIB_DEPRECATED_v329("Please use sg_actor_sleep_for()") XBT_PUBLIC e_smx_state_t
132     simcall_process_sleep(double duration);
133 SG_END_DECL
134
135 /************************** Communication simcalls ****************************/
136
137 #ifdef __cplusplus
138 XBT_PUBLIC void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
139                                   size_t src_buff_size,
140                                   int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
141                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
142                                   void* data, double timeout);
143
144 XBT_PUBLIC smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate,
145                                              void* src_buff, size_t src_buff_size,
146                                              int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
147                                              void (*clean_fun)(void*),
148                                              void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
149                                              void* data, bool detached);
150
151 XBT_PUBLIC void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
152                                   int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
153                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
154                                   void* data, double timeout, double rate);
155
156 XBT_PUBLIC smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff,
157                                              size_t* dst_buff_size,
158                                              int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
159                                              void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
160                                              void* data, double rate);
161
162 XBT_PUBLIC smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type,
163                                               int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
164                                               void* data);
165
166 /* FIXME: waitany is going to be a vararg function, and should take a timeout */
167 XBT_PUBLIC unsigned int simcall_comm_waitany(smx_activity_t comms[], size_t count, double timeout);
168 XBT_PUBLIC unsigned int simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count,
169                                              double timeout);
170 XBT_PUBLIC void simcall_comm_wait(const smx_activity_t& comm, double timeout);
171 XBT_PUBLIC bool simcall_comm_test(const smx_activity_t& comm);
172 XBT_PUBLIC int simcall_comm_testany(smx_activity_t comms[], size_t count);
173 XBT_PUBLIC int simcall_comm_testany(simgrid::kernel::activity::CommImpl* comms[], size_t count);
174 #endif
175
176 /************************** Synchro simcalls **********************************/
177 SG_BEGIN_DECL
178 XBT_PUBLIC smx_mutex_t simcall_mutex_init();
179 XBT_PUBLIC void simcall_mutex_lock(smx_mutex_t mutex);
180 XBT_PUBLIC int simcall_mutex_trylock(smx_mutex_t mutex);
181 XBT_PUBLIC void simcall_mutex_unlock(smx_mutex_t mutex);
182
183 XBT_PUBLIC smx_cond_t simcall_cond_init();
184 XBT_PUBLIC void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
185 XBT_PUBLIC int simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double max_duration);
186
187 XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
188 XBT_PUBLIC int simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
189 SG_END_DECL
190
191 /*****************************   Io   **************************************/
192 #ifdef __cplusplus
193 XBT_PUBLIC e_smx_state_t simcall_io_wait(const smx_activity_t& io);
194 #endif
195 /************************** MC simcalls   **********************************/
196 SG_BEGIN_DECL
197 XBT_PUBLIC int simcall_mc_random(int min, int max);
198 SG_END_DECL
199
200 #endif