Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Chord: update some messages displayed
[simgrid.git] / examples / msg / parallel_contexts / pcontexts2.c
1 #include <msg/msg.h>
2 /* Create a log channel to have nice outputs. */
3 #include "xbt/log.h"
4
5 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
6                              "Messages specific for this msg example");
7 #define MAX_ITER 200000
8 #define WORK 100000
9
10 int master(int argc, char **argv);
11 int slave(int argc, char **argv);
12
13 MSG_error_t test_all(const char *, const char *);
14 int main(int argc, char *argv[]);
15
16 int master(int argc, char** argv)
17 {
18   int i,j, id;
19   m_task_t task;
20   char mailbox[80];
21
22   sscanf(argv[1], "%d", &id);
23   sprintf(mailbox, "slave-%d", id);
24
25   for(i=0; i < MAX_ITER; i++){
26     task = MSG_task_create("test", 100000000, 1, NULL);
27
28     for(j=0; j < WORK; j++);
29
30     MSG_task_send(task, mailbox);
31     XBT_INFO("Task sent to %s", mailbox);
32   }
33
34   return 0;
35 }
36
37 int slave(int argc, char **argv)
38 {
39   int i, id;
40   m_task_t task;
41   char mailbox[80];
42
43   sscanf(argv[1], "%d", &id);
44   sprintf(mailbox, "slave-%d", id);
45
46   for(i=0; i < MAX_ITER; i++){
47     MSG_task_receive(&task, mailbox);
48     XBT_INFO("Task received to %s", mailbox);
49     MSG_task_destroy(task);
50     task=NULL;
51   }
52
53   return 0;
54 }
55
56 /** Test function */
57 MSG_error_t test_all(const char *platform_file,
58                      const char *application_file)
59 {
60   MSG_error_t res = MSG_OK;
61
62   /* MSG_config("workstation/model","KCCFLN05"); */
63   {                             /*  Simulation setting */
64     MSG_set_channel_number(0);
65     MSG_create_environment(platform_file);
66   }
67   {                             /*   Application deployment */
68     MSG_function_register("master", master);
69     MSG_function_register("slave", slave);
70     MSG_launch_application(application_file);
71   }
72   res = MSG_main();
73
74   XBT_INFO("Simulation time %g", MSG_get_clock());
75   return res;
76 }                               /* end_of_test_all */
77
78
79 /** Main function */
80 int main(int argc, char *argv[])
81 {
82   MSG_error_t res = MSG_OK;
83
84   MSG_global_init(&argc, argv);
85   if (argc < 3) {
86     printf("Usage: %s platform_file deployment_file\n", argv[0]);
87     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
88     exit(1);
89   }
90   res = test_all(argv[1], argv[2]);
91   MSG_clean();
92
93   if (res == MSG_OK)
94     return 0;
95   else
96     return 1;
97 }                               /* end_of_main */