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
#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 {
} 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
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;
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);
}
}
printf("%d %f\n", i, d);
+ MPI_Comm_rank(MPI_COMM_WORLD, &i);
MPI_Finalize();
return 0;
}
--- /dev/null
+#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;
+}
--- /dev/null
+#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;
+}
#include "private.h"
+#include <string.h>
void smpi_execute(double duration) {
smx_host_t host = SIMIX_host_self();
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);
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();
}
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();
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()
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);
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]);
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();
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);
}
}
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);