Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make these example files compile
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 26 Jan 2017 21:19:44 +0000 (22:19 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 26 Jan 2017 21:20:10 +0000 (22:20 +0100)
.gitignore
doc/msg-tuto-src/Makefile [new file with mode: 0644]
doc/msg-tuto-src/masterworker1.c
doc/msg-tuto-src/masterworker2.c
doc/msg-tuto-src/masterworker3.c
doc/msg-tuto-src/masterworker4.c

index 477d17a..d353406 100644 (file)
@@ -115,6 +115,10 @@ tags
 callgrind.out.*
 ### Examples and traces
 *.exe
 callgrind.out.*
 ### Examples and traces
 *.exe
+doc/msg-tuto-src/masterworker1
+doc/msg-tuto-src/masterworker2
+doc/msg-tuto-src/masterworker3
+doc/msg-tuto-src/masterworker4
 examples/msg/actions-comm/actions-comm
 examples/msg/actions-storage/actions-storage
 examples/msg/async-wait/async-wait
 examples/msg/actions-comm/actions-comm
 examples/msg/actions-storage/actions-storage
 examples/msg/async-wait/async-wait
diff --git a/doc/msg-tuto-src/Makefile b/doc/msg-tuto-src/Makefile
new file mode 100644 (file)
index 0000000..76f6084
--- /dev/null
@@ -0,0 +1,41 @@
+# This Makefile is specifically tailored for the binaries of this tutorial.\r
+\r
+# For your own project, you should use the one provided at \r
+# http://simgrid.gforge.inria.fr/simgrid/latest/doc/install_yours.html\r
+\r
+# Some configuration\r
+SIMGRID_INSTALL_PATH = /opt/simgrid # Where you installed simgrid\r
+CC = gcc                            # Your compiler (on Mac, use clang instead)\r
+\r
+# No change needed bellow for this tutorial.\r
+############################################################################\r
+\r
+all: masterworker1 masterworker2 masterworker3 masterworker4\r
+masterworker1: masterworker1.o\r
+masterworker2: masterworker2.o\r
+masterworker3: masterworker3.o\r
+masterworker4: masterworker4.o\r
+\r
+WARNING = -Wshadow -Wcast-align -Waggregate-return -Wmissing-prototypes \\r
+          -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes \\r
+          -Wmissing-declarations -Wmissing-noreturn -Wredundant-decls \\r
+         -Wnested-externs -Wpointer-arith -Wwrite-strings\r
+\r
+# CFLAGS = -g -O0 $(WARNINGS) # Use this line to make debugging easier\r
+CFLAGS = -g -O2 $(WARNINGS) # Use this line to get better performance\r
+\r
+# No change should be mandated past that line\r
+#############################################\r
+# The following are implicit rules, used by default to actually build\r
+# the targets for which you listed the dependencies above.\r
+\r
+# The blanks before the $(CC) must be a Tab char, not spaces\r
+%: %.o\r
+       $(CC) -L$(strip $(SIMGRID_INSTALL_PATH))/lib/    $(CFLAGS) $^ -lsimgrid -o $@\r
+%.o: %.c\r
+       $(CC) -I$(strip $(SIMGRID_INSTALL_PATH))/include $(CFLAGS) -c -o $@ $<\r
+       \r
+clean:\r
+       rm -f *.o *~\r
+.PHONY: clean\r
+               \r
index 4c43065..89ad922 100644 (file)
@@ -18,7 +18,10 @@ static char * build_channel_name(char *buffer, const char *sender, const char* r
   return buffer;
 }
 
   return buffer;
 }
 
-/** Emitter function  */
+/* forward definitions */
+static int master(int argc, char* argv[]);
+static int worker(int argc, char* argv[]);
+
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;
@@ -28,8 +31,6 @@ static int master(int argc, char *argv[])
   char *master_name = (char *) MSG_host_get_name(host_self);
   char channel[1024];
 
   char *master_name = (char *) MSG_host_get_name(host_self);
   char channel[1024];
 
