Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / surf / surf_usage / surf_usage2.cpp
1 /* A few basic tests for the surf library                                   */
2
3 /* Copyright (c) 2004-2015. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "simgrid/sg_config.h"
10 #include "surf/surf.h"
11 #include "src/surf/surf_interface.hpp"
12 #include "src/surf/cpu_interface.hpp"
13
14 #include "xbt/log.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
16
17 int main(int argc, char **argv)
18 {
19   sg_host_t hostA = NULL;
20   sg_host_t hostB = NULL;
21   double now = -1.0;
22   int running;
23
24   surf_init(&argc, argv);       /* Initialize some common structures */
25
26   xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02");
27   xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01");
28
29   xbt_assert(argc >1, "Usage : %s platform.txt\n", argv[0]);
30   parse_platform_file(argv[1]);
31
32   /*********************** HOST ***********************************/
33   hostA = sg_host_by_name("Cpu A");
34   hostB = sg_host_by_name("Cpu B");
35
36   /* Let's check that those two processors exist */
37   XBT_DEBUG("%s : %p", sg_host_get_name(hostA), hostA);
38   XBT_DEBUG("%s : %p", sg_host_get_name(hostB), hostB);
39
40   /* Let's do something on it */
41   hostA->pimpl_cpu->execution_start(1000.0);
42   hostB->pimpl_cpu->execution_start(1000.0);
43   surf_host_sleep(hostB, 7.32);
44
45   surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0);
46
47   surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
48   do {
49     surf_action_t action = NULL;
50     unsigned int iter;
51     surf_model_t model = NULL;
52     running = 0;
53
54     now = surf_get_clock();
55     XBT_INFO("Next Event : %g", now);
56
57     xbt_dynar_foreach(all_existing_models, iter, model) {
58       if (surf_model_running_action_set_size((surf_model_t)model)) {
59         XBT_DEBUG("\t Running that model");
60         running = 1;
61       }
62       while ((action = surf_model_extract_failed_action_set((surf_model_t)model))) {
63         XBT_INFO("   * Done Action");
64         XBT_DEBUG("\t * Failed Action: %p", action);
65         action->unref();
66       }
67       while ((action = surf_model_extract_done_action_set((surf_model_t)model))) {
68         XBT_INFO("   * Done Action");
69         XBT_DEBUG("\t * Done Action: %p", action);
70         action->unref();
71       }
72     }
73   } while (running && surf_solve(-1.0) >= 0.0);
74
75   XBT_INFO("Simulation Terminated");
76   surf_exit();
77   return 0;
78 }