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(void);
11 void *smpi_request_new()
13 smpi_mpi_request_t request = xbt_new(s_smpi_mpi_request_t, 1);
15 request->completed = 0;
16 request->mutex = SIMIX_mutex_init();
17 request->cond = SIMIX_cond_init();
22 void smpi_request_free(void *pointer);
24 void smpi_request_free(void *pointer)
27 smpi_mpi_request_t request = pointer;
29 if (NULL != request) {
30 SIMIX_cond_destroy(request->cond);
31 SIMIX_mutex_destroy(request->mutex);
38 void smpi_request_reset(void *pointer);
40 void smpi_request_reset(void *pointer)
42 smpi_mpi_request_t request = pointer;
44 request->completed = 0;
50 void *smpi_message_new(void);
52 void *smpi_message_new()
54 return xbt_new(s_smpi_received_message_t, 1);
57 void smpi_message_free(void *pointer);
59 void smpi_message_free(void *pointer)
61 if (NULL != pointer) {
68 void smpi_message_reset(void *pointer);
70 void smpi_message_reset(void *pointer)
75 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
76 int src, int dst, int tag, smpi_mpi_communicator_t comm, smpi_mpi_request_t *requestptr)
78 int retval = MPI_SUCCESS;
80 smpi_mpi_request_t request = NULL;
82 // FIXME: make sure requestptr is not null
84 retval = MPI_ERR_INTERN;
85 } else if (0 > count) {
86 retval = MPI_ERR_COUNT;
87 } else if (NULL == datatype) {
88 retval = MPI_ERR_TYPE;
89 } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
90 retval = MPI_ERR_RANK;
91 } else if (0 > dst || comm->size <= dst) {
92 retval = MPI_ERR_RANK;
93 } else if (MPI_ANY_TAG != tag && 0 > tag) {
95 } else if (NULL == comm) {
96 retval = MPI_ERR_COMM;
97 } else if (NULL == requestptr) {
98 retval = MPI_ERR_INTERN;
100 request = xbt_mallocator_get(smpi_global->request_mallocator);
101 request->comm = comm;
106 request->datatype = datatype;
107 request->count = count;
109 *requestptr = request;
114 void smpi_global_init()
118 int size = SIMIX_host_get_number();
120 smpi_global = xbt_new(s_smpi_global_t, 1);
123 smpi_global->reference_speed = SMPI_DEFAULT_SPEED;
125 smpi_global->root_ready = 0;
126 smpi_global->ready_process_count = 0;
129 smpi_global->start_stop_mutex = SIMIX_mutex_init();
130 smpi_global->start_stop_cond = SIMIX_cond_init();
133 smpi_global->sender_processes = xbt_new(smx_process_t, size);
134 smpi_global->receiver_processes = xbt_new(smx_process_t, size);
137 smpi_global->running_hosts_count_mutex = SIMIX_mutex_init();
138 smpi_global->running_hosts_count = 0;
141 smpi_global->request_mallocator = xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE,
142 smpi_request_new, smpi_request_free, smpi_request_reset);
143 smpi_global->message_mallocator = xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE,
144 smpi_message_new, smpi_message_free, smpi_message_reset);
147 smpi_global->pending_send_request_queues = xbt_new(xbt_fifo_t, size);
148 smpi_global->pending_send_request_queues_mutexes = xbt_new(smx_mutex_t, size);
149 smpi_global->pending_recv_request_queues = xbt_new(xbt_fifo_t, size);
150 smpi_global->pending_recv_request_queues_mutexes = xbt_new(smx_mutex_t, size);
151 smpi_global->received_message_queues = xbt_new(xbt_fifo_t, size);
152 smpi_global->received_message_queues_mutexes = xbt_new(smx_mutex_t, size);
155 smpi_global->timers = xbt_new(xbt_os_timer_t, size);
156 smpi_global->timers_mutexes = xbt_new(smx_mutex_t, size);
158 for(i = 0; i < size; i++) {
159 smpi_global->pending_send_request_queues[i] = xbt_fifo_new();
160 smpi_global->pending_send_request_queues_mutexes[i] = SIMIX_mutex_init();
161 smpi_global->pending_recv_request_queues[i] = xbt_fifo_new();
162 smpi_global->pending_recv_request_queues_mutexes[i] = SIMIX_mutex_init();
163 smpi_global->received_message_queues[i] = xbt_fifo_new();
164 smpi_global->received_message_queues_mutexes[i] = SIMIX_mutex_init();
165 smpi_global->timers[i] = xbt_os_timer_new();
166 smpi_global->timers_mutexes[i] = SIMIX_mutex_init();
171 void smpi_global_destroy()
175 int size = SIMIX_host_get_number();
178 SIMIX_mutex_destroy(smpi_global->start_stop_mutex);
179 SIMIX_cond_destroy(smpi_global->start_stop_cond);
182 xbt_free(smpi_global->sender_processes);
183 xbt_free(smpi_global->receiver_processes);
186 SIMIX_mutex_destroy(smpi_global->running_hosts_count_mutex);
189 xbt_mallocator_free(smpi_global->request_mallocator);
190 xbt_mallocator_free(smpi_global->message_mallocator);
192 for(i = 0; i < size; i++) {
193 xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
194 SIMIX_mutex_destroy(smpi_global->pending_send_request_queues_mutexes[i]);
195 xbt_fifo_free(smpi_global->pending_recv_request_queues[i]);
196 SIMIX_mutex_destroy(smpi_global->pending_recv_request_queues_mutexes[i]);
197 xbt_fifo_free(smpi_global->received_message_queues[i]);
198 SIMIX_mutex_destroy(smpi_global->received_message_queues_mutexes[i]);
199 xbt_os_timer_free(smpi_global->timers[i]);
200 SIMIX_mutex_destroy(smpi_global->timers_mutexes[i]);
203 xbt_free(smpi_global->pending_send_request_queues);
204 xbt_free(smpi_global->pending_send_request_queues_mutexes);
205 xbt_free(smpi_global->pending_recv_request_queues);
206 xbt_free(smpi_global->pending_recv_request_queues_mutexes);
207 xbt_free(smpi_global->received_message_queues);
208 xbt_free(smpi_global->received_message_queues_mutexes);
209 xbt_free(smpi_global->timers);
210 xbt_free(smpi_global->timers_mutexes);
212 xbt_free(smpi_global);
217 int smpi_run_simulation(int argc, char **argv)
219 xbt_fifo_item_t cond_item = NULL;
220 smx_cond_t cond = NULL;
221 xbt_fifo_item_t action_item = NULL;
222 smx_action_t action = NULL;
224 xbt_fifo_t actions_failed = xbt_fifo_new();
225 xbt_fifo_t actions_done = xbt_fifo_new();
227 srand(SMPI_RAND_SEED);
229 SIMIX_global_init(&argc, argv);
231 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
232 SIMIX_function_register("smpi_sender", smpi_sender);
233 SIMIX_function_register("smpi_receiver", smpi_receiver);
235 // FIXME: ought to verify these files...
236 SIMIX_create_environment(argv[1]);
238 // must initialize globals between creating environment and launching app....
241 SIMIX_launch_application(argv[2]);
243 /* Prepare to display some more info when dying on Ctrl-C pressing */
244 // FIXME: doesn't work
245 //signal(SIGINT, inthandler);
247 /* Clean IO before the run */
251 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
252 xbt_fifo_foreach(actions_failed, action_item, action, smx_action_t) {
253 DEBUG1("** %s failed **", action->name);
254 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
255 SIMIX_cond_broadcast(cond);
258 xbt_fifo_foreach(actions_done, action_item, action, smx_action_t) {
259 DEBUG1("** %s done **",action->name);
260 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
261 SIMIX_cond_broadcast(cond);
266 // FIXME: cleanup incomplete
267 xbt_fifo_free(actions_failed);
268 xbt_fifo_free(actions_done);
270 INFO1("simulation time %g", SIMIX_get_clock());
272 smpi_global_destroy();