5 XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories");
7 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi,
8 "Logging specific to SMPI (kernel)");
10 smpi_global_t smpi_global = NULL;
12 void *smpi_request_new(void);
14 void *smpi_request_new()
16 smpi_mpi_request_t request = xbt_new(s_smpi_mpi_request_t, 1);
19 request->completed = 0;
20 request->mutex = SIMIX_mutex_init();
21 request->cond = SIMIX_cond_init();
28 void smpi_request_free(void *pointer);
30 void smpi_request_free(void *pointer)
33 smpi_mpi_request_t request = pointer;
35 SIMIX_cond_destroy(request->cond);
36 SIMIX_mutex_destroy(request->mutex);
42 void smpi_request_reset(void *pointer);
44 void smpi_request_reset(void *pointer)
46 smpi_mpi_request_t request = pointer;
49 request->completed = 0;
50 request->consumed = 0;
58 void *smpi_message_new(void);
60 void *smpi_message_new()
62 smpi_received_message_t message = xbt_new(s_smpi_received_message_t, 1);
67 void smpi_message_free(void *pointer);
69 void smpi_message_free(void *pointer)
75 void smpi_message_reset(void *pointer);
77 void smpi_message_reset(void *pointer)
79 smpi_received_message_t message = pointer;
84 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
85 int src, int dst, int tag,
86 smpi_mpi_communicator_t comm,
87 smpi_mpi_request_t * requestptr)
89 int retval = MPI_SUCCESS;
91 smpi_mpi_request_t request = NULL;
93 // parameter checking prob belongs in smpi_mpi, but this is less repeat code
95 retval = MPI_ERR_INTERN;
96 } else if (0 > count) {
97 retval = MPI_ERR_COUNT;
98 } else if (NULL == datatype) {
99 retval = MPI_ERR_TYPE;
100 } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
101 retval = MPI_ERR_RANK;
102 } else if (0 > dst || comm->size <= dst) {
103 retval = MPI_ERR_RANK;
104 } else if (MPI_ANY_TAG != tag && 0 > tag) {
105 retval = MPI_ERR_TAG;
106 } else if (NULL == comm) {
107 retval = MPI_ERR_COMM;
108 } else if (NULL == requestptr) {
109 retval = MPI_ERR_ARG;
111 request = xbt_mallocator_get(smpi_global->request_mallocator);
112 request->comm = comm;
117 request->datatype = datatype;
118 request->count = count;
120 *requestptr = request;
125 /* FIXME: understand what they do and put the prototypes in a header file (live in smpi_base.c) */
126 void smpi_mpi_land_func(void *a, void *b, int *length,
127 MPI_Datatype * datatype);
128 void smpi_mpi_sum_func(void *a, void *b, int *length,
129 MPI_Datatype * datatype);
130 void smpi_mpi_prod_func(void *a, void *b, int *length,
131 MPI_Datatype * datatype);
132 void smpi_mpi_min_func(void *a, void *b, int *length,
133 MPI_Datatype * datatype);
134 void smpi_mpi_max_func(void *a, void *b, int *length,
135 MPI_Datatype * datatype);
137 void smpi_global_init()
141 /* Connect our log channels: that must be done manually under windows */
142 #ifdef XBT_LOG_CONNECT
143 XBT_LOG_CONNECT(smpi_base, smpi);
144 XBT_LOG_CONNECT(smpi_bench, smpi);
145 XBT_LOG_CONNECT(smpi_kernel, smpi);
146 XBT_LOG_CONNECT(smpi_mpi, smpi);
147 XBT_LOG_CONNECT(smpi_receiver, smpi);
148 XBT_LOG_CONNECT(smpi_sender, smpi);
149 XBT_LOG_CONNECT(smpi_util, smpi);
152 smpi_global = xbt_new(s_smpi_global_t, 1);
155 smpi_global->request_mallocator =
156 xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE, smpi_request_new,
157 smpi_request_free, smpi_request_reset);
158 smpi_global->message_mallocator =
159 xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE, smpi_message_new,
160 smpi_message_free, smpi_message_reset);
162 smpi_global->process_count = SIMIX_process_count();
163 DEBUG1("There is %d processes", smpi_global->process_count);
165 // sender/receiver processes
166 smpi_global->main_processes =
167 xbt_new(smx_process_t, smpi_global->process_count);
170 smpi_global->timer = xbt_os_timer_new();
171 smpi_global->timer_cond = SIMIX_cond_init();
173 smpi_global->do_once_duration_nodes = NULL;
174 smpi_global->do_once_duration = NULL;
175 smpi_global->do_once_mutex = SIMIX_mutex_init();
178 smpi_mpi_global = xbt_new(s_smpi_mpi_global_t, 1);
180 // global communicator
181 smpi_mpi_global->mpi_comm_world = xbt_new(s_smpi_mpi_communicator_t, 1);
182 smpi_mpi_global->mpi_comm_world->size = smpi_global->process_count;
183 smpi_mpi_global->mpi_comm_world->barrier_count = 0;
184 smpi_mpi_global->mpi_comm_world->barrier_mutex = SIMIX_mutex_init();
185 smpi_mpi_global->mpi_comm_world->barrier_cond = SIMIX_cond_init();
186 smpi_mpi_global->mpi_comm_world->rank_to_index_map =
187 xbt_new(int, smpi_global->process_count);
188 smpi_mpi_global->mpi_comm_world->index_to_rank_map =
189 xbt_new(int, smpi_global->process_count);
190 for (i = 0; i < smpi_global->process_count; i++) {
191 smpi_mpi_global->mpi_comm_world->rank_to_index_map[i] = i;
192 smpi_mpi_global->mpi_comm_world->index_to_rank_map[i] = i;
196 smpi_mpi_global->mpi_byte = xbt_new(s_smpi_mpi_datatype_t, 1);
197 smpi_mpi_global->mpi_byte->size = (size_t) 1;
198 smpi_mpi_global->mpi_char = xbt_new(s_smpi_mpi_datatype_t, 1);
199 smpi_mpi_global->mpi_char->size = (size_t) 1;
200 smpi_mpi_global->mpi_int = xbt_new(s_smpi_mpi_datatype_t, 1);
201 smpi_mpi_global->mpi_int->size = sizeof(int);
202 smpi_mpi_global->mpi_float = xbt_new(s_smpi_mpi_datatype_t, 1);
203 smpi_mpi_global->mpi_float->size = sizeof(float);
204 smpi_mpi_global->mpi_double = xbt_new(s_smpi_mpi_datatype_t, 1);
205 smpi_mpi_global->mpi_double->size = sizeof(double);
208 smpi_mpi_global->mpi_land = xbt_new(s_smpi_mpi_op_t, 1);
209 smpi_mpi_global->mpi_land->func = smpi_mpi_land_func;
210 smpi_mpi_global->mpi_sum = xbt_new(s_smpi_mpi_op_t, 1);
211 smpi_mpi_global->mpi_sum->func = smpi_mpi_sum_func;
212 smpi_mpi_global->mpi_prod = xbt_new(s_smpi_mpi_op_t, 1);
213 smpi_mpi_global->mpi_prod->func = smpi_mpi_prod_func;
214 smpi_mpi_global->mpi_min = xbt_new(s_smpi_mpi_op_t, 1);
215 smpi_mpi_global->mpi_min->func = smpi_mpi_min_func;
216 smpi_mpi_global->mpi_max = xbt_new(s_smpi_mpi_op_t, 1);
217 smpi_mpi_global->mpi_max->func = smpi_mpi_max_func;
221 void smpi_global_destroy()
223 smpi_do_once_duration_node_t curr, next;
226 xbt_free(smpi_global->main_processes);
229 xbt_mallocator_free(smpi_global->request_mallocator);
230 xbt_mallocator_free(smpi_global->message_mallocator);
232 xbt_os_timer_free(smpi_global->timer);
233 SIMIX_cond_destroy(smpi_global->timer_cond);
235 for (curr = smpi_global->do_once_duration_nodes; NULL != curr; curr = next) {
237 xbt_free(curr->file);
241 SIMIX_mutex_destroy(smpi_global->do_once_mutex);
243 xbt_free(smpi_global);
246 /* free smpi_mpi_global */
247 SIMIX_mutex_destroy(smpi_mpi_global->mpi_comm_world->barrier_mutex);
248 SIMIX_cond_destroy(smpi_mpi_global->mpi_comm_world->barrier_cond);
249 xbt_free(smpi_mpi_global->mpi_comm_world->rank_to_index_map);
250 xbt_free(smpi_mpi_global->mpi_comm_world);
252 xbt_free(smpi_mpi_global->mpi_byte);
253 xbt_free(smpi_mpi_global->mpi_char);
254 xbt_free(smpi_mpi_global->mpi_int);
255 xbt_free(smpi_mpi_global->mpi_double);
256 xbt_free(smpi_mpi_global->mpi_float);
258 xbt_free(smpi_mpi_global->mpi_land);
259 xbt_free(smpi_mpi_global->mpi_sum);
260 xbt_free(smpi_mpi_global->mpi_prod);
261 xbt_free(smpi_mpi_global->mpi_max);
262 xbt_free(smpi_mpi_global->mpi_min);
264 xbt_free(smpi_mpi_global);
268 int smpi_process_index()
270 smpi_process_data_t pdata =
271 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
275 smx_mutex_t smpi_process_mutex()
277 smpi_process_data_t pdata =
278 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
282 smx_cond_t smpi_process_cond()
284 smpi_process_data_t pdata =
285 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
289 static void smpi_cfg_cb_host_speed(const char *name, int pos)
291 smpi_global->reference_speed =
292 xbt_cfg_get_double_at(_surf_cfg_set, name, pos);
295 int smpi_run_simulation(int *argc, char **argv)
297 smx_action_t action = NULL;
299 xbt_fifo_t actions_failed = xbt_fifo_new();
300 xbt_fifo_t actions_done = xbt_fifo_new();
302 srand(SMPI_RAND_SEED);
304 double default_reference_speed = 20000.0;
305 xbt_cfg_register(&_surf_cfg_set, "reference_speed",
306 "Power of the host running the simulation (in flop/s). Used to bench the operations.",
307 xbt_cfgelm_double, &default_reference_speed, 1, 1,
308 smpi_cfg_cb_host_speed, NULL);
310 int default_display_timing = 0;
311 xbt_cfg_register(&_surf_cfg_set, "display_timing",
312 "Boolean indicating whether we should display the timing after simulation.",
313 xbt_cfgelm_int, &default_display_timing, 1, 1, NULL, NULL);
315 SIMIX_global_init(argc, argv);
318 // parse the platform file: get the host list
319 SIMIX_create_environment(argv[1]);
321 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
322 SIMIX_launch_application(argv[2]);
324 // must initialize globals between creating environment and launching app....
327 /* Clean IO before the run */
332 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
333 while ((action = xbt_fifo_pop(actions_failed))) {
334 DEBUG1("** %s failed **", SIMIX_action_get_name(action));
335 SIMIX_action_signal_all(action);
337 while ((action = xbt_fifo_pop(actions_done))) {
338 DEBUG1("** %s done **", SIMIX_action_get_name(action));
339 SIMIX_action_signal_all(action);
343 // FIXME: cleanup incomplete
344 xbt_fifo_free(actions_failed);
345 xbt_fifo_free(actions_done);
348 if (xbt_cfg_get_int(_surf_cfg_set, "display_timing"))
349 INFO1("simulation time %g", SIMIX_get_clock());
351 smpi_global_destroy();