-  int i;
-
   long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");    /** - Number of tasks      */
   double comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");  /** - Task compute cost    */
   double comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");  /** - Task communication size */
   long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");    /** - Number of tasks      */
   double comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");  /** - Task compute cost    */
   double comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");  /** - Task communication size */
@@ -39,9 +40,9 @@ static int master(int argc, char *argv[])
 
     todo = xbt_new0(msg_task_t, number_of_tasks);
 
 
     todo = xbt_new0(msg_task_t, number_of_tasks);
 
-    for (i = 0; i < number_of_tasks; i++) {
+    for (int i = 0; i < number_of_tasks; i++) {
       sprintf(sprintf_buffer, "Task_%d", i);
       sprintf(sprintf_buffer, "Task_%d", i);
-      todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
+      todo[i] = MSG_task_create(sprintf_buffer, comp_size, comm_size, NULL);
     }
   }
 
     }
   }
 
@@ -49,21 +50,21 @@ static int master(int argc, char *argv[])
     workers_count = MSG_get_host_number();
     workers = xbt_dynar_to_array(MSG_hosts_as_dynar());
 
     workers_count = MSG_get_host_number();
     workers = xbt_dynar_to_array(MSG_hosts_as_dynar());
 
-    for (i = 0; i < workers_count; i++)
+    for (int i = 0; i < workers_count; i++)
       if(host_self == workers[i]) {
          workers[i] = workers[workers_count-1];
          workers_count--;
          break;
       }
 
       if(host_self == workers[i]) {
          workers[i] = workers[workers_count-1];
          workers_count--;
          break;
       }
 
-    for (i = 0; i < workers_count; i++)
-  MSG_process_create("worker", worker, master_name, workers[i]);
+    for (int i = 0; i < workers_count; i++)
+      MSG_process_create("worker", worker, master_name, workers[i]);
   }
 
   XBT_INFO("Got %d workers and %Ld tasks to process", workers_count, number_of_tasks);
 
   }
 
   XBT_INFO("Got %d workers and %Ld tasks to process", workers_count, number_of_tasks);
 
-  for (i = 0; i < number_of_tasks; i++) {
-    build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count]));
+  for (int i = 0; i < number_of_tasks; i++) {
+    build_channel_name(channel, master_name, MSG_host_get_name(workers[i % workers_count]));
 
     XBT_INFO("Sending \"%s\" to channel \"%s\"", todo[i]->name, channel);
 
 
     XBT_INFO("Sending \"%s\" to channel \"%s\"", todo[i]->name, channel);
 
@@ -72,7 +73,7 @@ static int master(int argc, char *argv[])
   }
 
   XBT_INFO ("All tasks have been dispatched. Let's tell everybody the computation is over.");
   }
 
   XBT_INFO ("All tasks have been dispatched. Let's tell everybody the computation is over.");
-  for (i = 0; i < workers_count; i++) {
+  for (int i = 0; i < workers_count; i++) {
     msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE);
     MSG_task_send(finalize, build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count])));
   }
     msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE);
     MSG_task_send(finalize, build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count])));
   }
