Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
090cea9149313ed0812b46279ddf5689726e60c3
[simgrid.git] / examples / msg / start_kill_time / sk_time.c
1 /* Copyright (c) 2007, 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 "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
8 #include "xbt/sysdep.h"         /* calloc */
9
10 /* Create a log channel to have nice outputs. */
11 #include "xbt/log.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
13                              "Messages specific for this msg example");
14
15 /** Lazy guy function. This process suspends itself asap.  */
16 static int slave(int argc, char *argv[])
17 {
18   XBT_INFO("Hello!");
19   MSG_process_sleep(10.0);
20   XBT_INFO("OK, goodbye now.");
21   return 0;
22 }                               /* end_of_lazy_guy */
23
24 static int master(int argc, char *argv[])
25 {
26   m_process_t bob = NULL;
27
28   XBT_INFO("Hello!");
29   MSG_process_sleep(10.0);
30   XBT_INFO("OK, goodbye now.");
31   return 0;
32 }                               /* end_of_dram_master */
33
34 /** Test function */
35 static MSG_error_t test_all(const char *platform_file,
36                             const char *application_file)
37 {
38   MSG_error_t res = MSG_OK;
39
40   MSG_create_environment(platform_file);
41   MSG_function_register("master", master);
42   MSG_function_register("slave", slave);
43   MSG_launch_application(application_file);
44
45   res = MSG_main();
46
47   XBT_INFO("Simulation time %g", MSG_get_clock());
48   return res;
49 }                               /* end_of_test_all */
50
51
52 /** Main function */
53 int main(int argc, char *argv[])
54 {
55   MSG_error_t res = MSG_OK;
56
57   MSG_global_init(&argc, argv);
58   if (argc < 3) {
59     XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
60     XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
61               argv[0]);
62     exit(1);
63   }
64   test_all(argv[1], argv[2]);
65   res = MSG_clean();
66
67   if (res == MSG_OK)
68     return 0;
69   else
70     return 1;
71 }                               /* end_of_main */