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();
132 // host info blank until sim starts
133 // FIXME: is this okay?
134 smpi_global->hosts = NULL;
135 smpi_global->host_count = 0;
138 smpi_global->running_hosts_count_mutex = SIMIX_mutex_init();
139 smpi_global->running_hosts_count = 0;
142 smpi_global->request_mallocator = xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE,
143 smpi_request_new, smpi_request_free, smpi_request_reset);
144 smpi_global->message_mallocator = xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE,
145 smpi_message_new, smpi_message_free, smpi_message_reset);
148 smpi_global->pending_send_request_queues = xbt_new(xbt_fifo_t, size);
149 smpi_global->pending_send_request_queues_mutexes = xbt_new(smx_mutex_t, size);
150 smpi_global->pending_recv_request_queues = xbt_new(xbt_fifo_t, size);
151 smpi_global->pending_recv_request_queues_mutexes = xbt_new(smx_mutex_t, size);
152 smpi_global->received_message_queues = xbt_new(xbt_fifo_t, size);
153 smpi_global->received_message_queues_mutexes = xbt_new(smx_mutex_t, size);
155 // sender/receiver processes
156 smpi_global->sender_processes = xbt_new(smx_process_t, size);
157 smpi_global->receiver_processes = xbt_new(smx_process_t, size);
160 smpi_global->timers = xbt_new(xbt_os_timer_t, size);
161 smpi_global->timers_mutexes = xbt_new(smx_mutex_t, size);
163 for(i = 0; i < size; i++) {
164 smpi_global->pending_send_request_queues[i] = xbt_fifo_new();
165 smpi_global->pending_send_request_queues_mutexes[i] = SIMIX_mutex_init();
166 smpi_global->pending_recv_request_queues[i] = xbt_fifo_new();
167 smpi_global->pending_recv_request_queues_mutexes[i] = SIMIX_mutex_init();
168 smpi_global->received_message_queues[i] = xbt_fifo_new();
169 smpi_global->received_message_queues_mutexes[i] = SIMIX_mutex_init();
170 smpi_global->timers[i] = xbt_os_timer_new();
171 smpi_global->timers_mutexes[i] = SIMIX_mutex_init();
176 void smpi_global_destroy()
180 int size = SIMIX_host_get_number();
183 SIMIX_mutex_destroy(smpi_global->start_stop_mutex);
184 SIMIX_cond_destroy(smpi_global->start_stop_cond);
187 xbt_free(smpi_global->sender_processes);
188 xbt_free(smpi_global->receiver_processes);
191 SIMIX_mutex_destroy(smpi_global->running_hosts_count_mutex);
194 xbt_mallocator_free(smpi_global->request_mallocator);
195 xbt_mallocator_free(smpi_global->message_mallocator);
197 for(i = 0; i < size; i++) {
198 xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
199 SIMIX_mutex_destroy(smpi_global->pending_send_request_queues_mutexes[i]);
200 xbt_fifo_free(smpi_global->pending_recv_request_queues[i]);
201 SIMIX_mutex_destroy(smpi_global->pending_recv_request_queues_mutexes[i]);
202 xbt_fifo_free(smpi_global->received_message_queues[i]);
203 SIMIX_mutex_destroy(smpi_global->received_message_queues_mutexes[i]);
204 xbt_os_timer_free(smpi_global->timers[i]);
205 SIMIX_mutex_destroy(smpi_global->timers_mutexes[i]);
208 xbt_free(smpi_global->pending_send_request_queues);
209 xbt_free(smpi_global->pending_send_request_queues_mutexes);
210 xbt_free(smpi_global->pending_recv_request_queues);
211 xbt_free(smpi_global->pending_recv_request_queues_mutexes);
212 xbt_free(smpi_global->received_message_queues);
213 xbt_free(smpi_global->received_message_queues_mutexes);
214 xbt_free(smpi_global->timers);
215 xbt_free(smpi_global->timers_mutexes);
217 xbt_free(smpi_global);
222 int smpi_host_index()
224 smx_host_t host = SIMIX_host_self();
225 smpi_host_data_t hdata = (smpi_host_data_t)SIMIX_host_get_data(host);
230 int smpi_run_simulation(int argc, char **argv)
232 xbt_fifo_item_t cond_item = NULL;
233 smx_cond_t cond = NULL;
234 xbt_fifo_item_t action_item = NULL;
235 smx_action_t action = NULL;
237 xbt_fifo_t actions_failed = xbt_fifo_new();
238 xbt_fifo_t actions_done = xbt_fifo_new();
240 srand(SMPI_RAND_SEED);
242 SIMIX_global_init(&argc, argv);
244 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
245 SIMIX_function_register("smpi_sender", smpi_sender);
246 SIMIX_function_register("smpi_receiver", smpi_receiver);
248 // FIXME: ought to verify these files...
249 SIMIX_create_environment(argv[1]);
251 // must initialize globals between creating environment and launching app....
254 SIMIX_launch_application(argv[2]);
256 /* Prepare to display some more info when dying on Ctrl-C pressing */
257 // FIXME: doesn't work
258 //signal(SIGINT, inthandler);
260 /* Clean IO before the run */
264 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
265 xbt_fifo_foreach(actions_failed, action_item, action, smx_action_t) {
266 DEBUG1("** %s failed **", action->name);
267 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
268 SIMIX_cond_broadcast(cond);
271 xbt_fifo_foreach(actions_done, action_item, action, smx_action_t) {
272 DEBUG1("** %s done **",action->name);
273 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
274 SIMIX_cond_broadcast(cond);
279 // FIXME: cleanup incomplete
280 xbt_fifo_free(actions_failed);
281 xbt_fifo_free(actions_done);
283 INFO1("simulation time %g", SIMIX_get_clock());
285 smpi_global_destroy();