Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix dependency issue to prevent problems with make -jx
[simgrid.git] / teshsuite / msg / cloud-two-tasks / cloud-two-tasks.c
1 /* Copyright (c) 2014-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/msg.h"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
9
10 msg_task_t atask = NULL;
11
12 static int computation_fun(int argc, char* argv[])
13 {
14   const char* pr_name   = MSG_process_get_name(MSG_process_self());
15   const char* host_name = MSG_host_get_name(MSG_host_self());
16   atask                 = MSG_task_create("Task1", 1e9, 1e9, NULL);
17   double clock_sta      = MSG_get_clock();
18   XBT_INFO("%s:%s task 1 created %g", host_name, pr_name, clock_sta);
19   MSG_task_execute(atask);
20   double clock_end = MSG_get_clock();
21
22   XBT_INFO("%s:%s task 1 executed %g", host_name, pr_name, clock_end - clock_sta);
23
24   MSG_task_destroy(atask);
25   atask = NULL;
26
27   MSG_process_sleep(1);
28
29   atask = MSG_task_create("Task2", 1e10, 1e10, NULL);
30
31   clock_sta = MSG_get_clock();
32   XBT_INFO("%s:%s task 2 created %g", host_name, pr_name, clock_sta);
33   MSG_task_execute(atask);
34   clock_end = MSG_get_clock();
35
36   XBT_INFO("%s:%s task 2 executed %g", host_name, pr_name, clock_end - clock_sta);
37
38   MSG_task_destroy(atask);
39   atask = NULL;
40
41   return 0;
42 }
43
44 static int master_main(int argc, char* argv[])
45 {
46   msg_host_t pm0 = MSG_host_by_name("Fafard");
47   msg_vm_t vm0   = MSG_vm_create_core(pm0, "VM0");
48   MSG_vm_start(vm0);
49
50   MSG_process_create("compute", computation_fun, NULL, (msg_host_t)vm0);
51
52   while (MSG_get_clock() < 100) {
53     if (atask != NULL)
54       XBT_INFO("aTask remaining duration: %g", MSG_task_get_flops_amount(atask));
55     MSG_process_sleep(1);
56   }
57
58   MSG_process_sleep(10000);
59   MSG_vm_destroy(vm0);
60   return 1;
61 }
62
63 int main(int argc, char* argv[])
64 {
65   MSG_init(&argc, argv);
66
67   xbt_assert(argc == 2);
68   MSG_create_environment(argv[1]);
69
70   MSG_process_create("master_", master_main, NULL, MSG_host_by_name("Fafard"));
71
72   int res = MSG_main();
73   XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
74
75   return !(res == MSG_OK);
76 }