Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8eaf7313e1ef3654c86dea184e8d6e0b14001f4c
[simgrid.git] / examples / msg / priority / priority.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved.        */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include <stdio.h>
9 #include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
10 #include "xbt/sysdep.h"         /* calloc, printf */
11
12 /* Create a log channel to have nice outputs. */
13 #include "xbt/log.h"
14 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
16                              "Messages specific for this msg example");
17
18 static int test(int argc, char *argv[])
19 {
20   double computation_amount = 0.0;
21   double priority = 1.0;
22   m_task_t task = NULL;
23
24
25   xbt_assert1(sscanf(argv[1], "%lg", &computation_amount),
26               "Invalid argument %s\n", argv[1]);
27   xbt_assert1(sscanf(argv[2], "%lg", &priority),
28               "Invalid argument %s\n", argv[2]);
29
30   INFO2("Hello! Running a task of size %g with priority %g",
31         computation_amount, priority);
32   task = MSG_task_create("Task", computation_amount, 0.0, NULL);
33   MSG_task_set_priority(task, priority);
34
35   MSG_task_execute(task);
36
37
38   INFO0("Goodbye now!");
39   return 0;
40 }
41
42 static MSG_error_t test_all(const char *platform_file,
43                             const char *application_file)
44 {
45   MSG_error_t res = MSG_OK;
46
47   {                             /*  Simulation setting */
48     MSG_set_channel_number(1);
49     MSG_paje_output("msg_test.trace");
50     MSG_create_environment(platform_file);
51   }
52   {                             /*   Application deployment */
53     MSG_function_register("test", test);
54     MSG_launch_application(application_file);
55   }
56   res = MSG_main();
57
58   INFO1("Simulation time %g", MSG_get_clock());
59   return res;
60 }
61
62 int main(int argc, char *argv[])
63 {
64   MSG_error_t res = MSG_OK;
65
66 #ifdef _MSC_VER
67   unsigned int prev_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
68 #endif
69
70
71   MSG_global_init(&argc, argv);
72   if (argc < 3) {
73     printf("Usage: %s platform_file deployment_file\n", argv[0]);
74     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
75     exit(1);
76   }
77   res = test_all(argv[1], argv[2]);
78   MSG_clean();
79
80 #ifdef _MSC_VER
81   _set_output_format(prev_exponent_format);
82 #endif
83
84   if (res == MSG_OK)
85     return 0;
86   else
87     return 1;
88 }