Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e4686cbd261609f21f843333338b3ad08a7d35e1
[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_create_environment(platform_file);
47   }
48   {                             /*   Application deployment */
49     MSG_function_register("test", test);
50     MSG_launch_application(application_file);
51   }
52   res = MSG_main();
53
54   XBT_INFO("Simulation time %g", MSG_get_clock());
55   return res;
56 }
57
58 int main(int argc, char *argv[])
59 {
60   MSG_error_t res = MSG_OK;
61
62 #ifdef _MSC_VER
63   unsigned int prev_exponent_format =
64       _set_output_format(_TWO_DIGIT_EXPONENT);
65 #endif
66
67
68   MSG_global_init(&argc, argv);
69   if (argc < 3) {
70     printf("Usage: %s platform_file deployment_file\n", argv[0]);
71     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
72     exit(1);
73   }
74   res = test_all(argv[1], argv[2]);
75   MSG_clean();
76
77 #ifdef _MSC_VER
78   _set_output_format(prev_exponent_format);
79 #endif
80
81   if (res == MSG_OK)
82     return 0;
83   else
84     return 1;
85 }