Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add documentation for workstations and fix a few bugs
[simgrid.git] / examples / simdag / sd_test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "simdag/simdag.h"
4 #include "xbt/ex.h"
5
6 int main(int argc, char **argv) {
7   
8   /* initialisation of SD */
9   SD_init(&argc, argv);
10
11   if (argc < 2) {
12      printf ("Usage: %s platform_file\n", argv[0]);
13      printf ("example: %s msg_platform.xml\n", argv[0]);
14      exit(1);
15   }
16
17   /* creation of the environment */
18   char * platform_file = argv[1];
19   SD_create_environment(platform_file);
20
21   /* creation of the tasks and their dependencies */
22   SD_task_t taskA = SD_task_create("Task A", NULL, 10.0);
23   SD_task_t taskB = SD_task_create("Task B", NULL, 40.0);
24   SD_task_t taskC = SD_task_create("Task C", NULL, 30.0);
25   SD_task_t taskD = SD_task_create("Task D", NULL, 60.0);
26   
27   SD_task_dependency_add(NULL, NULL, taskB, taskA);
28   SD_task_dependency_add(NULL, NULL, taskC, taskA);
29   SD_task_dependency_add(NULL, NULL, taskD, taskB);
30   SD_task_dependency_add(NULL, NULL, taskD, taskC);
31   /*  SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
32
33   /* watch points */
34   /*  SD_task_watch(taskB, SD_DONE);*/
35
36
37   /* let's launch the simulation! */
38
39   int workstation_number = 2;
40   SD_workstation_t *workstation_list = SD_workstation_get_list();
41   double computation_amount[] = {100, 200};
42   double communication_amount[] =
43     {
44       0, 30,
45       20, 0
46     };
47   double rate = 1;
48
49   SD_task_schedule(taskA, workstation_number, workstation_list,
50                    computation_amount, communication_amount, rate);
51   SD_task_schedule(taskB, workstation_number, workstation_list,
52                    computation_amount, communication_amount, rate);
53   SD_task_schedule(taskC, workstation_number, workstation_list,
54                    computation_amount, communication_amount, rate);
55   SD_task_schedule(taskD, workstation_number, workstation_list,
56                    computation_amount, communication_amount, rate);
57
58   printf("Launching simulation...\n");
59   SD_task_t *changed_tasks = SD_simulate(100);
60   int i = 0;
61   
62   printf("Simulation results:\n");
63   while(changed_tasks[i] != NULL) {
64     switch (SD_task_get_state(changed_tasks[i])) {
65     case SD_SCHEDULED:
66       printf("%s is scheduled.\n", SD_task_get_name(changed_tasks[i]));
67       break;
68     case SD_READY:
69       printf("%s is ready.\n", SD_task_get_name(changed_tasks[i]));
70       break;
71     case SD_DONE:
72       printf("%s is done.\n", SD_task_get_name(changed_tasks[i]));
73       break;
74     case SD_FAILED:
75       printf("%s is failed.\n", SD_task_get_name(changed_tasks[i]));
76       break;
77     default:
78       printf("Unknown status for %s\n", SD_task_get_name(changed_tasks[i]));
79       break;
80     }
81     i++;
82   }
83
84   free(changed_tasks);
85
86   SD_task_destroy(taskA);
87   SD_task_destroy(taskB);
88   SD_task_destroy(taskC);
89   SD_task_destroy(taskD);
90   SD_exit();
91   return 0;
92 }