3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_sender, smpi,
4 "Logging specific to SMPI (sender)");
6 int smpi_sender(int argc, char **argv)
13 xbt_fifo_t request_queue;
15 int running_hosts_count;
17 smpi_mpi_request_t request;
23 e_surf_action_state_t state;
25 smpi_received_message_t message;
29 smx_process_t receiver_process;
31 self = SIMIX_process_self();
32 shost = SIMIX_host_self();
34 index = smpi_host_index();
36 request_queue = smpi_global->pending_send_request_queues[index];
38 smpi_global->sender_processes[index] = self;
42 request = xbt_fifo_shift(request_queue);
44 if (NULL == request) {
45 SIMIX_process_suspend(self);
48 message = xbt_mallocator_get(smpi_global->message_mallocator);
50 SIMIX_mutex_lock(request->mutex);
52 message->comm = request->comm;
53 message->src = request->comm->index_to_rank_map[index];
54 message->tag = request->tag;
55 message->data = request->data;
56 message->buf = xbt_malloc(request->datatype->size * request->count);
57 memcpy(message->buf, request->buf,
58 request->datatype->size * request->count);
60 dindex = request->comm->rank_to_index_map[request->dst];
61 dhost = smpi_global->hosts[dindex];
63 message->forward = (request->forward - 1) / 2;
64 request->forward = request->forward / 2;
66 if (0 < request->forward) {
68 (request->dst + message->forward + 1) % request->comm->size;
69 xbt_fifo_push(request_queue, request);
71 request->completed = 1;
75 SIMIX_action_communicate(shost, dhost, "communication",
76 request->datatype->size * request->count,
79 SIMIX_register_action_to_condition(action, request->cond);
81 for (state = SIMIX_action_get_state(action);
82 state == SURF_ACTION_READY ||
83 state == SURF_ACTION_RUNNING;
84 state = SIMIX_action_get_state(action)
86 SIMIX_cond_wait(request->cond, request->mutex);
89 xbt_fifo_push(smpi_global->received_message_queues[dindex], message);
91 SIMIX_unregister_action_to_condition(action, request->cond);
92 SIMIX_action_destroy(action);
94 SIMIX_mutex_unlock(request->mutex);
96 // wake up receiver if necessary
97 receiver_process = smpi_global->receiver_processes[dindex];
98 if (SIMIX_process_is_suspended(receiver_process)) {
99 SIMIX_process_resume(receiver_process);
104 SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
105 running_hosts_count = smpi_global->running_hosts_count;
106 SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
108 } while (0 < running_hosts_count);