Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cb463b712a509a745443f3cfda10761cb9f6d2f5
[simgrid.git] / examples / msg / task-priority / task-priority.c
1 /* Copyright (c) 2007-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/msg.h"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
9
10 /** @addtogroup MSG_examples
11  * 
12  * @section msg_ex_misc Miscellaneous
13  * - <b>Task priorities: task-priority/task-priority.c</b>. This examples demonstrates the use of
14  *   @ref MSG_task_set_priority to change the computation priority of a given task.
15  */
16
17 static int test(int argc, char *argv[])
18 {
19   double computation_amount = xbt_str_parse_double(argv[1], "Invalid argument: %s");
20   double priority = xbt_str_parse_double(argv[2], "Invalid argument: %s");
21
22   XBT_INFO("Hello! Running a task of size %g with priority %g", computation_amount, priority);
23   msg_task_t task = MSG_task_create("Task", computation_amount, 0.0, NULL);
24   MSG_task_set_priority(task, priority);
25
26   MSG_task_execute(task);
27   MSG_task_destroy(task);
28
29   XBT_INFO("Goodbye now!");
30   return 0;
31 }
32
33 int main(int argc, char *argv[])
34 {
35   msg_error_t res = MSG_OK;
36
37   MSG_init(&argc, argv);
38   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
39              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
40
41   MSG_create_environment(argv[1]);
42   MSG_function_register("test", test);
43   MSG_launch_application(argv[2]);
44
45   res = MSG_main();
46
47   XBT_INFO("Simulation time %g", MSG_get_clock());
48
49   return res != MSG_OK;
50 }