5 XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories");
7 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi, "Logging specific to SMPI (kernel)");
9 smpi_global_t smpi_global = NULL;
11 void *smpi_request_new(void);
13 void *smpi_request_new()
15 smpi_mpi_request_t request = xbt_new(s_smpi_mpi_request_t, 1);
18 request->completed = 0;
19 request->mutex = SIMIX_mutex_init();
20 request->cond = SIMIX_cond_init();
27 void smpi_request_free(void *pointer);
29 void smpi_request_free(void *pointer)
32 smpi_mpi_request_t request = pointer;
34 SIMIX_cond_destroy(request->cond);
35 SIMIX_mutex_destroy(request->mutex);
41 void smpi_request_reset(void *pointer);
43 void smpi_request_reset(void *pointer)
45 smpi_mpi_request_t request = pointer;
48 request->completed = 0;
56 void *smpi_message_new(void);
58 void *smpi_message_new()
60 smpi_received_message_t message = xbt_new(s_smpi_received_message_t, 1);
65 void smpi_message_free(void *pointer);
67 void smpi_message_free(void *pointer)
73 void smpi_message_reset(void *pointer);
75 void smpi_message_reset(void *pointer)
77 smpi_received_message_t message = pointer;
82 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
83 int src, int dst, int tag, smpi_mpi_communicator_t comm, smpi_mpi_request_t *requestptr)
85 int retval = MPI_SUCCESS;
87 smpi_mpi_request_t request = NULL;
89 // parameter checking prob belongs in smpi_mpi, but this is less repeat code
91 retval = MPI_ERR_INTERN;
92 } else if (0 > count) {
93 retval = MPI_ERR_COUNT;
94 } else if (NULL == datatype) {
95 retval = MPI_ERR_TYPE;
96 } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
97 retval = MPI_ERR_RANK;
98 } else if (0 > dst || comm->size <= dst) {
99 retval = MPI_ERR_RANK;
100 } else if (MPI_ANY_TAG != tag && 0 > tag) {
101 retval = MPI_ERR_TAG;
102 } else if (NULL == comm) {
103 retval = MPI_ERR_COMM;
104 } else if (NULL == requestptr) {
105 retval = MPI_ERR_ARG;
107 request = xbt_mallocator_get(smpi_global->request_mallocator);
108 request->comm = comm;
113 request->datatype = datatype;
114 request->count = count;
116 *requestptr = request;
121 void smpi_global_init()
125 int size = SIMIX_host_get_number();
127 smpi_global = xbt_new(s_smpi_global_t, 1);
130 smpi_global->reference_speed = SMPI_DEFAULT_SPEED;
132 smpi_global->root_ready = 0;
133 smpi_global->ready_process_count = 0;
136 smpi_global->start_stop_mutex = SIMIX_mutex_init();
137 smpi_global->start_stop_cond = SIMIX_cond_init();
139 // host info blank until sim starts
140 // FIXME: is this okay?
141 smpi_global->hosts = NULL;
142 smpi_global->host_count = 0;
145 smpi_global->running_hosts_count_mutex = SIMIX_mutex_init();
146 smpi_global->running_hosts_count = 0;
149 smpi_global->request_mallocator = xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE,
150 smpi_request_new, smpi_request_free, smpi_request_reset);
151 smpi_global->message_mallocator = xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE,
152 smpi_message_new, smpi_message_free, smpi_message_reset);
155 smpi_global->pending_send_request_queues = xbt_new(xbt_fifo_t, size);
156 smpi_global->pending_send_request_queues_mutexes = xbt_new(smx_mutex_t, size);
157 smpi_global->pending_recv_request_queues = xbt_new(xbt_fifo_t, size);
158 smpi_global->pending_recv_request_queues_mutexes = xbt_new(smx_mutex_t, size);
159 smpi_global->received_message_queues = xbt_new(xbt_fifo_t, size);
160 smpi_global->received_message_queues_mutexes = xbt_new(smx_mutex_t, size);
162 // sender/receiver processes
163 smpi_global->sender_processes = xbt_new(smx_process_t, size);
164 smpi_global->receiver_processes = xbt_new(smx_process_t, size);
167 smpi_global->timer = xbt_os_timer_new();
168 smpi_global->timer_mutex = SIMIX_mutex_init();
169 smpi_global->timer_cond = SIMIX_cond_init();
171 smpi_global->execute_mutex = SIMIX_mutex_init();
172 smpi_global->execute_cond = SIMIX_cond_init();
173 smpi_global->execute_count = 0;
175 smpi_global->do_once_duration_nodes = NULL;
176 smpi_global->do_once_duration = NULL;
177 smpi_global->do_once_mutex = SIMIX_mutex_init();
179 for (i = 0; i < size; i++) {
180 smpi_global->pending_send_request_queues[i] = xbt_fifo_new();
181 smpi_global->pending_send_request_queues_mutexes[i] = SIMIX_mutex_init();
182 smpi_global->pending_recv_request_queues[i] = xbt_fifo_new();
183 smpi_global->pending_recv_request_queues_mutexes[i] = SIMIX_mutex_init();
184 smpi_global->received_message_queues[i] = xbt_fifo_new();
185 smpi_global->received_message_queues_mutexes[i] = SIMIX_mutex_init();
190 void smpi_global_destroy()
194 int size = SIMIX_host_get_number();
196 smpi_do_once_duration_node_t curr, next;
199 SIMIX_mutex_destroy(smpi_global->start_stop_mutex);
200 SIMIX_cond_destroy(smpi_global->start_stop_cond);
203 xbt_free(smpi_global->sender_processes);
204 xbt_free(smpi_global->receiver_processes);
207 SIMIX_mutex_destroy(smpi_global->running_hosts_count_mutex);
210 xbt_mallocator_free(smpi_global->request_mallocator);
211 xbt_mallocator_free(smpi_global->message_mallocator);
213 xbt_os_timer_free(smpi_global->timer);
214 SIMIX_mutex_destroy(smpi_global->timer_mutex);
215 SIMIX_cond_destroy(smpi_global->timer_cond);
216 SIMIX_mutex_destroy(smpi_global->execute_mutex);
217 SIMIX_cond_destroy(smpi_global->execute_cond);
219 for(curr = smpi_global->do_once_duration_nodes; NULL != curr; curr = next) {
221 xbt_free(curr->file);
225 SIMIX_mutex_destroy(smpi_global->do_once_mutex);
227 for(i = 0; i < size; i++) {
228 xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
229 SIMIX_mutex_destroy(smpi_global->pending_send_request_queues_mutexes[i]);
230 xbt_fifo_free(smpi_global->pending_recv_request_queues[i]);
231 SIMIX_mutex_destroy(smpi_global->pending_recv_request_queues_mutexes[i]);
232 xbt_fifo_free(smpi_global->received_message_queues[i]);
233 SIMIX_mutex_destroy(smpi_global->received_message_queues_mutexes[i]);
236 xbt_free(smpi_global->pending_send_request_queues);
237 xbt_free(smpi_global->pending_send_request_queues_mutexes);
238 xbt_free(smpi_global->pending_recv_request_queues);
239 xbt_free(smpi_global->pending_recv_request_queues_mutexes);
240 xbt_free(smpi_global->received_message_queues);
241 xbt_free(smpi_global->received_message_queues_mutexes);
243 xbt_free(smpi_global);
248 int smpi_host_index()
250 smx_host_t host = SIMIX_host_self();
251 smpi_host_data_t hdata = (smpi_host_data_t)SIMIX_host_get_data(host);
256 int smpi_run_simulation(int *argc, char **argv)
258 smx_cond_t cond = NULL;
259 smx_action_t action = NULL;
261 xbt_fifo_t actions_failed = xbt_fifo_new();
262 xbt_fifo_t actions_done = xbt_fifo_new();
264 srand(SMPI_RAND_SEED);
266 SIMIX_global_init(argc, argv);
268 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
269 SIMIX_function_register("smpi_sender", smpi_sender);
270 SIMIX_function_register("smpi_receiver", smpi_receiver);
272 // FIXME: ought to verify these files...
273 SIMIX_create_environment(argv[1]);
275 // must initialize globals between creating environment and launching app....
278 SIMIX_launch_application(argv[2]);
280 /* Prepare to display some more info when dying on Ctrl-C pressing */
281 // FIXME: doesn't work
282 //signal(SIGINT, inthandler);
284 /* Clean IO before the run */
288 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
289 while ((action = xbt_fifo_pop(actions_failed))) {
290 DEBUG1("** %s failed **", action->name);
291 while((cond = xbt_fifo_pop(action->cond_list))) {
292 SIMIX_cond_broadcast(cond);
295 while((action = xbt_fifo_pop(actions_done))) {
296 DEBUG1("** %s done **",action->name);
297 while((cond = xbt_fifo_pop(action->cond_list))) {
298 SIMIX_cond_broadcast(cond);
303 // FIXME: cleanup incomplete
304 xbt_fifo_free(actions_failed);
305 xbt_fifo_free(actions_done);
307 INFO1("simulation time %g", SIMIX_get_clock());
309 smpi_global_destroy();