Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fb469c9266d4911f2829149ae12eaa96d9bc5273
[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_create_environment(platform_file);
65   }
66   {                             /*   Application deployment */
67     MSG_function_register("master", master);
68     MSG_function_register("slave", slave);
69     MSG_launch_application(application_file);
70   }
71   res = MSG_main();
72
73   XBT_INFO("Simulation time %g", MSG_get_clock());
74   return res;
75 }                               /* end_of_test_all */
76
77
78 /** Main function */
79 int main(int argc, char *argv[])
80 {
81   MSG_error_t res = MSG_OK;
82
83   MSG_global_init(&argc, argv);
84   if (argc < 3) {
85     printf("Usage: %s platform_file deployment_file\n", argv[0]);
86     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
87     exit(1);
88   }
89   res = test_all(argv[1], argv[2]);
90   MSG_clean();
91
92   if (res == MSG_OK)
93     return 0;
94   else
95     return 1;
96 }                               /* end_of_main */