Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SimDag Revolution: SD_workstation becomes sg_host
[simgrid.git] / teshsuite / simdag / basic / basic2.c
1 /* Copyright (c) 2007-2012, 2014-2015. 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 "simgrid/simdag.h"
10 #include "xbt/log.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(basic2, sd, "SimDag test basic2");
13
14 /* Basic SimDag Test 2
15  * Scenario:
16  *   - Create a no-op Init task
17  *   - Create two communication tasks: 1GB and 100MB
18  *   - Schedule them concurrently on the two hosts of the platform
19  * The two communications occur simultaneously. They share the network for the
20  * duration of the shortest one, then the longest one has the full bandwidth.
21  * Simulated time should be:
22  *          1e8/(1/2*1.25e8) + 9e8/1.25e8) + 1e-4 = 8.8001 seconds
23  */
24 int main(int argc, char **argv)
25 {
26
27   SD_task_t taskInit;
28   SD_task_t taskA;
29   SD_task_t taskB;
30
31   const sg_host_t *workstation;
32
33   double communication_amount1 = 1e9;
34   double communication_amount2 = 1e8;
35   double no_cost = 0.0;
36
37   /* initialization of SD */
38   SD_init(&argc, argv);
39
40   /* creation of the environment */
41   SD_create_environment(argv[1]);
42
43   /* creation of the tasks and their dependencies */
44   taskInit = SD_task_create("Init", NULL, 1.0);
45   taskA = SD_task_create("Task Comm A", NULL, 1.0);
46   taskB = SD_task_create("Task Comm B", NULL, 1.0);
47
48
49   /* scheduling parameters */
50
51   workstation = sg_host_list();
52
53   /* let's launch the simulation! */
54   SD_task_schedule(taskInit, 1, sg_host_list(), &no_cost,
55                    &no_cost, -1.0);
56   SD_task_schedule(taskA, 1, &workstation[0], &no_cost,
57                    &communication_amount1, -1.0);
58   SD_task_schedule(taskB, 1, &workstation[1], &no_cost,
59                    &communication_amount2, -1.0);
60
61   SD_task_dependency_add(NULL, NULL, taskInit, taskA);
62   SD_task_dependency_add(NULL, NULL, taskInit, taskB);
63
64   SD_simulate(-1.0);
65   SD_task_destroy(taskA);
66   SD_task_destroy(taskB);
67   SD_task_destroy(taskInit);
68
69   XBT_INFO("Simulation time: %f", SD_get_clock());
70
71   SD_exit();
72   return 0;
73 }