Logo AND Algorithmique Numérique Distribuée

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