Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleaning up and refactoring some of the code to create execution actions.
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 10 Nov 2007 01:35:48 +0000 (01:35 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 10 Nov 2007 01:35:48 +0000 (01:35 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5021 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/smpi/private.h
src/smpi/smpi_bench.c
src/smpi/smpi_global.c
src/smpi/smpi_util.c

index 8e215a6..3a5c8fa 100644 (file)
@@ -103,13 +103,19 @@ typedef struct smpi_global_t {
        int               running_hosts_count;
        smx_mutex_t       running_hosts_count_mutex;
 
+       // FIXME: maybe all code needs to lock timer?
        xbt_os_timer_t    timer;
        smx_mutex_t       timer_mutex;
        smx_cond_t        timer_cond;
+
+       // keeps track of previous times
        double            times[SMPI_MAX_TIMES];
        int               times_max;
        smx_mutex_t       times_mutex;
 
+       smx_mutex_t       execute_mutex;
+       smx_cond_t        execute_cond;
+
 } s_smpi_global_t;
 typedef struct smpi_global_t *smpi_global_t;
 extern smpi_global_t smpi_global;
@@ -129,6 +135,7 @@ int smpi_mpi_isend(smpi_mpi_request_t request);
 int smpi_mpi_irecv(smpi_mpi_request_t request);
 int smpi_mpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t *status);
 
+void smpi_execute(double duration);
 void smpi_bench_begin(void);
 double smpi_bench_end(void);
 void smpi_bench_skip(void);
index 8f43a58..b64c2f7 100644 (file)
@@ -1,58 +1,49 @@
-#include <stdio.h>
 #include "private.h"
 
-// FIXME: could cause trouble with multithreaded procs on same host...
-// FIXME: add benchmarking flag?
+void smpi_execute(double duration) {
+        smx_host_t host = SIMIX_host_self();
+        smx_action_t action;
+
+       SIMIX_mutex_lock(smpi_global->execute_mutex);
+
+       action = SIMIX_action_execute(host, "computation", duration * SMPI_DEFAULT_SPEED);
+
+        SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
+        SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
+        SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
+        SIMIX_action_destroy(action);
+
+        SIMIX_mutex_unlock(smpi_global->execute_mutex);
+
+       return;
+}
 
 void smpi_bench_begin()
 {
        SIMIX_mutex_lock(smpi_global->timer_mutex);
-
        xbt_os_timer_start(smpi_global->timer);
-
        return;
 }
 
 double smpi_bench_end()
 {
        double duration;
-       smx_host_t host;
-       smx_action_t action;
 
        xbt_os_timer_stop(smpi_global->timer);
 
        duration = xbt_os_timer_elapsed(smpi_global->timer);
 
-       host     = SIMIX_host_self();
-       action   = SIMIX_action_execute(host, "computation", duration * SMPI_DEFAULT_SPEED);
-
-       SIMIX_register_action_to_condition(action, smpi_global->timer_cond);
-       SIMIX_cond_wait(smpi_global->timer_cond, smpi_global->timer_mutex);
-       SIMIX_unregister_action_to_condition(action, smpi_global->timer_cond);
-       SIMIX_action_destroy(action);
-
        SIMIX_mutex_unlock(smpi_global->timer_mutex);
 
+       smpi_execute(duration);
+
        return duration;
 }
 
+
 void smpi_bench_skip() {
-       smx_host_t host;
-       smx_action_t action;
        double duration = smpi_global->times[0];
-
-       SIMIX_mutex_lock(smpi_global->timer_mutex);
-
-       host   = SIMIX_host_self();
-       action = SIMIX_action_execute(host, "computation", duration * SMPI_DEFAULT_SPEED);
-
-       SIMIX_register_action_to_condition(action, smpi_global->timer_cond);
-       SIMIX_cond_wait(smpi_global->timer_cond, smpi_global->timer_mutex);
-       SIMIX_unregister_action_to_condition(action, smpi_global->timer_cond);
-       SIMIX_action_destroy(action);
-
-       SIMIX_mutex_unlock(smpi_global->timer_mutex);
-
+       smpi_execute(duration);
        return;
 }
 
index aeec12f..08d693c 100644 (file)
@@ -165,9 +165,13 @@ void smpi_global_init()
        smpi_global->timer                               = xbt_os_timer_new();
        smpi_global->timer_mutex                         = SIMIX_mutex_init();
        smpi_global->timer_cond                          = SIMIX_cond_init();
+
        smpi_global->times_max                           = 0;
        smpi_global->times_mutex                         = SIMIX_mutex_init();
 
+       smpi_global->execute_mutex                       = SIMIX_mutex_init();
+       smpi_global->execute_cond                        = SIMIX_cond_init();
+
        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();
@@ -208,6 +212,8 @@ void smpi_global_destroy()
        SIMIX_mutex_destroy(smpi_global->timer_mutex);
        SIMIX_cond_destroy(smpi_global->timer_cond);
        SIMIX_mutex_destroy(smpi_global->times_mutex);
+       SIMIX_mutex_destroy(smpi_global->execute_mutex);
+       SIMIX_cond_destroy(smpi_global->execute_cond);
 
        for(i = 0; i < size; i++) {
                xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
index d1f1969..396863c 100644 (file)
@@ -23,18 +23,18 @@ unsigned int smpi_sleep(unsigned int seconds)
 
        smpi_bench_end();
 
-       host = SIMIX_host_self();
+       host  = SIMIX_host_self();
 
-       SIMIX_mutex_lock(smpi_global->timer_mutex);
+       SIMIX_mutex_lock(smpi_global->execute_mutex);
 
        action = SIMIX_action_sleep(host, seconds);
 
-       SIMIX_register_action_to_condition(action, smpi_global->timer_cond);
-       SIMIX_cond_wait(smpi_global->timer_cond, smpi_global->timer_mutex);
-       SIMIX_unregister_action_to_condition(action, smpi_global->timer_cond);
+       SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
+       SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
+       SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
        SIMIX_action_destroy(action);
 
-       SIMIX_mutex_unlock(smpi_global->timer_mutex);
+       SIMIX_mutex_unlock(smpi_global->execute_mutex);
 
        smpi_bench_begin();
        return 0;