Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a few memory leaks.
[simgrid.git] / examples / simdag / sd_seq_access.c
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. 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 "simdag/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   xbt_dynar_t changed_tasks;
23
24   /* initialization of SD */
25   SD_init(&argc, argv);
26
27   /*  xbt_log_control_set("sd.thres=debug"); */
28
29   if (argc < 2) {
30     XBT_INFO("Usage: %s platform_file", argv[0]);
31     XBT_INFO("example: %s sd_platform.xml", argv[0]);
32     exit(1);
33   }
34
35   /* creation of the environment */
36   platform_file = argv[1];
37   SD_create_environment(platform_file);
38
39   /* Change the access mode of the workstations */
40   workstations = SD_workstation_get_list();
41   for (i = 0; i < 2; i++) {
42     SD_workstation_dump(workstations[i]);
43     
44     SD_workstation_set_access_mode(workstations[i],
45                                    SD_WORKSTATION_SEQUENTIAL_ACCESS);
46     XBT_INFO(" Change access mode of %s to %s",
47           SD_workstation_get_name(workstations[i]),
48           (SD_workstation_get_access_mode(workstations[i]) ==
49            SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
50   }
51   /* Well I changed my mind, I want the second workstation to be shared */
52
53   SD_workstation_set_access_mode(workstations[1],
54                                      SD_WORKSTATION_SHARED_ACCESS);
55   XBT_INFO(" Change access mode of %s to %s",
56            SD_workstation_get_name(workstations[1]),
57            (SD_workstation_get_access_mode(workstations[1]) ==
58            SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
59
60   /* creation of the tasks and their dependencies */
61   taskA = SD_task_create_comp_seq("Task A", NULL, 2e10);
62   taskB = SD_task_create_comm_e2e("Task B", NULL, 2e8);
63   taskC = SD_task_create_comp_seq("Task C", NULL, 1e10);
64   taskD = SD_task_create_comp_seq("Task D", NULL, 1e11);
65
66   SD_task_dependency_add("B->C", NULL,taskB, taskC);
67
68   /* watch points */
69   SD_task_watch(taskA, SD_RUNNING);
70   SD_task_watch(taskB, SD_RUNNING);
71   SD_task_watch(taskC, SD_RUNNING);
72   SD_task_watch(taskC, SD_DONE);
73   SD_task_watch(taskD, SD_DONE);
74
75
76   /* scheduling parameters */
77   SD_task_schedulel(taskA, 1, workstations[0]);
78   SD_task_schedulel(taskB, 2, workstations[0], workstations[1]);
79   SD_task_schedulel(taskC, 1, workstations[1]);
80   SD_task_schedulel(taskD, 1, workstations[1]);
81
82   /* let's launch the simulation! */
83   while (!xbt_dynar_is_empty(changed_tasks = SD_simulate(-1.0))) {
84     XBT_INFO(" Simulation was suspended, check workstation states"); 
85     for (i = 0; i < 2; i++) {
86       SD_workstation_dump(workstations[i]);
87     }
88     xbt_dynar_free(&changed_tasks);
89   }
90   xbt_dynar_free(&changed_tasks);
91
92   XBT_DEBUG("Destroying tasks...");
93
94   SD_task_destroy(taskA);
95   SD_task_destroy(taskB);
96   SD_task_destroy(taskC);
97   SD_task_destroy(taskD);
98
99   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
100
101   SD_exit();
102   return 0;
103 }