Logo AND Algorithmique Numérique Distribuée

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