Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Start the SimDag revolution: function factoring
[simgrid.git] / examples / simdag / sd_seq_access.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   SD_task_t taskA, taskB, taskC, taskD;
22
23   /* initialization of SD */
24   SD_init(&argc, argv);
25
26   /*  xbt_log_control_set("sd.thres=debug"); */
27
28   if (argc < 2) {
29     XBT_INFO("Usage: %s platform_file", argv[0]);
30     XBT_INFO("example: %s sd_platform.xml", argv[0]);
31     exit(1);
32   }
33
34   /* creation of the environment */
35   platform_file = argv[1];
36   SD_create_environment(platform_file);
37
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]);
42     
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");
49   }
50   /* Well I changed my mind, I want the second workstation to be shared */
51
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");
58
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);
64
65   SD_task_dependency_add("B->C", NULL,taskB, taskC);
66
67   /* watch points */
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);
73
74
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]);
80
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]);
86     }
87   }
88
89   XBT_DEBUG("Destroying tasks...");
90
91   SD_task_destroy(taskA);
92   SD_task_destroy(taskB);
93   SD_task_destroy(taskC);
94   SD_task_destroy(taskD);
95
96   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
97
98   SD_exit();
99   return 0;
100 }