Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add Irecv and wait actions and corresponding example
authorsuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 22 Oct 2009 18:12:25 +0000 (18:12 +0000)
committersuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 22 Oct 2009 18:12:25 +0000 (18:12 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6812 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/msg/actions/actions.c
examples/msg/actions/actions_deployment.xml
examples/msg/actions/actions_with_isend.txt [new file with mode: 0644]
examples/msg/actions/homogeneous_3_hosts.xml [new file with mode: 0644]

index 8ca04c2..b6b7489 100644 (file)
 #include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
 #include "xbt.h"                /* calloc, printf */
 
+typedef enum {
+  LOCAL = 0,
+  MAX_CHANNEL
+} channel_t;
+
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
                  "Messages specific for this msg example");
 
+
 /* Helper function */
 static double parse_double(const char *string) {
   double value;
@@ -49,6 +55,48 @@ static void recv(xbt_dynar_t action)
   free(name);
 }
 
+static int spawned_recv(int argc, char *argv[])
+{
+  m_task_t task = NULL;
+  char* name = (char *) MSG_process_get_data(MSG_process_self());
+  INFO1("Receiving on %s", name);
+  MSG_task_receive(&task, name);
+  INFO1("Received %s", MSG_task_get_name(task));
+
+  MSG_task_put(MSG_task_create("waiter", 0, 0, NULL),
+       MSG_process_get_host(MSG_process_self()), LOCAL);
+  
+  MSG_task_destroy(task);
+  return 0;
+}
+
+static void Irecv(xbt_dynar_t action)
+{
+  char *name = xbt_str_join(action, " ");
+  m_process_t comm_helper;
+
+   INFO1("Irecv on %s: spawn process ", 
+        MSG_process_get_name(MSG_process_self()));
+
+  comm_helper = 
+    MSG_process_create("spawned_recv",
+                      spawned_recv, 
+                      (void *) MSG_process_get_name(MSG_process_self()),
+                      MSG_process_get_host(MSG_process_self()));       
+  free(name);
+}
+
+static void wait(xbt_dynar_t action)
+{
+  char *name = xbt_str_join(action, " ");
+  m_task_t task = NULL;
+  INFO1("wait: %s", name);
+  MSG_task_get(&(task), LOCAL);
+  INFO1("waited: %s", name);
+  free(name);
+}
+
 static void sleep(xbt_dynar_t action)
 {
   char *name = xbt_str_join(action, " ");
@@ -86,6 +134,7 @@ int main(int argc, char *argv[])
   }
 
   /*  Simulation setting */
+  MSG_set_channel_number(MAX_CHANNEL);
   MSG_create_environment(argv[1]);
 
   /* No need to register functions as in classical MSG programs: the actions get started anyway */
@@ -94,6 +143,8 @@ int main(int argc, char *argv[])
   /*   Action registration */
   MSG_action_register("send", send);
   MSG_action_register("recv", recv);
+  MSG_action_register("Irecv", Irecv);
+  MSG_action_register("wait", wait);
   MSG_action_register("sleep", sleep);
   MSG_action_register("compute", compute);
 
index e854ed0..7a401b4 100644 (file)
@@ -3,4 +3,5 @@
 <platform version="2">
   <process host="Tremblay" function="toto"/>
   <process host="Jupiter" function="tutu"/>
+  <process host="Fafard" function="titi"/>
 </platform>
diff --git a/examples/msg/actions/actions_with_isend.txt b/examples/msg/actions/actions_with_isend.txt
new file mode 100644 (file)
index 0000000..3e59843
--- /dev/null
@@ -0,0 +1,14 @@
+# sample action file
+tutu send toto 1e9
+tutu compute 1e9
+tutu recv
+
+toto Irecv 
+toto compute 1e9
+toto wait
+toto send titi 1e9
+
+titi Irecv
+titi compute 5e8
+titi wait
+titi send tutu 1e9
\ No newline at end of file
diff --git a/examples/msg/actions/homogeneous_3_hosts.xml b/examples/msg/actions/homogeneous_3_hosts.xml
new file mode 100644 (file)
index 0000000..50b720b
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+  <host id="Tremblay" power="1e7"/>
+  <host id="Jupiter" power="1e7"/>
+  <host id="Fafard" power="1e7"/>
+  <link id="0" bandwidth="1e9" latency="5e-4"/>
+  <link id="1" bandwidth="1e9" latency="5e-4"/>
+  <link id="2" bandwidth="1e9" latency="5e-4"/>
+  
+  <link id="loopback" bandwidth="498000000" latency="0.000015" sharing_policy="FATPIPE"/>
+  <route src="Tremblay" dst="Tremblay"><link:ctn id="loopback"/></route>
+  <route src="Jupiter" dst="Jupiter"><link:ctn id="loopback"/></route>
+  <route src="Fafard" dst="Fafard"><link:ctn id="loopback"/></route>
+  <route src="Tremblay" dst="Jupiter">
+    <link:ctn id="0"/>
+  </route>
+  <route src="Tremblay" dst="Fafard">
+    <link:ctn id="1"/>
+  </route>
+  <route src="Jupiter" dst="Tremblay">
+    <link:ctn id="0"/>
+  </route>
+  <route src="Jupiter" dst="Fafard">
+    <link:ctn id="2"/>
+  </route>
+  <route src="Fafard" dst="Tremblay">
+    <link:ctn id="1"/>
+  </route>
+  <route src="Fafard" dst="Jupiter">
+    <link:ctn id="2"/>
+  </route>
+</platform>