Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0351004bf7fa6a2370c5fd34c70fde48abbb8a0c
[simgrid.git] / examples / simdag / typed_tasks / sd_typed_tasks.c
1 /* Copyright (c) 2006-2019. 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 "simgrid/simdag.h"
8 #include "xbt/log.h"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_typed_tasks_test, "Logging specific to this SimDag example");
11
12 int main(int argc, char **argv)
13 {
14   unsigned int ctr;
15   SD_task_t task;
16
17   double computation_amount[4];
18   double communication_amount[16] = { 0 };
19   sg_host_t host_list[4];
20
21   SD_init(&argc, argv);
22
23   xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]);
24   SD_create_environment(argv[1]);
25
26   sg_host_t *hosts = sg_host_list();
27
28   /* creation of some typed tasks and their dependencies */
29   SD_task_t seq_comp1 = SD_task_create_comp_seq("Seq. comp. 1", NULL, 1e9);
30   SD_task_t e2e_comm = SD_task_create_comm_e2e("E2E comm.", NULL, 1e7);
31   SD_task_t seq_comp2 = SD_task_create_comp_seq("Seq. comp 2.", NULL, 1e9);
32   SD_task_t par_comp1 = SD_task_create_comp_par_amdahl("Par. Comp. 1", NULL, 1e9, 0.2);
33   SD_task_t redist = SD_task_create_comm_par_mxn_1d_block("MxN redist", NULL, 1.2e8);
34   SD_task_t par_comp2 = SD_task_create_comp_par_amdahl("Par. Comp. 2", NULL, 3e8, 0.5);
35   SD_task_t par_comp3 = SD_task_create("Par. Comp. 3", NULL, 1e9);
36
37   SD_task_dependency_add(seq_comp1, e2e_comm);
38   SD_task_dependency_add(e2e_comm, seq_comp2);
39
40   SD_task_dependency_add(par_comp1, redist);
41   SD_task_dependency_add(redist, par_comp2);
42
43   SD_task_schedulel(seq_comp1, 1, hosts[8]);
44   SD_task_schedulel(seq_comp2, 1, hosts[9]);
45
46   SD_task_schedulev(par_comp1, 4, hosts);
47   SD_task_schedulev(par_comp2, 3, hosts);
48
49   /* Let's unschedule these tasks and test the auto-scheduling in the opposite way. */
50   SD_task_unschedule(par_comp1);
51   SD_task_unschedule(par_comp2);
52   SD_task_unschedule(redist); /* yes, it was scheduled too */
53
54   SD_task_schedulev(par_comp2, 3, hosts);
55   SD_task_schedulev(par_comp1, 4, hosts);
56
57   for (int i=0;i<4;i++){
58     host_list[i]=hosts[i+4];
59     /* Apply Amdahl's law manually assuming a 20% serial part */
60     computation_amount[i]=(0.2 + (1 - 0.2)/4) * SD_task_get_amount(par_comp3);
61   }
62
63   SD_task_schedule(par_comp3, 4, host_list, computation_amount, communication_amount, -1);
64
65   xbt_dynar_t changed_tasks = xbt_dynar_new(sizeof(SD_task_t), NULL);
66   SD_simulate_with_update(-1.0, changed_tasks);
67   xbt_dynar_foreach(changed_tasks, ctr, task) {
68     XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task),
69              SD_task_get_finish_time(task));
70   }
71
72   xbt_dynar_foreach(changed_tasks, ctr, task)
73     SD_task_destroy(task);
74   xbt_dynar_free_container(&changed_tasks);
75
76   xbt_free(hosts);
77   return 0;
78 }