X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d6ce3162b34f0a964b8844368b9d86df4f1cf89b..994908f535190638662797b1215506fc0664bd37:/src/smpi/smpi_sender.c diff --git a/src/smpi/smpi_sender.c b/src/smpi/smpi_sender.c index 92db17bf8d..f8f9aa92f7 100644 --- a/src/smpi/smpi_sender.c +++ b/src/smpi/smpi_sender.c @@ -1,117 +1,109 @@ #include "private.h" +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_sender, smpi, + "Logging specific to SMPI (sender)"); + int smpi_sender(int argc, char **argv) { - smx_process_t self; - smx_host_t shost; - int rank; + smx_process_t self; + smx_host_t shost; - xbt_fifo_t request_queue; - smx_mutex_t request_queue_mutex; - int size; + int index; - int running_hosts_count; + xbt_fifo_t request_queue; - smpi_mpi_request_t *request; + int running_hosts_count; - smx_host_t dhost; + smpi_mpi_request_t request; - smx_action_t action; + smx_host_t dhost; - smpi_received_message_t *message; + smx_action_t action; - int drank; + e_surf_action_state_t state; - smx_process_t receiver_process; + smpi_received_message_t message; - self = SIMIX_process_self(); - shost = SIMIX_host_self(); - rank = smpi_mpi_comm_rank(smpi_mpi_global->mpi_comm_world, shost); + int dindex; - // make sure root is done before own initialization - SIMIX_mutex_lock(smpi_global->start_stop_mutex); - if (!smpi_global->root_ready) { - SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex); - } - SIMIX_mutex_unlock(smpi_global->start_stop_mutex); + smx_process_t receiver_process; - request_queue = smpi_global->pending_send_request_queues[rank]; - request_queue_mutex = smpi_global->pending_send_request_queues_mutexes[rank]; - size = smpi_mpi_comm_size(smpi_mpi_global->mpi_comm_world); + self = SIMIX_process_self(); + shost = SIMIX_host_self(); - smpi_global->sender_processes[rank] = self; + index = smpi_host_index(); - // wait for all nodes to signal initializatin complete - SIMIX_mutex_lock(smpi_global->start_stop_mutex); - smpi_global->ready_process_count++; - if (smpi_global->ready_process_count < 3 * size) { - SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex); - } else { - SIMIX_cond_broadcast(smpi_global->start_stop_cond); - } - SIMIX_mutex_unlock(smpi_global->start_stop_mutex); + request_queue = smpi_global->pending_send_request_queues[index]; - do { + smpi_global->sender_processes[index] = self; - SIMIX_mutex_lock(request_queue_mutex); - request = xbt_fifo_shift(request_queue); - SIMIX_mutex_unlock(request_queue_mutex); + do { - if (NULL == request) { - SIMIX_process_suspend(self); - } else { + request = xbt_fifo_shift(request_queue); - message = xbt_mallocator_get(smpi_global->message_mallocator); + if (NULL == request) { + SIMIX_process_suspend(self); + } else { - SIMIX_mutex_lock(request->simdata->mutex); + message = xbt_mallocator_get(smpi_global->message_mallocator); - message->comm = request->comm; - message->src = request->src; - message->dst = request->dst; - message->tag = request->tag; - message->buf = xbt_malloc(request->datatype->size * request->count); - memcpy(message->buf, request->buf, request->datatype->size * request->count); + SIMIX_mutex_lock(request->mutex); - dhost = request->comm->simdata->hosts[request->dst]; - drank = smpi_mpi_comm_rank(smpi_mpi_global->mpi_comm_world, dhost); + message->comm = request->comm; + message->src = request->comm->index_to_rank_map[index]; + message->tag = request->tag; + message->data = request->data; + message->buf = xbt_malloc(request->datatype->size * request->count); + memcpy(message->buf, request->buf, + request->datatype->size * request->count); - SIMIX_mutex_lock(smpi_global->received_message_queues_mutexes[drank]); - xbt_fifo_push(smpi_global->received_message_queues[drank], message); - SIMIX_mutex_unlock(smpi_global->received_message_queues_mutexes[drank]); + dindex = request->comm->rank_to_index_map[request->dst]; + dhost = smpi_global->hosts[dindex]; - request->completed = 1; + message->forward = (request->forward - 1) / 2; + request->forward = request->forward / 2; - action = SIMIX_action_communicate(shost, dhost, "communicate", request->datatype->size * request->count * 1.0, -1.0); + if (0 < request->forward) { + request->dst = + (request->dst + message->forward + 1) % request->comm->size; + xbt_fifo_push(request_queue, request); + } else { + request->completed = 1; + } - SIMIX_register_action_to_condition(action, request->simdata->cond); - SIMIX_cond_wait(request->simdata->cond, request->simdata->mutex); - SIMIX_unregister_action_to_condition(action, request->simdata->cond); + action = + SIMIX_action_communicate(shost, dhost, "communication", + request->datatype->size * request->count, + -1.0); - SIMIX_mutex_unlock(request->simdata->mutex); + SIMIX_register_action_to_condition(action, request->cond); - // wake up receiver if necessary - receiver_process = smpi_global->receiver_processes[drank]; - if (SIMIX_process_is_suspended(receiver_process)) { - SIMIX_process_resume(receiver_process); - } + for (state = SIMIX_action_get_state(action); + state == SURF_ACTION_READY || + state == SURF_ACTION_RUNNING; + state = SIMIX_action_get_state(action) + ) { + SIMIX_cond_wait(request->cond, request->mutex); + } - } + xbt_fifo_push(smpi_global->received_message_queues[dindex], message); - SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex); - running_hosts_count = smpi_global->running_hosts_count; - SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex); + SIMIX_unregister_action_to_condition(action, request->cond); + SIMIX_action_destroy(action); - } while (0 < running_hosts_count); + SIMIX_mutex_unlock(request->mutex); - SIMIX_mutex_lock(smpi_global->start_stop_mutex); - smpi_global->ready_process_count--; - if (smpi_global->ready_process_count == 0) { - SIMIX_cond_broadcast(smpi_global->start_stop_cond); - } else if (smpi_global->ready_process_count < 0) { - // FIXME: can't happen! abort! - } - SIMIX_mutex_unlock(smpi_global->start_stop_mutex); + // wake up receiver if necessary + receiver_process = smpi_global->receiver_processes[dindex]; + if (SIMIX_process_is_suspended(receiver_process)) { + SIMIX_process_resume(receiver_process); + } - return 0; -} + } + + running_hosts_count = smpi_global->running_hosts_count; + } while (0 < running_hosts_count); + + return 0; +}