Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
made some changes to allow more than one DO_ONCE block. also fixed bug in
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 12 Nov 2007 01:29:00 +0000 (01:29 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 12 Nov 2007 01:29:00 +0000 (01:29 +0000)
smpi_run_simulation and added some more tests of the compute benchmarking code.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5024 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/smpi/smpi.h
src/smpi/private.h
src/smpi/sample/compute.c
src/smpi/sample/compute2.c [new file with mode: 0644]
src/smpi/sample/compute3.c [new file with mode: 0644]
src/smpi/smpi_bench.c
src/smpi/smpi_global.c
src/smpi/smpi_util.c

index 1ab6b12..a93fc44 100644 (file)
@@ -97,9 +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);
+void smpi_do_once_1(const char *file, int line);
 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())
+#define DO_ONCE for (smpi_do_once_1(__FILE__, __LINE__); smpi_do_once_2(); smpi_do_once_3())
 
 #endif
index 3a5c8fa..285c547 100644 (file)
@@ -11,9 +11,6 @@
 #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 {
@@ -72,6 +69,14 @@ typedef struct smpi_received_message_t {
 } s_smpi_received_message_t;
 typedef struct smpi_received_message_t *smpi_received_message_t;
 
+typedef struct smpi_do_once_duration_node_t {
+       char *file;
+       int line;
+       double duration;
+       struct smpi_do_once_duration_node_t *next;
+} s_smpi_do_once_duration_node_t;
+typedef struct smpi_do_once_duration_node_t *smpi_do_once_duration_node_t;
+
 typedef struct smpi_global_t {
 
        // config vars
@@ -108,13 +113,14 @@ typedef struct smpi_global_t {
        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;
+       int               execute_count;
+
+       // keeps track of previous times
+       smpi_do_once_duration_node_t do_once_duration_nodes;
+       smx_mutex_t do_once_mutex;
+       double *do_once_duration;
 
 } s_smpi_global_t;
 typedef struct smpi_global_t *smpi_global_t;
@@ -136,8 +142,10 @@ 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_start_timer(void);
+double smpi_stop_timer(void);
 void smpi_bench_begin(void);
-double smpi_bench_end(void);
+void smpi_bench_end(void);
 void smpi_bench_skip(void);
 
 void smpi_global_init(void);
index 26ce12a..2e4b0e3 100644 (file)
@@ -13,6 +13,7 @@ int main(int argc, char *argv[]) {
                }
        }
        printf("%d %f\n", i, d);
+       MPI_Comm_rank(MPI_COMM_WORLD, &i);
        MPI_Finalize();
        return 0;
 }
diff --git a/src/smpi/sample/compute2.c b/src/smpi/sample/compute2.c
new file mode 100644 (file)
index 0000000..d9eb780
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+       int i;
+       double d;
+       MPI_Init(&argc, &argv);
+       d = 2.0;
+       DO_ONCE {
+               for (i = 0; i < atoi(argv[1]); i++) {
+                       if (d < 10000) {
+                               d = d*d;
+                       } else {
+                               d = 2;
+                       }
+               }
+               printf("%d %f\n", i, d);
+       }
+       MPI_Finalize();
+       return 0;
+}
diff --git a/src/smpi/sample/compute3.c b/src/smpi/sample/compute3.c
new file mode 100644 (file)
index 0000000..e2fe6ba
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+       int i;
+       double d;
+       MPI_Init(&argc, &argv);
+       d = 2.0;
+       DO_ONCE {
+               for (i = 0; i < atoi(argv[1]); i++) {
+                       if (d < 10000) {
+                               d = d*d;
+                       } else {
+                               d = 2;
+                       }
+               }
+               printf("%d %f\n", i, d);
+       }
+       DO_ONCE {
+               for (i = 0; i < 2*atoi(argv[1]); i++) {
+                       if (d < 10000) {
+                               d = d*d;
+                       } else {
+                               d = 2;
+                       }
+               }
+               printf("%d %f\n", i, d);
+       }
+       MPI_Finalize();
+       return 0;
+}
index b64c2f7..6bb7a8d 100644 (file)
@@ -1,4 +1,5 @@
 #include "private.h"
