Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use automated call to sd_exit
[simgrid.git] / teshsuite / simdag / basic6 / basic6.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/asserts.h"
9 #include "xbt/log.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(basic6, sd, "SimDag test basic6");
12 /* test scheduling 2 tasks at the same time without artificial dependencies */
13
14 /* Basic SimDag Test 6
15  * Scenario:
16  *   - Schedule two parallel tasks concurrently on a P2P platform
17  *   - Hosts computes 1B per second
18  * Computing power is shared between tasks.
19  * Simulated time should be:
20  *          1/(1/2) = 2 seconds
21  */
22
23 int main(int argc, char **argv)
24 {
25   double comm_cost[] = { 0.0, 0.0, 0.0, 0.0 };
26   double comp_cost[] = { 1.0 };
27   xbt_dynar_t ret    = xbt_dynar_new(sizeof(SD_task_t), NULL);
28
29   SD_init(&argc, argv);
30   SD_create_environment(argv[1]);
31
32   SD_task_t taskA = SD_task_create("Task A", NULL, 1.0);
33   SD_task_t taskB = SD_task_create("Task B", NULL, 1.0);
34
35   sg_host_t *hosts = sg_host_list();
36   SD_task_schedule(taskA, 1, hosts, comp_cost, comm_cost, -1.0);
37   SD_task_schedule(taskB, 1, hosts, comp_cost, comm_cost, -1.0);
38   xbt_free(hosts);
39
40   SD_simulate_with_update(-1.0, ret);
41   xbt_assert(xbt_dynar_length(ret) == 2, "I was expecting the completion of 2 tasks, but I got %lu instead",
42              xbt_dynar_length(ret));
43   SD_task_destroy(taskA);
44   SD_task_destroy(taskB);
45   xbt_dynar_free(&ret);
46
47   XBT_INFO("Simulation time: %f", SD_get_clock());
48
49   return 0;
50 }