Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9e9933a5352603fe194e03cba7052c723b52dd51
[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, seq_comp1, e2e_comm, seq_comp2;
23   SD_task_t par_comp1, redist, par_comp2, par_comp3;
24   xbt_dynar_t changed_tasks;
25
26   double computation_amount[4];
27   double communication_amount[16] = { 0 };
28   SD_workstation_t workstation_list[4];
29   
30   /* initialization of SD */
31   SD_init(&argc, argv);
32
33   /*  xbt_log_control_set("sd.thres=debug"); */
34
35   if (argc < 2) {
36     XBT_INFO("Usage: %s platform_file", argv[0]);
37     XBT_INFO("example: %s sd_platform.xml", argv[0]);
38     exit(1);
39   }
40
41   /* creation of the environment */
42   platform_file = argv[1];
43   SD_create_environment(platform_file);
44  
45   workstations = SD_workstation_get_list();
46
47   for (i=0;i<SD_workstation_get_number();i++)
48     XBT_INFO("%s runs at %f flops", SD_workstation_get_name(workstations[i]),
49        SD_workstation_get_power(workstations[i]));
50
51   /* creation of some typed tasks and their dependencies */
52   seq_comp1 = SD_task_create_comp_seq("Seq. comp. 1", NULL, 1e9);
53   e2e_comm = SD_task_create_comm_e2e("E2E comm.", NULL, 1e7);
54   seq_comp2 = SD_task_create_comp_seq("Seq. comp 2.", NULL, 1e9);
55   par_comp1 = SD_task_create_comp_par_amdahl("Par. Comp. 1", NULL, 1e9, 0.2);
56   redist = SD_task_create_comm_par_mxn_1d_block("MxN redist", NULL, 1.2e8);
57   par_comp2 = SD_task_create_comp_par_amdahl("Par. Comp. 2", NULL, 3e8, 0.5);
58
59   par_comp3 = SD_task_create("Par. Comp. 3", NULL, 1e9);
60
61   SD_task_dependency_add(NULL, NULL, seq_comp1, e2e_comm);
62   SD_task_dependency_add(NULL, NULL, e2e_comm, seq_comp2);
63
64   SD_task_dependency_add(NULL, NULL, par_comp1, redist);
65   SD_task_dependency_add(NULL, NULL, redist, par_comp2);
66
67   SD_task_schedulel(seq_comp1, 1, workstations[8]);
68   SD_task_schedulel(seq_comp2, 1, workstations[9]);
69
70   SD_task_schedulev(par_comp1, 4, workstations);
71   SD_task_schedulev(par_comp2, 3, workstations);
72
73   for (i=0;i<4;i++){
74     workstation_list[i]=workstations[i+4];
75     /* Apply Amdahl's law manually assuming a 20% serial part */
76     computation_amount[i]=(0.2 + (1 - 0.2)/4) * SD_task_get_amount(par_comp3);
77   }
78
79   SD_task_schedule(par_comp3, 4, workstation_list,
80                    computation_amount, communication_amount, -1);
81
82   changed_tasks = SD_simulate(-1.0);
83   xbt_dynar_foreach(changed_tasks, ctr, task) {
84     XBT_INFO("Task '%s' start time: %f, finish time: %f",
85           SD_task_get_name(task),
86           SD_task_get_start_time(task), SD_task_get_finish_time(task));
87     SD_task_destroy(task);
88   }
89
90   SD_exit();
91   return 0;
92 }