Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New msg_test with forwarder agents.
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 26 Jan 2005 17:29:26 +0000 (17:29 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 26 Jan 2005 17:29:26 +0000 (17:29 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@772 48e7efb5-ca39-0410-a469-dd3cf9ba447f

testsuite/msg/messages.h
testsuite/msg/msg_deployment.xml
testsuite/msg/msg_test.c

index 0ec66bf..02770d5 100644 (file)
 #include "msg/datatypes.h"
 #include "xbt/error.h"
 
+static void ASSERT(int value, const char *fmt, ...)
+{
+  m_process_t self = MSG_process_self();
+  va_list ap;
+
+  if(!value) {
+    va_start(ap, fmt);
+    if (self)
+      fprintf(stderr, "[%Lg] P%d | ", MSG_getClock(),
+             MSG_process_get_PID(self));
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    
+    xbt_abort();
+  }
+  return;
+}
+
 static void DIE(const char *fmt, ...)
 {
   m_process_t self = MSG_process_self();
@@ -37,8 +55,8 @@ static void PRINT_MESSAGE(const char *fmt, ...)
 
   va_start(ap, fmt);
   if (self)
-    fprintf(stderr, "[%Lg] P%d | ", MSG_getClock(),
-           MSG_process_get_PID(self));
+    fprintf(stderr, "[%Lg] P%d | (%s:%s) ", MSG_getClock(),
+           MSG_process_get_PID(self), MSG_host_self()->name, self->name);
   vfprintf(stderr, fmt, ap);
   va_end(ap);
 #endif
@@ -53,8 +71,8 @@ static void PRINT_DEBUG_MESSAGE(const char *fmt, ...)
 
   va_start(ap, fmt);
   if (self)
-    fprintf(stderr, "DEBUG [%Lg] P%d | ", MSG_getClock(),
-           MSG_process_get_PID(self));
+    fprintf(stderr, "DEBUG [%Lg] P%d | (%s) ", MSG_getClock(),
+           MSG_process_get_PID(self), MSG_host_self()->name);
   vfprintf(stderr, fmt, ap);
   va_end(ap);
 #endif
index 5ec19e8..7626bff 100644 (file)
@@ -2,16 +2,32 @@
 <!DOCTYPE platform_description SYSTEM "surfxml.dtd">
 <platform_description>
   <process host="Jacquelin" function="master">
+     <argument value="20"/>
+     <argument value="50000"/>
+     <argument value="10"/>
      <argument value="iRMX"/>
+     <argument value="Casavant"/>
      <argument value="Bousquet"/>
      <argument value="Soucy"/>
      <argument value="Jackson"/>
   </process>
+  <process host="Jackson" function="forwarder">
+     <argument value="Kuenning"/>
+     <argument value="Browne"/> 
+     <argument value="Stephen"/>
+ </process>
+  <process host="Casavant" function="forwarder">
+     <argument value="Robert"/>
+     <argument value="Sirois"/> 
+     <argument value="Monique"/>
+ </process>
   <process host="iRMX" function="slave"/>
   <process host="Bousquet" function="slave"/>
   <process host="Soucy" function="slave"/>
   <process host="Kuenning" function="slave"/>
-  <process host="Jackson" function="forwarder">
-     <argument value="Kuenning"/>
-  </process>
+  <process host="Browne" function="slave"/>
+  <process host="Stephen" function="slave"/>
+  <process host="Robert" function="slave"/>
+  <process host="Sirois" function="slave"/>
+  <process host="Monique" function="slave"/>
 </platform_description>
index 6695d53..06adbb9 100644 (file)
@@ -5,24 +5,17 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-/** \file msg_test.c 
- *  \brief Test program for msg.
-*/
-
 #include "msg/msg.h"
 
-/** This flag enable the debugging messages from PRINT_DEBUG_MESSAGE() */
 #define VERBOSE
 #include "messages.h"
 
-int unix_emitter(int argc, char *argv[]);
-int unix_receiver(int argc, char *argv[]);
-int unix_forwarder(int argc, char *argv[]);
+int master(int argc, char *argv[]);
+int slave(int argc, char *argv[]);
+int forwarder(int argc, char *argv[]);
 void test_all(const char *platform_file, const char *application_file);
 
 
-/** The names of the channels we will use in this simulation. There is
-    only one channel identified by the name PORT_22. */
 typedef enum {
   PORT_22 = 0,
   MAX_CHANNEL
@@ -39,42 +32,48 @@ void print_args(int argc, char** argv)
   fprintf(stderr,">\n");
 }
 
-/** The number of task each slave will process */
-#define NB_TASK 3
-int unix_emitter(int argc, char *argv[])
+int master(int argc, char *argv[])
 {
   int slaves_count = 0;
   m_host_t *slaves = NULL;
-  int todo_count = 0;
   m_task_t *todo = NULL;
+  int number_of_tasks = 0;
+  double task_comp_size = 0;
+  double task_comm_size = 0;
+
 
   int i;
 
   print_args(argc,argv);
 
-  {                  /* Process organisation */
-    slaves_count = argc - 1;
-    slaves = calloc(slaves_count, sizeof(m_host_t));
-    
-    for (i = 1; i < argc; i++) {
-      slaves[i-1] = MSG_get_host_by_name(argv[i]);
-      if(slaves[i-1]==NULL) {
-       PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[i]);
-       abort();
-      }
-    }
-  }
+  ASSERT(sscanf(argv[1],"%d", &number_of_tasks),
+        "Invalid argument %s\n",argv[1]);
+  ASSERT(sscanf(argv[2],"%lg", &task_comp_size),
+        "Invalid argument %s\n",argv[2]);
+  ASSERT(sscanf(argv[3],"%lg", &task_comm_size),
+        "Invalid argument %s\n",argv[3]);
 
   {                  /*  Task creation */
     char sprintf_buffer[64];
-    int slave  = slaves_count;
 
-    todo = calloc(NB_TASK * slave, sizeof(m_task_t));
-    todo_count = NB_TASK * slave;
+    todo = calloc(number_of_tasks, sizeof(m_task_t));
 
-    for (i = 0; i < NB_TASK * slave; i++) {
+    for (i = 0; i < number_of_tasks; i++) {
       sprintf(sprintf_buffer, "Task_%d", i);
-      todo[i] = MSG_task_create(sprintf_buffer, 5000, 10, NULL);
+      todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
+    }
+  }
+
+  {                  /* Process organisation */
+    slaves_count = argc - 4;
+    slaves = calloc(slaves_count, sizeof(m_host_t));
+    
+    for (i = 4; i < argc; i++) {
+      slaves[i-4] = MSG_get_host_by_name(argv[i]);
+      if(slaves[i-4]==NULL) {
+       PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[i]);
+       abort();
+      }
     }
   }
 
@@ -82,12 +81,12 @@ int unix_emitter(int argc, char *argv[])
   for (i = 0; i < slaves_count; i++)
     PRINT_MESSAGE("\t %s\n", slaves[i]->name);
 
-  PRINT_MESSAGE("Got %d task to process :\n", todo_count);
+  PRINT_MESSAGE("Got %d task to process :\n", number_of_tasks);
 
-  for (i = 0; i < todo_count; i++)
+  for (i = 0; i < number_of_tasks; i++)
     PRINT_MESSAGE("\t\"%s\"\n", todo[i]->name);
 
-  for (i = 0; i < todo_count; i++) {
+  for (i = 0; i < number_of_tasks; i++) {
     PRINT_MESSAGE("Sending \"%s\" to \"%s\"\n",
                   todo[i]->name,
                   slaves[i % slaves_count]->name);
@@ -96,69 +95,69 @@ int unix_emitter(int argc, char *argv[])
     PRINT_MESSAGE("Send completed\n");
   }
   
+  PRINT_MESSAGE("All tasks have been dispatched. Bye!\n");
   free(slaves);
   free(todo);
   return 0;
 }
 
-int unix_receiver(int argc, char *argv[])
+int slave(int argc, char *argv[])
 {
-  int todo_count = 0;
-  m_task_t *todo = (m_task_t *) calloc(NB_TASK, sizeof(m_task_t));
-  int i;
-
   print_args(argc,argv);
 
-  for (i = 0; i < NB_TASK;) {
+  while(1) {
+    m_task_t task = NULL;
     int a;
-    PRINT_MESSAGE("Awaiting Task %d \n", i);
-    a = MSG_task_get(&(todo[i]), PORT_22);
+    a = MSG_task_get(&(task), PORT_22);
     if (a == MSG_OK) {
-      todo_count++;
-      PRINT_MESSAGE("Received \"%s\" \n", todo[i]->name);
-      PRINT_MESSAGE("Processing \"%s\" \n", todo[i]->name);
-      MSG_task_execute(todo[i]);
-      PRINT_MESSAGE("\"%s\" done \n", todo[i]->name);
-      MSG_task_destroy(todo[i]);
-      i++;
+      PRINT_MESSAGE("Received \"%s\" \n", task->name);
+      PRINT_MESSAGE("Processing \"%s\" \n", task->name);
+      MSG_task_execute(task);
+      PRINT_MESSAGE("\"%s\" done \n", task->name);
+      MSG_task_destroy(task);
     } else {
       PRINT_MESSAGE("Hey ?! What's up ? \n");
       DIE("Unexpected behaviour");
     }
   }
-  free(todo);
   PRINT_MESSAGE("I'm done. See you!\n");
   return 0;
 }
 
 
-int unix_forwarder(int argc, char *argv[])
+int forwarder(int argc, char *argv[])
 {
-  m_host_t slave=NULL;
   int i;
+  int slaves_count = argc - 1;
+  m_host_t *slaves = calloc(slaves_count, sizeof(m_host_t));
 
   print_args(argc,argv);
 
-  if(argc<2) 
-    DIE("Need somebody to which I can send my work! ");
-
-  slave = MSG_get_host_by_name(argv[1]);
-
-  if(slave==NULL) {
-    PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[1]);
-    abort();
+  {                  /* Process organisation */
+    slaves_count = argc - 1;
+    slaves = calloc(slaves_count, sizeof(m_host_t));
+    
+    for (i = 1; i < argc; i++) {
+      slaves[i-1] = MSG_get_host_by_name(argv[i]);
+      if(slaves[i-1]==NULL) {
+       PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[i]);
+       abort();
+      }
+    }
   }
 
-  for (i = 0; i < NB_TASK;) {
+
+  while(1) {
     m_task_t task = NULL;
     int a;
-    PRINT_MESSAGE("Awaiting Task %d \n", i);
-    a = MSG_task_get(&task, PORT_22);
+    a = MSG_task_get(&(task), PORT_22);
     if (a == MSG_OK) {
       PRINT_MESSAGE("Received \"%s\" \n", task->name);
-      PRINT_MESSAGE("Sending to somebody else \"%s\" \n", task->name);
-      MSG_task_put(task,slave,PORT_22);
-      i++;
+      PRINT_MESSAGE("Sending \"%s\" to \"%s\"\n",
+                   task->name,
+                   slaves[i % slaves_count]->name);
+      MSG_task_put(task, slaves[i % slaves_count],
+                  PORT_22);
     } else {
       PRINT_MESSAGE("Hey ?! What's up ? \n");
       DIE("Unexpected behaviour");
@@ -177,9 +176,9 @@ void test_all(const char *platform_file,const char *application_file)
     MSG_create_environment(platform_file);
   }
   {                            /*   Application deployment */
-    MSG_function_register("master", unix_emitter);
-    MSG_function_register("slave", unix_receiver);
-    MSG_function_register("forwarder", unix_forwarder);
+    MSG_function_register("master", master);
+    MSG_function_register("slave", slave);
+    MSG_function_register("forwarder", forwarder);
     MSG_launch_application(application_file);
   }
   MSG_main();