Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate functions MSG_global_init() / MSG_global_init_args() in flavor of MSG_init()
[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;
22   xbt_dynar_t changed_tasks;
23
24   /* initialisation 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
52   /* creation of the tasks and their dependencies */
53   taskA = SD_task_create_comp_seq("Task A", NULL, 2e10);
54   taskB = SD_task_create_comm_e2e("Task B", NULL, 2e8);
55   taskC = SD_task_create_comp_seq("Task C", NULL, 1e10);
56
57   /* if everything is ok, no exception is forwarded or rethrown by main() */
58
59   /* watch points */
60   SD_task_watch(taskA, SD_RUNNING);
61   SD_task_watch(taskB, SD_RUNNING);
62   SD_task_watch(taskC, SD_RUNNING);
63   SD_task_watch(taskC, SD_DONE);
64
65
66   /* scheduling parameters */
67   SD_task_schedulel(taskA, 1, workstations[0]);
68   SD_task_schedulel(taskB, 2, workstations[0], workstations[1]);
69   SD_task_schedulel(taskC, 1, workstations[1]);
70
71   /* let's launch the simulation! */
72   while (!xbt_dynar_is_empty(changed_tasks = SD_simulate(-1.0))) {
73     XBT_INFO(" Simulation was suspended, check workstation states"); 
74     for (i = 0; i < 2; i++) {
75     SD_workstation_dump(workstations[i]);
76     }
77     xbt_dynar_free(&changed_tasks);
78   }
79   xbt_dynar_free(&changed_tasks);
80
81   XBT_DEBUG("Destroying tasks...");
82
83   SD_task_destroy(taskA);
84   SD_task_destroy(taskB);
85   SD_task_destroy(taskC);
86
87   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
88
89   SD_exit();
90   return 0;
91 }