Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add scala masterslave bypass and kill
authorPaul Bédaride <paul.bedaride@gmail.com>
Thu, 23 May 2013 13:06:31 +0000 (15:06 +0200)
committerPaul Bédaride <paul.bedaride@gmail.com>
Thu, 23 May 2013 13:06:31 +0000 (15:06 +0200)
17 files changed:
buildtools/Cmake/AddTests.cmake
buildtools/Cmake/DefinePackages.cmake
buildtools/Cmake/MakeExe.cmake
examples/scala/master_slave_bypass/CMakeLists.txt [new file with mode: 0644]
examples/scala/master_slave_bypass/FinalizeTask.scala [new file with mode: 0644]
examples/scala/master_slave_bypass/Master.scala [new file with mode: 0644]
examples/scala/master_slave_bypass/MsBypass.scala [new file with mode: 0644]
examples/scala/master_slave_bypass/Slave.scala [new file with mode: 0644]
examples/scala/master_slave_bypass/bypass.tesh [new file with mode: 0644]
examples/scala/master_slave_bypass/platform.xml [new file with mode: 0644]
examples/scala/master_slave_kill/CMakeLists.txt [new file with mode: 0644]
examples/scala/master_slave_kill/FinalizeTask.scala [new file with mode: 0644]
examples/scala/master_slave_kill/Master.scala [new file with mode: 0644]
examples/scala/master_slave_kill/MsKill.scala [new file with mode: 0644]
examples/scala/master_slave_kill/Slave.scala [new file with mode: 0644]
examples/scala/master_slave_kill/kill.tesh [new file with mode: 0644]
examples/scala/master_slave_kill/platform.xml [new file with mode: 0644]

index a9f938e..b9d48b4 100644 (file)
@@ -445,6 +445,8 @@ if(NOT enable_memcheck)
   # Scala examples
   if(enable_scala)
     set(TESH_CLASSPATH "${CMAKE_BINARY_DIR}/examples/scala/:${SIMGRID_JAR}:${SCALA_JARS}")
