1 /* Copyright (c) 2006-2015. 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 "simgrid/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;
21 SD_task_t taskA, taskB, taskC, taskD;
23 /* initialization of SD */
26 /* xbt_log_control_set("sd.thres=debug"); */
29 XBT_INFO("Usage: %s platform_file", argv[0]);
30 XBT_INFO("example: %s sd_platform.xml", argv[0]);
34 /* creation of the environment */
35 platform_file = argv[1];
36 SD_create_environment(platform_file);
38 /* Change the access mode of the workstations */
39 workstations = SD_workstation_get_list();
40 for (i = 0; i < 2; i++) {
41 SD_workstation_dump(workstations[i]);
43 SD_workstation_set_access_mode(workstations[i],
44 SD_WORKSTATION_SEQUENTIAL_ACCESS);
45 XBT_INFO(" Change access mode of %s to %s",
46 SD_workstation_get_name(workstations[i]),
47 (SD_workstation_get_access_mode(workstations[i]) ==
48 SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
50 /* Well I changed my mind, I want the second workstation to be shared */
52 SD_workstation_set_access_mode(workstations[1],
53 SD_WORKSTATION_SHARED_ACCESS);
54 XBT_INFO(" Change access mode of %s to %s",
55 SD_workstation_get_name(workstations[1]),
56 (SD_workstation_get_access_mode(workstations[1]) ==
57 SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
59 /* creation of the tasks and their dependencies */
60 taskA = SD_task_create_comp_seq("Task A", NULL, 2e10);
61 taskB = SD_task_create_comm_e2e("Task B", NULL, 2e8);
62 taskC = SD_task_create_comp_seq("Task C", NULL, 1e10);
63 taskD = SD_task_create_comp_seq("Task D", NULL, 1e11);
65 SD_task_dependency_add("B->C", NULL,taskB, taskC);
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);
72 SD_task_watch(taskD, SD_DONE);
75 /* scheduling parameters */
76 SD_task_schedulel(taskA, 1, workstations[0]);
77 SD_task_schedulel(taskB, 2, workstations[0], workstations[1]);
78 SD_task_schedulel(taskC, 1, workstations[1]);
79 SD_task_schedulel(taskD, 1, workstations[1]);
81 /* let's launch the simulation! */
82 while (!xbt_dynar_is_empty(SD_simulate(-1.0))) {
83 XBT_INFO(" Simulation was suspended, check workstation states");
84 for (i = 0; i < 2; i++) {
85 SD_workstation_dump(workstations[i]);
89 XBT_DEBUG("Destroying tasks...");
91 SD_task_destroy(taskA);
92 SD_task_destroy(taskB);
93 SD_task_destroy(taskC);
94 SD_task_destroy(taskD);
96 XBT_DEBUG("Tasks destroyed. Exiting SimDag...");