@@ -87,15 +88,14 @@ static int master(int argc, char *argv[])
 static int worker(int argc, char *argv[])
 {
   msg_task_t task = NULL;
 static int worker(int argc, char *argv[])
 {
   msg_task_t task = NULL;
-  XBT_ATTRIB_UNUSED int res;
   char channel[1024];
 
   char channel[1024];
 
-  build_channel_name(channel,MSG_process_get_data(MSG_process_self()), MSG_host_get_name(MSG_host_self()));
+  build_channel_name(channel, MSG_process_get_data(MSG_process_self()), MSG_host_get_name(MSG_host_self()));
 
   XBT_INFO("Receiving on channel \"%s\"", channel);
 
   while (1) {
 
   XBT_INFO("Receiving on channel \"%s\"", channel);
 
   while (1) {
-    res = MSG_task_receive(&(task),channel);
+    int res = MSG_task_receive(&(task), channel);
     xbt_assert(res == MSG_OK, "MSG_task_receive failed");
     
     XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
     xbt_assert(res == MSG_OK, "MSG_task_receive failed");
     
     XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
@@ -117,7 +117,6 @@ static int worker(int argc, char *argv[])
 /** Main function */
 int main(int argc, char *argv[])
 {
 /** Main function */
 int main(int argc, char *argv[])
 {
-  msg_error_t res = MSG_OK;
 
   MSG_init(&argc, argv);
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
 
   MSG_init(&argc, argv);
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
@@ -130,7 +129,7 @@ int main(int argc, char *argv[])
     MSG_function_register("worker", worker);
     MSG_launch_application(argv[2]);
   }
     MSG_function_register("worker", worker);
     MSG_launch_application(argv[2]);
   }
-  res = MSG_main();
+  msg_error_t res = MSG_main();
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return (res != MSG_OK);
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return (res != MSG_OK);
index 346953a..3a36097 100644 (file)
@@ -18,7 +18,10 @@ static char * build_channel_name(char *buffer, const char *sender, const char* r
   return buffer;
 }
 
   return buffer;
 }
 
-/** Master function  */
+/* forward definitions */
+static int master(int argc, char* argv[]);
+static int worker(int argc, char* argv[]);
+
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;
@@ -28,7 +31,6 @@ static int master(int argc, char *argv[])
   char *master_name = (char *) MSG_host_get_name(host_self);
   char channel[1024];
 
   char *master_name = (char *) MSG_host_get_name(host_self);
   char channel[1024];
 
-  int i;
   double timeout   = xbt_str_parse_double(argv[1], "Invalid timeout: %s");             /** - timeout      */
   double comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");  /** - Task compute cost    */
   double comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");  /** - Task communication size */
   double timeout   = xbt_str_parse_double(argv[1], "Invalid timeout: %s");             /** - timeout      */
   double comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");  /** - Task compute cost    */
   double comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");  /** - Task communication size */
@@ -37,39 +39,40 @@ static int master(int argc, char *argv[])
     workers_count = MSG_get_host_number();
     workers = xbt_dynar_to_array(MSG_hosts_as_dynar());
 
     workers_count = MSG_get_host_number();
     workers = xbt_dynar_to_array(MSG_hosts_as_dynar());
 
-    for (i = 0; i < workers_count; i++)
-      if(host_self == workers[i]) {
+    for (int i = 0; i < workers_count; i++)
+      if (host_self == workers[i]) {
         workers[i] = workers[workers_count-1];
         workers_count--;
         break;
       }
 
         workers[i] = workers[workers_count-1];
         workers_count--;
         break;
       }
 
-    for (i = 0; i < workers_count; i++)
+    for (int i = 0; i < workers_count; i++)
       MSG_process_create("worker", worker, master_name, workers[i]);
   }
 
   XBT_INFO("Got %d workers and will send tasks for %g seconds!", workers_count, timeout);
 
       MSG_process_create("worker", worker, master_name, workers[i]);
   }
 
   XBT_INFO("Got %d workers and will send tasks for %g seconds!", workers_count, timeout);
 
-  for (i = 0; 1; i++) {
+  int task_num = 0;
+  while (1) {
     char sprintf_buffer[64];
     msg_task_t task = NULL;
 
     if(MSG_get_clock()>timeout) break;
 
     char sprintf_buffer[64];
     msg_task_t task = NULL;
 
     if(MSG_get_clock()>timeout) break;
 
-    sprintf(sprintf_buffer, "Task_%d", i);
+    sprintf(sprintf_buffer, "Task_%d", task_num);
     task = MSG_task_create(sprintf_buffer, comp_size, comm_size, NULL);
 
     task = MSG_task_create(sprintf_buffer, comp_size, comm_size, NULL);
 
-    build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count]));
-    
+    build_channel_name(channel, master_name, MSG_host_get_name(workers[task_num % workers_count]));
+
     XBT_DEBUG("Sending \"%s\" to channel \"%s\"", task->name, channel);
     MSG_task_send(task, channel);
     XBT_DEBUG("Sent");
     XBT_DEBUG("Sending \"%s\" to channel \"%s\"", task->name, channel);
     MSG_task_send(task, channel);
     XBT_DEBUG("Sent");
