Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c4355e3e78b8139ba3e13b1ce37b7623645910b2
[simgrid.git] / examples / simdag / sd_typed_tasks_test.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_typed_tasks_test,
14                              "Logging specific to this SimDag example");
15
16 int main(int argc, char **argv)
17 {
18   int i;
19   unsigned int ctr;
20   const char *platform_file;
21   const SD_workstation_t *workstations;
22   SD_task_t task, taskA, taskB, taskC, taskD, taskE;
23   xbt_dynar_t changed_tasks;
24
25   double computation_amount[4];
26   double communication_amount[16] = { 0 };
27   SD_workstation_t workstation_list[4];
28   
29   /* initialization of SD */
30   SD_init(&argc, argv);
31
32   /*  xbt_log_control_set("sd.thres=debug"); */
33
34   if (argc < 2) {
35     XBT_INFO("Usage: %s platform_file", argv[0]);
36     XBT_INFO("example: %s sd_platform.xml", argv[0]);
37     exit(1);
38   }
39
40   /* creation of the environment */
41   platform_file = argv[1];
42   SD_create_environment(platform_file);
43  
44   workstations = SD_workstation_get_list();
45
46   for (i=0;i<4;i++)
47     XBT_INFO("%s runs at %f flops", SD_workstation_get_name(workstations[i]),
48              SD_workstation_get_power(workstations[i]));
49
50   /* creation of some typed tasks and their dependencies */
51   taskA = SD_task_create_comp_seq("Task A", NULL, 1e9);
52   taskB = SD_task_create_comm_e2e("Task B", NULL, 1e7);
53   taskC = SD_task_create_comp_seq("Task C", NULL, 1e9);
54   taskD = SD_task_create_comp_par_amdahl("Task D", NULL, 1e9, 0.2);
55   taskE = SD_task_create("Task E", NULL, 1e9);
56
57   double toto = (0.2 + (1 - 0.2)/4) * 1e9;
58   XBT_INFO("%f %f",toto ,toto/SD_workstation_get_power(workstations[0]));
59
60   SD_task_dependency_add(NULL, NULL, taskA, taskB);
61   SD_task_dependency_add(NULL, NULL, taskB, taskC);
62
63   SD_task_schedulel(taskA, 1, workstations[8]);
64   SD_task_schedulel(taskC, 1, workstations[9]);
65
66   SD_task_distribute_comp_amdhal(taskD, 4);
67   SD_task_schedulev(taskD, 4, workstations);
68
69   for (i=0;i<4;i++){
70     workstation_list[i]=workstations[i+4];
71     computation_amount[i]=toto;
72   }
73   SD_task_schedule(taskE, 4, workstation_list,
74                    computation_amount, communication_amount, -1);
75
76   changed_tasks = SD_simulate(-1.0);
77   xbt_dynar_foreach(changed_tasks, ctr, task) {
78     XBT_INFO("Task '%s' start time: %f, finish time: %f",
79           SD_task_get_name(task),
80           SD_task_get_start_time(task), SD_task_get_finish_time(task));
81   }
82
83   XBT_DEBUG("Destroying tasks...");
84
85   SD_task_destroy(taskA);
86   SD_task_destroy(taskB);
87   SD_task_destroy(taskC);
88   SD_task_destroy(taskD);
89   SD_task_destroy(taskE);
90
91   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
92
93   SD_exit();
94   return 0;
95 }