1 /* Copyright (c) 2014-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/msg.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11 msg_task_t atask = NULL;
13 static int computation_fun(int argc, char *argv[])
15 const char *pr_name = MSG_process_get_name(MSG_process_self());
16 const char *host_name = MSG_host_get_name(MSG_host_self());
17 atask = MSG_task_create("Task1", 1e9, 1e9, NULL);
18 double clock_sta = MSG_get_clock();
19 XBT_INFO("%s:%s task 1 created %g", host_name, pr_name, clock_sta);
20 MSG_task_execute(atask);
21 double clock_end = MSG_get_clock();
23 XBT_INFO("%s:%s task 1 executed %g", host_name, pr_name, clock_end - clock_sta);
25 MSG_task_destroy(atask);
30 atask = MSG_task_create("Task2", 1e10, 1e10, NULL);
32 clock_sta = MSG_get_clock();
33 XBT_INFO("%s:%s task 2 created %g", host_name, pr_name, clock_sta);
34 MSG_task_execute(atask);
35 clock_end = MSG_get_clock();
37 XBT_INFO("%s:%s task 2 executed %g", host_name, pr_name, clock_end - clock_sta);
39 MSG_task_destroy(atask);
45 static void launch_computation_worker(msg_host_t host)
47 const char *pr_name = "compute";
48 char **argv = xbt_new(char *, 2);
49 argv[0] = xbt_strdup(pr_name);
52 MSG_process_create_with_arguments(pr_name, computation_fun, NULL, host, 1, argv);
55 static int master_main(int argc, char *argv[])
57 xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
58 msg_host_t pm0 = MSG_host_by_name("Fafard");
59 msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
62 launch_computation_worker(vm0);
64 while(MSG_get_clock()<100) {
66 XBT_INFO("aTask remaining duration: %g", MSG_task_get_flops_amount(atask));
70 MSG_process_sleep(10000);
72 xbt_dynar_free(&hosts_dynar);
76 int main(int argc, char *argv[]){
77 MSG_init(&argc, argv);
79 xbt_assert(argc == 2);
80 MSG_create_environment(argv[1]);
82 MSG_process_create("master_", master_main, NULL, MSG_host_by_name("Fafard"));
85 XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
87 return !(res == MSG_OK);