Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SIMIX_display_process_status becomes Global::display_all_actor_status
[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_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_PUBLIC e_smx_state_t simcall_execution_wait(const smx_activity_t& execution);
118 XBT_PUBLIC unsigned int simcall_execution_waitany_for(simgrid::kernel::activity::ExecImpl* execs[], size_t count,
119                                                       double timeout);
120 XBT_PUBLIC bool simcall_execution_test(const smx_activity_t& execution);
121 #endif
122
123 /**************************** Process simcalls ********************************/
124 SG_BEGIN_DECL
125 XBT_ATTRIB_DEPRECATED_v329("This function will be removed in 3.29") void simcall_process_set_data(smx_actor_t process,
126                                                                                                   void* data);
127 XBT_ATTRIB_DEPRECATED_v328("Please use Actor::suspend()") XBT_PUBLIC void simcall_process_suspend(smx_actor_t process);
128
129 XBT_ATTRIB_DEPRECATED_v328("Please use Actor::join()") XBT_PUBLIC
130     void simcall_process_join(smx_actor_t process, double timeout);
131
132 XBT_ATTRIB_DEPRECATED_v329("Please use sg_actor_sleep_for()") XBT_PUBLIC e_smx_state_t
133     simcall_process_sleep(double duration);
134 SG_END_DECL
135
136 /************************** Communication simcalls ****************************/
137
138 #ifdef __cplusplus
139 XBT_PUBLIC void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
140                                   size_t src_buff_size,
141                                   int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
142                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
143                                   void* data, double timeout);
144
145 XBT_PUBLIC smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate,
146                                              void* src_buff, size_t src_buff_size,
147                                              int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
148                                              void (*clean_fun)(void*),
149                                              void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
150                                              void* data, bool detached);
151
152 XBT_PUBLIC void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
153                                   int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
154                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
155                                   void* data, double timeout, double rate);
156
157 XBT_PUBLIC smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff,
158                                              size_t* dst_buff_size,
159                                              int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
160                                              void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
161                                              void* data, double rate);
162
163 XBT_PUBLIC smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type,
164                                               int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
165                                               void* data);
166
167 /* FIXME: waitany is going to be a vararg function, and should take a timeout */
168 XBT_PUBLIC unsigned int simcall_comm_waitany(smx_activity_t comms[], size_t count, double timeout);
169 XBT_PUBLIC unsigned int simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count,
170                                              double timeout);
171 XBT_PUBLIC void simcall_comm_wait(const smx_activity_t& comm, double timeout);
172 XBT_PUBLIC bool simcall_comm_test(const smx_activity_t& comm);
173 XBT_PUBLIC int simcall_comm_testany(smx_activity_t comms[], size_t count);
174 XBT_PUBLIC int simcall_comm_testany(simgrid::kernel::activity::CommImpl* comms[], size_t count);
175 #endif
176
177 /************************** Synchro simcalls **********************************/
178 SG_BEGIN_DECL
179 XBT_PUBLIC smx_mutex_t simcall_mutex_init();
180 XBT_PUBLIC void simcall_mutex_lock(smx_mutex_t mutex);
181 XBT_PUBLIC int simcall_mutex_trylock(smx_mutex_t mutex);
182 XBT_PUBLIC void simcall_mutex_unlock(smx_mutex_t mutex);
183
184 XBT_PUBLIC smx_cond_t simcall_cond_init();
185 XBT_PUBLIC void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
186 XBT_PUBLIC int simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double max_duration);
187
188 XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
189 XBT_PUBLIC int simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
190 SG_END_DECL
191
192 /*****************************   Io   **************************************/
193 #ifdef __cplusplus
194 XBT_PUBLIC e_smx_state_t simcall_io_wait(const smx_activity_t& io);
195 #endif
196 /************************** MC simcalls   **********************************/
197 SG_BEGIN_DECL
198 XBT_PUBLIC int simcall_mc_random(int min, int max);
199 SG_END_DECL
200
201 #endif