+    task_num++;
   }
 
   }
 
-  int task_num = i;
 
   XBT_DEBUG ("All tasks have been dispatched. Let's tell everybody the computation is over.");
 
   XBT_DEBUG ("All tasks have been dispatched. Let's tell everybody the computation is over.");
-  for (i = 0; i < workers_count; i++) {
+  for (int i = 0; i < workers_count; i++) {
     msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE);
     MSG_task_send(finalize, build_channel_name(channel,master_name,
         MSG_host_get_name(workers[i % workers_count])));
     msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE);
     MSG_task_send(finalize, build_channel_name(channel,master_name,
         MSG_host_get_name(workers[i % workers_count])));
@@ -85,7 +88,6 @@ static int master(int argc, char *argv[])
 static int worker(int argc, char *argv[])
 {
   msg_task_t task = NULL;
 static int worker(int argc, char *argv[])
 {
   msg_task_t task = NULL;
-  XBT_ATTRIB_UNUSED int res;
   char channel[1024];
 
   build_channel_name(channel,MSG_process_get_data(MSG_process_self()),  MSG_host_get_name(MSG_host_self()));
   char channel[1024];
 
   build_channel_name(channel,MSG_process_get_data(MSG_process_self()),  MSG_host_get_name(MSG_host_self()));
@@ -93,7 +95,7 @@ static int worker(int argc, char *argv[])
   XBT_DEBUG("Receiving on channel \"%s\"", channel);
 
   while (1) {
   XBT_DEBUG("Receiving on channel \"%s\"", channel);
 
   while (1) {
-    res = MSG_task_receive(&(task),channel);
+    int res = MSG_task_receive(&(task), channel);
     xbt_assert(res == MSG_OK, "MSG_task_receive failed");
     
     XBT_DEBUG("Received \"%s\"", MSG_task_get_name(task));
     xbt_assert(res == MSG_OK, "MSG_task_receive failed");
     
     XBT_DEBUG("Received \"%s\"", MSG_task_get_name(task));
@@ -115,8 +117,6 @@ static int worker(int argc, char *argv[])
 /** Main function */
 int main(int argc, char *argv[])
 {
 /** Main function */
 int main(int argc, char *argv[])
 {
-  msg_error_t res = MSG_OK;
-
   MSG_init(&argc, argv);
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
   MSG_init(&argc, argv);
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
     MSG_function_register("worker", worker);
     MSG_launch_application(argv[2]);
   }
     MSG_function_register("worker", worker);
     MSG_launch_application(argv[2]);
   }
-  res = MSG_main();
+  msg_error_t res = MSG_main();
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return (res != MSG_OK);
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return (res != MSG_OK);
index 3761a26..39d2cec 100644 (file)
@@ -18,7 +18,10 @@ static char * build_channel_name(char *buffer, const char *sender, const char* r
   return buffer;
 }
 
   return buffer;
 }
 
-/** Master function  */
+/* forward definitions */
+static int master(int argc, char* argv[]);
+static int worker(int argc, char* argv[]);
+
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;
index c8f7619..03a3668 100644 (file)
@@ -18,7 +18,10 @@ static char * build_channel_name(char *buffer, const char *sender, const char* r
   return buffer;
 }
 
   return buffer;
 }
 
-/** Worker function  */
+/* forward definitions */
+static int master(int argc, char* argv[]);
+static int worker(int argc, char* argv[]);
+
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;
 static int master(int argc, char *argv[])
 {
   int workers_count = 0;