1 /* Copyright (c) 2014-2017. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/msg.h"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10 msg_task_t atask = NULL;
12 static int computation_fun(int argc, char* argv[])
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();
22 XBT_INFO("%s:%s task 1 executed %g", host_name, pr_name, clock_end - clock_sta);
24 MSG_task_destroy(atask);
29 atask = MSG_task_create("Task2", 1e10, 1e10, NULL);
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();
36 XBT_INFO("%s:%s task 2 executed %g", host_name, pr_name, clock_end - clock_sta);
38 MSG_task_destroy(atask);
44 static int master_main(int argc, char* argv[])
46 msg_host_t pm0 = MSG_host_by_name("Fafard");
47 msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
50 MSG_process_create("compute", computation_fun, NULL, (msg_host_t)vm0);
52 while (MSG_get_clock() < 100) {
54 XBT_INFO("aTask remaining duration: %g", MSG_task_get_flops_amount(atask));
58 MSG_process_sleep(10000);
63 int main(int argc, char* argv[])
65 MSG_init(&argc, argv);
67 xbt_assert(argc == 2);
68 MSG_create_environment(argv[1]);
70 MSG_process_create("master_", master_main, NULL, MSG_host_by_name("Fafard"));
73 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
75 return !(res == MSG_OK);