Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rewrite to use send/recv instead of put/get (+ add READMEs)
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 27 Feb 2010 23:05:51 +0000 (23:05 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 27 Feb 2010 23:05:51 +0000 (23:05 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7132 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/java/comm_time/CommTimeTest.java
examples/java/comm_time/Makefile.am
examples/java/comm_time/Master.java
examples/java/comm_time/MyTask.java [new file with mode: 0644]
examples/java/comm_time/README [new file with mode: 0644]
examples/java/comm_time/Slave.java
examples/java/comm_time/comm_time_deployment.xml
examples/java/ping_pong/README [new file with mode: 0644]

index 326985d..4ff274a 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * $Id$
  *
- * Copyright 2006,2007 Martin Quinson, Malek Cherier         
- * All right reserved. 
+ * Copyright 2006,2007,2010 The SimGrid Team. All right reserved. 
  *
  * 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. 
@@ -23,16 +22,12 @@ public class CommTimeTest {
        /* initialize the MSG simulation. Must be done before anything else (even logging). */
        Msg.init(args);
 
-       if(args.length < 2) {
-               
+       if(args.length < 2) {                   
          Msg.info("Usage   : CommTime platform_file deployment_file");
          Msg.info("example : CommTime comm_time_platform.xml comm_time_deployment.xml");
          System.exit(1);
        }
        
-        /* specify a paje output file. */
-        Msg.pajeOutput("comm_time.trace");
-               
        /* construct the platform and deploy the application */
        Msg.createEnvironment(args[0]);
        Msg.deployApplication(args[1]);
index c469a01..10b4b5b 100644 (file)
@@ -9,7 +9,7 @@ EXTRA_DIST=comm_time_deployment.xml comm_time_platform.xml
 
 # Declare sources:
 JAVA_SRC=Master.java Slave.java CommTimeTest.java \
-         CommTimeTask.java FinalizeTask.java
+         MyTask.java FinalizeTask.java
 JAVA_TESTS=CommTimeTest.class
 TESTS=$(JAVA_TESTS)
 
index 488dc3d..8343873 100644 (file)
@@ -1,8 +1,7 @@
 /*
- * $Id$
+ * Master of a basic master/slave example in Java
  *
- * Copyright 2006,2007 Martin Quinson, Malek Cherier         
- * All rights reserved. 
+ * Copyright 2006,2007,2010 The SimGrid Team. All rights reserved. 
  *
  * 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. 
 import simgrid.msg.*;
 
 public class Master extends simgrid.msg.Process {
-   
    public void main(String[] args) throws JniException, NativeException {
+      if (args.length < 4) {
+        Msg.info("Master needs 4 arguments");
+        System.exit(1);
+      }
       
-      Msg.info("Hello i'm the master");
-      
-      int numberoftasks = Integer.valueOf(args[0]).intValue();
+      int tasksCount = Integer.valueOf(args[0]).intValue();            
       double taskComputeSize = Double.valueOf(args[1]).doubleValue();          
       double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
-               
-      int slavecount = args.length - 3;
-      Host[] slaves = new Host[slavecount] ;
-       
-      for (int i = 3; i < args.length; i++) {
-        try {
-           slaves[i-3] = Host.getByName(args[i]);
-        } catch(HostNotFoundException e) {
-           Msg.info(e.toString());
-           Msg.info("Unknown host " +  args[i] +". Stopping Now! " );
-           System.exit(1);
-        }
-      }
-               
-      Msg.info("Got " + slavecount + " slave(s):");            
-      for (int i = 0; i < slavecount; i++)
-       Msg.info("\t " + slaves[i].getName());
       
-      Msg.info("Got "+numberoftasks+" task(s) to process.");
+      int slavesCount = Integer.valueOf(args[3]).intValue();
       
-      for (int i = 0; i < numberoftasks; i++) {                        
-        CommTimeTask task = new CommTimeTask("Task_" + i ,taskComputeSize,taskCommunicateSize);
-        task.setTime(Msg.getClock());
-        slaves[i % slavecount].put(0,task);
-        
-//      Msg.info("Send completed for the task " + task.getName() + " on the host " + slaves[i % slavecount].getName() +  " [" + (i % slavecount) + "]");
+      Msg.info("Hello! Got "+  slavesCount + " slaves and "+tasksCount+" tasks to process");
+      
+      for (int i = 0; i < tasksCount; i++) {
+        MyTask task = new MyTask("Task_" + i, taskComputeSize, taskCommunicateSize);
+        if (i%1000==0)
+          Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\"");
+        task.send("slave_"+(i%slavesCount));
       }
-               
+      
       Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
-               
-      for (int i = 0; i < slavecount; i++) { 
-                       
-        Msg.info("Finalize host " + slaves[i].getName() +  " [" + i + "]");
-        slaves[i].put(0, new FinalizeTask());
+      
+      for (int i = 0; i < slavesCount; i++) {
+        FinalizeTask task = new FinalizeTask();
+        task.send("slave_"+(i%slavesCount));
       }
       
-      Msg.info("All finalize messages have been dispatched. Goodbye now!");
-   }
-}
\ No newline at end of file
+      Msg.info("Goodbye now!");
+    }
+}
diff --git a/examples/java/comm_time/MyTask.java b/examples/java/comm_time/MyTask.java
new file mode 100644 (file)
index 0000000..633ab00
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006,2007,2010 The SimGrid Team. All rights reserved. 
+ *
+ * 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. 
+ */
+
+import simgrid.msg.*;
+
+public class MyTask extends Task {
+       
+   private double timeVal;
+       
+   public MyTask(String name, double computeDuration, double messageSize) throws JniException, NativeException{
+      super(name,computeDuration,messageSize);
+   }
+       
+   public void setTime(double timeVal){
+      this.timeVal = timeVal;
+   }
+   
+   public double getTime() {
+      return this.timeVal;
+   }
+}
+    
\ No newline at end of file
diff --git a/examples/java/comm_time/README b/examples/java/comm_time/README
new file mode 100644 (file)
index 0000000..6512acd
--- /dev/null
@@ -0,0 +1,5 @@
+This directory is almost exactly the same example than the
+master/slave, the only differences are:
+ * there is no forwarder here
+ * the outputs are a bit less verbose
+ * the example give a lot more work to do (this is used for benchmarking)
\ No newline at end of file
index 6fc7828..7a7ace7 100644 (file)
 import simgrid.msg.*;
 
 public class Slave extends simgrid.msg.Process {
-   
    public void main(String[] args) throws JniException, NativeException {
+      if (args.length < 1) {
+        Msg.info("Slave needs 1 argument (its number)");
+        System.exit(1);
+      }
+
+      int num = Integer.valueOf(args[0]).intValue();
+      Msg.info("Receiving on 'slave_"+num+"'");
       
-      Msg.info("Hello i'm a slave");
-      
-      while(true) {
-        double time1 = Msg.getClock();       
-        Task t = Task.get(0);  
+      while(true) { 
+        Task t = Task.receive("slave_"+num);   
+        
         if (t instanceof FinalizeTask) {
            break;
         }
-        CommTimeTask task = (CommTimeTask)t;
-            
-        if(time1 < task.getTime())
-          time1 = task.getTime();
-        
-/*      double time2 = Msg.getClock();
-        Msg.info("Processing \"" + task.getName() + "\" " + getHost().getName() + 
-                 " (Communication time : " +  (time2 - time1) + ")");
-*/          
+        MyTask task = (MyTask)t;
         task.execute();
-      }
+//      Msg.info("\"" + task.getName() + "\" done ");
+       }
        
       Msg.info("Received Finalize. I'm done. See you!");
-   }
+    }
 }
\ No newline at end of file
index bd29ebd..917190d 100644 (file)
@@ -2,48 +2,54 @@
 <!DOCTYPE platform SYSTEM "simgrid.dtd">
 <platform version="2">
   <process host="Jacquelin" function="Master">
-     <argument value="50000"/>
-     <argument value="50000"/>
-     <argument value="10"/>
-     <argument value="iRMX"/>
-     <argument value="Bousquet"/>
-     <argument value="Soucy"/>
-     <argument value="Casavant"/>
-     <argument value="Jackson"/>
-     <argument value="Geoff"/>
-     <argument value="Disney"/>
-     <argument value="McGee"/>
-     <argument value="Gatien"/>
-     <argument value="Laroche"/>
-     <argument value="Tanguay"/>
-     <argument value="Morin"/>
-     <argument value="Ethernet"/>
-     <argument value="Bellemarre"/>
-     <argument value="Harry"/>
-     <argument value="Olivier"/>
-     <argument value="Boucherville"/>
-     <argument value="Pointe_Claire"/>
-     <argument value="Kansas"/>
-     <argument value="King"/>
+     <argument value="50000"/>     <!-- Amount of tasks to dispatch -->
+     <argument value="50000"/> <!-- Computation size of each task -->
+     <argument value="10"/>    <!-- Communication size of each one -->
+     <argument value="21"/>     <!-- Amount of slaves waiting for orders -->
   </process>
-  <process host="iRMX" function="Slave"/>
-  <process host="Bousquet" function="Slave"/>
-  <process host="Soucy" function="Slave"/>
-  <process host="Casavant" function="Slave"/>
-  <process host="Jackson" function="Slave"/>
-  <process host="Geoff" function="Slave"/>
-  <process host="Disney" function="Slave"/>
-  <process host="McGee" function="Slave"/>
-  <process host="Gatien" function="Slave"/>
-  <process host="Laroche" function="Slave"/>
-  <process host="Tanguay" function="Slave"/>
-  <process host="Morin" function="Slave"/>
-  <process host="Ethernet" function="Slave"/>
-  <process host="Bellemarre" function="Slave"/>
-  <process host="Harry" function="Slave"/>
-  <process host="Olivier" function="Slave"/>
-  <process host="Boucherville" function="Slave"/>
-  <process host="Pointe_Claire" function="Slave"/>
-  <process host="Kansas" function="Slave"/>
-  <process host="King" function="Slave"/>
+  
+  <process host="iRMX" function="Slave">
+     <argument value="0"/>  <!-- Input mailbox -->
+  </process>
+  
+  <process host="Bousquet" function="Slave">
+     <argument value="1"/></process>
+  <process host="Soucy" function="Slave">
+     <argument value="2"/></process>
+  <process host="Casavant" function="Slave">
+     <argument value="3"/></process>
+  <process host="Jackson" function="Slave">
+     <argument value="4"/></process>
+  <process host="Geoff" function="Slave">
+     <argument value="5"/></process>
+  <process host="Disney" function="Slave">
+     <argument value="6"/></process>
+  <process host="McGee" function="Slave">
+     <argument value="7"/></process>
+  <process host="Gatien" function="Slave">
+     <argument value="8"/></process>
+  <process host="Laroche" function="Slave">
+     <argument value="9"/></process>
+  <process host="Tanguay" function="Slave">
+     <argument value="10"/></process>
+  <process host="Morin" function="Slave">
+     <argument value="11"/></process>
+  <process host="Ethernet" function="Slave">
+     <argument value="12"/></process>
+  <process host="Bellemarre" function="Slave">
+     <argument value="13"/></process>
+  <process host="Harry" function="Slave">
+     <argument value="14"/></process>
+  <process host="Olivier" function="Slave">
+     <argument value="15"/></process>
+  <process host="Boucherville" function="Slave">
+     <argument value="16"/></process>
+  <process host="Pointe_Claire" function="Slave">
+     <argument value="17"/></process>
+  <process host="Kansas" function="Slave">
+     <argument value="18"/></process>
+  <process host="King" function="Slave">
+     <argument value="19"/></process>
+  <process host="Lapointe" function="Slave">
+     <argument value="20"/></process>
 </platform>
diff --git a/examples/java/ping_pong/README b/examples/java/ping_pong/README
new file mode 100644 (file)
index 0000000..aa16de9
--- /dev/null
@@ -0,0 +1,2 @@
+This is a stupid ping/pong example. The processes exchange a simple
+task and time them.
\ No newline at end of file