5 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi,XBT_LOG_ROOT_CAT, "All SMPI categories");
7 SMPI_Global_t smpi_global = NULL;
9 void *smpi_request_new()
11 smpi_mpi_request_t request = xbt_new(s_smpi_mpi_request_t, 1);
13 request->completed = 0;
14 request->mutex = SIMIX_mutex_init();
15 request->cond = SIMIX_cond_init();
20 void smpi_request_free(void *pointer)
23 smpi_mpi_request_t request = pointer;
25 if (NULL != request) {
26 SIMIX_cond_destroy(request->cond);
27 SIMIX_mutex_destroy(request->mutex);
34 void smpi_request_reset(void *pointer)
40 void *smpi_message_new()
42 return xbt_new(s_smpi_received_message_t, 1);
45 void smpi_message_free(void *pointer)
47 if (NULL != pointer) {
54 void smpi_message_reset(void *pointer)
59 void smpi_global_init()
63 int size = SIMIX_host_get_number();
65 smpi_global = xbt_new(s_SMPI_Global_t, 1);
68 smpi_global->reference_speed = SMPI_DEFAULT_SPEED;
70 smpi_global->root_ready = 0;
71 smpi_global->ready_process_count = 0;
74 smpi_global->start_stop_mutex = SIMIX_mutex_init();
75 smpi_global->start_stop_cond = SIMIX_cond_init();
78 smpi_global->sender_processes = xbt_new(smx_process_t, size);
79 smpi_global->receiver_processes = xbt_new(smx_process_t, size);
82 smpi_global->running_hosts_count_mutex = SIMIX_mutex_init();
83 smpi_global->running_hosts_count = 0;
86 smpi_global->request_mallocator = xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE,
87 smpi_request_new, smpi_request_free, smpi_request_reset);
88 smpi_global->message_mallocator = xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE,
89 smpi_message_new, smpi_message_free, smpi_message_reset);
92 smpi_global->pending_send_request_queues = xbt_new(xbt_fifo_t, size);
93 smpi_global->pending_send_request_queues_mutexes = xbt_new(smx_mutex_t, size);
94 smpi_global->pending_recv_request_queues = xbt_new(xbt_fifo_t, size);
95 smpi_global->pending_recv_request_queues_mutexes = xbt_new(smx_mutex_t, size);
96 smpi_global->received_message_queues = xbt_new(xbt_fifo_t, size);
97 smpi_global->received_message_queues_mutexes = xbt_new(smx_mutex_t, size);
100 smpi_global->timers = xbt_new(xbt_os_timer_t, size);
101 smpi_global->timers_mutexes = xbt_new(smx_mutex_t, size);
103 for(i = 0; i < size; i++) {
104 smpi_global->pending_send_request_queues[i] = xbt_fifo_new();
105 smpi_global->pending_send_request_queues_mutexes[i] = SIMIX_mutex_init();
106 smpi_global->pending_recv_request_queues[i] = xbt_fifo_new();
107 smpi_global->pending_recv_request_queues_mutexes[i] = SIMIX_mutex_init();
108 smpi_global->received_message_queues[i] = xbt_fifo_new();
109 smpi_global->received_message_queues_mutexes[i] = SIMIX_mutex_init();
110 smpi_global->timers[i] = xbt_os_timer_new();
111 smpi_global->timers_mutexes[i] = SIMIX_mutex_init();
116 void smpi_global_destroy()
120 int size = SIMIX_host_get_number();
123 SIMIX_mutex_destroy(smpi_global->start_stop_mutex);
124 SIMIX_cond_destroy(smpi_global->start_stop_cond);
127 xbt_free(smpi_global->sender_processes);
128 xbt_free(smpi_global->receiver_processes);
131 SIMIX_mutex_destroy(smpi_global->running_hosts_count_mutex);
134 xbt_mallocator_free(smpi_global->request_mallocator);
135 xbt_mallocator_free(smpi_global->message_mallocator);
137 for(i = 0; i < size; i++) {
138 xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
139 SIMIX_mutex_destroy(smpi_global->pending_send_request_queues_mutexes[i]);
140 xbt_fifo_free(smpi_global->pending_recv_request_queues[i]);
141 SIMIX_mutex_destroy(smpi_global->pending_recv_request_queues_mutexes[i]);
142 xbt_fifo_free(smpi_global->received_message_queues[i]);
143 SIMIX_mutex_destroy(smpi_global->received_message_queues_mutexes[i]);
144 xbt_os_timer_free(smpi_global->timers[i]);
145 SIMIX_mutex_destroy(smpi_global->timers_mutexes[i]);
148 xbt_free(smpi_global->pending_send_request_queues);
149 xbt_free(smpi_global->pending_send_request_queues_mutexes);
150 xbt_free(smpi_global->pending_recv_request_queues);
151 xbt_free(smpi_global->pending_recv_request_queues_mutexes);
152 xbt_free(smpi_global->received_message_queues);
153 xbt_free(smpi_global->received_message_queues_mutexes);
154 xbt_free(smpi_global->timers);
155 xbt_free(smpi_global->timers_mutexes);
157 xbt_free(smpi_global);
162 int smpi_run_simulation(int argc, char **argv)
164 xbt_fifo_item_t cond_item = NULL;
165 smx_cond_t cond = NULL;
166 xbt_fifo_item_t action_item = NULL;
167 smx_action_t action = NULL;
169 xbt_fifo_t actions_failed = xbt_fifo_new();
170 xbt_fifo_t actions_done = xbt_fifo_new();
172 srand(SMPI_RAND_SEED);
174 SIMIX_global_init(&argc, argv);
176 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
177 SIMIX_function_register("smpi_sender", smpi_sender);
178 SIMIX_function_register("smpi_receiver", smpi_receiver);
180 // FIXME: ought to verify these files...
181 SIMIX_create_environment(argv[1]);
183 // must initialize globals between creating environment and launching app....
186 SIMIX_launch_application(argv[2]);
188 /* Prepare to display some more info when dying on Ctrl-C pressing */
189 // FIXME: doesn't work
190 //signal(SIGINT, inthandler);
192 /* Clean IO before the run */
196 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
197 xbt_fifo_foreach(actions_failed, action_item, action, smx_action_t) {
198 DEBUG1("** %s failed **", action->name);
199 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
200 SIMIX_cond_broadcast(cond);
203 xbt_fifo_foreach(actions_done, action_item, action, smx_action_t) {
204 DEBUG1("** %s done **",action->name);
205 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
206 SIMIX_cond_broadcast(cond);
211 // FIXME: cleanup incomplete
212 xbt_fifo_free(actions_failed);
213 xbt_fifo_free(actions_done);
215 INFO1("simulation time %g", SIMIX_get_clock());
217 smpi_global_destroy();