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;
57 void *smpi_message_new(void);
59 void *smpi_message_new()
61 smpi_received_message_t message = xbt_new(s_smpi_received_message_t, 1);
66 void smpi_message_free(void *pointer);
68 void smpi_message_free(void *pointer)
74 void smpi_message_reset(void *pointer);
76 void smpi_message_reset(void *pointer)
78 smpi_received_message_t message = pointer;
83 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
84 int src, int dst, int tag,
85 smpi_mpi_communicator_t comm,
86 smpi_mpi_request_t * requestptr)
88 int retval = MPI_SUCCESS;
90 smpi_mpi_request_t request = NULL;
92 // parameter checking prob belongs in smpi_mpi, but this is less repeat code
94 retval = MPI_ERR_INTERN;
95 } else if (0 > count) {
96 retval = MPI_ERR_COUNT;
97 } else if (NULL == datatype) {
98 retval = MPI_ERR_TYPE;
99 } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
100 retval = MPI_ERR_RANK;
101 } else if (0 > dst || comm->size <= dst) {
102 retval = MPI_ERR_RANK;
103 } else if (MPI_ANY_TAG != tag && 0 > tag) {
104 retval = MPI_ERR_TAG;
105 } else if (NULL == comm) {
106 retval = MPI_ERR_COMM;
107 } else if (NULL == requestptr) {
108 retval = MPI_ERR_ARG;
110 request = xbt_mallocator_get(smpi_global->request_mallocator);
111 request->comm = comm;
116 request->datatype = datatype;
117 request->count = count;
119 *requestptr = request;
123 /* FIXME: understand what they do and put the prototypes in a header file (live in smpi_base.c) */
124 void smpi_mpi_land_func(void *a, void *b, int *length,
125 MPI_Datatype * datatype);
126 void smpi_mpi_sum_func(void *a, void *b, int *length,
127 MPI_Datatype * datatype);
129 void smpi_global_init()
133 int size = SIMIX_host_get_number();
135 /* Connect our log channels: that must be done manually under windows */
136 #ifdef XBT_LOG_CONNECT
137 XBT_LOG_CONNECT(smpi_base, smpi);
138 XBT_LOG_CONNECT(smpi_bench, smpi);
139 XBT_LOG_CONNECT(smpi_kernel, smpi);
140 XBT_LOG_CONNECT(smpi_mpi, smpi);
141 XBT_LOG_CONNECT(smpi_receiver, smpi);
142 XBT_LOG_CONNECT(smpi_sender, smpi);
143 XBT_LOG_CONNECT(smpi_util, smpi);
146 smpi_global = xbt_new(s_smpi_global_t, 1);
148 smpi_global->reference_speed = SMPI_DEFAULT_SPEED;
150 smpi_global->root_ready = 0;
151 smpi_global->ready_process_count = 0;
154 smpi_global->start_stop_mutex = SIMIX_mutex_init();
155 smpi_global->start_stop_cond = SIMIX_cond_init();
157 // host info blank until sim starts
158 // FIXME: is this okay?
159 smpi_global->hosts = NULL;
160 smpi_global->host_count = 0;
163 smpi_global->running_hosts_count_mutex = SIMIX_mutex_init();
164 smpi_global->running_hosts_count = 0;
167 smpi_global->request_mallocator =
168 xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE, smpi_request_new,
169 smpi_request_free, smpi_request_reset);
170 smpi_global->message_mallocator =
171 xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE, smpi_message_new,
172 smpi_message_free, smpi_message_reset);
175 smpi_global->pending_send_request_queues = xbt_new(xbt_fifo_t, size);
176 smpi_global->pending_send_request_queues_mutexes =
177 xbt_new(smx_mutex_t, size);
178 smpi_global->pending_recv_request_queues = xbt_new(xbt_fifo_t, size);
179 smpi_global->pending_recv_request_queues_mutexes =
180 xbt_new(smx_mutex_t, size);
181 smpi_global->received_message_queues = xbt_new(xbt_fifo_t, size);
182 smpi_global->received_message_queues_mutexes = xbt_new(smx_mutex_t, size);
184 // sender/receiver processes
185 smpi_global->sender_processes = xbt_new(smx_process_t, size);
186 smpi_global->receiver_processes = xbt_new(smx_process_t, size);
189 smpi_global->timer = xbt_os_timer_new();
190 smpi_global->timer_mutex = SIMIX_mutex_init();
191 smpi_global->timer_cond = SIMIX_cond_init();
193 smpi_global->do_once_duration_nodes = NULL;
194 smpi_global->do_once_duration = NULL;
195 smpi_global->do_once_mutex = SIMIX_mutex_init();
197 for (i = 0; i < size; i++) {
198 smpi_global->pending_send_request_queues[i] = xbt_fifo_new();
199 smpi_global->pending_send_request_queues_mutexes[i] = SIMIX_mutex_init();
200 smpi_global->pending_recv_request_queues[i] = xbt_fifo_new();
201 smpi_global->pending_recv_request_queues_mutexes[i] = SIMIX_mutex_init();
202 smpi_global->received_message_queues[i] = xbt_fifo_new();
203 smpi_global->received_message_queues_mutexes[i] = SIMIX_mutex_init();
206 smpi_global->hosts = SIMIX_host_get_table();
207 smpi_global->host_count = SIMIX_host_get_number();
209 smpi_mpi_global = xbt_new(s_smpi_mpi_global_t, 1);
211 // global communicator
212 smpi_mpi_global->mpi_comm_world = xbt_new(s_smpi_mpi_communicator_t, 1);
213 smpi_mpi_global->mpi_comm_world->size = smpi_global->host_count;
214 smpi_mpi_global->mpi_comm_world->barrier_count = 0;
215 smpi_mpi_global->mpi_comm_world->barrier_mutex = SIMIX_mutex_init();
216 smpi_mpi_global->mpi_comm_world->barrier_cond = SIMIX_cond_init();
217 smpi_mpi_global->mpi_comm_world->rank_to_index_map =
218 xbt_new(int, smpi_global->host_count);
219 smpi_mpi_global->mpi_comm_world->index_to_rank_map =
220 xbt_new(int, smpi_global->host_count);
221 for (i = 0; i < smpi_global->host_count; i++) {
222 smpi_mpi_global->mpi_comm_world->rank_to_index_map[i] = i;
223 smpi_mpi_global->mpi_comm_world->index_to_rank_map[i] = i;
227 smpi_mpi_global->mpi_byte = xbt_new(s_smpi_mpi_datatype_t, 1);
228 smpi_mpi_global->mpi_byte->size = (size_t) 1;
229 smpi_mpi_global->mpi_int = xbt_new(s_smpi_mpi_datatype_t, 1);
230 smpi_mpi_global->mpi_int->size = sizeof(int);
231 smpi_mpi_global->mpi_double = xbt_new(s_smpi_mpi_datatype_t, 1);
232 smpi_mpi_global->mpi_double->size = sizeof(double);
235 smpi_mpi_global->mpi_land = xbt_new(s_smpi_mpi_op_t, 1);
236 smpi_mpi_global->mpi_land->func = smpi_mpi_land_func;
237 smpi_mpi_global->mpi_sum = xbt_new(s_smpi_mpi_op_t, 1);
238 smpi_mpi_global->mpi_sum->func = smpi_mpi_sum_func;
242 void smpi_global_destroy()
246 int size = SIMIX_host_get_number();
248 smpi_do_once_duration_node_t curr, next;
251 SIMIX_mutex_destroy(smpi_global->start_stop_mutex);
252 SIMIX_cond_destroy(smpi_global->start_stop_cond);
255 xbt_free(smpi_global->sender_processes);
256 xbt_free(smpi_global->receiver_processes);
259 SIMIX_mutex_destroy(smpi_global->running_hosts_count_mutex);
262 xbt_mallocator_free(smpi_global->request_mallocator);
263 xbt_mallocator_free(smpi_global->message_mallocator);
265 xbt_os_timer_free(smpi_global->timer);
266 SIMIX_mutex_destroy(smpi_global->timer_mutex);
267 SIMIX_cond_destroy(smpi_global->timer_cond);
269 for (curr = smpi_global->do_once_duration_nodes; NULL != curr; curr = next) {
271 xbt_free(curr->file);
275 SIMIX_mutex_destroy(smpi_global->do_once_mutex);
277 for (i = 0; i < size; i++) {
278 xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
279 SIMIX_mutex_destroy(smpi_global->pending_send_request_queues_mutexes[i]);
280 xbt_fifo_free(smpi_global->pending_recv_request_queues[i]);
281 SIMIX_mutex_destroy(smpi_global->pending_recv_request_queues_mutexes[i]);
282 xbt_fifo_free(smpi_global->received_message_queues[i]);
283 SIMIX_mutex_destroy(smpi_global->received_message_queues_mutexes[i]);
286 xbt_free(smpi_global->pending_send_request_queues);
287 xbt_free(smpi_global->pending_send_request_queues_mutexes);
288 xbt_free(smpi_global->pending_recv_request_queues);
289 xbt_free(smpi_global->pending_recv_request_queues_mutexes);
290 xbt_free(smpi_global->received_message_queues);
291 xbt_free(smpi_global->received_message_queues_mutexes);
293 xbt_free(smpi_global);
298 int smpi_host_index()
300 smx_host_t host = SIMIX_host_self();
301 smpi_host_data_t hdata = (smpi_host_data_t) SIMIX_host_get_data(host);
305 smx_mutex_t smpi_host_mutex()
307 smx_host_t host = SIMIX_host_self();
308 smpi_host_data_t hdata = (smpi_host_data_t) SIMIX_host_get_data(host);
312 smx_cond_t smpi_host_cond()
314 smx_host_t host = SIMIX_host_self();
315 smpi_host_data_t hdata = (smpi_host_data_t) SIMIX_host_get_data(host);
319 int smpi_run_simulation(int *argc, char **argv)
321 smx_cond_t cond = NULL;
322 smx_action_t action = NULL;
324 xbt_fifo_t actions_failed = xbt_fifo_new();
325 xbt_fifo_t actions_done = xbt_fifo_new();
327 srand(SMPI_RAND_SEED);
329 SIMIX_global_init(argc, argv);
331 // parse the platform file: get the host list
332 SIMIX_create_environment(argv[1]);
334 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
335 SIMIX_function_register("smpi_sender", smpi_sender);
336 SIMIX_function_register("smpi_receiver", smpi_receiver);
337 SIMIX_launch_application(argv[2]);
339 // must initialize globals between creating environment and launching app....
342 /* Prepare to display some more info when dying on Ctrl-C pressing */
343 // FIXME: doesn't work
344 //signal(SIGINT, inthandler);
346 /* Clean IO before the run */
351 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
352 while ((action = xbt_fifo_pop(actions_failed))) {
353 DEBUG1("** %s failed **", action->name);
354 while ((cond = xbt_fifo_pop(action->cond_list))) {
355 SIMIX_cond_broadcast(cond);
358 while ((action = xbt_fifo_pop(actions_done))) {
359 DEBUG1("** %s done **", action->name);
360 while ((cond = xbt_fifo_pop(action->cond_list))) {
361 SIMIX_cond_broadcast(cond);
366 // FIXME: cleanup incomplete
367 xbt_fifo_free(actions_failed);
368 xbt_fifo_free(actions_done);
370 INFO1("simulation time %g", SIMIX_get_clock());
372 smpi_global_destroy();