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 SD_task_t *changed_tasks;
25 const int workstation_number = 2;
26 SD_workstation_t workstation_list[2];
27 double computation_amount[2];
28 double communication_amount[4] = { 0 };
30 SD_workstation_t w1, w2;
32 /* initialisation of SD */
35 /* xbt_log_control_set("sd.thres=debug"); */
38 INFO1("Usage: %s platform_file", argv[0]);
39 INFO1("example: %s sd_platform.xml", argv[0]);
43 /* creation of the environment */
44 platform_file = argv[1];
45 SD_create_environment(platform_file);
47 /* Change the access mode of the workstations */
48 workstations = SD_workstation_get_list();
52 SD_workstation_set_access_mode(workstations[i],
53 SD_WORKSTATION_SEQUENTIAL_ACCESS);
54 INFO2("Access mode of %s is %s",
55 SD_workstation_get_name(workstations[i]),
56 (SD_workstation_get_access_mode(workstations[i]) ==
57 SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
60 /* creation of the tasks and their dependencies */
61 taskA = SD_task_create_comp_seq("Task A", NULL, 2e9);
62 taskB = SD_task_create_comm_e2e("Task B", NULL, 2e9);
63 taskC = SD_task_create_comp_seq("Task C", NULL, 1e9);
65 /* if everything is ok, no exception is forwarded or rethrown by main() */
68 SD_task_watch(taskA, SD_RUNNING);
69 SD_task_watch(taskB, SD_RUNNING);
70 SD_task_watch(taskC, SD_RUNNING);
71 SD_task_watch(taskC, SD_DONE);
74 /* scheduling parameters */
75 workstation_list[0] = w1;
76 workstation_list[1] = w2;
77 computation_amount[0] = SD_task_get_amount(taskA);
78 computation_amount[1] = SD_task_get_amount(taskB);
80 communication_amount[1] = SD_task_get_amount(taskC);
81 communication_amount[2] = 0.0;
83 SD_task_schedule(taskA, 1, &w1,
84 &(computation_amount[0]), SD_SCHED_NO_COST, rate);
85 SD_task_schedule(taskB, 2, workstation_list,
86 SD_SCHED_NO_COST, communication_amount, rate);
87 SD_task_schedule(taskC, 1, &w1,
88 &(computation_amount[1]), SD_SCHED_NO_COST, rate);
90 /* let's launch the simulation! */
91 while(*(changed_tasks = SD_simulate(-1.0))){
93 task = SD_workstation_get_current_task(workstations[i]);
95 kind = SD_task_get_kind(task);
97 INFO1("There is no task running on %s",
98 SD_workstation_get_name(workstations[i]));
103 case SD_TASK_COMP_SEQ:
104 INFO2("%s is currently running on %s (SD_TASK_COMP_SEQ)",
105 SD_task_get_name(task),
106 SD_workstation_get_name(workstations[i]));
108 case SD_TASK_COMM_E2E:
109 INFO2("%s is currently running on %s (SD_TASK_COMM_E2E)",
110 SD_task_get_name(task),
111 SD_workstation_get_name(workstations[i]));
113 case SD_TASK_NOT_TYPED:
114 INFO1("Task running on %s has no type",
115 SD_workstation_get_name(workstations[i]));
118 ERROR0("Shouldn't be here");
121 xbt_free(changed_tasks);
124 DEBUG0("Destroying tasks...");
126 SD_task_destroy(taskA);
127 SD_task_destroy(taskB);
128 SD_task_destroy(taskC);
130 DEBUG0("Tasks destroyed. Exiting SimDag...");