Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate e_smx_state_t.
[simgrid.git] / include / simgrid / simix.h
1 /* Copyright (c) 2007-2020. 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_ATTRIB_DEPRECATED_v329("Please use simix_global->display_all_actor_status()") XBT_PUBLIC
61     void SIMIX_display_process_status();
62 SG_END_DECL
63
64 /******************************** Deployment **********************************/
65 SG_BEGIN_DECL
66 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_default() or Engine::register_default()") XBT_PUBLIC
67     void SIMIX_function_register_default(xbt_main_func_t code);
68 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC void SIMIX_init_application();
69
70 XBT_PUBLIC void SIMIX_process_set_function(const char* process_host, const char* process_function,
71                                            xbt_dynar_t arguments, double process_start_time, double process_kill_time);
72 SG_END_DECL
73
74 #ifdef __cplusplus
75 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_function() or Engine::register_function()") XBT_PUBLIC
76     void SIMIX_function_register(const std::string& name, void (*code)(std::vector<std::string>));
77 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_register_function() or Engine::register_function()") XBT_PUBLIC
78     void SIMIX_function_register(const std::string& name, xbt_main_func_t code);
79 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_load_deployment() or Engine::load_deployment()") XBT_PUBLIC
80     void SIMIX_launch_application(const std::string& file);
81 #endif
82
83 /********************************* Process ************************************/
84 SG_BEGIN_DECL
85 XBT_ATTRIB_DEPRECATED_v329("Please use simgrid_get_actor_count()") XBT_PUBLIC int SIMIX_process_count();
86 XBT_PUBLIC smx_actor_t SIMIX_process_self();
87 XBT_PUBLIC const char* SIMIX_process_self_get_name();
88 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC
89     void SIMIX_process_self_set_data(void* data);
90 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC void* SIMIX_process_self_get_data();
91 SG_END_DECL
92
93 #ifdef __cplusplus
94 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") XBT_PUBLIC
95     void SIMIX_process_on_exit(smx_actor_t process, const std::function<void(bool /*failed*/)>& fun);
96 #endif
97
98 /****************************** Communication *********************************/
99 #ifdef __cplusplus
100 XBT_PUBLIC void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*,
101                                                                    size_t));
102 XBT_PUBLIC void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
103                                                  size_t buff_size);
104 XBT_PUBLIC void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
105                                                 size_t buff_size);
106 #endif
107
108 /******************************************************************************/
109 /*                            SIMIX simcalls                                  */
110 /******************************************************************************/
111 /* These functions are a system call-like interface to the simulation kernel. */
112 /* They can also be called from maestro's context, and they are thread safe.  */
113 /******************************************************************************/
114
115 /******************************* Host simcalls ********************************/
116 #ifdef __cplusplus
117 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
118     simcall_execution_wait(simgrid::kernel::activity::ActivityImpl* execution, double timeout);
119 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
120     simcall_execution_wait(const simgrid::kernel::activity::ActivityImplPtr& execution, double timeout);
121 XBT_PUBLIC unsigned int simcall_execution_waitany_for(simgrid::kernel::activity::ExecImpl* execs[], size_t count,
122                                                       double timeout);
123 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::test()") XBT_PUBLIC
124     bool simcall_execution_test(simgrid::kernel::activity::ActivityImpl* execution);
125 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Exec::test()") XBT_PUBLIC
126     bool simcall_execution_test(const simgrid::kernel::activity::ActivityImplPtr& execution);
127
128 #endif
129
130 /**************************** Process simcalls ********************************/
131 SG_BEGIN_DECL
132 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") void simcall_process_set_data(smx_actor_t process,
133                                                                                                   void* data);
134 XBT_ATTRIB_DEPRECATED_v328("Please use sg_actor_suspend()") XBT_PUBLIC
135     void simcall_process_suspend(smx_actor_t process);
136
137 XBT_ATTRIB_DEPRECATED_v328("Please use sg_actor_join()") XBT_PUBLIC
138     void simcall_process_join(smx_actor_t process, double timeout);
139
140 XBT_ATTRIB_DEPRECATED_v329("Please use sg_actor_sleep_for()") XBT_PUBLIC
141 #ifdef __cplusplus
142     simgrid::kernel::activity::State
143 #else
144     enum kernel_activity_state
145 #endif
146     simcall_process_sleep(double duration);
147 SG_END_DECL
148
149 /************************** Communication simcalls ****************************/
150
151 #ifdef __cplusplus
152 XBT_PUBLIC void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
153                                   size_t src_buff_size,
154                                   bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
155                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
156                                   void* data, double timeout);
157
158 XBT_PUBLIC simgrid::kernel::activity::ActivityImplPtr
159 simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
160                    size_t src_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
161                    void (*clean_fun)(void*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
162                    void* data, bool detached);
163
164 XBT_PUBLIC void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
165                                   bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
166                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
167                                   void* data, double timeout, double rate);
168
169 XBT_PUBLIC simgrid::kernel::activity::ActivityImplPtr
170 simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
171                    bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
172                    void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double rate);
173
174 XBT_ATTRIB_DEPRECATED_v330("Please use Mailbox::iprobe()") XBT_PUBLIC simgrid::kernel::activity::ActivityImplPtr
175     simcall_comm_iprobe(smx_mailbox_t mbox, int type,
176                         bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* data);
177
178 XBT_ATTRIB_DEPRECATED_v330("Please use a CommImpl*[] for first parameter") XBT_PUBLIC
179     unsigned int simcall_comm_waitany(simgrid::kernel::activity::ActivityImplPtr comms[], size_t count, double timeout);
180 XBT_PUBLIC unsigned int simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count,
181                                              double timeout);
182 XBT_PUBLIC void simcall_comm_wait(simgrid::kernel::activity::ActivityImpl* comm, double timeout);
183 XBT_PUBLIC bool simcall_comm_test(simgrid::kernel::activity::ActivityImpl* comm);
184 XBT_ATTRIB_DEPRECATED_v330("Please use a CommImpl*[] for first parameter") XBT_PUBLIC
185     int simcall_comm_testany(simgrid::kernel::activity::ActivityImplPtr comms[], size_t count);
186 XBT_PUBLIC int simcall_comm_testany(simgrid::kernel::activity::CommImpl* comms[], size_t count);
187
188 XBT_ATTRIB_DEPRECATED_v330("Please use a ActivityImpl* for first parameter") inline void simcall_comm_wait(
189     const simgrid::kernel::activity::ActivityImplPtr& comm, double timeout)
190 {
191   simcall_comm_wait(comm.get(), timeout);
192 }
193 XBT_ATTRIB_DEPRECATED_v330("Please use a ActivityImpl* for first parameter") inline bool simcall_comm_test(
194     const simgrid::kernel::activity::ActivityImplPtr& comm)
195 {
196   return simcall_comm_test(comm.get());
197 }
198 #endif
199
200 /************************** Synchro simcalls **********************************/
201 SG_BEGIN_DECL
202 XBT_ATTRIB_DEPRECATED_v330("Please use sg_mutex_init()") XBT_PUBLIC smx_mutex_t simcall_mutex_init();
203 XBT_PUBLIC void simcall_mutex_lock(smx_mutex_t mutex);
204 XBT_PUBLIC int simcall_mutex_trylock(smx_mutex_t mutex);
205 XBT_PUBLIC void simcall_mutex_unlock(smx_mutex_t mutex);
206
207 XBT_ATTRIB_DEPRECATED_v330("Please use sg_cond_init()") XBT_PUBLIC smx_cond_t simcall_cond_init();
208 XBT_PUBLIC void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
209 XBT_PUBLIC int simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double max_duration);
210
211 XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
212 XBT_PUBLIC int simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
213 SG_END_DECL
214
215 /*****************************   Io   **************************************/
216 #ifdef __cplusplus
217 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
218     simcall_io_wait(simgrid::kernel::activity::ActivityImpl* io, double timeout);
219 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::wait_for()") XBT_PUBLIC simgrid::kernel::activity::State
220     simcall_io_wait(const simgrid::kernel::activity::ActivityImplPtr& io, double timeout);
221 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::test()") XBT_PUBLIC
222     bool simcall_io_test(simgrid::kernel::activity::ActivityImpl* io);
223 XBT_ATTRIB_DEPRECATED_v330("Please use s4u::Io::test()") XBT_PUBLIC
224     bool simcall_io_test(const simgrid::kernel::activity::ActivityImplPtr& io);
225 #endif
226 /************************** MC simcalls   **********************************/
227 SG_BEGIN_DECL
228 XBT_PUBLIC int simcall_mc_random(int min, int max);
229 SG_END_DECL
230
231 #endif