Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c061e6ac01948fc866be8b496ba1953a616df74d
[simgrid.git] / teshsuite / simdag / basic4 / basic4.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 "simgrid/simdag.h"
8 #include "xbt/log.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(basic4, sd, "SimDag test basic4");
11
12 /* Basic SimDag Test 4
13  * Scenario:
14  *   - Create a chain of tasks (Init, A, Fin)
15  *   - Have a 1B communication between two no-op tasks.
16  * Verify that the tasks are actually simulated in the right order.
17  * The simulated time should be equal to the network latency: 0.0001 seconds.
18  */
19 int main(int argc, char **argv)
20 {
21   /* scheduling parameters */
22   double no_cost[] = { 0., 0., 0., 0. };
23   double amount[] = { 0., 1., 0., 0. };
24
25   /* SD initialization */
26   SD_init(&argc, argv);
27
28   /* creation of the environment */
29   SD_create_environment(argv[1]);
30
31   /* creation of the tasks and their dependencies */
32   SD_task_t taskInit = SD_task_create("Task Init", NULL, 1.0);
33   SD_task_t taskA = SD_task_create("Task A", NULL, 1.0);
34   SD_task_t taskFin = SD_task_create("Task Fin", NULL, 1.0);
35
36   SD_task_dependency_add(NULL, NULL, taskInit, taskA);
37   SD_task_dependency_add(NULL, NULL, taskA, taskFin);
38
39   sg_host_t *hosts = sg_host_list();
40   SD_task_schedule(taskInit, 1, hosts, no_cost, no_cost, -1.0);
41   SD_task_schedule(taskA, 2, hosts, no_cost, amount, -1.0);
42   SD_task_schedule(taskFin, 1, hosts, no_cost, no_cost, -1.0);
43   xbt_free(hosts);
44
45   /* let's launch the simulation! */
46   SD_simulate(-1.0);
47   SD_task_destroy(taskInit);
48   SD_task_destroy(taskA);
49   SD_task_destroy(taskFin);
50
51   XBT_INFO("Simulation time: %f", SD_get_clock());
52
53   SD_exit();
54   return 0;
55 }