4 #include "smpi_mpi_dt_private.h"
6 XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories");
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi,
9 "Logging specific to SMPI (kernel)");
11 smpi_global_t smpi_global = NULL;
13 void *smpi_request_new(void);
15 void *smpi_request_new()
17 smpi_mpi_request_t request = xbt_new(s_smpi_mpi_request_t, 1);
20 request->completed = 0;
21 request->mutex = SIMIX_mutex_init();
22 request->cond = SIMIX_cond_init();
29 void smpi_request_free(void *pointer);
31 void smpi_request_free(void *pointer)
34 smpi_mpi_request_t request = pointer;
36 SIMIX_cond_destroy(request->cond);
37 SIMIX_mutex_destroy(request->mutex);
43 void smpi_request_reset(void *pointer);
45 void smpi_request_reset(void *pointer)
47 smpi_mpi_request_t request = pointer;
50 request->completed = 0;
51 request->consumed = 0;
59 void *smpi_message_new(void);
61 void *smpi_message_new()
63 smpi_received_message_t message = xbt_new(s_smpi_received_message_t, 1);
68 void smpi_message_free(void *pointer);
70 void smpi_message_free(void *pointer)
76 void smpi_message_reset(void *pointer);
78 void smpi_message_reset(void *pointer)
80 smpi_received_message_t message = pointer;
85 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
86 int src, int dst, int tag,
87 smpi_mpi_communicator_t comm,
88 smpi_mpi_request_t * requestptr)
90 int retval = MPI_SUCCESS;
92 smpi_mpi_request_t request = NULL;
94 // parameter checking prob belongs in smpi_mpi, but this is less repeat code
96 retval = MPI_ERR_INTERN;
97 } else if (0 > count) {
98 retval = MPI_ERR_COUNT;
99 } else if (NULL == datatype) {
100 retval = MPI_ERR_TYPE;
101 } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
102 retval = MPI_ERR_RANK;
103 } else if (0 > dst || comm->size <= dst) {
104 retval = MPI_ERR_RANK;
105 } else if (MPI_ANY_TAG != tag && 0 > tag) {
106 retval = MPI_ERR_TAG;
107 } else if (NULL == comm) {
108 retval = MPI_ERR_COMM;
109 } else if (NULL == requestptr) {
110 retval = MPI_ERR_ARG;
112 request = xbt_mallocator_get(smpi_global->request_mallocator);
113 request->comm = comm;
118 request->datatype = datatype;
119 request->count = count;
121 *requestptr = request;
126 /* FIXME: understand what they do and put the prototypes in a header file (live in smpi_base.c) */
127 void smpi_mpi_land_func(void *a, void *b, int *length,
128 MPI_Datatype * datatype);
129 void smpi_mpi_sum_func(void *a, void *b, int *length,
130 MPI_Datatype * datatype);
131 void smpi_mpi_prod_func(void *a, void *b, int *length,
132 MPI_Datatype * datatype);
133 void smpi_mpi_min_func(void *a, void *b, int *length,
134 MPI_Datatype * datatype);
135 void smpi_mpi_max_func(void *a, void *b, int *length,
136 MPI_Datatype * datatype);
138 void smpi_global_init()
142 /* Connect our log channels: that must be done manually under windows */
143 #ifdef XBT_LOG_CONNECT
144 XBT_LOG_CONNECT(smpi_base, smpi);
145 XBT_LOG_CONNECT(smpi_bench, smpi);
146 XBT_LOG_CONNECT(smpi_kernel, smpi);
147 XBT_LOG_CONNECT(smpi_mpi, smpi);
148 XBT_LOG_CONNECT(smpi_receiver, smpi);
149 XBT_LOG_CONNECT(smpi_sender, smpi);
150 XBT_LOG_CONNECT(smpi_util, smpi);
153 smpi_global = xbt_new(s_smpi_global_t, 1);
156 smpi_global->request_mallocator =
157 xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE, smpi_request_new,
158 smpi_request_free, smpi_request_reset);
159 smpi_global->message_mallocator =
160 xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE, smpi_message_new,
161 smpi_message_free, smpi_message_reset);
163 smpi_global->process_count = SIMIX_process_count();
164 DEBUG1("There is %d processes", smpi_global->process_count);
166 // sender/receiver processes
167 smpi_global->main_processes =
168 xbt_new(smx_process_t, smpi_global->process_count);
171 smpi_global->timer = xbt_os_timer_new();
172 smpi_global->timer_cond = SIMIX_cond_init();
174 smpi_global->do_once_duration_nodes = NULL;
175 smpi_global->do_once_duration = NULL;
176 smpi_global->do_once_mutex = SIMIX_mutex_init();
179 smpi_mpi_global = xbt_new(s_smpi_mpi_global_t, 1);
181 // global communicator
182 smpi_mpi_global->mpi_comm_world = xbt_new(s_smpi_mpi_communicator_t, 1);
183 smpi_mpi_global->mpi_comm_world->size = smpi_global->process_count;
184 smpi_mpi_global->mpi_comm_world->barrier_count = 0;
185 smpi_mpi_global->mpi_comm_world->barrier_mutex = SIMIX_mutex_init();
186 smpi_mpi_global->mpi_comm_world->barrier_cond = SIMIX_cond_init();
187 smpi_mpi_global->mpi_comm_world->rank_to_index_map =
188 xbt_new(int, smpi_global->process_count);
189 smpi_mpi_global->mpi_comm_world->index_to_rank_map =
190 xbt_new(int, smpi_global->process_count);
191 for (i = 0; i < smpi_global->process_count; i++) {
192 smpi_mpi_global->mpi_comm_world->rank_to_index_map[i] = i;
193 smpi_mpi_global->mpi_comm_world->index_to_rank_map[i] = i;
197 smpi_mpi_global->mpi_byte = xbt_new(s_smpi_mpi_datatype_t, 1); /* we can think of it as a placeholder for value*/
198 smpi_mpi_global->mpi_byte->size = (size_t) 1;
199 smpi_mpi_global->mpi_byte->lb = (ptrdiff_t) 0;
200 smpi_mpi_global->mpi_byte->ub = smpi_mpi_global->mpi_byte->lb + smpi_mpi_global->mpi_byte->size;
201 smpi_mpi_global->mpi_byte->flags = DT_FLAG_BASIC;
203 smpi_mpi_global->mpi_char = xbt_new(s_smpi_mpi_datatype_t, 1);
204 smpi_mpi_global->mpi_char->size = (size_t) 1;
205 smpi_mpi_global->mpi_char->lb = (ptrdiff_t) 0; //&(smpi_mpi_global->mpi_char);
206 smpi_mpi_global->mpi_char->ub = smpi_mpi_global->mpi_char->lb + smpi_mpi_global->mpi_char->size;
207 smpi_mpi_global->mpi_char->flags = DT_FLAG_BASIC;
209 smpi_mpi_global->mpi_int = xbt_new(s_smpi_mpi_datatype_t, 1);
210 smpi_mpi_global->mpi_int->size = sizeof(int);
211 smpi_mpi_global->mpi_int->lb = (ptrdiff_t) 0; // &(smpi_mpi_global->mpi_int);
212 smpi_mpi_global->mpi_int->ub = smpi_mpi_global->mpi_int->lb + smpi_mpi_global->mpi_int->size;
213 smpi_mpi_global->mpi_int->flags = DT_FLAG_BASIC;
215 smpi_mpi_global->mpi_float = xbt_new(s_smpi_mpi_datatype_t, 1);
216 smpi_mpi_global->mpi_float->size = sizeof(float);
217 smpi_mpi_global->mpi_float->lb = (ptrdiff_t) 0; // &(smpi_mpi_global->mpi_float);
218 smpi_mpi_global->mpi_float->ub = smpi_mpi_global->mpi_float->lb + smpi_mpi_global->mpi_float->size;
219 smpi_mpi_global->mpi_float->flags = DT_FLAG_BASIC;
221 smpi_mpi_global->mpi_double = xbt_new(s_smpi_mpi_datatype_t, 1);
222 smpi_mpi_global->mpi_double->size = sizeof(double);
223 smpi_mpi_global->mpi_double->lb = (ptrdiff_t) 0; //&(smpi_mpi_global->mpi_float);
224 smpi_mpi_global->mpi_double->ub = smpi_mpi_global->mpi_double->lb + smpi_mpi_global->mpi_double->size;
225 smpi_mpi_global->mpi_double->flags = DT_FLAG_BASIC;
228 smpi_mpi_global->mpi_land = xbt_new(s_smpi_mpi_op_t, 1);
229 smpi_mpi_global->mpi_land->func = smpi_mpi_land_func;
230 smpi_mpi_global->mpi_sum = xbt_new(s_smpi_mpi_op_t, 1);
231 smpi_mpi_global->mpi_sum->func = smpi_mpi_sum_func;
232 smpi_mpi_global->mpi_prod = xbt_new(s_smpi_mpi_op_t, 1);
233 smpi_mpi_global->mpi_prod->func = smpi_mpi_prod_func;
234 smpi_mpi_global->mpi_min = xbt_new(s_smpi_mpi_op_t, 1);
235 smpi_mpi_global->mpi_min->func = smpi_mpi_min_func;
236 smpi_mpi_global->mpi_max = xbt_new(s_smpi_mpi_op_t, 1);
237 smpi_mpi_global->mpi_max->func = smpi_mpi_max_func;
241 void smpi_global_destroy()
243 smpi_do_once_duration_node_t curr, next;
246 xbt_free(smpi_global->main_processes);
249 xbt_mallocator_free(smpi_global->request_mallocator);
250 xbt_mallocator_free(smpi_global->message_mallocator);
252 xbt_os_timer_free(smpi_global->timer);
253 SIMIX_cond_destroy(smpi_global->timer_cond);
255 for (curr = smpi_global->do_once_duration_nodes; NULL != curr; curr = next) {
257 xbt_free(curr->file);
261 SIMIX_mutex_destroy(smpi_global->do_once_mutex);
263 xbt_free(smpi_global);
266 /* free smpi_mpi_global */
267 SIMIX_mutex_destroy(smpi_mpi_global->mpi_comm_world->barrier_mutex);
268 SIMIX_cond_destroy(smpi_mpi_global->mpi_comm_world->barrier_cond);
269 xbt_free(smpi_mpi_global->mpi_comm_world->rank_to_index_map);
270 xbt_free(smpi_mpi_global->mpi_comm_world);
272 xbt_free(smpi_mpi_global->mpi_byte);
273 xbt_free(smpi_mpi_global->mpi_char);
274 xbt_free(smpi_mpi_global->mpi_int);
275 xbt_free(smpi_mpi_global->mpi_double);
276 xbt_free(smpi_mpi_global->mpi_float);
278 xbt_free(smpi_mpi_global->mpi_land);
279 xbt_free(smpi_mpi_global->mpi_sum);
280 xbt_free(smpi_mpi_global->mpi_prod);
281 xbt_free(smpi_mpi_global->mpi_max);
282 xbt_free(smpi_mpi_global->mpi_min);
284 xbt_free(smpi_mpi_global);
288 int smpi_process_index()
290 smpi_process_data_t pdata =
291 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
295 smx_mutex_t smpi_process_mutex()
297 smpi_process_data_t pdata =
298 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
302 smx_cond_t smpi_process_cond()
304 smpi_process_data_t pdata =
305 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
309 static void smpi_cfg_cb_host_speed(const char *name, int pos)
311 smpi_global->reference_speed =
312 xbt_cfg_get_double_at(_surf_cfg_set, name, pos);
315 int smpi_run_simulation(int *argc, char **argv)
317 smx_action_t action = NULL;
319 xbt_fifo_t actions_failed = xbt_fifo_new();
320 xbt_fifo_t actions_done = xbt_fifo_new();
322 srand(SMPI_RAND_SEED);
324 double default_reference_speed = 20000.0;
325 xbt_cfg_register(&_surf_cfg_set, "reference_speed",
326 "Power of the host running the simulation (in flop/s). Used to bench the operations.",
327 xbt_cfgelm_double, &default_reference_speed, 1, 1,
328 smpi_cfg_cb_host_speed, NULL);
330 int default_display_timing = 0;
331 xbt_cfg_register(&_surf_cfg_set, "display_timing",
332 "Boolean indicating whether we should display the timing after simulation.",
333 xbt_cfgelm_int, &default_display_timing, 1, 1, NULL, NULL);
335 SIMIX_global_init(argc, argv);
338 // parse the platform file: get the host list
339 SIMIX_create_environment(argv[1]);
341 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
342 SIMIX_launch_application(argv[2]);
344 // must initialize globals between creating environment and launching app....
347 /* Clean IO before the run */
352 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
353 while ((action = xbt_fifo_pop(actions_failed))) {
354 DEBUG1("** %s failed **", SIMIX_action_get_name(action));
355 SIMIX_action_signal_all(action);
357 while ((action = xbt_fifo_pop(actions_done))) {
358 DEBUG1("** %s done **", SIMIX_action_get_name(action));
359 SIMIX_action_signal_all(action);
363 // FIXME: cleanup incomplete
364 xbt_fifo_free(actions_failed);
365 xbt_fifo_free(actions_done);
368 if (xbt_cfg_get_int(_surf_cfg_set, "display_timing"))
369 INFO1("simulation time %g", SIMIX_get_clock());
371 smpi_global_destroy();