+ int rank = smpi_mpi_comm_rank_self(&smpi_mpi_comm_world);
+ int size;
+ int running_hosts = 0;
+ smpi_mpi_request_t *request;
+ smx_process_t self;
+ smx_host_t shost, dhost;
+ smx_action_t communicate_action;
+
+ self = SIMIX_process_self();
+ shost = SIMIX_host_self();
+
+ // make sure root is done before own initialization
+ SIMIX_mutex_lock(init_mutex);
+ if (!smpi_root_ready) {
+ SIMIX_cond_wait(init_cond, init_mutex);
+ }
+ SIMIX_mutex_unlock(init_mutex);
+
+ size = smpi_mpi_comm_size(&smpi_mpi_comm_world);
+ smpi_sender_processes[rank] = self;
+
+ // wait for all nodes to signal initializatin complete
+ SIMIX_mutex_lock(init_mutex);
+ smpi_ready_count++;
+ if (smpi_ready_count < 3 * size) {
+ SIMIX_cond_wait(init_cond, init_mutex);
+ } else {
+ SIMIX_cond_broadcast(init_cond);
+ }
+ SIMIX_mutex_unlock(init_mutex);
+
+ SIMIX_mutex_lock(smpi_running_hosts_mutex);
+ running_hosts = smpi_running_hosts;
+ SIMIX_mutex_unlock(smpi_running_hosts_mutex);
+
+ while (0 < running_hosts) {
+
+ request = xbt_fifo_shift(smpi_pending_send_requests[rank]);
+
+ if (NULL == request) {
+ SIMIX_process_suspend(self);
+ } else {
+ SIMIX_mutex_lock(request->mutex);
+
+ dhost = request->comm->hosts[request->dst];
+
+ // FIXME: not at all sure I can assume magic just happens here....
+ communicate_action = SIMIX_action_communicate(shost, dhost,
+ "communication", request->datatype->size * request->count * 1.0, -1.0);
+
+ SIMIX_register_condition_to_action(communicate_action, request->cond);
+ SIMIX_register_action_to_condition(communicate_action, request->cond);
+
+ SIMIX_cond_wait(request->cond, request->mutex);
+
+ // fixme, create new request, copy over to
+ // should be malloc and memcpy
+
+ SIMIX_mutex_unlock(request->mutex);
+ }
+
+ SIMIX_mutex_lock(smpi_running_hosts_mutex);
+ running_hosts = smpi_running_hosts;
+ SIMIX_mutex_unlock(smpi_running_hosts_mutex);
+ }
+