Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ce6acfa7e8b9440360e509b1356a686bd88fe50d
[simgrid.git] / examples / msg / chainsend / chainsend.c
1 /* Copyright (c) 2007-2010, 2012-2015. 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 <stdio.h>
8 #include <stdlib.h>
9
10 #include "simgrid/msg.h"        /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
11 #include "xbt/sysdep.h"         /* calloc */
12
13 /* Create a log channel to have nice outputs. */
14 #include "xbt/log.h"
15 #include "xbt/asserts.h"
16
17 #include "iterator.h"
18 #include "messages.h"
19 #include "broadcaster.h"
20 #include "peer.h"
21
22 /** @addtogroup MSG_examples
23  * 
24  *  - <b>chainsend/chainsend.c: Chainsend implementation</b>.
25  */
26
27
28 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chainsend,
29                              "Messages specific for chainsend");
30
31 /*
32  Data structures
33  */
34
35 /* Initialization stuff */
36 msg_error_t test_all(const char *platform_file,
37                      const char *application_file);
38
39
40 /** Test function */
41 msg_error_t test_all(const char *platform_file,
42                      const char *application_file)
43 {
44
45   msg_error_t res = MSG_OK;
46
47
48
49   XBT_DEBUG("test_all");
50
51   /*  Simulation setting */
52   MSG_create_environment(platform_file);
53
54   /* Trace categories */
55   TRACE_category_with_color("host0", "0 0 1");
56   TRACE_category_with_color("host1", "0 1 0");
57   TRACE_category_with_color("host2", "0 1 1");
58   TRACE_category_with_color("host3", "1 0 0");
59   TRACE_category_with_color("host4", "1 0 1");
60   TRACE_category_with_color("host5", "0 0 0");
61   TRACE_category_with_color("host6", "1 1 0");
62   TRACE_category_with_color("host7", "1 1 1");
63   TRACE_category_with_color("host8", "0 1 0");
64
65   /*   Application deployment */
66   MSG_function_register("broadcaster", broadcaster);
67   MSG_function_register("peer", peer);
68
69   MSG_launch_application(application_file);
70
71   res = MSG_main();
72
73   return res;
74 }                               /* end_of_test_all */
75
76
77 /** Main function */
78 int main(int argc, char *argv[])
79 {
80   msg_error_t res = MSG_OK;
81
82 #ifdef _MSC_VER
83   unsigned int prev_exponent_format =
84       _set_output_format(_TWO_DIGIT_EXPONENT);
85 #endif
86
87   MSG_init(&argc, argv);
88
89   res = test_all(argv[1], argv[2]);
90
91   XBT_INFO("Total simulation time: %e", MSG_get_clock());
92
93 #ifdef _MSC_VER
94   _set_output_format(prev_exponent_format);
95 #endif
96
97   if (res == MSG_OK)
98     return 0;
99   else
100     return 1;
101 }                               /* end_of_main */