Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4e0a0d7ad02564e88406d3509e70ca692c8aacf6
[simgrid.git] / examples / simdag / simdag_trace.c
1 /* Copyright (c) 2006-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "simgrid/simdag.h"
10 #include "xbt/ex.h"
11 #include "xbt/log.h"
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_seq_access,
14                              "Logging specific to this SimDag example");
15
16 int main(int argc, char **argv)
17 {
18   int i;
19   const char *platform_file;
20   const SD_workstation_t *workstations;
21   int kind;
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 };
27   double rate = -1.0;
28   SD_workstation_t w1, w2;
29
30   /* initialisation of SD */
31   SD_init(&argc, argv);
32
33   /*  xbt_log_control_set("sd.thres=debug"); */
34
35   if (argc < 2) {
36     XBT_INFO("Usage: %s platform_file", argv[0]);
37     XBT_INFO("example: %s sd_platform.xml", argv[0]);
38     exit(1);
39   }
40
41   /* creation of the environment */
42   platform_file = argv[1];
43   SD_create_environment(platform_file);
44
45   /* Change the access mode of the workstations */
46   workstations = SD_workstation_get_list();
47   w1 = workstations[0];
48   w2 = workstations[1];
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");
56   }
57
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);
62   TRACE_category ("taskA");
63   TRACE_category ("taskB");
64   TRACE_category ("taskC");
65   TRACE_sd_set_task_category (taskA, "taskA");
66   TRACE_sd_set_task_category (taskB, "taskB");
67   TRACE_sd_set_task_category (taskC, "taskC");
68
69   /* if everything is ok, no exception is forwarded or rethrown by main() */
70
71   /* watch points */
72   SD_task_watch(taskA, SD_RUNNING);
73   SD_task_watch(taskB, SD_RUNNING);
74   SD_task_watch(taskC, SD_RUNNING);
75   SD_task_watch(taskC, SD_DONE);
76
77
78   /* scheduling parameters */
79   workstation_list[0] = w1;
80   workstation_list[1] = w2;
81   computation_amount[0] = SD_task_get_amount(taskA);
82   computation_amount[1] = SD_task_get_amount(taskB);
83
84   communication_amount[1] = SD_task_get_amount(taskC);
85   communication_amount[2] = 0.0;
86
87   SD_task_schedule(taskA, 1, &w1,
88                    &(computation_amount[0]), SD_SCHED_NO_COST, rate);
89   SD_task_schedule(taskB, 2, workstation_list,
90                    SD_SCHED_NO_COST, communication_amount, rate);
91   SD_task_schedule(taskC, 1, &w1,
92                    &(computation_amount[1]), SD_SCHED_NO_COST, rate);
93
94   /* let's launch the simulation! */
95   while (!xbt_dynar_is_empty(changed_tasks = SD_simulate(-1.0))) {
96     for (i = 0; i < 2; i++) {
97       task = SD_workstation_get_current_task(workstations[i]);
98       if (task)
99         kind = SD_task_get_kind(task);
100       else {
101         XBT_INFO("There is no task running on %s",
102               SD_workstation_get_name(workstations[i]));
103         continue;
104       }
105
106       switch (kind) {
107       case SD_TASK_COMP_SEQ:
108         XBT_INFO("%s is currently running on %s (SD_TASK_COMP_SEQ)",
109               SD_task_get_name(task),
110               SD_workstation_get_name(workstations[i]));
111         break;
112       case SD_TASK_COMM_E2E:
113         XBT_INFO("%s is currently running on %s (SD_TASK_COMM_E2E)",
114               SD_task_get_name(task),
115               SD_workstation_get_name(workstations[i]));
116         break;
117       case SD_TASK_NOT_TYPED:
118         XBT_INFO("Task running on %s has no type",
119               SD_workstation_get_name(workstations[i]));
120         break;
121       default:
122         XBT_ERROR("Shouldn't be here");
123       }
124     }
125     xbt_dynar_free_container(&changed_tasks);
126   }
127   xbt_dynar_free_container(&changed_tasks);
128
129   XBT_DEBUG("Destroying tasks...");
130
131   SD_task_destroy(taskA);
132   SD_task_destroy(taskB);
133   SD_task_destroy(taskC);
134
135   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
136
137   SD_exit();
138   return 0;
139 }