Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
added code to allow for DO_ONCE loops. very preliminary.
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 9 Nov 2007 00:42:03 +0000 (00:42 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 9 Nov 2007 00:42:03 +0000 (00:42 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5008 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/smpi/smpi.h
src/smpi/private.h
src/smpi/smpi_bench.c
src/smpi/smpi_global.c
src/smpi/smpi_mpi.c

index 186deeb..1ab6b12 100644 (file)
@@ -97,4 +97,9 @@ unsigned int smpi_sleep(unsigned int);
 void smpi_exit(int);
 int smpi_gettimeofday(struct timeval *tv, struct timezone *tz);
 
+void smpi_do_once_1(void);
+int  smpi_do_once_2(void);
+void smpi_do_once_3(void);
+#define DO_ONCE for (smpi_do_once_1(); smpi_do_once_2(); smpi_do_once_3())
+
 #endif
index f3379e6..4b92c75 100644 (file)
@@ -11,6 +11,9 @@
 #define SMPI_DEFAULT_SPEED 100
 #define SMPI_REQUEST_MALLOCATOR_SIZE 100
 #define SMPI_MESSAGE_MALLOCATOR_SIZE 100
+// FIXME: should probably be dynamic datatype...
+// or could include code to dynamically expand when full
+#define SMPI_MAX_TIMES 10
 
 // smpi mpi communicator
 typedef struct smpi_mpi_communicator_t {
@@ -103,6 +106,9 @@ typedef struct smpi_global_t {
        xbt_os_timer_t    timer;
        smx_mutex_t       timer_mutex;
        smx_cond_t        timer_cond;
+       double            times[SMPI_MAX_TIMES];
+       int               times_max;
+       smx_mutex_t       times_mutex;
 
 } s_smpi_global_t;
 typedef struct smpi_global_t *smpi_global_t;
@@ -124,7 +130,8 @@ 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_bench_begin(void);
-void smpi_bench_end(void);
+double smpi_bench_end(void);
+void smpi_bench_skip(void);
 
 void smpi_global_init(void);
 void smpi_global_destroy(void);
index a301b69..81ed0f0 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include "private.h"
 
 // FIXME: could cause trouble with multithreaded procs on same host...
@@ -6,18 +7,22 @@
 void smpi_bench_begin()
 {
        SIMIX_mutex_lock(smpi_global->timer_mutex);
+
        xbt_os_timer_start(smpi_global->timer);
+
        return;
 }
 
-void smpi_bench_end()
+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);
 
@@ -27,5 +32,48 @@ void smpi_bench_end()
 
        SIMIX_mutex_unlock(smpi_global->timer_mutex);
 
+       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_mutex_unlock(smpi_global->timer_mutex);
+
+       return;
+}
+
+void smpi_do_once_1() {
+       smpi_bench_end();
+       SIMIX_mutex_lock(smpi_global->times_mutex);
+       if (0 < smpi_global->times[0]) {
+               smpi_bench_skip();
+       }
+       return;
+}
+
+int smpi_do_once_2() {
+       int retval = 1;
+       if (0 < smpi_global->times[0]) {
+               SIMIX_mutex_unlock(smpi_global->times_mutex);
+               retval = 0;
+       }
+       smpi_bench_begin();
+       return retval;
+}
+
+void smpi_do_once_3() {
+       smpi_global->times[0] = smpi_bench_end();
        return;
 }
index a0786cd..af72607 100644 (file)
@@ -165,8 +165,10 @@ 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();
 
-       for(i = 0; i < size; i++) {
+       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();
                smpi_global->pending_recv_request_queues[i]         = xbt_fifo_new();
@@ -175,6 +177,10 @@ void smpi_global_init()
                smpi_global->received_message_queues_mutexes[i]     = SIMIX_mutex_init();
        }
 
+       for (i = 0; i < SMPI_MAX_TIMES; i++) {
+               smpi_global->times[i] = -1.0;
+       }
+
 }
 
 void smpi_global_destroy()
@@ -201,6 +207,7 @@ void smpi_global_destroy()
        xbt_os_timer_free(smpi_global->timer);
        SIMIX_mutex_destroy(smpi_global->timer_mutex);
        SIMIX_cond_destroy(smpi_global->timer_cond);
+       SIMIX_mutex_destroy(smpi_global->times_mutex);
 
        for(i = 0; i < size; i++) {
                xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
index b29243e..1d4e1ca 100644 (file)
@@ -1,5 +1,3 @@
-// FIXME: remove
-#include <stdio.h>
 #include "private.h"
 
 int MPI_Init(int *argc, char ***argv)