Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
minor changes
[simgrid.git] / src / smpi / src / smpi_base.c
index 2b9b8d8..7d66cf0 100644 (file)
@@ -37,8 +37,6 @@ int inline smpi_mpi_comm_world_rank_self()
 
 int smpi_sender(int argc, char **argv)
 {
-       smx_mutex_t mutex;
-       smx_cond_t cond;
        smx_process_t self;
        smx_host_t shost;
        int rank;
@@ -61,8 +59,6 @@ int smpi_sender(int argc, char **argv)
 
        smx_process_t receiver_process;
 
-       mutex = SIMIX_mutex_init();
-       cond  = SIMIX_cond_init();
        self  = SIMIX_process_self();
        shost = SIMIX_host_self();
        rank  = smpi_mpi_comm_rank(smpi_mpi_global->mpi_comm_world, shost);
@@ -99,19 +95,8 @@ int smpi_sender(int argc, char **argv)
                if (NULL == request) {
                        SIMIX_process_suspend(self);
                } else {
-                       SIMIX_mutex_lock(request->mutex);
-
-                       dhost = request->comm->hosts[request->dst];
-
-                       communicate_action = SIMIX_action_communicate(shost, dhost,
-                               "communication", request->datatype->size * request->count * 1.0, -1.0);
 
-                       SIMIX_register_condition_to_action(communicate_action, cond);
-                       SIMIX_register_action_to_condition(communicate_action, cond);
-
-                       SIMIX_mutex_lock(mutex);
-                       SIMIX_cond_wait(cond, mutex);
-                       SIMIX_mutex_unlock(mutex);
+                       SIMIX_mutex_lock(request->mutex);
 
                        // copy request to appropriate received queue
                        message       = xbt_mallocator_get(smpi_global->message_mallocator);
@@ -122,6 +107,7 @@ int smpi_sender(int argc, char **argv)
                        message->buf  = xbt_malloc(request->datatype->size * request->count);
                        memcpy(message->buf, request->buf, request->datatype->size * request->count);
 
+                       dhost = request->comm->hosts[request->dst];
                        drank = smpi_mpi_comm_rank(smpi_mpi_global->mpi_comm_world, dhost);
 
                        SIMIX_mutex_lock(smpi_global->received_message_queues_mutexes[drank]);
@@ -130,7 +116,13 @@ int smpi_sender(int argc, char **argv)
 
                        request->completed = 1;
 
-                       SIMIX_cond_broadcast(request->cond);
+                       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);
 
                        SIMIX_mutex_unlock(request->mutex);
 
@@ -158,9 +150,6 @@ int smpi_sender(int argc, char **argv)
        }
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
-       SIMIX_mutex_destroy(mutex);
-       SIMIX_cond_destroy(cond);
-
        return 0;
 }
 
@@ -251,7 +240,7 @@ stopsearch:
                        memcpy(request->buf, message->buf, request->datatype->size * request->count);
                        request->src = message->src;
                        request->completed = 1;
-                       SIMIX_broadcast(request->cond);
+                       SIMIX_cond_broadcast(request->cond);
 
                        SIMIX_mutex_unlock(request->mutex);
 
@@ -356,6 +345,8 @@ void smpi_global_init()
                                                             smpi_request_new, smpi_request_free, smpi_request_reset);
        smpi_global->message_mallocator                  = xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE,
                                                             smpi_message_new, smpi_message_free, smpi_message_reset);
+
+       //
        smpi_global->pending_send_request_queues         = xbt_new(xbt_fifo_t,  size);
        smpi_global->pending_send_request_queues_mutexes = xbt_new(smx_mutex_t, size);
        smpi_global->pending_recv_request_queues         = xbt_new(xbt_fifo_t,  size);
@@ -365,7 +356,6 @@ void smpi_global_init()
        smpi_global->timers                              = xbt_new(xbt_os_timer_t, size);
        smpi_global->timers_mutexes                      = xbt_new(smx_mutex_t, size);
 
-
        for(i = 0; i < size; i++) {
                smpi_global->pending_send_request_queues[i]         = xbt_fifo_new();
                smpi_global->pending_send_request_queues_mutexes[i] = SIMIX_mutex_init();
@@ -377,7 +367,6 @@ void smpi_global_init()
                smpi_global->timers_mutexes[i]                      = SIMIX_mutex_init();
        }
 
-
 }
 
 void smpi_global_destroy()
@@ -436,15 +425,16 @@ int smpi_run_simulation(int argc, char **argv)
 
        SIMIX_global_init(&argc, argv);
 
-       // initialize smpi_global
-       smpi_global_init();
-
        SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
        SIMIX_function_register("smpi_sender",         smpi_sender);
        SIMIX_function_register("smpi_receiver",       smpi_receiver);
 
        // FIXME: ought to verify these files...
        SIMIX_create_environment(argv[1]);
+
+       // must initialize globals between creating environment and launching app....
+       smpi_global_init();
+
        SIMIX_launch_application(argv[2]);
 
        /* Prepare to display some more info when dying on Ctrl-C pressing */
@@ -767,7 +757,9 @@ void smpi_wait(smpi_mpi_request_t *request, smpi_mpi_status_t *status)
                if (!request->completed) {
                        SIMIX_cond_wait(request->cond, request->mutex);
                }
-               status->MPI_SOURCE = request->src;
+               if (NULL != status) {
+                       status->MPI_SOURCE = request->src;
+               }
                SIMIX_mutex_unlock(request->mutex);
        }
 }