Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill tracing-gtnets examples
[simgrid.git] / examples / msg / priority / 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 = 0.0;
19   double priority = 1.0;
20   msg_task_t task = NULL;
21
22   XBT_ATTRIB_UNUSED int res = sscanf(argv[1], "%lg", &computation_amount);
23   xbt_assert(res, "Invalid argument %s\n", argv[1]);
24   res = sscanf(argv[2], "%lg", &priority);
25   xbt_assert(res, "Invalid argument %s\n", argv[2]);
26
27   XBT_INFO("Hello! Running a task of size %g with priority %g", computation_amount, priority);
28   task = MSG_task_create("Task", computation_amount, 0.0, NULL);
29   MSG_task_set_priority(task, priority);
30
31   MSG_task_execute(task);
32   MSG_task_destroy(task);
33
34   XBT_INFO("Goodbye now!");
35   return 0;
36 }
37
38 int main(int argc, char *argv[])
39 {
40   msg_error_t res = MSG_OK;
41
42   MSG_init(&argc, argv);
43   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
44              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
45
46   MSG_create_environment(argv[1]);
47   MSG_function_register("test", test);
48   MSG_launch_application(argv[2]);
49
50   res = MSG_main();
51
52   XBT_INFO("Simulation time %g", MSG_get_clock());
53
54   return res != MSG_OK;
55 }