X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/236075d9897437d7a58686ccaa78056d268df867..2a5d9a285cc2a553f5848b1389aaac65a9530b29:/examples/simdag/scheduling/sd_scheduling.c diff --git a/examples/simdag/scheduling/sd_scheduling.c b/examples/simdag/scheduling/sd_scheduling.c index 437ba691dd..eca4354bef 100644 --- a/examples/simdag/scheduling/sd_scheduling.c +++ b/examples/simdag/scheduling/sd_scheduling.c @@ -21,19 +21,6 @@ struct _HostAttribute { SD_task_t last_scheduled_task; }; -static void sg_host_allocate_attribute(sg_host_t host) -{ - void *data; - data = calloc(1, sizeof(struct _HostAttribute)); - sg_host_user_set(host, data); -} - -static void sg_host_free_attribute(sg_host_t host) -{ - free(sg_host_user(host)); - sg_host_user_set(host, NULL); -} - static double sg_host_get_available_at(sg_host_t host) { HostAttribute attr = (HostAttribute) sg_host_user(host); @@ -77,41 +64,30 @@ static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax) static double finish_on_at(SD_task_t task, sg_host_t host) { - volatile double result; + double result; unsigned int i; double data_available = 0.; double redist_time = 0; double last_data_available; - SD_task_t parent, grand_parent; - xbt_dynar_t parents, grand_parents; - - sg_host_t *grand_parent_host_list; - parents = SD_task_get_parents(task); + xbt_dynar_t parents = SD_task_get_parents(task); if (!xbt_dynar_is_empty(parents)) { /* compute last_data_available */ + SD_task_t parent; last_data_available = -1.0; xbt_dynar_foreach(parents, i, parent) { /* normal case */ if (SD_task_get_kind(parent) == SD_TASK_COMM_E2E) { - grand_parents = SD_task_get_parents(parent); - - xbt_assert(xbt_dynar_length(grand_parents) <2, "Error: transfer %s has 2 parents", SD_task_get_name(parent)); - - xbt_dynar_get_cpy(grand_parents, 0, &grand_parent); - - grand_parent_host_list = SD_task_get_workstation_list(grand_parent); + sg_host_t * parent_host= SD_task_get_workstation_list(parent); /* Estimate the redistribution time from this parent */ - if (SD_task_get_amount(parent) == 0){ + if (SD_task_get_amount(parent) <= 1e-6){ redist_time= 0; } else { - redist_time = SD_route_get_latency(grand_parent_host_list[0], host) + - SD_task_get_amount(parent) / SD_route_get_bandwidth(grand_parent_host_list[0], host); + redist_time = SD_route_get_latency(parent_host[0], host) + + SD_task_get_amount(parent) / SD_route_get_bandwidth(parent_host[0], host); } - data_available = SD_task_get_finish_time(grand_parent) + redist_time; - - xbt_dynar_free_container(&grand_parents); + data_available = SD_task_get_start_time(parent) + redist_time; } /* no transfer, control dependency */ @@ -136,17 +112,13 @@ static double finish_on_at(SD_task_t task, sg_host_t host) static sg_host_t SD_task_get_best_host(SD_task_t task) { - int i; - double EFT, min_EFT = -1.0; - const sg_host_t *hosts = sg_host_list(); + sg_host_t *hosts = sg_host_list(); int nhosts = sg_host_count(); - sg_host_t best_host; + sg_host_t best_host = hosts[0]; + double min_EFT = finish_on_at(task, hosts[0]); - best_host = hosts[0]; - min_EFT = finish_on_at(task, hosts[0]); - - for (i = 1; i < nhosts; i++) { - EFT = finish_on_at(task, hosts[i]); + for (int i = 1; i < nhosts; i++) { + double EFT = finish_on_at(task, hosts[i]); XBT_DEBUG("%s finishes on %s at %f", SD_task_get_name(task), sg_host_get_name(hosts[i]), EFT); if (EFT < min_EFT) { @@ -154,20 +126,18 @@ static sg_host_t SD_task_get_best_host(SD_task_t task) best_host = hosts[i]; } } + xbt_free(hosts); return best_host; } int main(int argc, char **argv) { unsigned int cursor; - double finish_time, min_finish_time = -1.0; - SD_task_t task, selected_task = NULL, last_scheduled_task; + double min_finish_time = -1.0; + SD_task_t task, selected_task = NULL; xbt_dynar_t ready_tasks; - sg_host_t host, selected_host = NULL; - int total_nhosts = 0; - const sg_host_t *hosts = NULL; + sg_host_t selected_host = NULL; char * tracefilename = NULL; - xbt_dynar_t dax; /* initialization of SD */ SD_init(&argc, argv); @@ -183,14 +153,14 @@ int main(int argc, char **argv) SD_create_environment(argv[1]); /* Allocating the host attribute */ - total_nhosts = sg_host_count(); - hosts = sg_host_list(); + int total_nhosts = sg_host_count(); + sg_host_t *hosts = sg_host_list(); for (cursor = 0; cursor < total_nhosts; cursor++) - sg_host_allocate_attribute(hosts[cursor]); + sg_host_user_set(hosts[cursor], xbt_new0(struct _HostAttribute, 1)); /* load the DAX file */ - dax = SD_daxload(argv[2]); + xbt_dynar_t dax = SD_daxload(argv[2]); xbt_dynar_foreach(dax, cursor, task) { SD_task_watch(task, SD_DONE); @@ -198,7 +168,7 @@ int main(int argc, char **argv) /* Schedule the root first */ xbt_dynar_get_cpy(dax, 0, &task); - host = SD_task_get_best_host(task); + sg_host_t host = SD_task_get_best_host(task); SD_task_schedulel(task, 1, host); while (!xbt_dynar_is_empty(SD_simulate(-1.0))) { @@ -216,8 +186,8 @@ int main(int argc, char **argv) xbt_dynar_foreach(ready_tasks, cursor, task) { XBT_DEBUG("%s is ready", SD_task_get_name(task)); host = SD_task_get_best_host(task); - finish_time = finish_on_at(task, host); - if (min_finish_time == -1. || finish_time < min_finish_time) { + double finish_time = finish_on_at(task, host); + if (min_finish_time < 0 || finish_time < min_finish_time) { min_finish_time = finish_time; selected_task = task; selected_host = host; @@ -236,7 +206,7 @@ int main(int argc, char **argv) * new dependency */ - last_scheduled_task = sg_host_get_last_scheduled_task(selected_host); + SD_task_t last_scheduled_task = sg_host_get_last_scheduled_task(selected_host); if (last_scheduled_task && (SD_task_get_state(last_scheduled_task) != SD_DONE) && (SD_task_get_state(last_scheduled_task) != SD_FAILED) && !SD_task_dependency_exists(sg_host_get_last_scheduled_task(selected_host), selected_task)) @@ -265,9 +235,12 @@ int main(int argc, char **argv) } xbt_dynar_free_container(&dax); - for (cursor = 0; cursor < total_nhosts; cursor++) - sg_host_free_attribute(hosts[cursor]); + for (cursor = 0; cursor < total_nhosts; cursor++) { + free(sg_host_user(hosts[cursor])); + sg_host_user_set(hosts[cursor], NULL); + } + xbt_free(hosts); /* exit */ SD_exit(); return 0;