+#include <string.h>
 
 void smpi_execute(double duration) {
         smx_host_t host = SIMIX_host_self();
@@ -6,7 +7,7 @@ void smpi_execute(double duration) {
 
        SIMIX_mutex_lock(smpi_global->execute_mutex);
 
-       action = SIMIX_action_execute(host, "computation", duration * SMPI_DEFAULT_SPEED);
+       action = SIMIX_action_execute(host, "execute", 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);
@@ -18,55 +19,68 @@ void smpi_execute(double duration) {
        return;
 }
 
-void smpi_bench_begin()
+void smpi_start_timer()
 {
        SIMIX_mutex_lock(smpi_global->timer_mutex);
        xbt_os_timer_start(smpi_global->timer);
-       return;
 }
 
-double smpi_bench_end()
+double smpi_stop_timer()
 {
        double duration;
-
        xbt_os_timer_stop(smpi_global->timer);
-
        duration = xbt_os_timer_elapsed(smpi_global->timer);
-
        SIMIX_mutex_unlock(smpi_global->timer_mutex);
-
-       smpi_execute(duration);
-
        return duration;
 }
 
+void smpi_bench_begin()
+{
+       smpi_start_timer();
+}
 
-void smpi_bench_skip() {
-       double duration = smpi_global->times[0];
-       smpi_execute(duration);
-       return;
+void smpi_bench_end()
+{
+       smpi_execute(smpi_stop_timer());
 }
 
-void smpi_do_once_1() {
+void smpi_do_once_1(const char *file, int line) {
+       smpi_do_once_duration_node_t curr, prev;
        smpi_bench_end();
-       SIMIX_mutex_lock(smpi_global->times_mutex);
-       if (0 < smpi_global->times[0]) {
-               smpi_bench_skip();
+       SIMIX_mutex_lock(smpi_global->do_once_mutex);
+       prev = NULL;
+       for(curr = smpi_global->do_once_duration_nodes;
+               NULL != curr && (strcmp(curr->file, file) || curr->line != line);
+               curr = curr->next) {
+               prev = curr;
        }
-       return;
+       if (NULL == curr) {
+               curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
+               curr->file = xbt_strdup(file);
+               curr->line = line;
+               curr->duration = -1;
+               curr->next = NULL;
+               if (NULL == prev) {
+                       smpi_global->do_once_duration_nodes = curr;
+               } else {
+                       prev->next = curr;
+               }
+       }
+       smpi_global->do_once_duration = &curr->duration;
 }
 
 int smpi_do_once_2() {
-       int retval = 1;
-       if (0 < smpi_global->times[0]) {
-               SIMIX_mutex_unlock(smpi_global->times_mutex);
-               retval = 0;
+       double duration = *(smpi_global->do_once_duration);
+       if (0 < duration) {
+               SIMIX_mutex_unlock(smpi_global->do_once_mutex);
+               smpi_execute(duration);
+               smpi_bench_begin();
+               return 0;
        }
-       smpi_bench_begin();
-       return retval;
+       smpi_start_timer();
+       return 1;
 }
 
 void smpi_do_once_3() {
-       smpi_global->times[0] = smpi_bench_end();
-       return;
+       *(smpi_global->do_once_duration) = smpi_stop_timer();
 }
index 08d693c..4f8fed0 100644 (file)
@@ -166,11 +166,13 @@ void smpi_global_init()
        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();
+       smpi_global->execute_count                       = 0;
+
+       smpi_global->do_once_duration_nodes              = NULL;
+       smpi_global->do_once_duration                    = NULL;
+       smpi_global->do_once_mutex                       = SIMIX_mutex_init();
 
        for (i = 0; i < size; i++) {
                smpi_global->pending_send_request_queues[i]         = xbt_fifo_new();
@@ -181,10 +183,6 @@ 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()
@@ -193,6 +191,8 @@ void smpi_global_destroy()
 
        int size = SIMIX_host_get_number();
 
+       smpi_do_once_duration_node_t curr, next;
+
        // start/stop
        SIMIX_mutex_destroy(smpi_global->start_stop_mutex);
        SIMIX_cond_destroy(smpi_global->start_stop_cond);
@@ -211,10 +211,17 @@ 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);
        SIMIX_mutex_destroy(smpi_global->execute_mutex);
        SIMIX_cond_destroy(smpi_global->execute_cond);
 
+       for(curr = smpi_global->do_once_duration_nodes; NULL != curr; curr = next) {
+               next = curr->next;
+               xbt_free(curr->file);
+               xbt_free(curr);
+       }
+
+       SIMIX_mutex_destroy(smpi_global->do_once_mutex);
+
        for(i = 0; i < size; i++) {
                xbt_fifo_free(smpi_global->pending_send_request_queues[i]);
                SIMIX_mutex_destroy(smpi_global->pending_send_request_queues_mutexes[i]);
@@ -246,9 +253,7 @@ int smpi_host_index()
 
 int smpi_run_simulation(int *argc, char **argv)
 {
-       xbt_fifo_item_t cond_item   = NULL;
        smx_cond_t   cond           = NULL;
-       xbt_fifo_item_t action_item = NULL;
        smx_action_t action         = NULL;
 
        xbt_fifo_t   actions_failed = xbt_fifo_new();
@@ -279,15 +284,15 @@ int smpi_run_simulation(int *argc, char **argv)
        fflush(stderr);
 
        while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
-               xbt_fifo_foreach(actions_failed, action_item, action, smx_action_t) {
+               while ((action = xbt_fifo_pop(actions_failed))) {
                        DEBUG1("** %s failed **", action->name);
-                       xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
+                       while((cond = xbt_fifo_pop(action->cond_list))) {
                                SIMIX_cond_broadcast(cond);
                        }
                }
-               xbt_fifo_foreach(actions_done, action_item, action, smx_action_t) {
+               while((action = xbt_fifo_pop(actions_done))) {
                        DEBUG1("** %s done **",action->name);
-                       xbt_fifo_foreach(action->cond_list, cond_item, cond, smx_cond_t) {
+                       while((cond = xbt_fifo_pop(action->cond_list))) {
                                SIMIX_cond_broadcast(cond);
                        }
                }
index 396863c..ac5d372 100644 (file)
@@ -27,6 +27,7 @@ unsigned int smpi_sleep(unsigned int seconds)
 
        SIMIX_mutex_lock(smpi_global->execute_mutex);
 
+       // FIXME: explicit conversion to double?
        action = SIMIX_action_sleep(host, seconds);
 
        SIMIX_register_action_to_condition(action, smpi_global->execute_cond);