Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / src / smpi / smpi_base.c
index 62834b6..6ebefe4 100644 (file)
@@ -1,5 +1,14 @@
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi, "Logging specific to SMPI (base)");
+XBT_LOG_EXTERNAL_CATEGORY(smpi_base);
+XBT_LOG_EXTERNAL_CATEGORY(smpi_bench);
+XBT_LOG_EXTERNAL_CATEGORY(smpi_kernel);
+XBT_LOG_EXTERNAL_CATEGORY(smpi_mpi);
+XBT_LOG_EXTERNAL_CATEGORY(smpi_receiver);
+XBT_LOG_EXTERNAL_CATEGORY(smpi_sender);
+XBT_LOG_EXTERNAL_CATEGORY(smpi_util);
+
 smpi_mpi_global_t smpi_mpi_global = NULL;
 
 void smpi_mpi_land_func(void *a, void *b, int *length, MPI_Datatype *datatype);
@@ -28,7 +37,7 @@ void smpi_mpi_sum_func(void *a, void *b, int *length, MPI_Datatype *datatype)
        }
 }
 
-int inline smpi_mpi_comm_rank(smpi_mpi_communicator_t comm)
+int smpi_mpi_comm_rank(smpi_mpi_communicator_t comm)
 {
        return comm->index_to_rank_map[smpi_host_index()];
 }
@@ -55,6 +64,8 @@ void smpi_mpi_init()
        for (i = 0; i < host_count && host != hosts[i]; i ++);
 
        hdata->index = i;
+       hdata->mutex = SIMIX_mutex_init();
+       hdata->cond  = SIMIX_cond_init();
 
        SIMIX_host_set_data(host, hdata);
 
@@ -103,7 +114,7 @@ void smpi_mpi_init()
 
                // make sure root is done before own initialization
                SIMIX_mutex_lock(smpi_global->start_stop_mutex);
-               if (!smpi_global->root_ready) {
+               while (!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);
@@ -113,11 +124,12 @@ void smpi_mpi_init()
        // 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 * host_count) {
-               SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
-       } else {
+       if (smpi_global->ready_process_count >= 3 * host_count) {
                SIMIX_cond_broadcast(smpi_global->start_stop_cond);
        }
+       while (smpi_global->ready_process_count < 3 * host_count) {
+               SIMIX_cond_wait(smpi_global->start_stop_cond, smpi_global->start_stop_mutex);
+       }
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
        return;
@@ -135,6 +147,9 @@ void smpi_mpi_finalize()
        smpi_global->ready_process_count--;
        SIMIX_mutex_unlock(smpi_global->start_stop_mutex);
 
+       SIMIX_mutex_destroy(smpi_host_mutex());
+       SIMIX_cond_destroy(smpi_host_cond());
+
        if (0 >= i) {
 
                // wake up senders/receivers
@@ -168,12 +183,15 @@ int smpi_mpi_barrier(smpi_mpi_communicator_t comm)
 {
 
        SIMIX_mutex_lock(comm->barrier_mutex);
-       if(++comm->barrier_count < comm->size) {
-               SIMIX_cond_wait(comm->barrier_cond, comm->barrier_mutex);
-       } else {
+       ++comm->barrier_count;
+       if (comm->barrier_count > comm->size) { // only happens on second barrier...
                comm->barrier_count = 0;
+       } else if (comm->barrier_count == comm->size) {
                SIMIX_cond_broadcast(comm->barrier_cond);
        }
+       while (comm->barrier_count < comm->size) {
+               SIMIX_cond_wait(comm->barrier_cond, comm->barrier_mutex);
+       }
        SIMIX_mutex_unlock(comm->barrier_mutex);
 
        return MPI_SUCCESS;