1 /* Copyright (c) 2007, 2008, 2009, 2010. 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 static int test(int argc, char *argv[])
19 double computation_amount = 0.0;
20 double priority = 1.0;
23 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]);
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);
33 MSG_task_execute(task);
34 MSG_task_destroy(task);
36 XBT_INFO("Goodbye now!");
40 static MSG_error_t test_all(const char *platform_file,
41 const char *application_file)
43 MSG_error_t res = MSG_OK;
45 { /* Simulation setting */
46 MSG_set_channel_number(1);
47 MSG_create_environment(platform_file);
49 { /* Application deployment */
50 MSG_function_register("test", test);
51 MSG_launch_application(application_file);
55 XBT_INFO("Simulation time %g", MSG_get_clock());
59 int main(int argc, char *argv[])
61 MSG_error_t res = MSG_OK;
64 unsigned int prev_exponent_format =
65 _set_output_format(_TWO_DIGIT_EXPONENT);
69 MSG_global_init(&argc, argv);
71 printf("Usage: %s platform_file deployment_file\n", argv[0]);
72 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
75 res = test_all(argv[1], argv[2]);
79 _set_output_format(prev_exponent_format);