1 /* Copyright (c) 2007-2012. The SimGrid Team.
2 * All rights reserved. */
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. */
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 */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15 "Messages specific for this msg example");
17 /** @addtogroup MSG_examples
19 * - <b>priority/priority.c</b>: Demonstrates the use of @ref
20 * MSG_task_set_priority to change the computation priority of a
25 static int test(int argc, char *argv[])
27 double computation_amount = 0.0;
28 double priority = 1.0;
29 msg_task_t task = NULL;
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]);
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);
41 MSG_task_execute(task);
42 MSG_task_destroy(task);
44 XBT_INFO("Goodbye now!");
48 static msg_error_t test_all(const char *platform_file,
49 const char *application_file)
51 msg_error_t res = MSG_OK;
53 { /* Simulation setting */
54 MSG_create_environment(platform_file);
56 { /* Application deployment */
57 MSG_function_register("test", test);
58 MSG_launch_application(application_file);
62 XBT_INFO("Simulation time %g", MSG_get_clock());
66 int main(int argc, char *argv[])
68 msg_error_t res = MSG_OK;
71 unsigned int prev_exponent_format =
72 _set_output_format(_TWO_DIGIT_EXPONENT);
76 MSG_init(&argc, argv);
78 printf("Usage: %s platform_file deployment_file\n", argv[0]);
79 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
82 res = test_all(argv[1], argv[2]);
85 _set_output_format(prev_exponent_format);