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);
16 request->completed = 0;
17 request->mutex = SIMIX_mutex_init();
18 request->cond = SIMIX_cond_init();
25 void smpi_request_free(void *pointer);
27 void smpi_request_free(void *pointer)
30 smpi_mpi_request_t request = pointer;
32 SIMIX_cond_destroy(request->cond);
33 SIMIX_mutex_destroy(request->mutex);
39 void smpi_request_reset(void *pointer);
41 void smpi_request_reset(void *pointer)
43 smpi_mpi_request_t request = pointer;
46 request->completed = 0;
54 void *smpi_message_new(void);
56 void *smpi_message_new()
58 smpi_received_message_t message = xbt_new(s_smpi_received_message_t, 1);
63 void smpi_message_free(void *pointer);
65 void smpi_message_free(void *pointer)
71 void smpi_message_reset(void *pointer);
73 void smpi_message_reset(void *pointer)
75 smpi_received_message_t message = pointer;
80 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
81 int src, int dst, int tag, smpi_mpi_communicator_t comm, smpi_mpi_request_t *requestptr)
83 int retval = MPI_SUCCESS;
85 smpi_mpi_request_t request = NULL;
87 // parameter checking prob belongs in smpi_mpi, but this is less repeat code
89 retval = MPI_ERR_INTERN;
90 } else if (0 > count) {
91 retval = MPI_ERR_COUNT;
92 } else if (NULL == datatype) {
93 retval = MPI_ERR_TYPE;
94 } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
95 retval = MPI_ERR_RANK;
96 } else if (0 > dst || comm->size <= dst) {
97 retval = MPI_ERR_RANK;
98 } else if (MPI_ANY_TAG != tag && 0 > tag) {
100 } else if (NULL == comm) {
101 retval = MPI_ERR_COMM;
102 } else if (NULL == requestptr) {
103 retval = MPI_ERR_ARG;
105 request = xbt_mallocator_get(smpi_global->request_mallocator);
106 request->comm = comm;
111 request->datatype = datatype;
112 request->count = count;
114 *requestptr = request;
119 void smpi_global_init()
123 int size = SIMIX_host_get_number();
125 smpi_global = xbt_new(s_smpi_global_t, 1);
128 smpi_global->reference_speed = SMPI_DEFAULT_SPEED;
130 smpi_global->root_ready = 0;
131 smpi_global->ready_process_count = 0;
134 smpi_global->start_stop_mutex = SIMIX_mutex_init();
135 smpi_global->start_stop_cond = SIMIX_cond_init();
137 // host info blank until sim starts
138 // FIXME: is this okay?
139 smpi_global->hosts = NULL;
140 smpi_global->host_count = 0;
143 smpi_global->running_hosts_count_mutex = SIMIX_mutex_init();
144 smpi_global->running_hosts_count = 0;
147 smpi_global->request_mallocator = xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE,
148 smpi_request_new, smpi_request_free, smpi_request_reset);
149 smpi_global->message_mallocator = xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE,
150 smpi_message_new, smpi_message_free, smpi_message_reset);
153 smpi_global->pending_send_request_queues = xbt_new(xbt_fifo_t, size);
154 smpi_global->pending_send_request_queues_mutexes = xbt_new(smx_mutex_t, size);
155 smpi_global->pending_recv_request_queues = xbt_new(xbt_fifo_t, size);
156 smpi_global->pending_recv_request_queues_mutexes = xbt_new(smx_mutex_t, size);
157 smpi_global->received_message_queues = xbt_new(xbt_fifo_t, size);
158 smpi_global->received_message_queues_mutexes = xbt_new(smx_mutex_t, size);
160 // sender/receiver processes
161 smpi_global->sender_processes = xbt_new(smx_process_t, size);
162 smpi_global->receiver_processes = xbt_new(smx_process_t, size);
165 smpi_global->timer = xbt_os_timer_new();
166 smpi_global->timer_mutex = SIMIX_mutex_init();
167 smpi_global->timer_cond = SIMIX_cond_init();
168 smpi_global->times_max = 0;
169 smpi_global->times_mutex = SIMIX_mutex_init();
171 for (i = 0; i < size; i++) {
172 smpi_global->pending_send_request_queues[i] = xbt_fifo_new();
173 smpi_global->pending_send_request_queues_mutexes[i] = SIMIX_mutex_init();
174 smpi_global->pending_recv_request_queues[i] = xbt_fifo_new();
175 smpi_global->pending_recv_request_queues_mutexes[i] = SIMIX_mutex_init();
176 smpi_global->received_message_queues[i] = xbt_fifo_new();
177 smpi_global->received_message_queues_mutexes[i] = SIMIX_mutex_init();
180 for (i = 0; i < SMPI_MAX_TIMES; i++) {
181 smpi_global->times[i] = -1.0;
186 void smpi_global_destroy()
190 int size = SIMIX_host_get_number();
193 SIMIX_mutex_destroy(smpi_global->start_stop_mutex);
194 SIMIX_cond_destroy(smpi_global->start_stop_cond);
197 xbt_free(smpi_global->sender_processes);
198 xbt_free(smpi_global->receiver_processes);
201 SIMIX_mutex_destroy(smpi_global->running_hosts_count_mutex);
204 xbt_mallocator_free(smpi_global->request_mallocator);
205 xbt_mallocator_free(smpi_global->message_mallocator);
207 xbt_os_timer_free(smpi_global->timer);
208 SIMIX_mutex_destroy(smpi_global->timer_mutex);
209 SIMIX_cond_destroy(smpi_global->timer_cond);
210 SIMIX_mutex_destroy(smpi_global->times_mutex);
212 for(i = 0; i < size; i++) {
213 xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
214 SIMIX_mutex_destroy(smpi_global->pending_send_request_queues_mutexes[i]);
215 xbt_fifo_free(smpi_global->pending_recv_request_queues[i]);
216 SIMIX_mutex_destroy(smpi_global->pending_recv_request_queues_mutexes[i]);
217 xbt_fifo_free(smpi_global->received_message_queues[i]);
218 SIMIX_mutex_destroy(smpi_global->received_message_queues_mutexes[i]);
221 xbt_free(smpi_global->pending_send_request_queues);
222 xbt_free(smpi_global->pending_send_request_queues_mutexes);
223 xbt_free(smpi_global->pending_recv_request_queues);
224 xbt_free(smpi_global->pending_recv_request_queues_mutexes);
225 xbt_free(smpi_global->received_message_queues);
226 xbt_free(smpi_global->received_message_queues_mutexes);
228 xbt_free(smpi_global);
233 int smpi_host_index()
235 smx_host_t host = SIMIX_host_self();
236 smpi_host_data_t hdata = (smpi_host_data_t)SIMIX_host_get_data(host);
241 int smpi_run_simulation(int *argc, char **argv)
243 xbt_fifo_item_t cond_item = NULL;
244 smx_cond_t cond = NULL;
245 xbt_fifo_item_t action_item = NULL;
246 smx_action_t action = NULL;
248 xbt_fifo_t actions_failed = xbt_fifo_new();
249 xbt_fifo_t actions_done = xbt_fifo_new();
251 srand(SMPI_RAND_SEED);
253 SIMIX_global_init(argc, argv);
255 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
256 SIMIX_function_register("smpi_sender", smpi_sender);
257 SIMIX_function_register("smpi_receiver", smpi_receiver);
259 // FIXME: ought to verify these files...
260 SIMIX_create_environment(argv[1]);
262 // must initialize globals between creating environment and launching app....
265 SIMIX_launch_application(argv[2]);
267 /* Prepare to display some more info when dying on Ctrl-C pressing */
268 // FIXME: doesn't work
269 //signal(SIGINT, inthandler);
271 /* Clean IO before the run */
275 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
276 xbt_fifo_foreach(actions_failed, action_item, action, smx_action_t) {
277 DEBUG1("** %s failed **", action->name);
278 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
279 SIMIX_cond_broadcast(cond);
282 xbt_fifo_foreach(actions_done, action_item, action, smx_action_t) {
283 DEBUG1("** %s done **",action->name);
284 xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
285 SIMIX_cond_broadcast(cond);
290 // FIXME: cleanup incomplete
291 xbt_fifo_free(actions_failed);
292 xbt_fifo_free(actions_done);
294 INFO1("simulation time %g", SIMIX_get_clock());
296 smpi_global_destroy();