Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[ci-skip] Update lua tesh files with deprecation warning.
[simgrid.git] / include / simgrid / simix.h
1 /* Copyright (c) 2007-2021. 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 <xbt/dynar.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_ATTRIB_DEPRECATED_v331("Please use sg_actor_by_pid() instead.") XBT_PUBLIC smx_actor_t
27     SIMIX_process_from_PID(aid_t pid);
28
29 /* parallelism */
30 XBT_PUBLIC int SIMIX_context_is_parallel();
31 XBT_PUBLIC int SIMIX_context_get_nthreads();
32 XBT_PUBLIC void SIMIX_context_set_nthreads(int nb_threads);
33 XBT_PUBLIC e_xbt_parmap_mode_t SIMIX_context_get_parallel_mode();
34 XBT_PUBLIC void SIMIX_context_set_parallel_mode(e_xbt_parmap_mode_t mode);
35 XBT_PUBLIC int SIMIX_is_maestro();
36
37 /********************************** Global ************************************/
38 /* Initialization and exit */
39 XBT_PUBLIC void SIMIX_global_init(int* argc, char** argv);
40
41 /* Set some code to execute in the maestro (must be used before the engine creation)
42  *
43  * If no maestro code is registered (the default), the main thread
44  * is assumed to be the maestro. */
45 XBT_PUBLIC void SIMIX_set_maestro(void (*code)(void*), void* data);
46
47 /* Simulation execution */
48 XBT_PUBLIC void SIMIX_run();
49 XBT_PUBLIC double SIMIX_get_clock();
50
51 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::set()") XBT_PUBLIC smx_timer_t
52     SIMIX_timer_set(double date, void (*function)(void*), void* arg);
53 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::remove()") XBT_PUBLIC
54     void SIMIX_timer_remove(smx_timer_t timer);
55 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::next()") XBT_PUBLIC double SIMIX_timer_next();
56 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::get_date()") XBT_PUBLIC
57     double SIMIX_timer_get_date(smx_timer_t timer);
58
59 XBT_ATTRIB_DEPRECATED_v329("Please use simix_global->display_all_actor_status()") XBT_PUBLIC
60     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") 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 sg_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") XBT_PUBLIC void SIMIX_process_self_set_data(void* data);
88 XBT_ATTRIB_DEPRECATED_v329("This function will be removed") XBT_PUBLIC void* SIMIX_process_self_get_data();
89 SG_END_DECL
90
91 #ifdef __cplusplus
92 XBT_ATTRIB_DEPRECATED_v329("This function will be removed") XBT_PUBLIC
93     void SIMIX_process_on_exit(smx_actor_t process, const std::function<void(bool /*failed*/)>& fun);
94 #endif
95
96 /****************************** Communication *********************************/
97 #ifdef __cplusplus
98 XBT_PUBLIC void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*,
99                                                                    size_t));
100 XBT_PUBLIC void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
101                                                  size_t buff_size);
102 XBT_PUBLIC void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
103                                                 size_t buff_size);
104 #endif
105
106 /******************************************************************************/
107 /*                            SIMIX simcalls                                  */
108 /******************************************************************************/
109 /* These functions are a system call-like interface to the simulation kernel. */
110 /* They can also be called from maestro's context, and they are thread safe.  */
111 /******************************************************************************/
112
113 /******************************* Host simcalls ********************************/
114 #ifdef __cplusplus
115 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
116     simcall_execution_wait(simgrid::kernel::activity::ActivityImpl* execution, double timeout);
117 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
118     simcall_execution_wait(const simgrid::kernel::activity::ActivityImplPtr& execution, double timeout);
119 XBT_ATTRIB_DEPRECATED_v331("Please use s4u::Exec::wait_any_for()") XBT_PUBLIC
120     unsigned int simcall_execution_waitany_for(simgrid::kernel::activity::ExecImpl* execs[], size_t count,
121                                                double timeout);
122 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::test()") XBT_PUBLIC
123     bool simcall_execution_test(simgrid::kernel::activity::ActivityImpl* execution);
124 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::test()") XBT_PUBLIC
125     bool simcall_execution_test(const simgrid::kernel::activity::ActivityImplPtr& execution);
126
127 #endif
128
129 /**************************** Process simcalls ********************************/
130 SG_BEGIN_DECL
131 XBT_ATTRIB_DEPRECATED_v329("This function will be removed") void simcall_process_set_data(smx_actor_t process,
132                                                                                           void* data);
133 XBT_ATTRIB_DEPRECATED_v329("Please use sg_actor_sleep_for()") XBT_PUBLIC
134 #ifdef __cplusplus
135     simgrid::kernel::activity::State
136 #else
137     enum kernel_activity_state
138 #endif
139     simcall_process_sleep(double duration);
140 SG_END_DECL
141
142 /************************** Communication simcalls ****************************/
143
144 #ifdef __cplusplus
145 XBT_PUBLIC void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
146                                   size_t src_buff_size,
147                                   bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
148                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
149                                   void* data, double timeout);
150
151 XBT_PUBLIC simgrid::kernel::activity::ActivityImplPtr
152 simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
153                    size_t src_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
154                    void (*clean_fun)(void*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
155                    void* data, bool detached);
156
157 XBT_PUBLIC void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
158                                   bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
159                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
160                                   void* data, double timeout, double rate);
161
162 XBT_PUBLIC simgrid::kernel::activity::ActivityImplPtr
163 simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
164                    bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
165                    void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double rate);
166
167 XBT_ATTRIB_DEPRECATED_v330("Please use Mailbox::iprobe()") XBT_PUBLIC simgrid::kernel::activity::ActivityImplPtr
168     simcall_comm_iprobe(smx_mailbox_t mbox, int type,
169                         bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* data);
170
171 XBT_ATTRIB_DEPRECATED_v330("Please use a CommImpl*[] for first parameter") XBT_PUBLIC
172     unsigned int simcall_comm_waitany(simgrid::kernel::activity::ActivityImplPtr comms[], size_t count, double timeout);
173 XBT_PUBLIC unsigned int simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count,
174                                              double timeout);
175 XBT_PUBLIC void simcall_comm_wait(simgrid::kernel::activity::ActivityImpl* comm, double timeout);
176 XBT_PUBLIC bool simcall_comm_test(simgrid::kernel::activity::ActivityImpl* comm);
177 XBT_ATTRIB_DEPRECATED_v330("Please use a CommImpl*[] for first parameter") XBT_PUBLIC
178     int simcall_comm_testany(simgrid::kernel::activity::ActivityImplPtr comms[], size_t count);
179 XBT_PUBLIC int simcall_comm_testany(simgrid::kernel::activity::CommImpl* comms[], size_t count);
180
181 XBT_ATTRIB_DEPRECATED_v330("Please use an ActivityImpl* for first parameter") inline void simcall_comm_wait(
182     const simgrid::kernel::activity::ActivityImplPtr& comm, double timeout)
183 {
184   simcall_comm_wait(comm.get(), timeout);
185 }
186 XBT_ATTRIB_DEPRECATED_v330("Please use an ActivityImpl* for first parameter") inline bool simcall_comm_test(
187     const simgrid::kernel::activity::ActivityImplPtr& comm)
188 {
189   return simcall_comm_test(comm.get());
190 }
191 #endif
192
193 /************************** Synchro simcalls **********************************/
194 SG_BEGIN_DECL
195 XBT_ATTRIB_DEPRECATED_v330("Please use sg_mutex_init()") XBT_PUBLIC smx_mutex_t simcall_mutex_init();
196 XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_lock()") XBT_PUBLIC void simcall_mutex_lock(smx_mutex_t mutex);
197 XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_try_lock()") XBT_PUBLIC int simcall_mutex_trylock(smx_mutex_t mutex);
198 XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_unlock()") XBT_PUBLIC void simcall_mutex_unlock(smx_mutex_t mutex);
199
200 XBT_ATTRIB_DEPRECATED_v330("Please use sg_cond_init()") XBT_PUBLIC smx_cond_t simcall_cond_init();
201 XBT_ATTRIB_DEPRECATED_v331("Please use sg_cond_wait()") XBT_PUBLIC
202     void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
203 XBT_ATTRIB_DEPRECATED_v331("Please use sg_cond_wait_for()") XBT_PUBLIC
204     int simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double max_duration);
205
206 XBT_ATTRIB_DEPRECATED_v331("Please use sg_sem_acquire()") XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
207 XBT_ATTRIB_DEPRECATED_v331("Please use sg_sem_acquire_timeout()") XBT_PUBLIC
208     int simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
209 SG_END_DECL
210
211 /*****************************   Io   **************************************/
212 #ifdef __cplusplus
213 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
214     simcall_io_wait(simgrid::kernel::activity::ActivityImpl* io, double timeout);
215 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
216     simcall_io_wait(const simgrid::kernel::activity::ActivityImplPtr& io, double timeout);
217 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::test()") XBT_PUBLIC
218     bool simcall_io_test(simgrid::kernel::activity::ActivityImpl* io);
219 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::test()") XBT_PUBLIC
220     bool simcall_io_test(const simgrid::kernel::activity::ActivityImplPtr& io);
221 #endif
222 /************************** MC simcalls   **********************************/
223 SG_BEGIN_DECL
224 XBT_ATTRIB_DEPRECATED_v331("Please use MC_random()") XBT_PUBLIC int simcall_mc_random(int min, int max);
225 SG_END_DECL
226
227 #endif