Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add some _XBT_GNUC_UNUSED to avoid compilation warnings with NDEBUG
[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 static int test(int argc, char *argv[])
18 {
19   double computation_amount = 0.0;
20   double priority = 1.0;
21   m_task_t task = NULL;
22
23   _XBT_GNUC_UNUSED int res = sscanf(argv[1], "%lg", &computation_amount);
24   xbt_assert(res, "Invalid argument %s\n", argv[1]);
25   res = sscanf(argv[2], "%lg", &priority);
26   xbt_assert(res, "Invalid argument %s\n", argv[2]);
27
28   XBT_INFO("Hello! Running a task of size %g with priority %g",
29         computation_amount, priority);
30   task = MSG_task_create("Task", computation_amount, 0.0, NULL);
31   MSG_task_set_priority(task, priority);
32
33   MSG_task_execute(task);
34   MSG_task_destroy(task);
35
36   XBT_INFO("Goodbye now!");
37   return 0;
38 }
39
40 static MSG_error_t test_all(const char *platform_file,
41                             const char *application_file)
42 {
43   MSG_error_t res = MSG_OK;
44
45   {                             /*  Simulation setting */
46     MSG_set_channel_number(1);
47     MSG_create_environment(platform_file);
48   }
49   {                             /*   Application deployment */
50     MSG_function_register("test", test);
51     MSG_launch_application(application_file);
52   }
53   res = MSG_main();
54
55   XBT_INFO("Simulation time %g", MSG_get_clock());
56   return res;
57 }
58
59 int main(int argc, char *argv[])
60 {
61   MSG_error_t res = MSG_OK;
62
63 #ifdef _MSC_VER
64   unsigned int prev_exponent_format =
65       _set_output_format(_TWO_DIGIT_EXPONENT);
66 #endif
67
68
69   MSG_global_init(&argc, argv);
70   if (argc < 3) {
71     printf("Usage: %s platform_file deployment_file\n", argv[0]);
72     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
73     exit(1);
74   }
75   res = test_all(argv[1], argv[2]);
76   MSG_clean();
77
78 #ifdef _MSC_VER
79   _set_output_format(prev_exponent_format);
80 #endif
81
82   if (res == MSG_OK)
83     return 0;
84   else
85     return 1;
86 }