Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a reduce X bytes Y flops action
authorsuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 29 Oct 2009 22:24:49 +0000 (22:24 +0000)
committersuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 29 Oct 2009 22:24:49 +0000 (22:24 +0000)
once the root has received all the contributions of X bytes from the
other processes, it computes Y flops. The other processes exit the
function as soon as they their send is completed.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6825 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/msg/actions/actions.c
examples/msg/actions/actions_reduce.txt [new file with mode: 0644]

index 309bc61..9f79b73 100644 (file)
@@ -17,6 +17,7 @@ int communicator_size=0;
 
 typedef struct coll_ctr_t{
   int bcast_counter;
 
 typedef struct coll_ctr_t{
   int bcast_counter;
+  int reduce_counter;
 } *coll_ctr;
 
 /* Helper function */
 } *coll_ctr;
 
 /* Helper function */
@@ -93,10 +94,11 @@ static void recv(xbt_dynar_t action)
 static int spawned_recv(int argc, char *argv[])
 {
   m_task_t task = NULL;
 static int spawned_recv(int argc, char *argv[])
 {
   m_task_t task = NULL;
-  char* name = (char *) MSG_process_get_data(MSG_process_self());
+  char* name = (char *) MSG_process_self()->data;
   INFO1("Receiving on %s", name);
   MSG_task_receive(&task, name);
   INFO1("Received %s", MSG_task_get_name(task));
   INFO1("Receiving on %s", name);
   MSG_task_receive(&task, name);
   INFO1("Received %s", MSG_task_get_name(task));
+  INFO1("waiter on %s", MSG_process_self()->name);
   MSG_task_send(MSG_task_create("waiter",0,0,NULL),MSG_process_self()->name); 
   
   MSG_task_destroy(task);
   MSG_task_send(MSG_task_create("waiter",0,0,NULL),MSG_process_self()->name); 
   
   MSG_task_destroy(task);
@@ -114,7 +116,7 @@ static void Irecv(xbt_dynar_t action)
 
   sprintf(name,"%s_wait",MSG_process_self()->name);
   comm_helper = MSG_process_create(name,spawned_recv,
 
   sprintf(name,"%s_wait",MSG_process_self()->name);
   comm_helper = MSG_process_create(name,spawned_recv,
-                 (void *) MSG_process_get_name(MSG_process_self()),
+                 (void *) MSG_process_self()->name,
                  MSG_host_self());
 
 
                  MSG_host_self());
 
 
@@ -131,6 +133,7 @@ static void wait(xbt_dynar_t action)
   INFO1("wait: %s", name);
   sprintf(task_name,"%s_wait",MSG_process_self()->name);
   MSG_task_receive(&task,task_name);
   INFO1("wait: %s", name);
   sprintf(task_name,"%s_wait",MSG_process_self()->name);
   MSG_task_receive(&task,task_name);
+  MSG_task_destroy(task);
   INFO1("waited: %s", name);
   free(name);
 }
   INFO1("waited: %s", name);
   free(name);
 }
@@ -145,6 +148,70 @@ static void barrier (xbt_dynar_t action)
 
 }
 
 
 }
 
+static void reduce(xbt_dynar_t action)
+{
+  int i;
+  char *name;
+  char task_name[80];
+  char spawn_name[80];
+  char *comm_size = xbt_dynar_get_as(action, 2, char *);
+  char *comp_size = xbt_dynar_get_as(action, 3, char *);
+  m_process_t comm_helper=NULL;
+  m_task_t task=NULL, comp_task=NULL;
+  const char* process_name;
+  
+  coll_ctr counters =  (coll_ctr) MSG_process_get_data(MSG_process_self());
+
+  xbt_assert0(communicator_size, "Size of Communicator is not defined"
+             ", can't use collective operations");
+
+  MSG_process_self()->data=NULL;
+
+  process_name = MSG_process_self()->name;
+
+  if (!counters){
+    DEBUG0("Initialize the counters");
+    counters = (coll_ctr) calloc (1, sizeof(struct coll_ctr_t));
+  }
+
+  name = bprintf("reduce_%d", counters->reduce_counter++);
+
+  if (!strcmp(process_name, "process0")){
+    INFO2("%s: %s is the Root",name, process_name);
+    for(i=1;i<communicator_size;i++){
+      sprintf(spawn_name,"%s_process%d", name, i);
+      sprintf(task_name,"%s_wait", spawn_name);
+      comm_helper = 
+       MSG_process_create(task_name, spawned_recv, 
+                          (void *) xbt_strdup(spawn_name),
+                          MSG_host_self());      
+    }
+
+    for(i=1;i<communicator_size;i++){
+      sprintf(task_name,"%s_process%d_wait", name, i);
+      MSG_task_receive(&task,task_name);
+      MSG_task_destroy(task);
+      task=NULL;
+    }
+
+    comp_task = 
+      MSG_task_create("reduce_comp", parse_double(comp_size), 0, NULL);
+    INFO1("%s: computing 'reduce_comp'", name);
+    MSG_task_execute(comp_task);
+    MSG_task_destroy(comp_task);
+    INFO1("%s: computed", name);
+  } else {
+    INFO2("%s: %s sends", name, process_name);
+    sprintf(task_name,"%s_%s", name, process_name);
+    INFO1("put on %s", task_name);
+    MSG_task_send(MSG_task_create(name, 0, parse_double(comm_size), NULL),
+                 task_name);
+  }
+
+  MSG_process_set_data(MSG_process_self(), (void*)counters);
+  free(name);
+}
+
 static void bcast (xbt_dynar_t action)
 {
   int i;
 static void bcast (xbt_dynar_t action)
 {
   int i;
@@ -266,6 +333,7 @@ int main(int argc, char *argv[])
   MSG_action_register("wait", wait);
   MSG_action_register("barrier", barrier);
   MSG_action_register("bcast", bcast);
   MSG_action_register("wait", wait);
   MSG_action_register("barrier", barrier);
   MSG_action_register("bcast", bcast);
+  MSG_action_register("reduce", reduce);
   MSG_action_register("sleep", sleep);
   MSG_action_register("compute", compute);
 
   MSG_action_register("sleep", sleep);
   MSG_action_register("compute", compute);
 
diff --git a/examples/msg/actions/actions_reduce.txt b/examples/msg/actions/actions_reduce.txt
new file mode 100644 (file)
index 0000000..e3b6199
--- /dev/null
@@ -0,0 +1,9 @@
+process0 comm_size 3
+process0 reduce 5e8 5e8
+process1 reduce 5e8 5e8
+process2 reduce 5e8 5e8
+
+process0 compute 5e8
+process1 compute 5e8
+process2 compute 5e8
+