3 int smpi_sender(int argc, char **argv)
9 xbt_fifo_t request_queue;
10 smx_mutex_t request_queue_mutex;
12 int running_hosts_count;
14 smpi_mpi_request_t request;
18 char communication[] = "communication";
21 smpi_received_message_t message;
25 smx_process_t receiver_process;
27 self = SIMIX_process_self();
28 shost = SIMIX_host_self();
30 // make sure root is done before own initialization
31 SIMIX_mutex_lock(smpi_global->start_stop_mutex);
32 if (!smpi_global->root_ready) {
33 SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
35 SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
37 index = smpi_host_index();
39 request_queue = smpi_global->pending_send_request_queues[index];
40 request_queue_mutex = smpi_global->pending_send_request_queues_mutexes[index];
42 smpi_global->sender_processes[index] = self;
44 // wait for all nodes to signal initializatin complete
45 SIMIX_mutex_lock(smpi_global->start_stop_mutex);
46 smpi_global->ready_process_count++;
47 if (smpi_global->ready_process_count < 3 * smpi_global->host_count) {
48 SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
50 SIMIX_cond_broadcast(smpi_global->start_stop_cond);
52 SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
56 SIMIX_mutex_lock(request_queue_mutex);
57 request = xbt_fifo_shift(request_queue);
58 SIMIX_mutex_unlock(request_queue_mutex);
60 if (NULL == request) {
61 SIMIX_process_suspend(self);
64 message = xbt_mallocator_get(smpi_global->message_mallocator);
66 SIMIX_mutex_lock(request->mutex);
68 message->comm = request->comm;
69 message->src = smpi_mpi_comm_rank(request->comm);
70 message->tag = request->tag;
71 message->buf = xbt_malloc(request->datatype->size * request->count);
72 memcpy(message->buf, request->buf, request->datatype->size * request->count);
73 message->data = request->data;
75 dindex = request->comm->rank_to_index_map[request->dst];
76 dhost = smpi_global->hosts[dindex];
78 SIMIX_mutex_lock(smpi_global->received_message_queues_mutexes[dindex]);
79 xbt_fifo_push(smpi_global->received_message_queues[dindex], message);
80 SIMIX_mutex_unlock(smpi_global->received_message_queues_mutexes[dindex]);
82 request->completed = 1;
84 action = SIMIX_action_communicate(shost, dhost, communication, request->datatype->size * request->count, -1.0);
86 SIMIX_register_action_to_condition(action, request->cond);
87 SIMIX_cond_wait(request->cond, request->mutex);
88 SIMIX_unregister_action_to_condition(action, request->cond);
90 SIMIX_mutex_unlock(request->mutex);
92 //SIMIX_action_destroy(action);
94 // wake up receiver if necessary
95 receiver_process = smpi_global->receiver_processes[dindex];
96 if (SIMIX_process_is_suspended(receiver_process)) {
97 SIMIX_process_resume(receiver_process);
102 SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
103 running_hosts_count = smpi_global->running_hosts_count;
104 SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
106 } while (0 < running_hosts_count);