+    ADD_TEST(scala-bypass                        ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/scala --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/scala ${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_bypass/bypass.tesh)
+    ADD_TEST(scala-kill                          ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/scala --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/scala ${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_kill/kill.tesh)
     ADD_TEST(scala-masterslave                   ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/scala --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/scala ${CMAKE_HOME_DIRECTORY}/examples/scala/masterslave/masterslave.tesh)
   endif()
 
index 9e426e0..f2b449a 100644 (file)
@@ -834,6 +834,8 @@ set(EXAMPLES_CMAKEFILES_TXT
   examples/java/tracing/CMakeLists.txt
   examples/scala/CMakeLists.txt
   examples/scala/masterslave/CMakeLists.txt
+  examples/scala/master_slave_bypass/CMakeLists.txt
+  examples/scala/master_slave_kill/CMakeLists.txt
   examples/lua/CMakeLists.txt
   examples/msg/CMakeLists.txt
   examples/msg/actions/CMakeLists.txt
index 7a6d9f4..33e9e2e 100644 (file)
@@ -54,6 +54,8 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/tracing)
 
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/masterslave)
+add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_bypass)
+add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_kill)
 
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/properties)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/actions)
diff --git a/examples/scala/master_slave_bypass/CMakeLists.txt b/examples/scala/master_slave_bypass/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f5c954a
--- /dev/null
@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 2.6)
+
+set(example scala_master_slave_bypass)
+set(sources
+  ${CMAKE_CURRENT_SOURCE_DIR}/FinalizeTask.scala
+  ${CMAKE_CURRENT_SOURCE_DIR}/Master.scala
+  ${CMAKE_CURRENT_SOURCE_DIR}/MsBypass.scala
+  ${CMAKE_CURRENT_SOURCE_DIR}/Slave.scala
+  )
+
+if(enable_scala)
+  add_custom_command(
+    COMMENT "Building ${example}..."
+    OUTPUT ${example}_compiled
+    DEPENDS ${sources} SG_java_jar ${SIMGRID_JAR}
+    COMMAND ${SCALA_COMPILE} -cp ${SIMGRID_JAR}
+                             -d ${CMAKE_CURRENT_BINARY_DIR}/.. ${sources}
+    COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled
+    COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled
+  )
+  add_custom_target(${example} ALL DEPENDS ${example}_compiled)
+endif()
+
+set(tesh_files
+  ${tesh_files}
+  ${CMAKE_CURRENT_SOURCE_DIR}/bypass.tesh
+  PARENT_SCOPE
+  )
+set(xml_files
+  ${xml_files}
+  ${CMAKE_CURRENT_SOURCE_DIR}/platform.xml
+  PARENT_SCOPE
+  )
+set(examples_src
+  ${examples_src}
+  ${sources}
+  PARENT_SCOPE
+  )
+set(bin_files
+  ${bin_files}
+  PARENT_SCOPE
+  )
+set(txt_files
+  ${txt_files}
+  PARENT_SCOPE
+  )
diff --git a/examples/scala/master_slave_bypass/FinalizeTask.scala b/examples/scala/master_slave_bypass/FinalizeTask.scala
new file mode 100644 (file)
index 0000000..d83759d
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Copyright 2006-2012. 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. 
+ */
+
+package master_slave_bypass
+import org.simgrid.msg.Task
+
+class FinalizeTask extends Task("finalize",0,0) {}
diff --git a/examples/scala/master_slave_bypass/Master.scala b/examples/scala/master_slave_bypass/Master.scala
new file mode 100644 (file)
index 0000000..5e2fbee
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Master of a basic master/slave example in Java
+ *
+ * Copyright 2006-2012 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. 
+ */
+
+package master_slave_bypass
+
+import Stream._
+import org.simgrid.msg.HostNotFoundException
+import org.simgrid.msg.Msg
+import org.simgrid.msg.MsgException
+import org.simgrid.msg.Process
+import org.simgrid.msg.Task
+
+class Master(hostname:String, name:String) extends Process(hostname,name) {
+  
+  def main(args:Array[String]) {
+    Msg.info("Master Hello!")
+       
+    //Create a slave on host "alice"
+    try {
+      Msg.info("Create process on host 'alice'")
+      new Slave("alice","process2").start()
+    } catch {
+      case e:MsgException => println("Process2!")
+    }
+       
+    //Wait for slave "alice"
+    continually({Task.receive("alice")})
+      .takeWhile(!_.isInstanceOf[FinalizeTask])
+      .force // to force the list to be compute
+
+    Msg.info("Received Finalize. I'm done. See you!")
+  }
+}
diff --git a/examples/scala/master_slave_bypass/MsBypass.scala b/examples/scala/master_slave_bypass/MsBypass.scala
new file mode 100644 (file)
index 0000000..563f250
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006-2012. 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. 
+ */
+
+package master_slave_bypass
+
+import org.simgrid.msg.Msg
+import org.simgrid.msg.MsgException
+import org.simgrid.msg.NativeException
+
+object MsBypass extends App {
+ /* This only contains the launcher. If you do nothing more than than you can run 
+  *   scala simgrid.msg.Msg
+  * which also contains such a launcher
+  */
+  
+  /* initialize the MSG simulation. Must be done before anything else (even logging). */
+  Msg.init(args)
+  Msg.createEnvironment(args(0))
+
+  /* bypass deployment */
+  try {
+    new Master("bob","process1").start()
+  }
+  catch {
+    case e:MsgException => println("Create processes failed!")
+  }
+    
+  /*  execute the simulation. */
+  Msg.run()
+}
diff --git a/examples/scala/master_slave_bypass/Slave.scala b/examples/scala/master_slave_bypass/Slave.scala
new file mode 100644 (file)
index 0000000..d8538c4
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2006-2012. 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. 
+ */
+package master_slave_bypass
+
+import org.simgrid.msg.HostFailureException
+import org.simgrid.msg.HostNotFoundException
+import org.simgrid.msg.Msg
+import org.simgrid.msg.TimeoutException
+import org.simgrid.msg.TransferFailureException
+import org.simgrid.msg.Process
+
+class Slave(hostname:String, name:String) extends Process(hostname, name) {
+  def main(args:Array[String]) {
+    Msg.info("Slave Hello!")
+    val task = new FinalizeTask()
+    Msg.info("Send finalize!")
+    task.send("alice")
+  }
+}
diff --git a/examples/scala/master_slave_bypass/bypass.tesh b/examples/scala/master_slave_bypass/bypass.tesh
new file mode 100644 (file)
index 0000000..6b28603
--- /dev/null
@@ -0,0 +1,11 @@
+#! tesh
+
+! output sort
+$ java -cp ${classpath:=.} master_slave_bypass/MsBypass ${srcdir:=.}/master_slave_bypass/platform.xml
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [0.013010] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
+> [alice:process2:(2) 0.000000] [jmsg/INFO] Slave Hello!
+> [alice:process2:(2) 0.000000] [jmsg/INFO] Send finalize!
+> [bob:process1:(1) 0.000000] [jmsg/INFO] Master Hello!
+> [bob:process1:(1) 0.000000] [jmsg/INFO] Create process on host 'alice'
+> [bob:process1:(1) 0.013010] [jmsg/INFO] Received Finalize. I'm done. See you!
diff --git a/examples/scala/master_slave_bypass/platform.xml b/examples/scala/master_slave_bypass/platform.xml
new file mode 100644 (file)
index 0000000..d0faf97
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+<AS  id="AS0"  routing="Full">
+       <host id="bob" power="137.333Mf"/>
+       <host id="alice" power="98.095Mf"/>
+       <host id="nono" power="98.095Mf"/>
+       
+       <link id="1" bandwidth="100MBps" latency="1ms"/>
+       <link id="2" bandwidth="100MBps" latency="1ms"/>
+       <link id="3" bandwidth="100MBps" latency="1ms"/>
+       
+       <route  src="bob"
+                       dst="alice"
+                       symmetrical="YES">
+                               <link_ctn id="1"/>
+   </route>
+       <route  src="alice"
+                       dst="nono"
+                       symmetrical="YES">
+                               <link_ctn id="2"/>
+   </route>
+       <route  src="bob"
+                       dst="nono"
+                       symmetrical="YES">
+                               <link_ctn id="3"/>
+   </route>
+</AS>
+</platform>
diff --git a/examples/scala/master_slave_kill/CMakeLists.txt b/examples/scala/master_slave_kill/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ca978c6
--- /dev/null
@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 2.6)
+
+set(example scala_master_slave_kill)
+set(sources
+  ${CMAKE_CURRENT_SOURCE_DIR}/FinalizeTask.scala
+  ${CMAKE_CURRENT_SOURCE_DIR}/Master.scala
+  ${CMAKE_CURRENT_SOURCE_DIR}/MsKill.scala
+  ${CMAKE_CURRENT_SOURCE_DIR}/Slave.scala
+  )
+
+if(enable_scala)
+  add_custom_command(
+    COMMENT "Building ${example}..."
+    OUTPUT ${example}_compiled
+    DEPENDS ${sources} SG_java_jar ${SIMGRID_JAR}
+    COMMAND ${SCALA_COMPILE} -cp ${SIMGRID_JAR}
+                             -d ${CMAKE_CURRENT_BINARY_DIR}/.. ${sources}
+    COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled
+    COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled
+  )
+  add_custom_target(${example} ALL DEPENDS ${example}_compiled)
+endif()
+
+set(tesh_files
+  ${tesh_files}
+  ${CMAKE_CURRENT_SOURCE_DIR}/kill.tesh
+  PARENT_SCOPE
+  )
+set(xml_files
+  ${xml_files}
+  ${CMAKE_CURRENT_SOURCE_DIR}/platform.xml
+  PARENT_SCOPE
+  )
+set(examples_src
+  ${examples_src}
+  ${sources}
+  PARENT_SCOPE
+  )
+set(bin_files
+  ${bin_files}
+  PARENT_SCOPE
+  )
+set(txt_files
+  ${txt_files}
+  PARENT_SCOPE
+  )
diff --git a/examples/scala/master_slave_kill/FinalizeTask.scala b/examples/scala/master_slave_kill/FinalizeTask.scala
new file mode 100644 (file)
index 0000000..452860b
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2006-2012. 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. 
+ */
+
+package master_slave_kill
+
+import org.simgrid.msg.Task
+
+class FinalizeTask extends Task("finalize",0,0) {}
+    
diff --git a/examples/scala/master_slave_kill/Master.scala b/examples/scala/master_slave_kill/Master.scala
new file mode 100644 (file)
index 0000000..01dca86
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Master of a basic master/slave example in Java
+ *
+ * Copyright 2006-2012 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. 
+ */
+
+package master_slave_kill
+
+import Stream._
+import org.simgrid.msg.HostNotFoundException
+import org.simgrid.msg.Msg
+import org.simgrid.msg.MsgException
+import org.simgrid.msg.Process
+import org.simgrid.msg.Task
+
+class Master(hostname:String, name:String) extends Process(hostname, name) {
+  def main(args:Array[String]) {
+    Msg.info("Master Hello!")
+    var process2:Slave = null
+    
+    //Create a slave on host "alice"
+    try {
+      Msg.info("Create process on host 'alice'")
+      process2 = new Slave("alice","slave")
+      process2.start()
+    } catch {
+      case e:MsgException => println("Process2!")
+    }
+    
+    //Wait for slave "alice"
+    continually({Task.receive("mail1")})
+      .takeWhile(!_.isInstanceOf[FinalizeTask])
+      .force // to force the list to be compute
+    
+    Msg.info("Received mail1!")
+    process2.kill()
+    Msg.info("Process2 is now killed, should exit now")
+  }
+}
diff --git a/examples/scala/master_slave_kill/MsKill.scala b/examples/scala/master_slave_kill/MsKill.scala
new file mode 100644 (file)
index 0000000..ec69031
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2006-2012. 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. 
+ */
+
+package master_slave_kill;
+
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.NativeException;
+
+object MsKill extends App{
+   
+  /* This only contains the launcher. If you do nothing more than than you can run 
+  *   scala simgrid.msg.Msg
+  * which also contains such a launcher
+  */
+   
+       
+  /* initialize the MSG simulation. Must be done before anything else (even logging). */
+  Msg.init(args)
+  Msg.createEnvironment(args(0))
+
+  /* bypass deploymemt */
+  try {
+    val process1 = new Master("bob","master")
+    process1.start()
+  }
+  catch {
+    case e:MsgException => println("Create processes failed!")
+  }
+    
+  /*  execute the simulation. */
+  Msg.run()   
+}
diff --git a/examples/scala/master_slave_kill/Slave.scala b/examples/scala/master_slave_kill/Slave.scala
new file mode 100644 (file)
index 0000000..38c266a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006-2012. 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. 
+ */
+package master_slave_kill
+
+import org.simgrid.msg.HostFailureException
+import org.simgrid.msg.HostNotFoundException
+import org.simgrid.msg.Msg
+import org.simgrid.msg.MsgException
+import org.simgrid.msg.Task
+import org.simgrid.msg.TimeoutException
+import org.simgrid.msg.TransferFailureException
+import org.simgrid.msg.Process
+
+class Slave(hostname:String, name:String) extends Process(hostname, name) {
+  def main(args:Array[String]) {
+    Msg.info("Slave Hello!")
+       
+    val task = new FinalizeTask();
+    Msg.info("Send Mail1!");
+    task.send("mail1");
+       
+    try {
+      Task.receive("mail2");
+    } catch {
+      case e:MsgException => {Msg.debug("Received failed")
+                              return}
+    }
+    Msg.info("Receive Mail2!")
+  }
+}
diff --git a/examples/scala/master_slave_kill/kill.tesh b/examples/scala/master_slave_kill/kill.tesh
new file mode 100644 (file)
index 0000000..f22d582
--- /dev/null
@@ -0,0 +1,13 @@
+#! tesh
+
+! output sort
+
+$ java -cp ${classpath:=.} master_slave_kill/MsKill ${srcdir:=.}/master_slave_kill/platform.xml
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [0.013010] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
+> [alice:slave:(2) 0.000000] [jmsg/INFO] Slave Hello!
+> [alice:slave:(2) 0.000000] [jmsg/INFO] Send Mail1!
+> [bob:master:(1) 0.000000] [jmsg/INFO] Master Hello!
+> [bob:master:(1) 0.000000] [jmsg/INFO] Create process on host 'alice'
+> [bob:master:(1) 0.013010] [jmsg/INFO] Received mail1!
+> [bob:master:(1) 0.013010] [jmsg/INFO] Process2 is now killed, should exit now
diff --git a/examples/scala/master_slave_kill/platform.xml b/examples/scala/master_slave_kill/platform.xml
new file mode 100644 (file)
index 0000000..a37f9c8
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+<AS  id="AS0"  routing="Full">
+       <host id="bob" power="137.333Mf"/>
+       <host id="alice" power="98.095Mf"/>
+       <host id="nono" power="98.095Mf"/>
+       
+       <link id="1" bandwidth="100MBps" latency="1ms"/>
+       <link id="2" bandwidth="100MBps" latency="1ms"/>
+       <link id="3" bandwidth="100MBps" latency="1ms"/>
+       
+       <route  src="bob"
+                       dst="alice"
+                       symmetrical="YES">
+                               <link_ctn id="1"/>
+   </route>
+       <route  src="alice"
+                       dst="nono"
+                       symmetrical="YES">
+                               <link_ctn id="2"/>
+   </route>
+       <route  src="bob"
+                       dst="nono"
+                       symmetrical="YES">
+                               <link_ctn id="3"/>
+   </route>
+</AS>
+</platform>
\ No newline at end of file