1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "simdag/simdag.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_seq_access,
14 "Logging specific to this SimDag example");
16 int main(int argc, char **argv)
19 const char *platform_file;
20 const SD_workstation_t *workstations;
22 SD_task_t task, taskA, taskB, taskC;
23 xbt_dynar_t changed_tasks;
24 SD_workstation_t workstation_list[2];
25 double computation_amount[2];
26 double communication_amount[4] = { 0 };
28 SD_workstation_t w1, w2;
30 /* initialisation of SD */
33 /* xbt_log_control_set("sd.thres=debug"); */
36 XBT_INFO("Usage: %s platform_file", argv[0]);
37 XBT_INFO("example: %s sd_platform.xml", argv[0]);
41 /* creation of the environment */
42 platform_file = argv[1];
43 SD_create_environment(platform_file);
45 /* Change the access mode of the workstations */
46 workstations = SD_workstation_get_list();
49 for (i = 0; i < 2; i++) {
50 SD_workstation_set_access_mode(workstations[i],
51 SD_WORKSTATION_SEQUENTIAL_ACCESS);
52 XBT_INFO("Access mode of %s is %s",
53 SD_workstation_get_name(workstations[i]),
54 (SD_workstation_get_access_mode(workstations[i]) ==
55 SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
58 /* creation of the tasks and their dependencies */
59 taskA = SD_task_create_comp_seq("Task A", NULL, 2e9);
60 taskB = SD_task_create_comm_e2e("Task B", NULL, 2e9);
61 taskC = SD_task_create_comp_seq("Task C", NULL, 1e9);
63 /* if everything is ok, no exception is forwarded or rethrown by main() */
66 SD_task_watch(taskA, SD_RUNNING);
67 SD_task_watch(taskB, SD_RUNNING);
68 SD_task_watch(taskC, SD_RUNNING);
69 SD_task_watch(taskC, SD_DONE);
72 /* scheduling parameters */
73 workstation_list[0] = w1;
74 workstation_list[1] = w2;
75 computation_amount[0] = SD_task_get_amount(taskA);
76 computation_amount[1] = SD_task_get_amount(taskB);
78 communication_amount[1] = SD_task_get_amount(taskC);
79 communication_amount[2] = 0.0;
81 SD_task_schedule(taskA, 1, &w1,
82 &(computation_amount[0]), SD_SCHED_NO_COST, rate);
83 SD_task_schedule(taskB, 2, workstation_list,
84 SD_SCHED_NO_COST, communication_amount, rate);
85 SD_task_schedule(taskC, 1, &w1,
86 &(computation_amount[1]), SD_SCHED_NO_COST, rate);
88 /* let's launch the simulation! */
89 while (xbt_dynar_length(changed_tasks = SD_simulate(-1.0)) > 0) {
90 for (i = 0; i < 2; i++) {
91 task = SD_workstation_get_current_task(workstations[i]);
93 kind = SD_task_get_kind(task);
95 XBT_INFO("There is no task running on %s",
96 SD_workstation_get_name(workstations[i]));
101 case SD_TASK_COMP_SEQ:
102 XBT_INFO("%s is currently running on %s (SD_TASK_COMP_SEQ)",
103 SD_task_get_name(task),
104 SD_workstation_get_name(workstations[i]));
106 case SD_TASK_COMM_E2E:
107 XBT_INFO("%s is currently running on %s (SD_TASK_COMM_E2E)",
108 SD_task_get_name(task),
109 SD_workstation_get_name(workstations[i]));
111 case SD_TASK_NOT_TYPED:
112 XBT_INFO("Task running on %s has no type",
113 SD_workstation_get_name(workstations[i]));
116 XBT_ERROR("Shouldn't be here");
119 xbt_dynar_free(&changed_tasks);
121 xbt_dynar_free(&changed_tasks);
123 XBT_DEBUG("Destroying tasks...");
125 SD_task_destroy(taskA);
126 SD_task_destroy(taskB);
127 SD_task_destroy(taskC);
129 XBT_DEBUG("Tasks destroyed. Exiting SimDag...");