Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1b293b396c9deac427f788b1f2c6368b83957d38
[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   XBT_INFO("Hello!");
27   MSG_process_sleep(10.0);
28   XBT_INFO("OK, goodbye now.");
29   return 0;
30 }                               /* end_of_dram_master */
31
32 /** Test function */
33 static MSG_error_t test_all(const char *platform_file,
34                             const char *application_file)
35 {
36   MSG_error_t res = MSG_OK;
37
38   MSG_create_environment(platform_file);
39   MSG_function_register("master", master);
40   MSG_function_register("slave", slave);
41   MSG_launch_application(application_file);
42
43   res = MSG_main();
44
45   XBT_INFO("Simulation time %g", MSG_get_clock());
46   return res;
47 }                               /* end_of_test_all */
48
49
50 /** Main function */
51 int main(int argc, char *argv[])
52 {
53   MSG_error_t res = MSG_OK;
54
55   MSG_init(&argc, argv);
56   if (argc < 3) {
57     XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
58     XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
59               argv[0]);
60     exit(1);
61   }
62   test_all(argv[1], argv[2]);
63   res = MSG_clean();
64
65   if (res == MSG_OK)
66     return 0;
67   else
68     return 1;
69 }                               /* end_of_main */