Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simdag,dotloader] clean the valgrind output
[simgrid.git] / examples / msg / priority / priority.c
1 /* Copyright (c) 2007, 2008, 2009, 2010. 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 <stdio.h>
8 #include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h"         /* calloc, printf */
10
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15                              "Messages specific for this msg example");
16
17 /** @addtogroup MSG_examples
18  * 
19  * - <b>priority/priority.c</b>: Demonstrates the use of @ref
20  *   MSG_task_set_priority to change the computation priority of a
21  *   given task.
22  *
23  */
24
25 static int test(int argc, char *argv[])
26 {
27   double computation_amount = 0.0;
28   double priority = 1.0;
29   m_task_t task = NULL;
30
31   _XBT_GNUC_UNUSED int res = sscanf(argv[1], "%lg", &computation_amount);
32   xbt_assert(res, "Invalid argument %s\n", argv[1]);
33   res = sscanf(argv[2], "%lg", &priority);
34   xbt_assert(res, "Invalid argument %s\n", argv[2]);
35
36   XBT_INFO("Hello! Running a task of size %g with priority %g",
37         computation_amount, priority);
38   task = MSG_task_create("Task", computation_amount, 0.0, NULL);
39   MSG_task_set_priority(task, priority);
40
41   MSG_task_execute(task);
42   MSG_task_destroy(task);
43
44   XBT_INFO("Goodbye now!");
45   return 0;
46 }
47
48 static MSG_error_t test_all(const char *platform_file,
49                             const char *application_file)
50 {
51   MSG_error_t res = MSG_OK;
52
53   {                             /*  Simulation setting */
54     MSG_create_environment(platform_file);
55   }
56   {                             /*   Application deployment */
57     MSG_function_register("test", test);
58     MSG_launch_application(application_file);
59   }
60   res = MSG_main();
61
62   XBT_INFO("Simulation time %g", MSG_get_clock());
63   return res;
64 }
65
66 int main(int argc, char *argv[])
67 {
68   MSG_error_t res = MSG_OK;
69
70 #ifdef _MSC_VER
71   unsigned int prev_exponent_format =
72       _set_output_format(_TWO_DIGIT_EXPONENT);
73 #endif
74
75
76   MSG_global_init(&argc, argv);
77   if (argc < 3) {
78     printf("Usage: %s platform_file deployment_file\n", argv[0]);
79     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
80     exit(1);
81   }
82   res = test_all(argv[1], argv[2]);
83   MSG_clean();
84
85 #ifdef _MSC_VER
86   _set_output_format(prev_exponent_format);
87 #endif
88
89   if (res == MSG_OK)
90     return 0;
91   else
92     return 1;
93 }