hdata->index = i;
hdata->mutex = SIMIX_mutex_init();
hdata->cond = SIMIX_cond_init();
+ hdata->finalize = 0;
hdata->pending_recv_request_queue = xbt_fifo_new();
i = --smpi_global->running_hosts_count;
- SIMIX_mutex_destroy(smpi_host_mutex());
- SIMIX_cond_destroy(smpi_host_cond());
+ hdata->finalize = 2; /* Tell sender and receiver to quit */
+ SIMIX_process_resume(hdata->sender);
+ SIMIX_process_resume(hdata->receiver);
+ while (hdata->finalize>0) { /* wait until it's done */
+ SIMIX_cond_wait(hdata->cond,hdata->mutex);
+ }
+
+ SIMIX_mutex_destroy(hdata->mutex);
+ SIMIX_cond_destroy(hdata->cond);
xbt_fifo_free(hdata->pending_recv_request_queue);
+
if (0 >= i) {
// wake up senders/receivers
xbt_fifo_t request_queue;
xbt_fifo_t message_queue;
- int running_hosts_count;
-
smpi_mpi_request_t request;
smpi_received_message_t message;
request_queue = mydata->pending_recv_request_queue;
message_queue = smpi_global->received_message_queues[index];
- do {
-
+ while (1) {
// FIXME: better algorithm, maybe some kind of balanced tree? or a heap?
xbt_fifo_foreach(request_queue,request_item,request,smpi_mpi_request_t){
message = NULL;
stopsearch:
- if (NULL == request || NULL == message) {
- SIMIX_process_suspend(self);
+ if (NULL != request) {
+ if (NULL == message)
+ DIE_IMPOSSIBLE;
+
+ SIMIX_mutex_lock(request->mutex);
+ memcpy(request->buf, message->buf,
+ request->datatype->size * request->count);
+ request->src = message->src;
+ request->data = message->data;
+ request->forward = message->forward;
+
+ if (0 == request->forward) {
+ request->completed = 1;
+ SIMIX_cond_broadcast(request->cond);
+ } else {
+ request->src = request->comm->index_to_rank_map[index];
+ request->dst = (request->src + 1) % request->comm->size;
+ smpi_mpi_isend(request);
+ }
+
+ SIMIX_mutex_unlock(request->mutex);
+
+ xbt_free(message->buf);
+ xbt_mallocator_release(smpi_global->message_mallocator, message);
+
+ } else if (mydata->finalize>0) { /* main wants me to die and nothing to do */
+ // FIXME: display the list of remaining requests and messages (user code synchronization faulty?)
+ mydata->finalize--;
+ SIMIX_cond_signal(mydata->cond);
+ return 0;
} else {
-
- SIMIX_mutex_lock(request->mutex);
- memcpy(request->buf, message->buf,
- request->datatype->size * request->count);
- request->src = message->src;
- request->data = message->data;
- request->forward = message->forward;
-
- if (0 == request->forward) {
- request->completed = 1;
- SIMIX_cond_broadcast(request->cond);
- } else {
- request->src = request->comm->index_to_rank_map[index];
- request->dst = (request->src + 1) % request->comm->size;
- smpi_mpi_isend(request);
- }
-
- SIMIX_mutex_unlock(request->mutex);
-
- xbt_free(message->buf);
- xbt_mallocator_release(smpi_global->message_mallocator, message);
-
+ SIMIX_process_suspend(self);
}
-
- running_hosts_count = smpi_global->running_hosts_count;
-
- } while (0 < running_hosts_count);
+ }
return 0;
}
xbt_fifo_t request_queue;
- int running_hosts_count;
-
smpi_mpi_request_t request;
smx_host_t dhost;
int dindex;
- smx_process_t receiver_process;
-
self = SIMIX_process_self();
shost = SIMIX_host_self();
request_queue = smpi_global->pending_send_request_queues[index];
- do {
-
+ while (1) {
request = xbt_fifo_shift(request_queue);
- if (NULL == request) {
- SIMIX_process_suspend(self);
- } else {
-
+ if (NULL != request) {
message = xbt_mallocator_get(smpi_global->message_mallocator);
SIMIX_mutex_lock(request->mutex);
// wake up receiver if necessary
smpi_host_data_t remote_host = SIMIX_host_get_data(SIMIX_process_get_host(smpi_global->main_processes[dindex]));
- receiver_process = remote_host->receiver;
- if (SIMIX_process_is_suspended(receiver_process))
- SIMIX_process_resume(receiver_process);
- }
-
- running_hosts_count = smpi_global->running_hosts_count;
-
- } while (0 < running_hosts_count);
+ SIMIX_process_resume(remote_host->receiver);
+ } else if (mydata->finalize>0) { /* main wants me to die and nothing to do */
+ mydata->finalize--;
+ SIMIX_cond_signal(mydata->cond);
+ return 0;
+ } else {
+ SIMIX_process_suspend(self);
+ }
+ }
return 0;
}