From fc783dc02e4e1bf955b152713d1df4914ae3adb8 Mon Sep 17 00:00:00 2001 From: mquinson Date: Thu, 2 Dec 2010 16:15:33 +0000 Subject: [PATCH 1/1] initial (almost working) release of a separate package for the Java bindings of SimGrid git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/contrib/trunk/simgrid-java@8900 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- CMakeLists.txt | 168 + ChangeLog | 6 + FindSimGrid.cmake | 77 + examples/basic/.project | 17 + examples/basic/BasicTest.java | 42 + examples/basic/FinalizeTask.java | 15 + examples/basic/Forwarder.java | 49 + examples/basic/Master.java | 42 + examples/basic/README | 11 + examples/basic/Slave.java | 42 + examples/basic/basic.tesh | 75 + examples/basic/basic_deployment.xml | 49 + examples/basic/basic_platform.xml | 8298 +++++++++++++++++ examples/basic/deploy.xml | 114 + examples/comm_time/CommTimeTest.java | 36 + examples/comm_time/FinalizeTask.java | 15 + examples/comm_time/Master.java | 43 + examples/comm_time/README | 5 + examples/comm_time/Slave.java | 31 + examples/comm_time/comm_time.tesh | 90 + examples/comm_time/comm_time_deployment.xml | 55 + examples/comm_time/comm_time_platform.xml | 8298 +++++++++++++++++ examples/java_test.mk | 26 + .../mutualExclusion/centralized/.classpath | 7 + examples/mutualExclusion/centralized/.project | 17 + .../centralized/Coordinator.java | 48 + .../centralized/GrantTask.java | 5 + .../centralized/MutexCentral.java | 39 + .../mutualExclusion/centralized/Node.java | 31 + .../centralized/ReleaseTask.java | 2 + .../centralized/RequestTask.java | 9 + .../centralized/mutex_centralized.tesh | 16 + .../mutex_centralized_deployment.xml | 15 + examples/mutualExclusion/ring3.xml | 37 + examples/ping_pong/PingPongTask.java | 30 + examples/ping_pong/PingPongTest.java | 38 + examples/ping_pong/README | 2 + examples/ping_pong/Receiver.java | 42 + examples/ping_pong/Sender.java | 51 + examples/ping_pong/hs_err_pid27276.log | 254 + examples/ping_pong/hs_err_pid28000.log | 256 + examples/ping_pong/ping_pong.tesh | 16 + examples/ping_pong/ping_pong_deployment.xml | 8 + examples/ping_pong/ping_pong_platform.xml | 92 + examples/runtest | 15 + examples/suspend/DreamMaster.java | 39 + examples/suspend/LazyGuy.java | 30 + examples/suspend/README | 1 + examples/suspend/SuspendTest.java | 35 + examples/suspend/suspend.tesh | 15 + examples/suspend/suspend_deployment.xml | 5 + examples/suspend/suspend_platform.xml | 8298 +++++++++++++++++ org/simgrid/msg/ApplicationHandler.java | 144 + org/simgrid/msg/Host.java | 165 + org/simgrid/msg/HostFailureException.java | 32 + org/simgrid/msg/HostNotFoundException.java | 32 + org/simgrid/msg/JniException.java | 35 + org/simgrid/msg/Msg.java | 113 + org/simgrid/msg/MsgException.java | 42 + org/simgrid/msg/MsgNative.java | 428 + org/simgrid/msg/NativeException.java | 28 + org/simgrid/msg/Process.java | 380 + org/simgrid/msg/ProcessNotFoundException.java | 35 + org/simgrid/msg/Sem.java | 35 + org/simgrid/msg/Task.java | 223 + org/simgrid/msg/TaskCancelledException.java | 32 + org/simgrid/msg/TimeoutException.java | 32 + org/simgrid/msg/TransferFailureException.java | 32 + src/jmsg.c | 1152 +++ src/jmsg.h | 344 + src/jmsg_application_handler.c | 110 + src/jmsg_application_handler.h | 21 + src/jmsg_host.c | 88 + src/jmsg_host.h | 110 + src/jmsg_process.c | 216 + src/jmsg_process.h | 242 + src/jmsg_task.c | 41 + src/jmsg_task.h | 78 + src/jxbt_utilities.c | 296 + src/jxbt_utilities.h | 94 + 80 files changed, 31637 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 ChangeLog create mode 100644 FindSimGrid.cmake create mode 100644 examples/basic/.project create mode 100644 examples/basic/BasicTest.java create mode 100644 examples/basic/FinalizeTask.java create mode 100644 examples/basic/Forwarder.java create mode 100644 examples/basic/Master.java create mode 100644 examples/basic/README create mode 100644 examples/basic/Slave.java create mode 100644 examples/basic/basic.tesh create mode 100644 examples/basic/basic_deployment.xml create mode 100644 examples/basic/basic_platform.xml create mode 100644 examples/basic/deploy.xml create mode 100644 examples/comm_time/CommTimeTest.java create mode 100644 examples/comm_time/FinalizeTask.java create mode 100644 examples/comm_time/Master.java create mode 100644 examples/comm_time/README create mode 100644 examples/comm_time/Slave.java create mode 100644 examples/comm_time/comm_time.tesh create mode 100644 examples/comm_time/comm_time_deployment.xml create mode 100644 examples/comm_time/comm_time_platform.xml create mode 100644 examples/java_test.mk create mode 100644 examples/mutualExclusion/centralized/.classpath create mode 100644 examples/mutualExclusion/centralized/.project create mode 100644 examples/mutualExclusion/centralized/Coordinator.java create mode 100644 examples/mutualExclusion/centralized/GrantTask.java create mode 100644 examples/mutualExclusion/centralized/MutexCentral.java create mode 100644 examples/mutualExclusion/centralized/Node.java create mode 100644 examples/mutualExclusion/centralized/ReleaseTask.java create mode 100644 examples/mutualExclusion/centralized/RequestTask.java create mode 100644 examples/mutualExclusion/centralized/mutex_centralized.tesh create mode 100644 examples/mutualExclusion/centralized/mutex_centralized_deployment.xml create mode 100644 examples/mutualExclusion/ring3.xml create mode 100644 examples/ping_pong/PingPongTask.java create mode 100644 examples/ping_pong/PingPongTest.java create mode 100644 examples/ping_pong/README create mode 100644 examples/ping_pong/Receiver.java create mode 100644 examples/ping_pong/Sender.java create mode 100644 examples/ping_pong/hs_err_pid27276.log create mode 100644 examples/ping_pong/hs_err_pid28000.log create mode 100644 examples/ping_pong/ping_pong.tesh create mode 100644 examples/ping_pong/ping_pong_deployment.xml create mode 100644 examples/ping_pong/ping_pong_platform.xml create mode 100755 examples/runtest create mode 100644 examples/suspend/DreamMaster.java create mode 100644 examples/suspend/LazyGuy.java create mode 100644 examples/suspend/README create mode 100644 examples/suspend/SuspendTest.java create mode 100644 examples/suspend/suspend.tesh create mode 100644 examples/suspend/suspend_deployment.xml create mode 100644 examples/suspend/suspend_platform.xml create mode 100644 org/simgrid/msg/ApplicationHandler.java create mode 100644 org/simgrid/msg/Host.java create mode 100644 org/simgrid/msg/HostFailureException.java create mode 100644 org/simgrid/msg/HostNotFoundException.java create mode 100644 org/simgrid/msg/JniException.java create mode 100644 org/simgrid/msg/Msg.java create mode 100644 org/simgrid/msg/MsgException.java create mode 100644 org/simgrid/msg/MsgNative.java create mode 100644 org/simgrid/msg/NativeException.java create mode 100644 org/simgrid/msg/Process.java create mode 100644 org/simgrid/msg/ProcessNotFoundException.java create mode 100644 org/simgrid/msg/Sem.java create mode 100644 org/simgrid/msg/Task.java create mode 100644 org/simgrid/msg/TaskCancelledException.java create mode 100644 org/simgrid/msg/TimeoutException.java create mode 100644 org/simgrid/msg/TransferFailureException.java create mode 100644 src/jmsg.c create mode 100644 src/jmsg.h create mode 100644 src/jmsg_application_handler.c create mode 100644 src/jmsg_application_handler.h create mode 100644 src/jmsg_host.c create mode 100644 src/jmsg_host.h create mode 100644 src/jmsg_process.c create mode 100644 src/jmsg_process.h create mode 100644 src/jmsg_task.c create mode 100644 src/jmsg_task.h create mode 100644 src/jxbt_utilities.c create mode 100644 src/jxbt_utilities.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..5ba42eb3e5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,168 @@ +cmake_minimum_required(VERSION 2.6) +project(simgrid-java C) +include(FindSimGrid.cmake) + +############################### +# Test the build dependencies # +############################### +SET(HAVE_JAVA 0) +include(FindJava) +include(FindJNI) +if(JAVA_INCLUDE_PATH) + set(HAVE_JNI_H 1) +endif(JAVA_INCLUDE_PATH) +if(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2) + SET(HAVE_JAVA 1) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${JAVA_INCLUDE_PATH} ") + if(NOT JAVA_INCLUDE_PATH STREQUAL JAVA_INCLUDE_PATH2) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${JAVA_INCLUDE_PATH2} ") + endif(NOT JAVA_INCLUDE_PATH STREQUAL JAVA_INCLUDE_PATH2) +else(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2) + SET(HAVE_JAVA 0) +endif(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2) + + +############################### +# Declare our package content # +############################### + +set(JMSG_C_SRC + src/simix/smx_context_java.h + src/simix/smx_context_java.c + src/java/jxbt_utilities.c + src/java/jxbt_utilities.h + src/java/jmsg.c + src/java/jmsg.h + src/java/jmsg_host.c + src/java/jmsg_host.h + src/java/jmsg_process.c + src/java/jmsg_process.h + src/java/jmsg_task.c + src/java/jmsg_task.h + src/java/jmsg_application_handler.c + src/java/jmsg_application_handler.h +) + +set(JMSG_JAVA_SRC + org/simgrid/msg/ApplicationHandler.java + org/simgrid/msg/Host.java + org/simgrid/msg/HostFailureException.java + org/simgrid/msg/HostNotFoundException.java + org/simgrid/msg/JniException.java + org/simgrid/msg/Msg.java + org/simgrid/msg/MsgException.java + org/simgrid/msg/MsgNative.java + org/simgrid/msg/NativeException.java + org/simgrid/msg/Process.java + org/simgrid/msg/ProcessNotFoundException.java + org/simgrid/msg/Sem.java + org/simgrid/msg/Task.java + org/simgrid/msg/TaskCancelledException.java + org/simgrid/msg/TimeoutException.java + org/simgrid/msg/TransferFailureException.java +) + +file(GLOB_RECURSE examples_sources + "examples/*.java" + "examples/*.xml" + "examples/*.txt" + "examples/java/runtest" +) + +############### +# Build Stuff # +############### + +set(JAVA_FILES ${JMSG_JAVA_SRC}) +set(JAVA_CLASSES ${JAVA_FILES}) + +string(REPLACE "org/" "${CMAKE_HOME_DIRECTORY}/org/" + JAVA_FILES "${JAVA_FILES}") + +string(REPLACE "org/simgrid/msg" "${CMAKE_CURRENT_BINARY_DIR}/classes/simgrid/msg" + JAVA_CLASSES "${JAVA_CLASSES}") +string(REPLACE ".java" ".class;" + JAVA_CLASSES "${JAVA_CLASSES}") + + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/classes/ + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/classes/") + +# compile all .java files with javac to .class +ADD_CUSTOM_COMMAND( + OUTPUT ${JAVA_CLASSES} + DEPENDS ${JAVA_FILES} ${CMAKE_CURRENT_BINARY_DIR}/classes/ + COMMAND ${JAVA_COMPILE} -d ${CMAKE_CURRENT_BINARY_DIR}/classes/ + -cp ${CMAKE_CURRENT_BINARY_DIR}/classes/ + ${JAVA_FILES} + COMMENT "Compiling java sources of core library..." +) + +ADD_CUSTOM_TARGET(simgrid_java ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar) + +ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar + DEPENDS ${JAVA_CLASSES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/classes + COMMAND ${JAVA_ARCHIVE} -cvf ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar . + COMMENT "Building simgrid.jar..." +) + +ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/BasicTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/FinalizeTask.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/Forwarder.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/Slave.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/Master.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/PingPongTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/Sender.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/PingPongTask.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/Receiver.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/FinalizeTask.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/CommTimeTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/Slave.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/Master.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend/SuspendTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend/LazyGuy.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend/DreamMaster.class + + DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar + ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java + ${CMAKE_HOME_DIRECTORY}/examples/ping_pong/*.java + ${CMAKE_HOME_DIRECTORY}/examples/comm_time/*.java + ${CMAKE_HOME_DIRECTORY}/examples/suspend/*.java + + COMMENT "Build examples for java" + + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/examples/basic + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend + + COMMAND ${JAVA_COMPILE} -d ${CMAKE_CURRENT_BINARY_DIR}/examples/basic -cp ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java + COMMAND ${JAVA_COMPILE} -d ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong -cp ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/ping_pong/*.java + COMMAND ${JAVA_COMPILE} -d ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time -cp ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/comm_time/*.java + COMMAND ${JAVA_COMPILE} -d ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend -cp ${CMAKE_CURRENT_BINARY_DIR}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/suspend/*.java +) + +ADD_CUSTOM_TARGET(simgrid_java_examples ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/BasicTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/FinalizeTask.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/Forwarder.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/Slave.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/basic/Master.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/PingPongTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/Sender.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/PingPongTask.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/ping_pong/Receiver.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/FinalizeTask.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/CommTimeTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/Slave.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/comm_time/Master.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend/SuspendTest.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend/LazyGuy.class + ${CMAKE_CURRENT_BINARY_DIR}/examples/suspend/DreamMaster.class +) \ No newline at end of file diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000000..ba4641ade4 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,6 @@ +SimGrid-java (3.6) unstable; urgency=low + + * Initial release. + * Split of every thing from simgrid v3.5 into a separate package. + + -- Da SimGrid team diff --git a/FindSimGrid.cmake b/FindSimGrid.cmake new file mode 100644 index 0000000000..a5d247f1df --- /dev/null +++ b/FindSimGrid.cmake @@ -0,0 +1,77 @@ +#IF YOU HAVE INSTALL SIMGRID LIBRARIES AND SIMGRID BINARIES IN A SPECIAL DIRECTORY +#YOU CAN SPECIFY SIMGRID_LIBRARY_PAT AND SIMGRID_BIN_PATH OR SIMPLY LD_LIBRARY_PATH + +# TO CALL THIS FILE USE + #set(CMAKE_MODULE_PATH + #${CMAKE_MODULE_PATH} + #${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Modules + #) + +message("SIMGRID_LIBRARY_PATH = $ENV{SIMGRID_LIBRARY_PATH}") +message("SIMGRID_BIN_PATH = $ENV{SIMGRID_BIN_PATH}") +message("LD_LIBRARY_PATH = $ENV{LD_LIBRARY_PATH}") + +find_library(HAVE_SIMGRID_LIB + NAME simgrid + HINTS + $ENV{LIBRARIES} + $ENV{LD_LIBRARY_PATH} + $ENV{SIMGRID_LIBRARY_PATH} + PATH_SUFFIXES lib64 lib simgrid/lib64 simgrid/lib + PATHS + /opt + /opt/local + /opt/csw + /sw + /usr +) + +find_path(HAVE_GRAS_H gras.h + HINTS + $ENV{INCLUDES} + $ENV{LD_LIBRARY_PATH} + $ENV{SIMGRID_LIBRARY_PATH} + PATH_SUFFIXES include simgrid/include + PATHS + /opt + /opt/local + /opt/csw + /sw + /usr +) + +string(REPLACE "/include" "/bin" OPTIONAL_BIN_PATH "HAVE_GRAS_H") + +find_program(HAVE_TESH +NAMES tesh +HINTS +$ENV{SIMGRID_BIN_PATH} +$ENV{LD_LIBRARY_PATH} +PATH_SUFFIXES bin simgrid/bin +PATHS +${OPTIONAL_BIN_PATH} +/opt +/opt/local +/opt/csw +/sw +/usr +) + +find_program(HAVE_GRAS_STUB +NAMES gras_stub_generator +HINTS +$ENV{SIMGRID_BIN_PATH} +$ENV{LD_LIBRARY_PATH} +PATH_SUFFIXES bin simgrid/bin +PATHS +/opt +/opt/local +/opt/csw +/sw +/usr +) + +message("HAVE_SIMGRID_LIB = ${HAVE_SIMGRID_LIB}") +message("HAVE_GRAS_H = ${HAVE_GRAS_H}") +message("HAVE_TESH = ${HAVE_TESH}") +message("HAVE_GRAS_STUB = ${HAVE_GRAS_STUB}") \ No newline at end of file diff --git a/examples/basic/.project b/examples/basic/.project new file mode 100644 index 0000000000..174192eab9 --- /dev/null +++ b/examples/basic/.project @@ -0,0 +1,17 @@ + + + java_MasterSlaves + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/examples/basic/BasicTest.java b/examples/basic/BasicTest.java new file mode 100644 index 0000000000..e6c6a8f672 --- /dev/null +++ b/examples/basic/BasicTest.java @@ -0,0 +1,42 @@ +/* + * 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 BasicTest { + + /* This only contains the launcher. If you do nothing more than than you can run + * java simgrid.msg.Msg + * which also contains such a launcher + */ + + public static void main(String[] args) throws NativeException { + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + + if(args.length == 0) { + Msg.createEnvironment("basic_platform.xml"); + Msg.deployApplication("basic_deployment.xml"); + + } else if (args.length < 2) { + + + Msg.info("Usage : Basic platform_file deployment_file"); + Msg.info("example : Basic basic_platform.xml basic_deployment.xml"); + System.exit(1); + } else { + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + } + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/basic/FinalizeTask.java b/examples/basic/FinalizeTask.java new file mode 100644 index 0000000000..3764382617 --- /dev/null +++ b/examples/basic/FinalizeTask.java @@ -0,0 +1,15 @@ +/* + * 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 FinalizeTask extends Task { + public FinalizeTask() { + super("finalize",0,0); + } +} + \ No newline at end of file diff --git a/examples/basic/Forwarder.java b/examples/basic/Forwarder.java new file mode 100644 index 0000000000..741133f7c9 --- /dev/null +++ b/examples/basic/Forwarder.java @@ -0,0 +1,49 @@ +/* + * 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 Forwarder extends simgrid.msg.Process { + + public void main(String[] args) throws MsgException { + if (args.length < 3) { + Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)"); + Msg.info("Got "+args.length+" instead"); + System.exit(1); + } + int input = Integer.valueOf(args[0]).intValue(); + int firstOutput = Integer.valueOf(args[1]).intValue(); + int lastOutput = Integer.valueOf(args[2]).intValue(); + + int taskCount = 0; + int slavesCount = lastOutput - firstOutput + 1; + Msg.info("Receiving on 'slave_"+input+"'"); + while(true) { + Task task = Task.receive("slave_"+input); + + if (task instanceof FinalizeTask) { + Msg.info("Got a finalize task. Let's forward that we're done."); + + for (int cpt = firstOutput; cpt<=lastOutput; cpt++) { + Task tf = new FinalizeTask(); + tf.send("slave_"+cpt); + } + break; + } + int dest = firstOutput + (taskCount % slavesCount); + + Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\""); + task.send("slave_"+dest); + + taskCount++; + } + + + Msg.info("I'm done. See you!"); + } +} + diff --git a/examples/basic/Master.java b/examples/basic/Master.java new file mode 100644 index 0000000000..021220c85f --- /dev/null +++ b/examples/basic/Master.java @@ -0,0 +1,42 @@ +/* + * Master of a basic master/slave example in Java + * + * 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 MsgException { + if (args.length < 4) { + Msg.info("Master needs 4 arguments"); + System.exit(1); + } + + int tasksCount = Integer.valueOf(args[0]).intValue(); + double taskComputeSize = Double.valueOf(args[1]).doubleValue(); + double taskCommunicateSize = Double.valueOf(args[2]).doubleValue(); + + int slavesCount = Integer.valueOf(args[3]).intValue(); + + Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process"); + + for (int i = 0; i < tasksCount; i++) { + Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); + //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 < slavesCount; i++) { + FinalizeTask task = new FinalizeTask(); + task.send("slave_"+(i%slavesCount)); + } + + Msg.info("Goodbye now!"); + } +} diff --git a/examples/basic/README b/examples/basic/README new file mode 100644 index 0000000000..9207911abc --- /dev/null +++ b/examples/basic/README @@ -0,0 +1,11 @@ +This is a somehow basic master/slaves example. + +There is 3 kind of processes: + * Master: creates some tasks, and dispatches them to its slaves + * Forwarder: get tasks from master, and dispatch them further + * Slave: get tasks from either master or forwarder, and run them + +At the end of the execution: + - the master sends FinalizeTask to every known slave to stop them + - On reception of FT, forwarders send FT to every slave, and stop. + - On reception of FinalizeTask, slaves stop. \ No newline at end of file diff --git a/examples/basic/Slave.java b/examples/basic/Slave.java new file mode 100644 index 0000000000..d55ae0a224 --- /dev/null +++ b/examples/basic/Slave.java @@ -0,0 +1,42 @@ +/* + * 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.HostFailureException; +import simgrid.msg.Msg; +import simgrid.msg.Task; +import simgrid.msg.TaskCancelledException; +import simgrid.msg.TimeoutException; +import simgrid.msg.TransferFailureException; + +public class Slave extends simgrid.msg.Process { + public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { + 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+"'"); + + while(true) { + Task task = Task.receive("slave_"+num); + + if (task instanceof FinalizeTask) { + break; + } + Msg.info("Received \"" + task.getName() + "\". Processing it."); + try { + task.execute(); + } catch (TaskCancelledException e) { + + } + // Msg.info("\"" + task.getName() + "\" done "); + } + + //Msg.info("Received Finalize. I'm done. See you!"); + } +} \ No newline at end of file diff --git a/examples/basic/basic.tesh b/examples/basic/basic.tesh new file mode 100644 index 0000000000..8bbea2bb62 --- /dev/null +++ b/examples/basic/basic.tesh @@ -0,0 +1,75 @@ +# compile the example +$ javac -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR. *.java + +# run the basic sample +$ java -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR BasicTest basic_platform.xml basic_deployment.xml +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] hello! +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argc=8 +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:5 +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:50000 +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:10 +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:iRMX +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Casavant +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Bousquet +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Soucy +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Jackson +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Got 5 slave(s) : +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] iRMX +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Casavant +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Bousquet +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Soucy +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Jackson +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Got 5 task to process. +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Sending "Task_0" to "iRMX" +> [Jackson:Forwarder:(2) 0.000000] [jmsg/INFO] hello! +> [Casavant:Forwarder:(3) 0.000000] [jmsg/INFO] hello! +> [iRMX:Slave:(4) 0.000000] [jmsg/INFO] Hello ! +> [Bousquet:Slave:(5) 0.000000] [jmsg/INFO] Hello ! +> [Soucy:Slave:(6) 0.000000] [jmsg/INFO] Hello ! +> [Kuenning:Slave:(7) 0.000000] [jmsg/INFO] Hello ! +> [Browne:Slave:(8) 0.000000] [jmsg/INFO] Hello ! +> [Stephen:Slave:(9) 0.000000] [jmsg/INFO] Hello ! +> [Robert:Slave:(10) 0.000000] [jmsg/INFO] Hello ! +> [Sirois:Slave:(11) 0.000000] [jmsg/INFO] Hello ! +> [Monique:Slave:(12) 0.000000] [jmsg/INFO] Hello ! +> [Jacquelin:Master:(1) 0.234181] [jmsg/INFO] Sending "Task_1" to "Casavant" +> [iRMX:Slave:(4) 0.234181] [jmsg/INFO] Received "Task_0" +> [iRMX:Slave:(4) 0.234181] [jmsg/INFO] Processing "Task_0" +> [iRMX:Slave:(4) 0.234910] [jmsg/INFO] "Task_0" done +> [Jacquelin:Master:(1) 0.338591] [jmsg/INFO] Sending "Task_2" to "Bousquet" +> [Casavant:Forwarder:(3) 0.338591] [jmsg/INFO] Received "Task_1" +> [Casavant:Forwarder:(3) 0.338591] [jmsg/INFO] Sending "Task_1" to "Robert" +> [Jacquelin:Master:(1) 0.416661] [jmsg/INFO] Sending "Task_3" to "Soucy" +> [Bousquet:Slave:(5) 0.416661] [jmsg/INFO] Received "Task_2" +> [Bousquet:Slave:(5) 0.416661] [jmsg/INFO] Processing "Task_2" +> [Bousquet:Slave:(5) 0.417826] [jmsg/INFO] "Task_2" done +> [Robert:Slave:(10) 0.454402] [jmsg/INFO] Received "Task_1" +> [Robert:Slave:(10) 0.454402] [jmsg/INFO] Processing "Task_1" +> [Robert:Slave:(10) 0.454766] [jmsg/INFO] "Task_1" done +> [Jacquelin:Master:(1) 0.527739] [jmsg/INFO] Sending "Task_4" to "Jackson" +> [Soucy:Slave:(6) 0.527739] [jmsg/INFO] Received "Task_3" +> [Soucy:Slave:(6) 0.527739] [jmsg/INFO] Processing "Task_3" +> [Soucy:Slave:(6) 0.528103] [jmsg/INFO] "Task_3" done +> [Jacquelin:Master:(1) 0.593252] [jmsg/INFO] Send completed +> [Jacquelin:Master:(1) 0.593252] [jmsg/INFO] All tasks have been dispatched. Let's tell everybody the computation is over. +> [Jackson:Forwarder:(2) 0.593252] [jmsg/INFO] Received "Task_4" +> [Jackson:Forwarder:(2) 0.593252] [jmsg/INFO] Sending "Task_4" to "Kuenning" +> [Kuenning:Slave:(7) 0.593708] [jmsg/INFO] Received "Task_4" +> [Kuenning:Slave:(7) 0.593708] [jmsg/INFO] Processing "Task_4" +> [Kuenning:Slave:(7) 0.594291] [jmsg/INFO] "Task_4" done +> [iRMX:Slave:(4) 0.827199] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Casavant:Forwarder:(3) 0.931504] [jmsg/INFO] All tasks have been dispatched. Let's tell everybody the computation is over. +> [Bousquet:Slave:(5) 1.009496] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Robert:Slave:(10) 1.047200] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Sirois:Slave:(11) 1.086548] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Soucy:Slave:(6) 1.120464] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Casavant:Forwarder:(3) 1.154764] [jmsg/INFO] I'm done. See you! +> [Monique:Slave:(12) 1.154764] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 1.185911] [jmsg/INFO] Goodbye now! +> [Jackson:Forwarder:(2) 1.185911] [jmsg/INFO] All tasks have been dispatched. Let's tell everybody the computation is over. +> [Kuenning:Slave:(7) 1.186360] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Browne:Slave:(8) 1.325058] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jackson:Forwarder:(2) 1.532781] [jmsg/INFO] I'm done. See you! +> [Stephen:Slave:(9) 1.532781] [jmsg/INFO] Received Finalize. I'm done. See you! + + diff --git a/examples/basic/basic_deployment.xml b/examples/basic/basic_deployment.xml new file mode 100644 index 0000000000..b6195d1c6e --- /dev/null +++ b/examples/basic/basic_deployment.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/basic/basic_platform.xml b/examples/basic/basic_platform.xml new file mode 100644 index 0000000000..484de26362 --- /dev/null +++ b/examples/basic/basic_platform.xml @@ -0,0 +1,8298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/basic/deploy.xml b/examples/basic/deploy.xml new file mode 100644 index 0000000000..e2d3632fb0 --- /dev/null +++ b/examples/basic/deploy.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + diff --git a/examples/comm_time/CommTimeTest.java b/examples/comm_time/CommTimeTest.java new file mode 100644 index 0000000000..ef31c0baa2 --- /dev/null +++ b/examples/comm_time/CommTimeTest.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + + +import simgrid.msg.*; + +public class CommTimeTest { + + /* This only contains the launcher. If you do nothing more than than you can run + * java simgrid.msg.Msg + * which also contains such a launcher + */ + + public static void main(String[] args) throws NativeException { + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + + 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); + } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/comm_time/FinalizeTask.java b/examples/comm_time/FinalizeTask.java new file mode 100644 index 0000000000..b7878fd75f --- /dev/null +++ b/examples/comm_time/FinalizeTask.java @@ -0,0 +1,15 @@ +/* + * 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 FinalizeTask extends Task { + public FinalizeTask() { + super("",0,0); + } +} + \ No newline at end of file diff --git a/examples/comm_time/Master.java b/examples/comm_time/Master.java new file mode 100644 index 0000000000..c2bbc5ce8b --- /dev/null +++ b/examples/comm_time/Master.java @@ -0,0 +1,43 @@ +/* + * Master of a basic master/slave example in Java + * + * 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 MsgException { + if (args.length < 4) { + Msg.info("Master needs 4 arguments"); + System.exit(1); + } + + int tasksCount = Integer.valueOf(args[0]).intValue(); + double taskComputeSize = Double.valueOf(args[1]).doubleValue(); + double taskCommunicateSize = Double.valueOf(args[2]).doubleValue(); + + int slavesCount = Integer.valueOf(args[3]).intValue(); + + Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process"); + + for (int i = 0; i < tasksCount; i++) { + Task task = new Task("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 < slavesCount; i++) { + FinalizeTask task = new FinalizeTask(); + task.send("slave_"+(i%slavesCount)); + } + + Msg.info("Goodbye now!"); + } +} diff --git a/examples/comm_time/README b/examples/comm_time/README new file mode 100644 index 0000000000..6512acd7fe --- /dev/null +++ b/examples/comm_time/README @@ -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 diff --git a/examples/comm_time/Slave.java b/examples/comm_time/Slave.java new file mode 100644 index 0000000000..539fd34f59 --- /dev/null +++ b/examples/comm_time/Slave.java @@ -0,0 +1,31 @@ +/* + * 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 Slave extends simgrid.msg.Process { + public void main(String[] args) throws MsgException { + 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+"'"); + + while(true) { + Task task = Task.receive("slave_"+num); + + if (task instanceof FinalizeTask) { + break; + } + task.execute(); + } + + Msg.info("Received Finalize. I'm done. See you!"); + } +} \ No newline at end of file diff --git a/examples/comm_time/comm_time.tesh b/examples/comm_time/comm_time.tesh new file mode 100644 index 0000000000..36be196da1 --- /dev/null +++ b/examples/comm_time/comm_time.tesh @@ -0,0 +1,90 @@ +# compile the example +$ javac -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR. *.java + +# run the comm_time sample +$ java -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR CommTimeTest comm_time_platform.xml comm_time_deployment.xml +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Hello i'm the master +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Got 20 slave(s): +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] iRMX +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Bousquet +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Soucy +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Casavant +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Jackson +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Geoff +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Disney +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] McGee +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Gatien +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Laroche +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Tanguay +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Morin +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Ethernet +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Bellemarre +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Harry +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Olivier +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Boucherville +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Pointe_Claire +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Kansas +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] King +> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Got 50000 task(s) to process. +> [iRMX:Slave:(2) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Bousquet:Slave:(3) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Soucy:Slave:(4) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Casavant:Slave:(5) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Jackson:Slave:(6) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Geoff:Slave:(7) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Disney:Slave:(8) 0.000000] [jmsg/INFO] Hello i'm a slave +> [McGee:Slave:(9) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Gatien:Slave:(10) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Laroche:Slave:(11) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Tanguay:Slave:(12) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Morin:Slave:(13) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Ethernet:Slave:(14) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Bellemarre:Slave:(15) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Harry:Slave:(16) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Olivier:Slave:(17) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Boucherville:Slave:(18) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Pointe_Claire:Slave:(19) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Kansas:Slave:(20) 0.000000] [jmsg/INFO] Hello i'm a slave +> [King:Slave:(21) 0.000000] [jmsg/INFO] Hello i'm a slave +> [Jacquelin:Master:(1) 5385.510565] [jmsg/INFO] All tasks have been dispatched. Let's tell everybody the computation is over. +> [Jacquelin:Master:(1) 5385.510565] [jmsg/INFO] Finalize host iRMX [0] +> [Jacquelin:Master:(1) 5385.744512] [jmsg/INFO] Finalize host Bousquet [1] +> [iRMX:Slave:(2) 5385.744512] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5385.822504] [jmsg/INFO] Finalize host Soucy [2] +> [Bousquet:Slave:(3) 5385.822504] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5385.933472] [jmsg/INFO] Finalize host Casavant [3] +> [Soucy:Slave:(4) 5385.933472] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.037777] [jmsg/INFO] Finalize host Jackson [4] +> [Casavant:Slave:(5) 5386.037777] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.103224] [jmsg/INFO] Finalize host Geoff [5] +> [Jackson:Slave:(6) 5386.103224] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.103634] [jmsg/INFO] Finalize host Disney [6] +> [Geoff:Slave:(7) 5386.103634] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.243798] [jmsg/INFO] Finalize host McGee [7] +> [Disney:Slave:(8) 5386.243798] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.312081] [jmsg/INFO] Finalize host Gatien [8] +> [McGee:Slave:(9) 5386.312081] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.410039] [jmsg/INFO] Finalize host Laroche [9] +> [Gatien:Slave:(10) 5386.410039] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.548443] [jmsg/INFO] Finalize host Tanguay [10] +> [Laroche:Slave:(11) 5386.548443] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.624602] [jmsg/INFO] Finalize host Morin [11] +> [Tanguay:Slave:(12) 5386.624602] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.767895] [jmsg/INFO] Finalize host Ethernet [12] +> [Morin:Slave:(13) 5386.767895] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.849385] [jmsg/INFO] Finalize host Bellemarre [13] +> [Ethernet:Slave:(14) 5386.849385] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5386.988558] [jmsg/INFO] Finalize host Harry [14] +> [Bellemarre:Slave:(15) 5386.988558] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5387.129807] [jmsg/INFO] Finalize host Olivier [15] +> [Harry:Slave:(16) 5387.129807] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5387.240138] [jmsg/INFO] Finalize host Boucherville [16] +> [Olivier:Slave:(17) 5387.240138] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5387.386104] [jmsg/INFO] Finalize host Pointe_Claire [17] +> [Boucherville:Slave:(18) 5387.386104] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5387.528570] [jmsg/INFO] Finalize host Kansas [18] +> [Pointe_Claire:Slave:(19) 5387.528570] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5387.597140] [jmsg/INFO] Finalize host King [19] +> [Kansas:Slave:(20) 5387.597140] [jmsg/INFO] Received Finalize. I'm done. See you! +> [Jacquelin:Master:(1) 5387.662613] [jmsg/INFO] All finalize messages have been dispatched. Goodbye now! +> [King:Slave:(21) 5387.662613] [jmsg/INFO] Received Finalize. I'm done. See you! \ No newline at end of file diff --git a/examples/comm_time/comm_time_deployment.xml b/examples/comm_time/comm_time_deployment.xml new file mode 100644 index 0000000000..0afeaa124c --- /dev/null +++ b/examples/comm_time/comm_time_deployment.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/comm_time/comm_time_platform.xml b/examples/comm_time/comm_time_platform.xml new file mode 100644 index 0000000000..484de26362 --- /dev/null +++ b/examples/comm_time/comm_time_platform.xml @@ -0,0 +1,8298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/java_test.mk b/examples/java_test.mk new file mode 100644 index 0000000000..90a568c6b0 --- /dev/null +++ b/examples/java_test.mk @@ -0,0 +1,26 @@ +######################### +# How to compile the code +# All this to only get a dumb javac *java... Automake still have issues with java + +JAVAROOT=. + +AM_JAVACFLAGS=-classpath .:$(top_srcdir)/src/simgrid.jar:../../../src/simgrid.jar:.. + + +########################## +# What to do on make check +# We need to rely on an external script (../runtest) because automake adds a ./ in front of the test name +# We need to override LD_LIBRARY_PATH so that the VM finds the libsimgrid4java.so +# We need to override the CLASSPATH to add simgrid.jar and current dir to the picture +# We also need to express dependencies manually (in each test dir) +# Damn... +if HAVE_JAVA + TESTS_ENVIRONMENT=LD_LIBRARY_PATH="$(top_srcdir)/src/.libs:$$LD_LIBRARY_PATH" \ + CLASSPATH=".:../../../src/simgrid.jar:$(top_srcdir)/src/simgrid.jar:$$CLASSPATH" \ + $(srcdir)/../runtest +else + TESTS_ENVIRONMENT=DO_NOT_HAVE_JAVA=1 $(srcdir)/../runtest +endif + +# declare that we must recompile everything before lauching tests +$(TESTS): classnoinst.stamp diff --git a/examples/mutualExclusion/centralized/.classpath b/examples/mutualExclusion/centralized/.classpath new file mode 100644 index 0000000000..38d109ccb7 --- /dev/null +++ b/examples/mutualExclusion/centralized/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/mutualExclusion/centralized/.project b/examples/mutualExclusion/centralized/.project new file mode 100644 index 0000000000..e8ab2edcaf --- /dev/null +++ b/examples/mutualExclusion/centralized/.project @@ -0,0 +1,17 @@ + + + MutexCentral + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/examples/mutualExclusion/centralized/Coordinator.java b/examples/mutualExclusion/centralized/Coordinator.java new file mode 100644 index 0000000000..03da2f63fe --- /dev/null +++ b/examples/mutualExclusion/centralized/Coordinator.java @@ -0,0 +1,48 @@ +/* + * $Id$ + * + * Copyright 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 java.util.LinkedList; + +import simgrid.msg.Msg; +import simgrid.msg.MsgException; +import simgrid.msg.Task; + +public class Coordinator extends simgrid.msg.Process { + + LinkedList waitingQueue=new LinkedList(); + int CsToServe; + + public void main(String[] args) throws MsgException { + CsToServe = Integer.parseInt(args[0]); + Task task; + while (CsToServe >0) { + task = Task.receive("coordinator"); + if (task instanceof RequestTask) { + RequestTask t = (RequestTask) task; + if (waitingQueue.isEmpty()) { + Msg.info("Got a request from "+t.from+". Queue empty: grant it"); + GrantTask tosend = new GrantTask(); + tosend.send(t.from); + } else { + waitingQueue.push(t); + } + } else if (task instanceof ReleaseTask) { + if (!waitingQueue.isEmpty()) { + RequestTask req = waitingQueue.removeLast(); + GrantTask tosend = new GrantTask(); + tosend.send(req.from); + } + CsToServe--; + if (waitingQueue.isEmpty() && CsToServe==0) { + Msg.info("we should shutdown the simulation now"); + } + } + } + } +} \ No newline at end of file diff --git a/examples/mutualExclusion/centralized/GrantTask.java b/examples/mutualExclusion/centralized/GrantTask.java new file mode 100644 index 0000000000..f9322d1252 --- /dev/null +++ b/examples/mutualExclusion/centralized/GrantTask.java @@ -0,0 +1,5 @@ +import simgrid.msg.Task; + + +public class GrantTask extends Task { +} diff --git a/examples/mutualExclusion/centralized/MutexCentral.java b/examples/mutualExclusion/centralized/MutexCentral.java new file mode 100644 index 0000000000..f6a747ac61 --- /dev/null +++ b/examples/mutualExclusion/centralized/MutexCentral.java @@ -0,0 +1,39 @@ +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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 MutexCentral { + + /* This only contains the launcher. If you do nothing more than than you can run + * java simgrid.msg.Msg + * which also contains such a launcher + */ + + public static void main(String[] args) throws NativeException { + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + + if(args.length < 2) { + Msg.info("Usage: Basic platform_file deployment_file"); + Msg.info("Fallback to default values"); + Msg.createEnvironment("../ring3.xml"); + Msg.deployApplication("mutex_centralized_deployment.xml"); + } else { + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + } + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/mutualExclusion/centralized/Node.java b/examples/mutualExclusion/centralized/Node.java new file mode 100644 index 0000000000..fd2af4c6d3 --- /dev/null +++ b/examples/mutualExclusion/centralized/Node.java @@ -0,0 +1,31 @@ +/* + * $Id$ + * + * Copyright 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.MsgException; +import simgrid.msg.Task; +import simgrid.msg.Msg; + +public class Node extends simgrid.msg.Process { + + public void request(double CStime) throws MsgException { + RequestTask req = new RequestTask(this.name); + Msg.info("Send a request to the coordinator"); + req.send("coordinator"); + Msg.info("Wait for a grant from the coordinator"); + Task.receive(this.name); // FIXME: ensure that this is a grant + Task compute = new Task("CS", CStime, 0); + compute.execute(); + ReleaseTask release = new ReleaseTask(); + release.send("coordinator"); + } + + public void main(String[] args) throws MsgException { + request(Double.parseDouble(args[1])); + } +} \ No newline at end of file diff --git a/examples/mutualExclusion/centralized/ReleaseTask.java b/examples/mutualExclusion/centralized/ReleaseTask.java new file mode 100644 index 0000000000..28a259c197 --- /dev/null +++ b/examples/mutualExclusion/centralized/ReleaseTask.java @@ -0,0 +1,2 @@ +public class ReleaseTask extends simgrid.msg.Task { +} diff --git a/examples/mutualExclusion/centralized/RequestTask.java b/examples/mutualExclusion/centralized/RequestTask.java new file mode 100644 index 0000000000..484db0680f --- /dev/null +++ b/examples/mutualExclusion/centralized/RequestTask.java @@ -0,0 +1,9 @@ +import simgrid.msg.Task; + +public class RequestTask extends Task { + String from; + public RequestTask(String name) { + super(); + from=name; + } +} diff --git a/examples/mutualExclusion/centralized/mutex_centralized.tesh b/examples/mutualExclusion/centralized/mutex_centralized.tesh new file mode 100644 index 0000000000..5001f23b41 --- /dev/null +++ b/examples/mutualExclusion/centralized/mutex_centralized.tesh @@ -0,0 +1,16 @@ +# compile the example +$ javac -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR. *.java + +# run the comm_time sample +$ java -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR PingPongTest ../ring3.xml mutex_centralized_deployment.xml +> [Inmos:Sender:(1) 0.000000] [jmsg/INFO] hello! +> [Inmos:Sender:(1) 0.000000] [jmsg/INFO] host count : 1 +> [Inmos:Sender:(1) 0.000000] [jmsg/INFO] sender time : 0.0 +> [Bellevue:Receiver:(2) 0.000000] [jmsg/INFO] hello! +> [Bellevue:Receiver:(2) 0.000000] [jmsg/INFO] try to get a task +> [Inmos:Sender:(1) 0.001462] [jmsg/INFO] goodbye! +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] Got at time 0.0014616631517 +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] Was sent at time 0.0 +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] Communication time : 0.0014616631517 +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] --- bw 6.841521583389041E10 ---- +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] goodbye! \ No newline at end of file diff --git a/examples/mutualExclusion/centralized/mutex_centralized_deployment.xml b/examples/mutualExclusion/centralized/mutex_centralized_deployment.xml new file mode 100644 index 0000000000..b5c7eef413 --- /dev/null +++ b/examples/mutualExclusion/centralized/mutex_centralized_deployment.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/examples/mutualExclusion/ring3.xml b/examples/mutualExclusion/ring3.xml new file mode 100644 index 0000000000..9f418554de --- /dev/null +++ b/examples/mutualExclusion/ring3.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/ping_pong/PingPongTask.java b/examples/ping_pong/PingPongTask.java new file mode 100644 index 0000000000..79fa7d2cd7 --- /dev/null +++ b/examples/ping_pong/PingPongTask.java @@ -0,0 +1,30 @@ +/* + * 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 PingPongTask extends Task { + + private double timeVal; + + public PingPongTask() throws NativeException { + this.timeVal = 0; + } + + public PingPongTask(String name, double computeDuration, double messageSize) throws 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/ping_pong/PingPongTest.java b/examples/ping_pong/PingPongTest.java new file mode 100644 index 0000000000..48c86b13b0 --- /dev/null +++ b/examples/ping_pong/PingPongTest.java @@ -0,0 +1,38 @@ +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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 PingPongTest { + + /* This only contains the launcher. If you do nothing more than than you can run + * java simgrid.msg.Msg + * which also contains such a launcher + */ + + public static void main(String[] args) throws NativeException { + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + + if(args.length < 2) { + Msg.info("Usage : PingPong platform_file deployment_file"); + Msg.info("example : PingPong ping_pong_platform.xml ping_pong_deployment.xml"); + System.exit(1); + } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/ping_pong/README b/examples/ping_pong/README new file mode 100644 index 0000000000..aa16de9c89 --- /dev/null +++ b/examples/ping_pong/README @@ -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 diff --git a/examples/ping_pong/Receiver.java b/examples/ping_pong/Receiver.java new file mode 100644 index 0000000000..9603a76a82 --- /dev/null +++ b/examples/ping_pong/Receiver.java @@ -0,0 +1,42 @@ +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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 Receiver extends simgrid.msg.Process { + + final double commSizeLat = 1; + final double commSizeBw = 100000000; + + public void main(String[] args) throws MsgException { + + Msg.info("hello!"); + double communicationTime=0; + + double time = Msg.getClock(); + + Msg.info("try to get a task"); + + PingPongTask task = (PingPongTask)Task.receive(getHost().getName()); + double timeGot = Msg.getClock(); + double timeSent = task.getTime(); + + Msg.info("Got at time "+ timeGot); + Msg.info("Was sent at time "+timeSent); + time=timeSent; + + communicationTime=timeGot - time; + Msg.info("Communication time : " + communicationTime); + + Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); + + Msg.info("goodbye!"); + } +} \ No newline at end of file diff --git a/examples/ping_pong/Sender.java b/examples/ping_pong/Sender.java new file mode 100644 index 0000000000..17f2dfd267 --- /dev/null +++ b/examples/ping_pong/Sender.java @@ -0,0 +1,51 @@ +/* + * Sender of basic ping/pong example + * + * 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 Sender extends simgrid.msg.Process { + + private final double commSizeLat = 1; + final double commSizeBw = 100000000; + + public void main(String[] args) throws MsgException { + + Msg.info("hello!"); + + int hostCount = args.length; + + Msg.info("host count: " + hostCount); + String mailboxes[] = new String[hostCount]; + double time; + double computeDuration = 0; + PingPongTask task; + + for(int pos = 0; pos < args.length ; pos++) { + try { + mailboxes[pos] = Host.getByName(args[pos]).getName(); + } catch (HostNotFoundException e) { + Msg.info("Invalid deployment file: " + e.toString()); + System.exit(1); + } + } + + for (int pos = 0; pos < hostCount; pos++) { + time = Msg.getClock(); + + Msg.info("sender time: " + time); + + task = new PingPongTask("no name",computeDuration,commSizeLat); + task.setTime(time); + + task.send(mailboxes[pos]); + } + + Msg.info("goodbye!"); + } +} \ No newline at end of file diff --git a/examples/ping_pong/hs_err_pid27276.log b/examples/ping_pong/hs_err_pid27276.log new file mode 100644 index 0000000000..89ad8bfb6b --- /dev/null +++ b/examples/ping_pong/hs_err_pid27276.log @@ -0,0 +1,254 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# SIGSEGV (0xb) at pc=0x7f3026c3, pid=27276, tid=3063774064 +# +# JRE version: 6.0_22-b04 +# Java VM: Java HotSpot(TM) Server VM (17.1-b03 mixed mode linux-x86 ) +# Problematic frame: +# C [libsimgrid.so.3.5+0x336c3] xbt_fifo_push_item+0xc3 +# +# If you would like to submit a bug report, please visit: +# http://java.sun.com/webapps/bugreport/crash.jsp +# The crash happened outside the Java Virtual Machine in native code. +# See problematic frame for where to report the bug. +# + +--------------- T H R E A D --------------- + +Current thread (0x0850e000): JavaThread "main" [_thread_in_native, id=27332, stack(0xb6987000,0xb69d8000)] + +siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x00000004 + +Registers: +EAX=0x085cfe70, EBX=0x7f3f3d38, ECX=0x00000000, EDX=0x00000000 +ESP=0xb69d6640, EBP=0xb69d6668, ESI=0x00000000, EDI=0x085d00b0 +EIP=0x7f3026c3, CR2=0x00000004, EFLAGS=0x00010246 + +Top of Stack: (sp=0xb69d6640) +0xb69d6640: b7169668 0850e910 b69d6668 00000000 +0xb69d6650: 0000000e b69d6550 7f2d70d8 7f3f3d38 +0xb69d6660: 085cfe70 085d00b0 b69d6688 7f33166b +0xb69d6670: 00000000 085cfe70 b77325d6 7f3f3d38 +0xb69d6680: 7f3f3d38 085d9968 b69d66c8 7f3317b0 +0xb69d6690: 00000000 085d00b0 001259a8 7f2cf000 +0xb69d66a0: 00000000 bff00000 00000000 3ff00000 +0xb69d66b0: b69d6708 b77382c0 085d66c8 7f3f3d38 + +Instructions: (pc=0x7f3026c3) +0x7f3026b3: fe ff 8d 76 00 8b 48 08 85 c9 0f 85 68 ff ff ff +0x7f3026c3: 8b 7a 04 83 02 01 85 ff 74 2b 8b 4a 08 89 48 08 + +Stack: [0xb6987000,0xb69d8000], sp=0xb69d6640, free space=13db69d5fc0k +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +C [libsimgrid.so.3.5+0x336c3] xbt_fifo_push_item+0xc3 +C [libsimgrid.so.3.5+0x6266b] xbt_fifo_push+0x3b +C [libsimgrid.so.3.5+0x627b0] SIMIX_comm_isend+0xa0 +C [libsimgrid.so.3.5+0x8c87a] SIMIX_request_pre+0x1ea +C [libsimgrid.so.3.5+0x9581e] SIMIX_run+0x3e +C [libsimgrid.so.3.5+0x959dc] MSG_main+0x3c +C [libsimgrid.so.3.5+0x95a0f] Java_simgrid_msg_Msg_run+0x1f +j simgrid.msg.Msg.run()V+0 +j PingPongTest.main([Ljava/lang/String;)V+36 +v ~StubRoutines::call_stub +V [libjvm.so+0x395980] +V [libjvm.so+0x579408] +V [libjvm.so+0x3957df] +V [libjvm.so+0x3c7c83] +V [libjvm.so+0x3b7edc] +C [java+0x1b98] JavaMain+0x2c8 +C [libpthread.so.0+0x5955] + +Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) +j simgrid.msg.Msg.run()V+0 +j PingPongTest.main([Ljava/lang/String;)V+36 +v ~StubRoutines::call_stub + +--------------- P R O C E S S --------------- + +Java Threads: ( => current thread ) + 0x085da800 JavaThread "Thread-1" [_thread_blocked, id=27449, stack(0x7f0c5000,0x7f116000)] + 0x085d9c00 JavaThread "Thread-0" [_thread_blocked, id=27447, stack(0x7f116000,0x7f167000)] + 0x085a7400 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=27434, stack(0x7f47b000,0x7f4cc000)] + 0x085a4000 JavaThread "CompilerThread1" daemon [_thread_blocked, id=27433, stack(0x7f4cc000,0x7f54d000)] + 0x085a2000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=27432, stack(0x7f54d000,0x7f5ce000)] + 0x085a0800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=27430, stack(0x7f5ce000,0x7f61f000)] + 0x0858d800 JavaThread "Finalizer" daemon [_thread_blocked, id=27374, stack(0x7f794000,0x7f7e5000)] + 0x0858c000 JavaThread "Reference Handler" daemon [_thread_blocked, id=27373, stack(0x7f7e5000,0x7f836000)] +=>0x0850e000 JavaThread "main" [_thread_in_native, id=27332, stack(0xb6987000,0xb69d8000)] + +Other Threads: + 0x08589800 VMThread [stack: 0x7f836000,0x7f8b7000] [id=27369] + 0x085a9400 WatcherThread [stack: 0x7f3fa000,0x7f47b000] [id=27436] + +VM state:not at safepoint (normal execution) + +VM Mutex/Monitor currently owned by a thread: None + +Heap + PSYoungGen total 14208K, used 978K [0xa3a40000, 0xa4a10000, 0xb3840000) + eden space 12224K, 8% used [0xa3a40000,0xa3b34800,0xa4630000) + from space 1984K, 0% used [0xa4820000,0xa4820000,0xa4a10000) + to space 1984K, 0% used [0xa4630000,0xa4630000,0xa4820000) + PSOldGen total 32512K, used 0K [0x83e40000, 0x85e00000, 0xa3a40000) + object space 32512K, 0% used [0x83e40000,0x83e40000,0x85e00000) + PSPermGen total 16384K, used 1943K [0x7fe40000, 0x80e40000, 0x83e40000) + object space 16384K, 11% used [0x7fe40000,0x80025f98,0x80e40000) + +Dynamic libraries: +08048000-08052000 r-xp 00000000 08:01 9338 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/bin/java +08052000-08053000 rwxp 00009000 08:01 9338 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/bin/java +08508000-085fd000 rwxp 00000000 00:00 0 [heap] +105dc000-105dd000 rwxp 00000000 00:00 0 +7f0c5000-7f0c8000 ---p 00000000 00:00 0 +7f0c8000-7f116000 rwxp 00000000 00:00 0 +7f116000-7f119000 ---p 00000000 00:00 0 +7f119000-7f167000 rwxp 00000000 00:00 0 +7f25d000-7f282000 r-xp 00000000 08:01 147450 /usr/lib/liblua5.1.so.0.0.0 +7f282000-7f283000 rwxp 00024000 08:01 147450 /usr/lib/liblua5.1.so.0.0.0 +7f283000-7f2b5000 r-xp 00000000 08:01 431643 /lib/libpcre.so.3.12.1 +7f2b5000-7f2b6000 rwxp 00031000 08:01 431643 /lib/libpcre.so.3.12.1 +7f2cf000-7f3f3000 r-xp 00000000 08:03 1933476 /home/mquinson/Code/simgrid/lib/libsimgrid.so.3.5 +7f3f3000-7f3f7000 rwxp 00124000 08:03 1933476 /home/mquinson/Code/simgrid/lib/libsimgrid.so.3.5 +7f3f7000-7f3fa000 rwxp 00000000 00:00 0 +7f3fa000-7f3fb000 ---p 00000000 00:00 0 +7f3fb000-7f47b000 rwxp 00000000 00:00 0 +7f47b000-7f47e000 ---p 00000000 00:00 0 +7f47e000-7f4cc000 rwxp 00000000 00:00 0 +7f4cc000-7f4cf000 ---p 00000000 00:00 0 +7f4cf000-7f54d000 rwxp 00000000 00:00 0 +7f54d000-7f550000 ---p 00000000 00:00 0 +7f550000-7f5ce000 rwxp 00000000 00:00 0 +7f5ce000-7f5d1000 ---p 00000000 00:00 0 +7f5d1000-7f61f000 rwxp 00000000 00:00 0 +7f61f000-7f794000 r-xp 00000000 08:01 366595 /usr/lib/locale/locale-archive +7f794000-7f797000 ---p 00000000 00:00 0 +7f797000-7f7e5000 rwxp 00000000 00:00 0 +7f7e5000-7f7e8000 ---p 00000000 00:00 0 +7f7e8000-7f836000 rwxp 00000000 00:00 0 +7f836000-7f837000 ---p 00000000 00:00 0 +7f837000-7f8ea000 rwxp 00000000 00:00 0 +7f8ea000-7fa82000 r-xs 03013000 08:01 255096 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/rt.jar +7fa82000-7fa83000 ---p 00000000 00:00 0 +7fa83000-7fb03000 rwxp 00000000 00:00 0 +7fb03000-7fb04000 ---p 00000000 00:00 0 +7fb04000-7fb8c000 rwxp 00000000 00:00 0 +7fb8c000-7fba4000 rwxp 00000000 00:00 0 +7fba4000-7fbb4000 rwxp 00000000 00:00 0 +7fbb4000-7fca2000 rwxp 00000000 00:00 0 +7fca2000-7fcaa000 rwxp 00000000 00:00 0 +7fcaa000-7fcc2000 rwxp 00000000 00:00 0 +7fcc2000-7fcd2000 rwxp 00000000 00:00 0 +7fcd2000-7fdc0000 rwxp 00000000 00:00 0 +7fdc0000-7fdc8000 rwxp 00000000 00:00 0 +7fdc8000-7fe3f000 rwxp 00000000 00:00 0 +7fe3f000-80e40000 rwxp 00000000 00:00 0 +80e40000-83e40000 rwxp 00000000 00:00 0 +83e40000-85e00000 rwxp 00000000 00:00 0 +85e00000-a3a40000 rwxp 00000000 00:00 0 +a3a40000-a4a10000 rwxp 00000000 00:00 0 +a4a10000-b3840000 rwxp 00000000 00:00 0 +b384b000-b3854000 rwxp 00000000 00:00 0 +b3854000-b390b000 rwxp 00000000 00:00 0 +b390b000-b3b4b000 rwxp 00000000 00:00 0 +b3b4b000-b690b000 rwxp 00000000 00:00 0 +b690b000-b6915000 r-xp 00000000 08:01 444869 /lib/i686/cmov/libnss_files-2.11.2.so +b6915000-b6916000 r-xp 00009000 08:01 444869 /lib/i686/cmov/libnss_files-2.11.2.so +b6916000-b6917000 rwxp 0000a000 08:01 444869 /lib/i686/cmov/libnss_files-2.11.2.so +b6917000-b691f000 r-xp 00000000 08:01 444566 /lib/i686/cmov/libnss_nis-2.11.2.so +b691f000-b6920000 r-xp 00008000 08:01 444566 /lib/i686/cmov/libnss_nis-2.11.2.so +b6920000-b6921000 rwxp 00009000 08:01 444566 /lib/i686/cmov/libnss_nis-2.11.2.so +b6921000-b6927000 r-xp 00000000 08:01 444559 /lib/i686/cmov/libnss_compat-2.11.2.so +b6927000-b6928000 r-xp 00006000 08:01 444559 /lib/i686/cmov/libnss_compat-2.11.2.so +b6928000-b6929000 rwxp 00007000 08:01 444559 /lib/i686/cmov/libnss_compat-2.11.2.so +b6929000-b693c000 r-xp 00000000 08:01 444885 /lib/i686/cmov/libnsl-2.11.2.so +b693c000-b693d000 r-xp 00012000 08:01 444885 /lib/i686/cmov/libnsl-2.11.2.so +b693d000-b693e000 rwxp 00013000 08:01 444885 /lib/i686/cmov/libnsl-2.11.2.so +b693e000-b6940000 rwxp 00000000 00:00 0 +b6940000-b694f000 r-xp 00000000 08:01 104324 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libzip.so +b694f000-b6951000 rwxp 0000e000 08:01 104324 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libzip.so +b6951000-b6959000 rwxs 00000000 08:01 270818 /tmp/hsperfdata_mquinson/27276 +b6959000-b697c000 r-xp 00000000 08:01 104450 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libjava.so +b697c000-b697e000 rwxp 00023000 08:01 104450 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libjava.so +b697e000-b6985000 r-xp 00000000 08:01 444624 /lib/i686/cmov/librt-2.11.2.so +b6985000-b6986000 r-xp 00006000 08:01 444624 /lib/i686/cmov/librt-2.11.2.so +b6986000-b6987000 rwxp 00007000 08:01 444624 /lib/i686/cmov/librt-2.11.2.so +b6987000-b698a000 ---p 00000000 00:00 0 +b698a000-b69d8000 rwxp 00000000 00:00 0 +b69d8000-b69fc000 r-xp 00000000 08:01 444560 /lib/i686/cmov/libm-2.11.2.so +b69fc000-b69fd000 r-xp 00023000 08:01 444560 /lib/i686/cmov/libm-2.11.2.so +b69fd000-b69fe000 rwxp 00024000 08:01 444560 /lib/i686/cmov/libm-2.11.2.so +b69fe000-b712a000 r-xp 00000000 08:01 111331 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/server/libjvm.so +b712a000-b717d000 rwxp 0072c000 08:01 111331 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/server/libjvm.so +b717d000-b759d000 rwxp 00000000 00:00 0 +b759d000-b76dd000 r-xp 00000000 08:01 444886 /lib/i686/cmov/libc-2.11.2.so +b76dd000-b76df000 r-xp 0013f000 08:01 444886 /lib/i686/cmov/libc-2.11.2.so +b76df000-b76e0000 rwxp 00141000 08:01 444886 /lib/i686/cmov/libc-2.11.2.so +b76e0000-b76e3000 rwxp 00000000 00:00 0 +b76e3000-b76e5000 r-xp 00000000 08:01 444649 /lib/i686/cmov/libdl-2.11.2.so +b76e5000-b76e6000 r-xp 00001000 08:01 444649 /lib/i686/cmov/libdl-2.11.2.so +b76e6000-b76e7000 rwxp 00002000 08:01 444649 /lib/i686/cmov/libdl-2.11.2.so +b76e7000-b76ee000 r-xp 00000000 08:01 146798 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/jli/libjli.so +b76ee000-b76f0000 rwxp 00006000 08:01 146798 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/jli/libjli.so +b76f0000-b76f1000 rwxp 00000000 00:00 0 +b76f1000-b7706000 r-xp 00000000 08:01 444583 /lib/i686/cmov/libpthread-2.11.2.so +b7706000-b7707000 r-xp 00014000 08:01 444583 /lib/i686/cmov/libpthread-2.11.2.so +b7707000-b7708000 rwxp 00015000 08:01 444583 /lib/i686/cmov/libpthread-2.11.2.so +b7708000-b770a000 rwxp 00000000 00:00 0 +b770c000-b770e000 r-xs 00002000 08:03 9135067 /home/mquinson/Code/simgrid/simgrid.jar +b770e000-b7714000 r-xp 00000000 08:01 187405 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/native_threads/libhpi.so +b7714000-b7715000 rwxp 00006000 08:01 187405 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/native_threads/libhpi.so +b7715000-b7716000 rwxp 00000000 00:00 0 +b7716000-b7717000 r-xp 00000000 00:00 0 +b7717000-b7722000 r-xp 00000000 08:01 104465 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libverify.so +b7722000-b7723000 rwxp 0000b000 08:01 104465 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libverify.so +b7723000-b7725000 rwxp 00000000 00:00 0 +b7725000-b7740000 r-xp 00000000 08:01 432710 /lib/ld-2.11.2.so +b7740000-b7741000 r-xp 0001a000 08:01 432710 /lib/ld-2.11.2.so +b7741000-b7742000 rwxp 0001b000 08:01 432710 /lib/ld-2.11.2.so +bfee1000-bfef6000 rwxp 00000000 00:00 0 [stack] + +VM Arguments: +java_command: PingPongTest ping_pong_platform.xml ping_pong_deployment.xml +Launcher Type: SUN_STANDARD + +Environment Variables: +PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/mquinson/SCRIPTS:/usr/sbin:/sbin:/opt/simgrid/bin +USERNAME=mquinson +LD_LIBRARY_PATH=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/i386:/opt/simgrid/lib:/opt/allegro5/lib:/home/mquinson/Code/simgrid/lib +SHELL=/bin/bash +DISPLAY=:0.0 + +Signal Handlers: +SIGSEGV: [libjvm.so+0x6a9f20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGBUS: [libjvm.so+0x6a9f20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGFPE: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGPIPE: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGXFSZ: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGILL: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000 +SIGUSR2: [libjvm.so+0x57ae20], sa_mask[0]=0x00000000, sa_flags=0x10000004 +SIGHUP: [libjvm.so+0x57ab50], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGINT: [libsimgrid.so.3.5+0x4bb60], sa_mask[0]=0x00000002, sa_flags=0x10000000 +SIGTERM: [libjvm.so+0x57ab50], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGQUIT: [libjvm.so+0x57ab50], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 + + +--------------- S Y S T E M --------------- + +OS:squeeze/sid + +uname:Linux 2.6.32-5-686 #1 SMP Sat Oct 30 22:47:19 UTC 2010 i686 +libc:glibc 2.11.2 NPTL 2.11.2 +rlimit: STACK 8192k, CORE 0k, NPROC infinity, NOFILE 1024, AS infinity +load average:2.28 0.72 0.53 + +CPU:total 2 (2 cores per cpu, 1 threads per core) family 6 model 15 stepping 11, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3 + +Memory: 4k page, physical 3113680k(312340k free), swap 2931852k(2931728k free) + +vm_info: Java HotSpot(TM) Server VM (17.1-b03) for linux-x86 JRE (1.6.0_22-b04), built on Sep 15 2010 01:02:09 by "java_re" with gcc 3.2.1-7a (J2SE release) + +time: Tue Nov 9 22:12:01 2010 +elapsed time: 4 seconds + diff --git a/examples/ping_pong/hs_err_pid28000.log b/examples/ping_pong/hs_err_pid28000.log new file mode 100644 index 0000000000..cfa050f5a8 --- /dev/null +++ b/examples/ping_pong/hs_err_pid28000.log @@ -0,0 +1,256 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# SIGSEGV (0xb) at pc=0x7f1b56c3, pid=28000, tid=3063688048 +# +# JRE version: 6.0_22-b04 +# Java VM: Java HotSpot(TM) Server VM (17.1-b03 mixed mode linux-x86 ) +# Problematic frame: +# C [libsimgrid.so.3.5+0x336c3] xbt_fifo_push_item+0xc3 +# +# If you would like to submit a bug report, please visit: +# http://java.sun.com/webapps/bugreport/crash.jsp +# The crash happened outside the Java Virtual Machine in native code. +# See problematic frame for where to report the bug. +# + +--------------- T H R E A D --------------- + +Current thread (0x08168000): JavaThread "main" [_thread_in_native, id=28001, stack(0xb6972000,0xb69c3000)] + +siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x00000004 + +Registers: +EAX=0x08229d58, EBX=0x7f2a6d38, ECX=0x00000000, EDX=0x00000000 +ESP=0xb69c1640, EBP=0xb69c1668, ESI=0x00000000, EDI=0x7f4006e0 +EIP=0x7f1b56c3, CR2=0x00000004, EFLAGS=0x00010246 + +Top of Stack: (sp=0xb69c1640) +0xb69c1640: b7154668 08168910 b69c1668 00000000 +0xb69c1650: 0000000e b69c1550 7f18a0d8 7f2a6d38 +0xb69c1660: 08229d58 7f4006e0 b69c1688 7f1e466b +0xb69c1670: 00000000 08229d58 b771d5d6 7f2a6d38 +0xb69c1680: 7f2a6d38 7f400670 b69c16c8 7f1e47b0 +0xb69c1690: 00000000 7f4006e0 001259a8 7f182000 +0xb69c16a0: 00000000 bff00000 00000000 3ff00000 +0xb69c16b0: b69c1708 b77232c0 08229f48 7f2a6d38 + +Instructions: (pc=0x7f1b56c3) +0x7f1b56b3: fe ff 8d 76 00 8b 48 08 85 c9 0f 85 68 ff ff ff +0x7f1b56c3: 8b 7a 04 83 02 01 85 ff 74 2b 8b 4a 08 89 48 08 + +Stack: [0xb6972000,0xb69c3000], sp=0xb69c1640, free space=13db69c0fc0k +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +C [libsimgrid.so.3.5+0x336c3] xbt_fifo_push_item+0xc3 +C [libsimgrid.so.3.5+0x6266b] xbt_fifo_push+0x3b +C [libsimgrid.so.3.5+0x627b0] SIMIX_comm_isend+0xa0 +C [libsimgrid.so.3.5+0x8c87a] SIMIX_request_pre+0x1ea +C [libsimgrid.so.3.5+0x9581e] SIMIX_run+0x3e +C [libsimgrid.so.3.5+0x959dc] MSG_main+0x3c +C [libsimgrid.so.3.5+0x95a0f] Java_simgrid_msg_Msg_run+0x1f +j simgrid.msg.Msg.run()V+0 +j PingPongTest.main([Ljava/lang/String;)V+36 +v ~StubRoutines::call_stub +V [libjvm.so+0x395980] +V [libjvm.so+0x579408] +V [libjvm.so+0x3957df] +V [libjvm.so+0x3c7c83] +V [libjvm.so+0x3b7edc] +C [java+0x1b98] JavaMain+0x2c8 +C [libpthread.so.0+0x5955] + +Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) +j simgrid.msg.Msg.run()V+0 +j PingPongTest.main([Ljava/lang/String;)V+36 +v ~StubRoutines::call_stub + +--------------- P R O C E S S --------------- + +Java Threads: ( => current thread ) + 0x08234800 JavaThread "Thread-1" [_thread_blocked, id=28013, stack(0x7ef92000,0x7efe3000)] + 0x08233c00 JavaThread "Thread-0" [_thread_blocked, id=28012, stack(0x7efe3000,0x7f034000)] + 0x08201400 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=28010, stack(0x7f32e000,0x7f37f000)] + 0x081fe000 JavaThread "CompilerThread1" daemon [_thread_blocked, id=28009, stack(0x7f37f000,0x7f400000)] + 0x081fc000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=28008, stack(0x7f53d000,0x7f5be000)] + 0x081fa800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=28007, stack(0x7f5be000,0x7f60f000)] + 0x081e7800 JavaThread "Finalizer" daemon [_thread_blocked, id=28006, stack(0x7f784000,0x7f7d5000)] + 0x081e6000 JavaThread "Reference Handler" daemon [_thread_blocked, id=28005, stack(0x7f7d5000,0x7f826000)] +=>0x08168000 JavaThread "main" [_thread_in_native, id=28001, stack(0xb6972000,0xb69c3000)] + +Other Threads: + 0x081e3800 VMThread [stack: 0x7f826000,0x7f8a7000] [id=28004] + 0x08203000 WatcherThread [stack: 0x7f2ad000,0x7f32e000] [id=28011] + +VM state:not at safepoint (normal execution) + +VM Mutex/Monitor currently owned by a thread: None + +Heap + PSYoungGen total 14208K, used 978K [0xa3a30000, 0xa4a00000, 0xb3830000) + eden space 12224K, 8% used [0xa3a30000,0xa3b24800,0xa4620000) + from space 1984K, 0% used [0xa4810000,0xa4810000,0xa4a00000) + to space 1984K, 0% used [0xa4620000,0xa4620000,0xa4810000) + PSOldGen total 32512K, used 0K [0x83e30000, 0x85df0000, 0xa3a30000) + object space 32512K, 0% used [0x83e30000,0x83e30000,0x85df0000) + PSPermGen total 16384K, used 1943K [0x7fe30000, 0x80e30000, 0x83e30000) + object space 16384K, 11% used [0x7fe30000,0x80015f98,0x80e30000) + +Dynamic libraries: +08048000-08052000 r-xp 00000000 08:01 9338 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/bin/java +08052000-08053000 rwxp 00009000 08:01 9338 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/bin/java +08162000-08259000 rwxp 00000000 00:00 0 [heap] +10236000-10237000 rwxp 00000000 00:00 0 +7ef92000-7ef95000 ---p 00000000 00:00 0 +7ef95000-7efe3000 rwxp 00000000 00:00 0 +7efe3000-7efe6000 ---p 00000000 00:00 0 +7efe6000-7f034000 rwxp 00000000 00:00 0 +7f129000-7f14e000 r-xp 00000000 08:01 147450 /usr/lib/liblua5.1.so.0.0.0 +7f14e000-7f14f000 rwxp 00024000 08:01 147450 /usr/lib/liblua5.1.so.0.0.0 +7f14f000-7f181000 r-xp 00000000 08:01 431643 /lib/libpcre.so.3.12.1 +7f181000-7f182000 rwxp 00031000 08:01 431643 /lib/libpcre.so.3.12.1 +7f182000-7f2a6000 r-xp 00000000 08:03 1933476 /home/mquinson/Code/simgrid/lib/libsimgrid.so.3.5 +7f2a6000-7f2aa000 rwxp 00124000 08:03 1933476 /home/mquinson/Code/simgrid/lib/libsimgrid.so.3.5 +7f2aa000-7f2ad000 rwxp 00000000 00:00 0 +7f2ad000-7f2ae000 ---p 00000000 00:00 0 +7f2ae000-7f32e000 rwxp 00000000 00:00 0 +7f32e000-7f331000 ---p 00000000 00:00 0 +7f331000-7f37f000 rwxp 00000000 00:00 0 +7f37f000-7f382000 ---p 00000000 00:00 0 +7f382000-7f400000 rwxp 00000000 00:00 0 +7f400000-7f421000 rwxp 00000000 00:00 0 +7f421000-7f500000 ---p 00000000 00:00 0 +7f53d000-7f540000 ---p 00000000 00:00 0 +7f540000-7f5be000 rwxp 00000000 00:00 0 +7f5be000-7f5c1000 ---p 00000000 00:00 0 +7f5c1000-7f60f000 rwxp 00000000 00:00 0 +7f60f000-7f784000 r-xp 00000000 08:01 366595 /usr/lib/locale/locale-archive +7f784000-7f787000 ---p 00000000 00:00 0 +7f787000-7f7d5000 rwxp 00000000 00:00 0 +7f7d5000-7f7d8000 ---p 00000000 00:00 0 +7f7d8000-7f826000 rwxp 00000000 00:00 0 +7f826000-7f827000 ---p 00000000 00:00 0 +7f827000-7f8da000 rwxp 00000000 00:00 0 +7f8da000-7fa72000 r-xs 03013000 08:01 255096 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/rt.jar +7fa72000-7fa73000 ---p 00000000 00:00 0 +7fa73000-7faf3000 rwxp 00000000 00:00 0 +7faf3000-7faf4000 ---p 00000000 00:00 0 +7faf4000-7fb7c000 rwxp 00000000 00:00 0 +7fb7c000-7fb94000 rwxp 00000000 00:00 0 +7fb94000-7fba4000 rwxp 00000000 00:00 0 +7fba4000-7fc92000 rwxp 00000000 00:00 0 +7fc92000-7fc9a000 rwxp 00000000 00:00 0 +7fc9a000-7fcb2000 rwxp 00000000 00:00 0 +7fcb2000-7fcc2000 rwxp 00000000 00:00 0 +7fcc2000-7fdb0000 rwxp 00000000 00:00 0 +7fdb0000-7fdb8000 rwxp 00000000 00:00 0 +7fdb8000-7fe2f000 rwxp 00000000 00:00 0 +7fe2f000-80e30000 rwxp 00000000 00:00 0 +80e30000-83e30000 rwxp 00000000 00:00 0 +83e30000-85df0000 rwxp 00000000 00:00 0 +85df0000-a3a30000 rwxp 00000000 00:00 0 +a3a30000-a4a00000 rwxp 00000000 00:00 0 +a4a00000-b3830000 rwxp 00000000 00:00 0 +b3836000-b383f000 rwxp 00000000 00:00 0 +b383f000-b38f6000 rwxp 00000000 00:00 0 +b38f6000-b3b36000 rwxp 00000000 00:00 0 +b3b36000-b68f6000 rwxp 00000000 00:00 0 +b68f6000-b6900000 r-xp 00000000 08:01 444869 /lib/i686/cmov/libnss_files-2.11.2.so +b6900000-b6901000 r-xp 00009000 08:01 444869 /lib/i686/cmov/libnss_files-2.11.2.so +b6901000-b6902000 rwxp 0000a000 08:01 444869 /lib/i686/cmov/libnss_files-2.11.2.so +b6902000-b690a000 r-xp 00000000 08:01 444566 /lib/i686/cmov/libnss_nis-2.11.2.so +b690a000-b690b000 r-xp 00008000 08:01 444566 /lib/i686/cmov/libnss_nis-2.11.2.so +b690b000-b690c000 rwxp 00009000 08:01 444566 /lib/i686/cmov/libnss_nis-2.11.2.so +b690c000-b6912000 r-xp 00000000 08:01 444559 /lib/i686/cmov/libnss_compat-2.11.2.so +b6912000-b6913000 r-xp 00006000 08:01 444559 /lib/i686/cmov/libnss_compat-2.11.2.so +b6913000-b6914000 rwxp 00007000 08:01 444559 /lib/i686/cmov/libnss_compat-2.11.2.so +b6914000-b6927000 r-xp 00000000 08:01 444885 /lib/i686/cmov/libnsl-2.11.2.so +b6927000-b6928000 r-xp 00012000 08:01 444885 /lib/i686/cmov/libnsl-2.11.2.so +b6928000-b6929000 rwxp 00013000 08:01 444885 /lib/i686/cmov/libnsl-2.11.2.so +b6929000-b692b000 rwxp 00000000 00:00 0 +b692b000-b693a000 r-xp 00000000 08:01 104324 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libzip.so +b693a000-b693c000 rwxp 0000e000 08:01 104324 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libzip.so +b693c000-b6944000 rwxs 00000000 08:01 270801 /tmp/hsperfdata_mquinson/28000 +b6944000-b6967000 r-xp 00000000 08:01 104450 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libjava.so +b6967000-b6969000 rwxp 00023000 08:01 104450 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libjava.so +b6969000-b6970000 r-xp 00000000 08:01 444624 /lib/i686/cmov/librt-2.11.2.so +b6970000-b6971000 r-xp 00006000 08:01 444624 /lib/i686/cmov/librt-2.11.2.so +b6971000-b6972000 rwxp 00007000 08:01 444624 /lib/i686/cmov/librt-2.11.2.so +b6972000-b6975000 ---p 00000000 00:00 0 +b6975000-b69c3000 rwxp 00000000 00:00 0 +b69c3000-b69e7000 r-xp 00000000 08:01 444560 /lib/i686/cmov/libm-2.11.2.so +b69e7000-b69e8000 r-xp 00023000 08:01 444560 /lib/i686/cmov/libm-2.11.2.so +b69e8000-b69e9000 rwxp 00024000 08:01 444560 /lib/i686/cmov/libm-2.11.2.so +b69e9000-b7115000 r-xp 00000000 08:01 111331 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/server/libjvm.so +b7115000-b7168000 rwxp 0072c000 08:01 111331 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/server/libjvm.so +b7168000-b7588000 rwxp 00000000 00:00 0 +b7588000-b76c8000 r-xp 00000000 08:01 444886 /lib/i686/cmov/libc-2.11.2.so +b76c8000-b76ca000 r-xp 0013f000 08:01 444886 /lib/i686/cmov/libc-2.11.2.so +b76ca000-b76cb000 rwxp 00141000 08:01 444886 /lib/i686/cmov/libc-2.11.2.so +b76cb000-b76ce000 rwxp 00000000 00:00 0 +b76ce000-b76d0000 r-xp 00000000 08:01 444649 /lib/i686/cmov/libdl-2.11.2.so +b76d0000-b76d1000 r-xp 00001000 08:01 444649 /lib/i686/cmov/libdl-2.11.2.so +b76d1000-b76d2000 rwxp 00002000 08:01 444649 /lib/i686/cmov/libdl-2.11.2.so +b76d2000-b76d9000 r-xp 00000000 08:01 146798 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/jli/libjli.so +b76d9000-b76db000 rwxp 00006000 08:01 146798 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/jli/libjli.so +b76db000-b76dc000 rwxp 00000000 00:00 0 +b76dc000-b76f1000 r-xp 00000000 08:01 444583 /lib/i686/cmov/libpthread-2.11.2.so +b76f1000-b76f2000 r-xp 00014000 08:01 444583 /lib/i686/cmov/libpthread-2.11.2.so +b76f2000-b76f3000 rwxp 00015000 08:01 444583 /lib/i686/cmov/libpthread-2.11.2.so +b76f3000-b76f5000 rwxp 00000000 00:00 0 +b76f7000-b76f9000 r-xs 00002000 08:03 9135067 /home/mquinson/Code/simgrid/simgrid.jar +b76f9000-b76ff000 r-xp 00000000 08:01 187405 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/native_threads/libhpi.so +b76ff000-b7700000 rwxp 00006000 08:01 187405 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/native_threads/libhpi.so +b7700000-b7701000 rwxp 00000000 00:00 0 +b7701000-b7702000 r-xp 00000000 00:00 0 +b7702000-b770d000 r-xp 00000000 08:01 104465 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libverify.so +b770d000-b770e000 rwxp 0000b000 08:01 104465 /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/libverify.so +b770e000-b7710000 rwxp 00000000 00:00 0 +b7710000-b772b000 r-xp 00000000 08:01 432710 /lib/ld-2.11.2.so +b772b000-b772c000 r-xp 0001a000 08:01 432710 /lib/ld-2.11.2.so +b772c000-b772d000 rwxp 0001b000 08:01 432710 /lib/ld-2.11.2.so +bffba000-bffcf000 rwxp 00000000 00:00 0 [stack] + +VM Arguments: +java_command: PingPongTest ping_pong_platform.xml ping_pong_deployment.xml +Launcher Type: SUN_STANDARD + +Environment Variables: +PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/mquinson/SCRIPTS:/usr/sbin:/sbin:/opt/simgrid/bin +USERNAME=mquinson +LD_LIBRARY_PATH=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/i386:/opt/simgrid/lib:/opt/allegro5/lib:/home/mquinson/Code/simgrid/lib +SHELL=/bin/bash +DISPLAY=:0.0 + +Signal Handlers: +SIGSEGV: [libjvm.so+0x6a9f20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGBUS: [libjvm.so+0x6a9f20], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGFPE: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGPIPE: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGXFSZ: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGILL: [libjvm.so+0x5781e0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000 +SIGUSR2: [libjvm.so+0x57ae20], sa_mask[0]=0x00000000, sa_flags=0x10000004 +SIGHUP: [libjvm.so+0x57ab50], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGINT: [libsimgrid.so.3.5+0x4bb60], sa_mask[0]=0x00000002, sa_flags=0x10000000 +SIGTERM: [libjvm.so+0x57ab50], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGQUIT: [libjvm.so+0x57ab50], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 + + +--------------- S Y S T E M --------------- + +OS:squeeze/sid + +uname:Linux 2.6.32-5-686 #1 SMP Sat Oct 30 22:47:19 UTC 2010 i686 +libc:glibc 2.11.2 NPTL 2.11.2 +rlimit: STACK 8192k, CORE 0k, NPROC infinity, NOFILE 1024, AS infinity +load average:2.44 1.13 0.68 + +CPU:total 2 (2 cores per cpu, 1 threads per core) family 6 model 15 stepping 11, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3 + +Memory: 4k page, physical 3113680k(359884k free), swap 2931852k(2931728k free) + +vm_info: Java HotSpot(TM) Server VM (17.1-b03) for linux-x86 JRE (1.6.0_22-b04), built on Sep 15 2010 01:02:09 by "java_re" with gcc 3.2.1-7a (J2SE release) + +time: Tue Nov 9 22:13:02 2010 +elapsed time: 0 seconds + diff --git a/examples/ping_pong/ping_pong.tesh b/examples/ping_pong/ping_pong.tesh new file mode 100644 index 0000000000..dd53f02b34 --- /dev/null +++ b/examples/ping_pong/ping_pong.tesh @@ -0,0 +1,16 @@ +# compile the example +$ javac -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR. *.java + +# run the comm_time sample +$ java -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR PingPongTest ping_pong_platform.xml ping_pong_deployment.xml +> [Inmos:Sender:(1) 0.000000] [jmsg/INFO] hello! +> [Inmos:Sender:(1) 0.000000] [jmsg/INFO] host count : 1 +> [Inmos:Sender:(1) 0.000000] [jmsg/INFO] sender time : 0.0 +> [Bellevue:Receiver:(2) 0.000000] [jmsg/INFO] hello! +> [Bellevue:Receiver:(2) 0.000000] [jmsg/INFO] try to get a task +> [Inmos:Sender:(1) 0.001462] [jmsg/INFO] goodbye! +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] Got at time 0.0014616631517 +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] Was sent at time 0.0 +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] Communication time : 0.0014616631517 +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] --- bw 6.841521583389041E10 ---- +> [Bellevue:Receiver:(2) 0.001462] [jmsg/INFO] goodbye! \ No newline at end of file diff --git a/examples/ping_pong/ping_pong_deployment.xml b/examples/ping_pong/ping_pong_deployment.xml new file mode 100644 index 0000000000..e4600d36ae --- /dev/null +++ b/examples/ping_pong/ping_pong_deployment.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/examples/ping_pong/ping_pong_platform.xml b/examples/ping_pong/ping_pong_platform.xml new file mode 100644 index 0000000000..246f1f2253 --- /dev/null +++ b/examples/ping_pong/ping_pong_platform.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/runtest b/examples/runtest new file mode 100755 index 0000000000..98d65c0dd2 --- /dev/null +++ b/examples/runtest @@ -0,0 +1,15 @@ +#! /bin/sh + +if test "x$DO_NOT_HAVE_JAVA" = x1 ; then + exit 77 +fi + +t=`basename $1 .class` + +# uncomment this when JNI becomes mad +# options="-verbose:jni -Xcheck:jni " + +echo "(LD_LIBRARY_PATH=$LD_LIBRARY_PATH)" +echo "(CLASSPATH=$CLASSPATH)" +echo java $options $t *platform.xml *deployment.xml +java $options $t *platform.xml *deployment.xml diff --git a/examples/suspend/DreamMaster.java b/examples/suspend/DreamMaster.java new file mode 100644 index 0000000000..c548d9a857 --- /dev/null +++ b/examples/suspend/DreamMaster.java @@ -0,0 +1,39 @@ +/* + * $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 DreamMaster extends simgrid.msg.Process { + + public void main(String[] args) throws MsgException { + Msg.info("Hello !"); + Msg.info("Let's create a lazy guy."); + + try { + Host currentHost = Host.currentHost(); + Msg.info("Current hostname: " + currentHost.getName()); + + LazyGuy lazy = new LazyGuy(currentHost,"LazyGuy"); + Msg.info("Let's wait a little bit..."); + + simgrid.msg.Process.waitFor(10.0); + + Msg.info("Let's wake the lazy guy up! >:) "); + lazy.restart(); + + } catch(HostNotFoundException e) { + System.err.println(e); + System.exit(1); + } + + //lazy.migrate(currentHost); + + Msg.info("OK, goodbye now."); + } +} \ No newline at end of file diff --git a/examples/suspend/LazyGuy.java b/examples/suspend/LazyGuy.java new file mode 100644 index 0000000000..e31bae0ba3 --- /dev/null +++ b/examples/suspend/LazyGuy.java @@ -0,0 +1,30 @@ +/* + * 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 LazyGuy extends simgrid.msg.Process { + public LazyGuy() { + super(); + } + + public LazyGuy(Host host,String name) throws HostNotFoundException, NativeException + { + super(host,name,null); + } + + + public void main(String[] args) throws NativeException { + Msg.info("Hello !"); + + Msg.info("Nobody's watching me ? Let's go to sleep."); + pause(); + + Msg.info("Uuuh ? Did somebody call me ?"); + Msg.info("Mmmh, goodbye now."); + } +} \ No newline at end of file diff --git a/examples/suspend/README b/examples/suspend/README new file mode 100644 index 0000000000..e7d4d54ca5 --- /dev/null +++ b/examples/suspend/README @@ -0,0 +1 @@ +A simple example of the functions to stop and resume a process. \ No newline at end of file diff --git a/examples/suspend/SuspendTest.java b/examples/suspend/SuspendTest.java new file mode 100644 index 0000000000..60acfd160a --- /dev/null +++ b/examples/suspend/SuspendTest.java @@ -0,0 +1,35 @@ +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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 SuspendTest { + + public static void main(String[] args) throws NativeException { + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + + if(args.length < 2) { + + Msg.info("Usage : Suspend platform_file deployment_file"); + Msg.info("example : Suspend msg_test_suspend_platform.xml msg_test_suspend_deployment.xml"); + System.exit(1); + } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/suspend/suspend.tesh b/examples/suspend/suspend.tesh new file mode 100644 index 0000000000..000a4492f3 --- /dev/null +++ b/examples/suspend/suspend.tesh @@ -0,0 +1,15 @@ +# compile the example +$ javac -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR. *.java + +# run the comm_time sample +$ java -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR SuspendTest suspend_platform.xml suspend_deployment.xml +> [Jacquelin:DreamMaster:(1) 0.000000] [jmsg/INFO] Hello ! +> [Jacquelin:DreamMaster:(1) 0.000000] [jmsg/INFO] Let's create a lazy guy. +> [Jacquelin:DreamMaster:(1) 0.000000] [jmsg/INFO] Current host name : Jacquelin +> [Jacquelin:DreamMaster:(1) 0.000000] [jmsg/INFO] Let's wait a little bit... +> [Jacquelin:LazyGuy:(2) 0.000000] [jmsg/INFO] Hello ! +> [Jacquelin:LazyGuy:(2) 0.000000] [jmsg/INFO] Nobody's watching me ? Let's go to sleep. +> [Jacquelin:DreamMaster:(1) 10.000000] [jmsg/INFO] Let's wake the lazy guy up! >:) +> [Jacquelin:DreamMaster:(1) 10.000000] [jmsg/INFO] OK, goodbye now. +> [Jacquelin:LazyGuy:(2) 10.000000] [jmsg/INFO] Uuuh ? Did somebody call me ? +> [Jacquelin:LazyGuy:(2) 10.000000] [jmsg/INFO] Mmmh, goodbye now. \ No newline at end of file diff --git a/examples/suspend/suspend_deployment.xml b/examples/suspend/suspend_deployment.xml new file mode 100644 index 0000000000..2bfd68e6c0 --- /dev/null +++ b/examples/suspend/suspend_deployment.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/examples/suspend/suspend_platform.xml b/examples/suspend/suspend_platform.xml new file mode 100644 index 0000000000..484de26362 --- /dev/null +++ b/examples/suspend/suspend_platform.xml @@ -0,0 +1,8298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org/simgrid/msg/ApplicationHandler.java b/org/simgrid/msg/ApplicationHandler.java new file mode 100644 index 0000000000..ac5a699f9a --- /dev/null +++ b/org/simgrid/msg/ApplicationHandler.java @@ -0,0 +1,144 @@ +/* + * These are the upcalls used by the FleXML parser for application files + * + * 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. + */ + +package simgrid.msg; + +import java.util.Hashtable; +import java.util.Vector; + +public final class ApplicationHandler { + + + /** + * The vector which contains the arguments of the main function + * of the process object. + */ + public static Vector args; + + public static Hashtable properties; + + /** + * The name of the host of the process. + */ + private static String hostName; + + /** + * The function of the process. + */ + private static String function; + + /** + * This method is called by the start element handler. + * It sets the host and the function of the process to create, + * and clear the vector containing the arguments of the + * previouse process function if needed. + * + * @host The host of the process to create. + * @function The function of the process to create. + * + */ + public static void setProcessIdentity(String hostName_, String function_) { + hostName = hostName_; + function = function_; + + if (!args.isEmpty()) + args.clear(); + + if(!properties.isEmpty()) + properties.clear(); + } + /** + * This method is called by the startElement() handler. + * It stores the argument of the function of the next + * process to create in the vector of arguments. + * + * @arg The argument to add. + * + */ public static void registerProcessArg(String arg) { + args.add(arg); + } + + public static void setProperty(String id, String value) + { + properties.put(id,value); + } + + public static String getHostName() + { + return hostName; + } + + @SuppressWarnings("unchecked") + public static void createProcess() { + try { + Class cls = (Class) Class.forName(function); + + simgrid.msg.Process process = cls.newInstance(); + process.name = function; + process.id = simgrid.msg.Process.nextProcessId++; + Host host = Host.getByName(hostName); + + MsgNative.processCreate(process, host); + Vector args_ = args; + int size = args_.size(); + + for (int index = 0; index < size; index++) + process.args.add(args_.get(index)); + + process.properties = properties; + properties = new Hashtable(); + + } catch(HostNotFoundException e) { + System.out.println(e.toString()); + e.printStackTrace(); + + } catch(ClassNotFoundException e) { + System.out.println(function + + " class not found\n The attribut function of the element process of your deployment file\n must correspond to the name of a Msg Proces class)"); + e.printStackTrace(); + + } catch(InstantiationException e) { + System.out.println("Unable to create the process. I got an instantiation exception"); + e.printStackTrace(); + } catch(IllegalAccessException e) { + System.out.println("Unable to create the process. I got an illegal access exception"); + e.printStackTrace(); + } + + } + + + public static void onStartDocument() { + args = new Vector(); + properties = new Hashtable(); + hostName = null; + function = null; + } + + public static void onBeginProcess(String hostName, String function) { + setProcessIdentity(hostName, function); + + } + public static void onProperty(String id, String value) { + setProperty(id, value); + } + + public static void onProcessArg(String arg) { + registerProcessArg(arg); + } + + public static void onEndProcess() { + createProcess(); + } + + public static void onEndDocument() { + } +} diff --git a/org/simgrid/msg/Host.java b/org/simgrid/msg/Host.java new file mode 100644 index 0000000000..45af7ff8de --- /dev/null +++ b/org/simgrid/msg/Host.java @@ -0,0 +1,165 @@ +/* + * Bindings to the MSG hosts + * + * 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. + * + */ +package simgrid.msg; + +/** + * A host object represents a location (any possible place) where a process may run. + * Thus it is represented as a physical resource with computing capabilities, some + * mailboxes to enable running process to communicate with remote ones, and some private + * data that can be only accessed by local process. An instance of this class is always + * binded with the corresponding native host. All the native hosts are automatically created + * during the call of the method Msg.createEnvironment(). This method take as parameter a + * platform file which describes all elements of the platform (host, link, root..). + * You cannot create a host yourself. + * + * The best way to get an host instance is to call the static method + * Host.getByName(). + * + * For example to get the instance of the host. If your platform + * file description contains an host named "Jacquelin" : + * + * \verbatim +Host jacquelin; + +try { + jacquelin = Host.getByName("Jacquelin"); +} catch(HostNotFoundException e) { + System.err.println(e.toString()); +} +... +\endverbatim + * + */ +public class Host { + + /** + * This attribute represents a bind between a java host object and + * a native host. Even if this attribute is public you must never + * access to it. It is set automatically during the call of the + * static method Host.getByName(). + * + * @see Host.getByName(). + */ + public long bind; + + + /** + * User data. + */ + private Object data; + protected Host() { + this.bind = 0; + this.data = null; + }; + + /** + * This static method gets an host instance associated with a native + * host of your platform. This is the best way to get a java host object. + * + * @param name The name of the host to get. + * + * @exception HostNotFoundException if the name of the host is not valid. + * NativeException if the native version of this method failed. + */ + public static Host getByName(String name) + throws HostNotFoundException { + if (name==null) + throw new NullPointerException("No host can have a null name"); + return MsgNative.hostGetByName(name); + } + + /** + * This static method returns the count of the installed hosts. + * + * @return The count of the installed hosts. + * + */ + public static int getCount() { + return MsgNative.hostGetCount(); + } + + /** + * This static method return an instance to the host of the current process. + * + * @return The host on which the current process is executed. + */ + public static Host currentHost() { + return MsgNative.hostSelf(); + } + + /** + * This static method returns all of the hosts of the installed platform. + * + * @return An array containing all the hosts installed. + * + */ + public static Host[] all() { + return MsgNative.allHosts(); + } + + /** + * This method returns the name of a host. + * + * @return The name of the host. + * + */ + public String getName() { + return MsgNative.hostGetName(this); + } + + /** + * Sets the data of the host. + * + */ + public void setData(Object data) { + this.data = data; + } + /** + * Gets the data of the host. + */ + public Object getData() { + return this.data; + } + + /** + * Checks whether a host has data. + */ + public boolean hasData() { + return null != this.data; + } + + /** + * This method returns the number of tasks currently running on a host. + * The external load is not taken in account. + * + * @return The number of tasks currently running on a host. + */ + public int getLoad() { + return MsgNative.hostGetLoad(this); + } + + /** + * This method returns the speed of the processor of a host, + * regardless of the current load of the machine. + * + * @return The speed of the processor of the host in flops. + * + */ + public double getSpeed() { + return MsgNative.hostGetSpeed(this); + } + + /** This method tests if a host is avail. */ + public boolean isAvail() { + return MsgNative.hostIsAvail(this); + } +} diff --git a/org/simgrid/msg/HostFailureException.java b/org/simgrid/msg/HostFailureException.java new file mode 100644 index 0000000000..dfa65f19ec --- /dev/null +++ b/org/simgrid/msg/HostFailureException.java @@ -0,0 +1,32 @@ +/* + * This exception is raised when looking for a non-existing host. + * + * 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. + */ + +package simgrid.msg; + +/** + * This exception is raised when The host on which you are running has just been rebooted. + */ +public class HostFailureException extends MsgException { + private static final long serialVersionUID = 1L; + + /** Constructs an HostFailureException without a detail message. */ + public HostFailureException() { + super(); + } + /** + * Constructs an HostFailureException with a detail message. + * + * @param s the detail message. + */ + public HostFailureException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/HostNotFoundException.java b/org/simgrid/msg/HostNotFoundException.java new file mode 100644 index 0000000000..d0e852f282 --- /dev/null +++ b/org/simgrid/msg/HostNotFoundException.java @@ -0,0 +1,32 @@ +/* + * This exception is raised when looking for a non-existing host. + * + * 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. + */ + +package simgrid.msg; + +/** + * This exception is raised when looking for a non-existing host. + */ +public class HostNotFoundException extends MsgException { + private static final long serialVersionUID = 1L; + + /** Constructs an HostNotFoundException without a detail message. */ + public HostNotFoundException() { + super(); + } + /** + * Constructs an HostNotFoundException with a detail message. + * + * @param s the detail message. + */ + public HostNotFoundException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/JniException.java b/org/simgrid/msg/JniException.java new file mode 100644 index 0000000000..6592ef5fc8 --- /dev/null +++ b/org/simgrid/msg/JniException.java @@ -0,0 +1,35 @@ +/* + * This exception is raised when there is a problem within the bindings (in JNI). + * + * 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. + */ +package simgrid.msg; + +/** + * This exception is raised when there is a problem within the bindings (in JNI). + * That's a RuntimeException: I guess nobody wants to survive a JNI error in SimGrid + */ +public class JniException extends RuntimeException { + private static final long serialVersionUID = 1L; + + + /** + * Constructs an JniException without a + * detail message. + */ + public JniException() { + super(); + } + /** + * Constructs an JniException with a detail message. + * + * @param s the detail message. + */ public JniException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/Msg.java b/org/simgrid/msg/Msg.java new file mode 100644 index 0000000000..40c9ea2d13 --- /dev/null +++ b/org/simgrid/msg/Msg.java @@ -0,0 +1,113 @@ +/* + * JNI interface to C code for MSG. + * + * 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. + */ + +package simgrid.msg; + +public final class Msg { + /* Statically load the library which contains all native functions used in here */ + static { + try { + System.loadLibrary("simgrid"); + } catch(UnsatisfiedLinkError e) { + System.err.println("Cannot load simgrid library: "); + e.printStackTrace(); + System.err.println( + "Please check your LD_LIBRARY_PATH, or copy the library to the current directory"); + System.exit(1); + } + } + + /* FIXME: kill these C crufts */ + /** Returns the last error code of the simulation */ + public final static native int getErrCode(); + + /** Everything is right. Keep on going the way ! */ + public static final int SUCCESS = 0; + + /** Something must be not perfectly clean (but I may be paranoid freak...) */ + public static final int WARNING = 1; + + /** There has been a problem during your task transfer. + * Either the network is down or the remote host has been shutdown */ + public static final int TRANSFERT_FAILURE = 2; + + /** System shutdown. + * The host on which you are running has just been rebooted. + * Free your data structures and return now ! */ + public static final int HOST_FAILURE = 3; + + /** Canceled task. This task has been canceled by somebody ! */ + public static final int TASK_CANCELLLED = 4; + + /** You've done something wrong. You'd better look at it... */ + public static final int FATAL_ERROR = 5; + + /** Retrieve the simulation time */ + public final static native double getClock(); + + /** Issue an information logging message */ + public final static native void info(String s); + + /********************************************************************************* + * Deployment and initialization related functions * + *********************************************************************************/ + + /** + * The natively implemented method to initialize a MSG simulation. + * + * @param args The arguments of the command line of the simulation. + * + * @see Msg.init() + */ + public final static native void init(String[]args); + + /** + * Run the MSG simulation, and cleanup everything afterward. + * + * If you want to chain simulations in the same process, you + * should call again createEnvironment and deployApplication afterward. + * + * @see MSG_run, MSG_clean + */ + public final static native void run() ; + + /** + * The native implemented method to create the environment of the simulation. + * + * @param platformFile The XML file which contains the description of the environment of the simulation + * + */ + public final static native void createEnvironment(String platformFile); + + /** + * The method to deploy the simulation. + * + * @param platformFile The XML file which contains the description of the application to deploy. + */ + public final static native void deployApplication(String deploymentFile); + + /** Example launcher. You can use it or provide your own launcher, as you wish */ + static public void main(String[]args) throws MsgException { + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + + if (args.length < 2) { + Msg.info("Usage: Msg platform_file deployment_file"); + System.exit(1); + } + + /* Load the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + /* Execute the simulation */ + Msg.run(); + } +} diff --git a/org/simgrid/msg/MsgException.java b/org/simgrid/msg/MsgException.java new file mode 100644 index 0000000000..c3591a81db --- /dev/null +++ b/org/simgrid/msg/MsgException.java @@ -0,0 +1,42 @@ +/* + * This exception is an abstract class grouping all MSG-related exceptions + * + * 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. + */ +package simgrid.msg; + +/** + * This exception is an abstract class grouping all MSG-related exceptions + + \htmlonly \endhtmlonly + + */ +public abstract class MsgException extends Exception { + private static final long serialVersionUID = 1L; + + /** + * Constructs an MsgException without a + * detail message. + */ + public MsgException() { + super(); + } + /** + * Constructs an MsgException with a detail message. + * + * @param s the detail message. + */ + public MsgException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/MsgNative.java b/org/simgrid/msg/MsgNative.java new file mode 100644 index 0000000000..e7f7759a2d --- /dev/null +++ b/org/simgrid/msg/MsgNative.java @@ -0,0 +1,428 @@ +/* + * Contains all the native methods related to Process, Host and Task. + * + * 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. + */ + +package simgrid.msg; + +/* FIXME: split into internal classes of Msg, Task, Host etc. */ + +/** + * Contains all the native methods related to Process, Host and Task. + */ +final class MsgNative { + + /****************************************************************** + * The natively implemented methods connected to the MSG Process * + ******************************************************************/ + /** + * The natively implemented method to create an MSG process. + * + * @param process The java process object to bind with the MSG native process. + * @param host A valid (binded) host where create the process. + * + * @see Process constructors. + */ + final static native + void processCreate(Process process, Host host); + + /** + * The natively implemented method to kill all the process of the simulation. + * + * @param resetPID Should we reset the PID numbers. A negative number means no reset + * and a positive number will be used to set the PID of the next newly + * created process. + * + * @return The function returns the PID of the next created process. + */ + final static native int processKillAll(int resetPID); + + /** + * The natively implemented method to suspend an MSG process. + * + * @param process The valid (binded with a native process) java process to suspend. + * + * @see Process.pause() + */ + final static native void processSuspend(Process process); + + /** + * The natively implemented method to kill a MSG process. + * + * @param process The valid (binded with a native process) java process to kill. + * + * @see Process.kill() + */ + final static native void processKill(Process process); + + /** + * The natively implemented method to resume a suspended MSG process. + * + * @param process The valid (binded with a native process) java process to resume. + * + * + * @see Process.restart() + */ + final static native void processResume(Process process); + + /** + * The natively implemented method to test if MSG process is suspended. + * + * @param process The valid (binded with a native process) java process to test. + * + * @return If the process is suspended the method retuns true. Otherwise the + * method returns false. + * + * @see Process.isSuspended() + */ + final static native boolean processIsSuspended(Process process); + + /** + * The natively implemented method to get the host of a MSG process. + * + * @param process The valid (binded with a native process) java process to get the host. + * + * @return The method returns the host where the process is running. + * + * @exception HostNotFoundException if the SimGrid native code failed (initialization error?). + * + * @see Process.getHost() + */ + final static native Host processGetHost(Process process); + + /** + * The natively implemented method to get a MSG process from his PID. + * + * @param PID The PID of the process to get. + * + * @return The process with the specified PID. + * + * @see Process.getFromPID() + */ + final static native Process processFromPID(int PID) ; + + /** + * The natively implemented method to get the PID of a MSG process. + * + * @param process The valid (binded with a native process) java process to get the PID. + * + * @return The PID of the specified process. + * + * @see Process.getPID() + */ + final static native int processGetPID(Process process); + + /** + * The natively implemented method to get the PPID of a MSG process. + * + * @param process The valid (binded with a native process) java process to get the PID. + * + * @return The PPID of the specified process. + * + * @see Process.getPPID() + */ + final static native int processGetPPID(Process process); + + /** + * The natively implemented method to get the current running process. + * + * @return The current process. + * + * @see Process.currentProcess() + */ + final static native Process processSelf(); + + /** + * The natively implemented method to migrate a process from his currnet host to a new host. + * + * @param process The (valid) process to migrate. + * @param host A (valid) host where move the process. + * + * + * @see Process.migrate() + * @see Host.getByName() + */ + final static native void processChangeHost(Process process, Host host) ; + + /** + * The natively implemented native to request the current process to sleep + * until time seconds have elapsed. + * + * @param seconds The time the current process must sleep. + * + * @exception HostFailureException if the SimGrid native code failed. + * + * @see Process.waitFor() + */ + final static native void processWaitFor(double seconds) throws HostFailureException; + + /** + * The natively implemented native method to exit a process. + * + * @see Process.exit() + */ + final static native void processExit(Process process); + + + /****************************************************************** + * The natively implemented methods connected to the MSG host * + ******************************************************************/ + + /** + * The natively implemented method to get an host from his name. + * + * @param name The name of the host to get. + * + * @return The host having the specified name. + * + * @exception HostNotFoundException if there is no such host + * + * + * @see Host.getByName() + */ + final static native Host hostGetByName(String name) throws HostNotFoundException; + + /** + * The natively implemented method to get the name of an MSG host. + * + * @param host The host (valid) to get the name. + * + * @return The name of the specified host. + * + * @see Host.getName() + */ + final static native String hostGetName(Host host); + + /** + * The natively implemented method to get the number of hosts of the simulation. + * + * @return The number of hosts of the simulation. + * + * @see Host.getNumber() + */ + final static native int hostGetCount(); + + /** + * The natively implemented method to get the host of the current runing process. + * + * @return The host of the current running process. + * + * @see Host.currentHost() + */ + final static native Host hostSelf(); + + /** + * The natively implemented method to get the speed of a MSG host. + * + * @param host The host to get the host. + * + * @return The speed of the specified host. + * + * @see Host.getSpeed() + */ + + final static native double hostGetSpeed(Host host); + + /** + * The natively implemented native method to test if an host is avail. + * + * @param host The host to test. + * + * @return If the host is avail the method returns true. + * Otherwise the method returns false. + * + * @see Host.isAvail() + */ + final static native boolean hostIsAvail(Host host); + + /** + * The natively implemented native method to get all the hosts of the simulation. + * + * @return A array which contains all the hosts of simulation. + */ + + final static native Host[] allHosts(); + + /** + * The natively implemented native method to get the number of running tasks on a host. + * + * @param The host concerned by the operation. + * + * @return The number of running tasks. + */ + final static native int hostGetLoad(Host host); + + /****************************************************************** + * The natively implemented methods connected to the MSG task * + ******************************************************************/ + + /** + * The natively implemented method to create a MSG task. + * + * @param name The name of th task. + * @param computeDuration A value of the processing amount (in flop) needed + * to process the task. If 0, then it cannot be executed + * with the execute() method. This value has to be >= 0. + * @param messageSize A value of amount of data (in bytes) needed to transfert + * this task. If 0, then it cannot be transfered this task. + * If 0, then it cannot be transfered with the get() and put() + * methods. This value has to be >= 0. + * @param task The java task object to bind with the native task to create. + * + * @exception IllegalArgumentException if compute duration <0 or message size <0 + * + * @see Task.create() + */ + final static native void taskCreate(Task task, String name, + double computeDuration, + double messageSize) + throws IllegalArgumentException; + + /** + * The natively implemented method to get the sender of a task. + * + * @param task The task (valid) to get the sender. + * + * @return The sender of the task. + * + * @see Task.getSender() + */ + final static native Process taskGetSender(Task task); + + /** + * The natively implementd method to get the source of a task. + * + * @param task The task to get the source. + * + * @return The source of the task. + * + * + * @see Task.getSource() + */ + final static native Host taskGetSource(Task task); + + /** + * The natively implemented method to get the name of the task. + * + * @param task The task to get the name. + * + * @return The name of the specified task. + * + * @see Task.getName() + */ + final static native String taskGetName(Task task); + + /** + * The natively implemented method to cancel a task. + * + * @param task The task to cancel. + * + * + * @see Task.cancel(). + */ + final static native void taskCancel(Task task); + + /** + * The natively implemented method to create a MSG parallel task. + * + * @param name The name of the parallel task. + * @param hosts The list of hosts implied by the parallel task. + * @param computeDurations The total number of operations that have to be performed + * on the hosts. + * @param messageSizes An array of doubles + * + * @see ParallelTask.create() + */ + final static native void parallelTaskCreate(Task pTask, String name, + Host[]hosts, + double[]computeDurations, + double[]messageSizes) + throws NullPointerException, IllegalArgumentException; + + /** + * The natively implemented method to get the computing amount of the task. + * + * @param task The task to get the computing amount. + * + * @return The computing amount of the specified task. + * + * @see Task.getComputeDuration() + */ + final static native double taskGetComputeDuration(Task task); + + /** + * The natively implemented method to get the remaining computation + * + * @param task The task to get the remaining computation. + * + * @return The remaining computation of the specified task. + * + * @see Task.getRemainingDuration() + */ + final static native double taskGetRemainingDuration(Task task); + + /** + * The natively implemented method to set the priority of a task. + * + * @param task The task to set the priority + * + * @param priority The new priority of the specified task. + * + * @see Task.setPriority() + */ + final static native void taskSetPriority(Task task, double priority); + + /** + * The natively implemented method to destroy a MSG task. + * + * @param The task to destroy. + * + * + * @see Task.destroy() + */ + final static native void taskDestroy(Task task) ; + + /** + * The natively implemented method to execute a MSG task. + * + * @param task The task to execute. + * + * @exception HostFailureException,TaskCancelledException on error in the C world + * + * @see Task.execute() + */ + final static native void taskExecute(Task task) throws HostFailureException,TaskCancelledException; + + /* **************************************************************** + * Communication methods thru mailboxes * + **************************************************************** */ + + final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,TimeoutException; + final static native Task taskReceive(String alias, double timeout, Host host) throws TransferFailureException,HostFailureException,TimeoutException; + final static native int taskListenFrom(String alias); + final static native boolean taskListen(String alias); + final static native int taskListenFromHost(String alias, Host host); + + /* *************************************************************** + * Task sending methods * + *************************************************************** */ + + /** + * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition + * rate. + * + * @param alias The alias of the mailbox. + * @param task The task to put. + * @param max_rate The bounded transmition rate. + * + * @exception NativeException on error in the C world + */ + final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException; + +} diff --git a/org/simgrid/msg/NativeException.java b/org/simgrid/msg/NativeException.java new file mode 100644 index 0000000000..deffee5732 --- /dev/null +++ b/org/simgrid/msg/NativeException.java @@ -0,0 +1,28 @@ +/* + * This exception is raised when there is an error within the C world of SimGrid. + * + * 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. + */ +package simgrid.msg; + +/** + * This exception is raised when there is an error within the C world of SimGrid. + * Refer to the string message for more info on what went wrong. + */ +public class NativeException extends MsgException { + private static final long serialVersionUID = 1L; + + /** + * Constructs an NativeException with a detail message. + * + * @param s the detail message. + */ + public NativeException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/Process.java b/org/simgrid/msg/Process.java new file mode 100644 index 0000000000..8d2b2ca0a8 --- /dev/null +++ b/org/simgrid/msg/Process.java @@ -0,0 +1,380 @@ +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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. + */ + +package simgrid.msg; + +import java.util.Arrays; +import java.util.Hashtable; +import java.util.Vector; + +/** + * A process may be defined as a code, with some private data, executing + * in a location (host). All the process used by your simulation must be + * declared in the deployment file (XML format). + * To create your own process you must inherit your own process from this + * class and override the method "main()". For example if you want to use + * a process named Slave proceed as it : + * + * (1) import the class Process of the package simgrid.msg + * import simgrid.msg.Process; + * + * public class Slave extends simgrid.msg.Process { + * + * (2) Override the method function + * + * \verbatim + * public void main(String[] args) { + * System.out.println("Hello MSG"); + * } + * \endverbatim + * } + * The name of your process must be declared in the deployment file of your simulation. + * For the example, for the previous process Slave this file must contains a line : + * <process host="Maxims" function="Slave"/>, where Maxims is the host of the process + * Slave. All the process of your simulation are automatically launched and managed by Msg. + * A process use tasks to simulate communications or computations with another process. + * For more information see Task. For more information on host concept + * see Host. + * + */ + +public abstract class Process extends Thread { + /** + * This attribute represents a bind between a java process object and + * a native process. Even if this attribute is public you must never + * access to it. It is set automatically during the build of the object. + */ + public long bind; + + /** + * Even if this attribute is public you must never access to it. + * It is used to compute the id of an MSG process. + */ + public static long nextProcessId = 0; + + /** + * Even if this attribute is public you must never access to it. + * It is compute automatically during the creation of the object. + * The native functions use this identifier to synchronize the process. + */ + public long id; + + public Hashtable properties; + + /** + * The name of the process. + */ + protected String name; + public String msgName() { + return this.name; + } + /** The arguments of the method function of the process. */ + public Vector args; + + /* process synchronization tools */ + protected Sem schedBegin, schedEnd; + + /** + * Default constructor (used in ApplicationHandler to initialize it) + */ + protected Process() { + super(); + this.id = nextProcessId++; + this.name = null; + this.bind = 0; + this.args = new Vector(); + this.properties = null; + schedBegin = new Sem(0); + schedEnd = new Sem(0); + } + + + /** + * Constructs a new process from the name of a host and his name. The method + * function of the process doesn't have argument. + * + * @param hostname The name of the host of the process to create. + * @param name The name of the process. + * + * @exception HostNotFoundException if no host with this name exists. + * + * + */ + public Process(String hostname, String name) throws HostNotFoundException { + this(Host.getByName(hostname), name, null); + } + /** + * Constructs a new process from the name of a host and his name. The arguments + * of the method function of the process are specified by the parameter args. + * + * @param hostname The name of the host of the process to create. + * @param name The name of the process. + * @param args The arguments of the main function of the process. + * + * @exception HostNotFoundException if no host with this name exists. + * NativeException + * + */ + public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException { + this(Host.getByName(hostname), name, args); + } + /** + * Constructs a new process from a host and his name. The method function of the + * process doesn't have argument. + * + * @param host The host of the process to create. + * @param name The name of the process. + * + */ + public Process(Host host, String name) { + this(host, name, null); + } + /** + * Constructs a new process from a host and his name, the arguments of here method function are + * specified by the parameter args. + * + * @param host The host of the process to create. + * @param name The name of the process. + * @param args The arguments of main method of the process. + * + */ + public Process(Host host, String name, String[]args) { + /* This is the constructor called by all others */ + this(); + + if (name == null) + throw new NullPointerException("Process name cannot be NULL"); + this.name = name; + + this.args = new Vector(); + if (null != args) + this.args.addAll(Arrays.asList(args)); + + MsgNative.processCreate(this, host); + } + + + /** + * This method kills all running process of the simulation. + * + * @param resetPID Should we reset the PID numbers. A negative number means no reset + * and a positive number will be used to set the PID of the next newly + * created process. + * + * @return The function returns the PID of the next created process. + * + */ + public static int killAll(int resetPID) { + return MsgNative.processKillAll(resetPID); + } + + /** + * This method adds an argument in the list of the arguments of the main function + * of the process. + * + * @param arg The argument to add. + */ + @Deprecated + protected void addArg(String arg) { + args.add(arg); + } + + /** + * Suspends the process by suspending the task on which it was + * waiting for the completion. + * + */ + public void pause() { + MsgNative.processSuspend(this); + } + /** + * Resumes a suspended process by resuming the task on which it was + * waiting for the completion. + * + * + */ + public void restart() { + MsgNative.processResume(this); + } + /** + * Tests if a process is suspended. + * + * @return The method returns true if the process is suspended. + * Otherwise the method returns false. + */ + public boolean isSuspended() { + return MsgNative.processIsSuspended(this); + } + /** + * Returns the host of a process. + * + * @return The host instance of the process. + * + * @exception NativeException on error in the native SimGrid code + * + */ + public Host getHost() { + return MsgNative.processGetHost(this); + } + /** + * This static method gets a process from a PID. + * + * @param PID The process identifier of the process to get. + * + * @return The process with the specified PID. + * + * @exception NativeException on error in the native SimGrid code + */ + public static Process fromPID(int PID) throws NativeException { + return MsgNative.processFromPID(PID); + } + /** + * This method returns the PID of the process. + * + * @return The PID of the process. + * + */ + public int getPID() { + return MsgNative.processGetPID(this); + } + /** + * This method returns the PID of the parent of a process. + * + * @return The PID of the parent of the process. + * + */ + public int getPPID() { + return MsgNative.processGetPPID(this); + } + /** + * This static method returns the currently running process. + * + * @return The current process. + * + */ + public static Process currentProcess() { + return MsgNative.processSelf(); + } + /** + * Migrates a process to another host. + * + * @param host The host where to migrate the process. + * + */ + public void migrate(Host host) { + MsgNative.processChangeHost(this, host); + } + /** + * Makes the current process sleep until time seconds have elapsed. + * + * @param seconds The time the current process must sleep. + * + * @exception HostFailureException on error in the native SimGrid code + */ + public static void waitFor(double seconds) throws HostFailureException { + MsgNative.processWaitFor(seconds); + } + public void showArgs() { + Msg.info("[" + this.name + "/" + this.getHost().getName() + "] argc=" + + this.args.size()); + for (int i = 0; i < this.args.size(); i++) + Msg.info("[" + this.msgName() + "/" + this.getHost().getName() + + "] args[" + i + "]=" + (String) (this.args.get(i))); + } + /** + * This method runs the process. Il calls the method function that you must overwrite. + */ + public void run() { + + String[]args = null; /* do not fill it before the signal or this.args will be empty */ + + //waitSignal(); /* wait for other people to fill the process in */ + + + try { + schedBegin.acquire(); + } catch(InterruptedException e) { + } + + try { + args = new String[this.args.size()]; + if (this.args.size() > 0) { + this.args.toArray(args); + } + + this.main(args); + MsgNative.processExit(this); + schedEnd.release(); + } catch(MsgException e) { + e.printStackTrace(); + Msg.info("Unexpected behavior. Stopping now"); + System.exit(1); + } + } + + /** + * The main function of the process (to implement). + */ + public abstract void main(String[]args) throws MsgException; + + + public void unschedule() { + try { + schedEnd.release(); + schedBegin.acquire(); + } catch(InterruptedException e) { + } + } + + public void schedule() { + try { + schedBegin.release(); + schedEnd.acquire(); + } catch(InterruptedException e) { + } + } + + /** Send the given task in the mailbox associated with the specified alias (waiting at most given time) + * @throws TimeoutException + * @throws HostFailureException + * @throws TransferFailureException */ + public void taskSend(String mailbox, Task task, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { + MsgNative.taskSend(mailbox, task, timeout); + } + + /** Send the given task in the mailbox associated with the specified alias + * @throws TimeoutException + * @throws HostFailureException + * @throws TransferFailureException */ + public void taskSend(String mailbox, Task task) throws TransferFailureException, HostFailureException, TimeoutException { + MsgNative.taskSend(mailbox, task, -1); + } + + /** Receive a task on mailbox associated with the specified mailbox */ + public Task taskReceive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, -1.0, null); + } + + /** Receive a task on mailbox associated with the specified alias (waiting at most given time) */ + public Task taskReceive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, timeout, null); + } + + /** Receive a task on mailbox associated with the specified alias from given sender */ + public Task taskReceive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, timeout, host); + } + + /** Receive a task on mailbox associated with the specified alias from given sender*/ + public Task taskReceive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, -1.0, host); + } +} diff --git a/org/simgrid/msg/ProcessNotFoundException.java b/org/simgrid/msg/ProcessNotFoundException.java new file mode 100644 index 0000000000..e3c7df8e09 --- /dev/null +++ b/org/simgrid/msg/ProcessNotFoundException.java @@ -0,0 +1,35 @@ +/* + * This exception is raised when looking for a non-existing process. + * + * 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. + */ + +package simgrid.msg; + +/** + * This exception is raised when looking for a non-existing process. + */ +public class ProcessNotFoundException extends MsgException { + private static final long serialVersionUID = 1L; + + /** + * Constructs an ProcessNotFoundException without a + * detail message. + */ + public ProcessNotFoundException() { + super(); + } + /** + * Constructs an ProcessNotFoundException with a detail message. + * + * @param s the detail message. + */ + public ProcessNotFoundException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/Sem.java b/org/simgrid/msg/Sem.java new file mode 100644 index 0000000000..af1d60bf83 --- /dev/null +++ b/org/simgrid/msg/Sem.java @@ -0,0 +1,35 @@ +/* + * Simple semaphore implementation, from Doug Lea (public domain) + * + * 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. + */ + package simgrid.msg; + public class Sem { + /******************************************************************/ + /* Simple semaphore implementation, from Doug Lea (public domain) */ + /******************************************************************/ + private int permits_; + public Sem(int i) { permits_ = i; } public void acquire() throws InterruptedException { + if (Thread.interrupted()) + throw new InterruptedException(); + synchronized(this) { + try { + while (permits_ <= 0) + wait(); + --permits_; + } + catch(InterruptedException ex) { + notify(); + throw ex; + } + } + } + public synchronized void release() { + ++(this.permits_); + notify(); + } } diff --git a/org/simgrid/msg/Task.java b/org/simgrid/msg/Task.java new file mode 100644 index 0000000000..bc2cdaa23b --- /dev/null +++ b/org/simgrid/msg/Task.java @@ -0,0 +1,223 @@ +/* + * simgrid.msg.Task.java 1.00 07/05/01 + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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. + */ + +package simgrid.msg; + +/** + * A task is either something to compute somewhere, or something to exchange between two hosts (or both). + * It is defined by a computing amount and a message size. + * + */ +public class Task { + /** + * This attribute represents a bind between a java task object and + * a native task. Even if this attribute is public you must never + * access to it. It is set automatically during the build of the object. + */ + public long bind = 0; + + + /** Default constructor (all fields to 0 or null) */ + public Task() { + MsgNative.taskCreate(this, null, 0, 0); + } + /* * * * + * * Constructors * * + * * * */ + /** + * Construct an new task with the specified processing amount and amount + * of data needed. + * + * @param name Task's name + * + * @param computeDuration A value of the processing amount (in flop) needed to process the task. + * If 0, then it cannot be executed with the execute() method. + * This value has to be >= 0. + * + * @param messageSize A value of amount of data (in bytes) needed to transfert this task. + * If 0, then it cannot be transfered with the get() and put() methods. + * This value has to be >= 0. + */ + public Task(String name, double computeDuration, double messageSize) { + MsgNative.taskCreate(this, name, computeDuration, messageSize); + } + /** + * Construct an new parallel task with the specified processing amount and amount for each host + * implied. + * + * @param name The name of the parallel task. + * @param hosts The list of hosts implied by the parallel task. + * @param computeDurations The amount of operations to be performed by each host of \a hosts. + * @param messageSizes A matrix describing the amount of data to exchange between hosts. + */ + public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) { + MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes); + } + /* * * * + * * Getters / Setters * * + * * * */ + /** Gets the name of a task */ + public String getName() { + return MsgNative.taskGetName(this); + } + /** Gets the sender of the task */ + Process getSender() { + return MsgNative.taskGetSender(this); + } + /** Gets the source of the task */ + public Host getSource() { + return MsgNative.taskGetSource(this); + } + /** Gets the computing amount of the task */ + public double getComputeDuration() { + return MsgNative.taskGetComputeDuration(this); + } + /** Gets the remaining computation of the task */ + public double getRemainingDuration() { + return MsgNative.taskGetRemainingDuration(this); + } + /** + * This method sets the priority of the computation of the task. + * The priority doesn't affect the transfert rate. For example a + * priority of 2 will make the task receive two times more cpu than + * the other ones. + * + * @param priority The new priority of the task. + */ + public void setPriority(double priority) { + MsgNative.taskSetPriority(this, priority); + } + /* * * * + * * Communication-related * * + * * * */ + + + /* * * * + * * Computation-related * * + * * * */ + /** + * Executes a task on the location on which the process is running. + * + * @exception HostFailureException,TaskCancelledException + */ + public void execute() throws HostFailureException,TaskCancelledException { + MsgNative.taskExecute(this); + } + /** + * Cancels a task. + * + * @exception NativeException if the cancellation failed. + */ + public void cancel() { + MsgNative.taskCancel(this); + } + /** Deletes a task. + * + * @exception NativeException if the destruction failed. + */ + protected void finalize() throws NativeException { + if (this.bind != 0) + MsgNative.taskDestroy(this); + } + + /** + * Sends the task on the mailbox identified by the specified name + * + * @throws TimeoutException + * @throws HostFailureException + * @throws TransferFailureException + */ + public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { + MsgNative.taskSend(mailbox, this, -1); + } + + /** + * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds) + * + * @exception NativeException if the retrieval fails. + * @throws TimeoutException + * @throws HostFailureException + * @throws TransferFailureException + */ + public void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException { + MsgNative.taskSend(mailbox, this, timeout); + } + + /** + * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) + * + * @exception TransferFailureException, HostFailureException, TimeoutException. + */ + public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException { + MsgNative.taskSendBounded(alias, this, maxrate); + } + + /** + * Retrieves next task from the mailbox identified by the specified name + * + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. + */ + + public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, -1.0, null); + } + + /** + * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds) + * + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. + */ + public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, timeout, null); + } + + /** + * Retrieves next task sent by a given host on the mailbox identified by the specified alias + * + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. + */ + + public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, -1.0, host); + } + + /** + * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds) + * + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. + */ + public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException { + return MsgNative.taskReceive(mailbox, timeout, host); + } + + /** + * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it + * + */ + public static int listenFrom(String mailbox) { + return MsgNative.taskListenFrom(mailbox); + } + /** + * Listen whether there is a waiting task on the mailbox identified by the specified alias + * + */ + public static boolean listen(String mailbox) { + return MsgNative.taskListen(mailbox); + } + + /** + * Counts the number of tasks waiting to be received on the \a mailbox identified by the specified alia and sended by the specified \a host. + * + */ + public static int listenFromHost(String alias, Host host) { + return MsgNative.taskListenFromHost(alias, host); + } +} diff --git a/org/simgrid/msg/TaskCancelledException.java b/org/simgrid/msg/TaskCancelledException.java new file mode 100644 index 0000000000..7c11d2a0b5 --- /dev/null +++ b/org/simgrid/msg/TaskCancelledException.java @@ -0,0 +1,32 @@ +/* + * This exception is raised when looking for a non-existing host. + * + * 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. + */ + +package simgrid.msg; + +/** + * This exception is raised when task is cancelled. + */ +public class TaskCancelledException extends MsgException { + private static final long serialVersionUID = 1L; + + /** Constructs an TaskCancelledException without a detail message. */ + public TaskCancelledException() { + super(); + } + /** + * Constructs an TaskCancelledException with a detail message. + * + * @param s the detail message. + */ + public TaskCancelledException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/TimeoutException.java b/org/simgrid/msg/TimeoutException.java new file mode 100644 index 0000000000..bd6a115891 --- /dev/null +++ b/org/simgrid/msg/TimeoutException.java @@ -0,0 +1,32 @@ +/* + * This exception is raised when looking for a non-existing host. + * + * 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. + */ + +package simgrid.msg; + +/** + * This exception is raised when time's out while sending tasks. + */ +public class TimeoutException extends MsgException { + private static final long serialVersionUID = 1L; + + /** Constructs an TimeoutFailureException without a detail message. */ + public TimeoutException() { + super(); + } + /** + * Constructs an TransferFailureException with a detail message. + * + * @param s the detail message. + */ + public TimeoutException(String s) { + super(s); + } +} diff --git a/org/simgrid/msg/TransferFailureException.java b/org/simgrid/msg/TransferFailureException.java new file mode 100644 index 0000000000..e1f90cd5a7 --- /dev/null +++ b/org/simgrid/msg/TransferFailureException.java @@ -0,0 +1,32 @@ +/* + * This exception is raised when looking for a non-existing host. + * + * 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. + */ + +package simgrid.msg; + +/** + * This exception is raised if transfer failed while sending tasks. + */ +public class TransferFailureException extends MsgException { + private static final long serialVersionUID = 1L; + + /** Constructs an TransferFailureException without a detail message. */ + public TransferFailureException() { + super(); + } + /** + * Constructs an TransferFailureException with a detail message. + * + * @param s the detail message. + */ + public TransferFailureException(String s) { + super(s); + } +} diff --git a/src/jmsg.c b/src/jmsg.c new file mode 100644 index 0000000000..57367ff560 --- /dev/null +++ b/src/jmsg.c @@ -0,0 +1,1152 @@ +/* Java Wrappers to the MSG API. */ + +/* Copyright (c) 2007, 2008, 2009, 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. */ + +#include "msg/msg.h" +#include "msg/private.h" +#include "simix/private.h" +#include "simix/smx_context_java.h" + +#include "jmsg_process.h" +#include "jmsg_host.h" +#include "jmsg_task.h" +#include "jmsg_application_handler.h" +#include "jxbt_utilities.h" + +#include "jmsg.h" +#include "msg/mailbox.h" +#include "surf/surfxml_parse.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); + +static JavaVM *__java_vm = NULL; + +static jobject native_to_java_process(m_process_t process); + +JavaVM *get_java_VM(void) +{ + return __java_vm; +} + +JNIEnv *get_current_thread_env(void) +{ + JNIEnv *env; + + (*__java_vm)->AttachCurrentThread(__java_vm, (void **) &env, NULL); + + return env; +} + +static jobject native_to_java_process(m_process_t process) +{ + return ((smx_ctx_java_t) + (process->simdata->s_process->context))->jprocess; +} + +/* + * The MSG process connected functions implementation. + */ + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls, + jobject jprocess_arg, + jobject jhost) +{ + jobject jprocess; /* the global reference to the java process instance */ + jstring jname; /* the name of the java process instance */ + const char *name; /* the C name of the process */ + m_process_t process; /* the native process to create */ + char alias[MAX_ALIAS_NAME + 1] = { 0 }; + msg_mailbox_t mailbox; + + DEBUG4 + ("Java_simgrid_msg_MsgNative_processCreate(env=%p,cls=%p,jproc=%p,jhost=%p)", + env, cls, jprocess_arg, jhost); + /* get the name of the java process */ + jname = jprocess_get_name(jprocess_arg, env); + + if (!jname) { + jxbt_throw_null(env, + xbt_strdup + ("Internal error: Process name cannot be NULL")); + return; + } + + /* allocate the data of the simulation */ + process = xbt_new0(s_m_process_t, 1); + process->simdata = xbt_new0(s_simdata_process_t, 1); + + /* create a global java process instance */ + jprocess = jprocess_new_global_ref(jprocess_arg, env); + + if (!jprocess) { + free(process->simdata); + free(process); + jxbt_throw_jni(env, "Can't get a global ref to the java process"); + return; + } + + /* bind the java process instance to the native process */ + jprocess_bind(jprocess, process, env); + + /* build the C name of the process */ + name = (*env)->GetStringUTFChars(env, jname, 0); + process->name = xbt_strdup(name); + (*env)->ReleaseStringUTFChars(env, jname, name); + + process->simdata->m_host = jhost_get_native(env, jhost); + + + if (!(process->simdata->m_host)) { /* not binded */ + free(process->simdata); + free(process->data); + free(process); + jxbt_throw_notbound(env, "host", jhost); + return; + } + process->simdata->PID = msg_global->PID++; + + /* create a new context */ + DEBUG8 + ("fill in process %s/%s (pid=%d) %p (sd=%p, host=%p, host->sd=%p); env=%p", + process->name, process->simdata->m_host->name, + process->simdata->PID, process, process->simdata, + process->simdata->m_host, process->simdata->m_host->simdata, env); + + process->simdata->s_process = + SIMIX_process_create(process->name, (xbt_main_func_t) jprocess, + /*data */ (void *) process, + process->simdata->m_host->simdata-> + smx_host->name, 0, NULL, NULL); + + DEBUG1("context created (s_process=%p)", process->simdata->s_process); + + + if (SIMIX_process_self()) { /* someone created me */ + process->simdata->PPID = + MSG_process_get_PID(SIMIX_process_self()->data); + } else { + process->simdata->PPID = -1; + } + + process->simdata->last_errno = MSG_OK; + + /* add the process to the list of the processes of the simulation */ + xbt_fifo_unshift(msg_global->process_list, process); + + sprintf(alias, "%s:%s", + (process->simdata->m_host->simdata->smx_host)->name, + process->name); + + mailbox = MSG_mailbox_new(alias); + +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls, + jobject jprocess) +{ + m_process_t process = jprocess_to_native_process(jprocess, env); + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return; + } + + /* try to suspend the process */ + MSG_error_t rv = MSG_process_suspend(process); + + jxbt_check_res("MSG_process_suspend()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); + +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls, + jobject jprocess) +{ + m_process_t process = jprocess_to_native_process(jprocess, env); + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return; + } + + /* try to resume the process */ + MSG_error_t rv = MSG_process_resume(process); + + jxbt_check_res("MSG_process_resume()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); +} + +JNIEXPORT jboolean JNICALL +Java_simgrid_msg_MsgNative_processIsSuspended(JNIEnv * env, jclass cls, + jobject jprocess) +{ + m_process_t process = jprocess_to_native_process(jprocess, env); + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return 0; + } + + /* true is the process is suspended, false otherwise */ + return (jboolean) MSG_process_is_suspended(process); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processKill(JNIEnv * env, jclass cls, + jobject jprocess) +{ + /* get the native instances from the java ones */ + m_process_t process = jprocess_to_native_process(jprocess, env); + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return; + } + + /* delete the global reference */ + jprocess_delete_global_ref(native_to_java_process(process), env); + + /* kill the native process (this wrapper is call by the destructor of the java + * process instance) + */ + MSG_process_kill(process); +} + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_processGetHost(JNIEnv * env, jclass cls, + jobject jprocess) +{ + /* get the native instances from the java ones */ + m_process_t process = jprocess_to_native_process(jprocess, env); + m_host_t host; + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return NULL; + } + + host = MSG_process_get_host(process); + + if (!MSG_host_get_data(host)) { + jxbt_throw_jni(env, "MSG_process_get_host() failed"); + return NULL; + } + + /* return the global reference to the java host instance */ + return (jobject) MSG_host_get_data(host); + +} + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_processFromPID(JNIEnv * env, jclass cls, + jint PID) +{ + m_process_t process = MSG_process_from_PID(PID); + + if (!process) { + jxbt_throw_process_not_found(env, bprintf("PID = %d",(int) PID)); + return NULL; + } + + if (!native_to_java_process(process)) { + jxbt_throw_jni(env, "SIMIX_process_get_jprocess() failed"); + return NULL; + } + + return (jobject) (native_to_java_process(process)); +} + + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_processGetPID(JNIEnv * env, jclass cls, + jobject jprocess) +{ + m_process_t process = jprocess_to_native_process(jprocess, env); + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return 0; + } + + return (jint) MSG_process_get_PID(process); +} + + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_processGetPPID(JNIEnv * env, jclass cls, + jobject jprocess) +{ + m_process_t process = jprocess_to_native_process(jprocess, env); + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return 0; + } + + return (jint) MSG_process_get_PPID(process); +} + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_processSelf(JNIEnv * env, jclass cls) +{ + m_process_t process = MSG_process_self(); + jobject jprocess; + + if (!process) { + jxbt_throw_jni(env, xbt_strdup("MSG_process_self() failed")); + return NULL; + } + + jprocess = native_to_java_process(process); + + if (!jprocess) + jxbt_throw_jni(env, xbt_strdup("SIMIX_process_get_jprocess() failed")); + + return jprocess; +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv * env, jclass cls, + jobject jhost) +{ + m_host_t host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return; + } + + /* try to change the host of the process */ + MSG_error_t rv = MSG_process_change_host(host); + + jxbt_check_res("MSG_process_change_host()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); + +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processWaitFor(JNIEnv * env, jclass cls, + jdouble seconds) +{ + MSG_error_t rv = MSG_process_sleep((double) seconds); + + jxbt_check_res("MSG_process_sleep()", rv, MSG_HOST_FAILURE, + bprintf("while process was waiting for %f seconds", + (double) seconds)); + +} + + +/*************************************************************************************** + * The MSG host connected functions implementation. * + ***************************************************************************************/ + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls, + jstring jname) +{ + m_host_t host; /* native host */ + jobject jhost; /* global reference to the java host instance returned */ + + /* get the C string from the java string */ + const char *name = (*env)->GetStringUTFChars(env, jname, 0); + + /* get the host by name (the hosts are created during the grid resolution) */ + host = MSG_get_host_by_name(name); + DEBUG2("MSG gave %p as native host (simdata=%p)", host, host->simdata); + + (*env)->ReleaseStringUTFChars(env, jname, name); + + if (!host) { /* invalid name */ + jxbt_throw_host_not_found(env, name); + return NULL; + } + + if (!MSG_host_get_data(host)) { /* native host not associated yet with java host */ + + /* instanciate a new java host */ + jhost = jhost_new_instance(env); + + if (!jhost) { + jxbt_throw_jni(env, "java host instantiation failed"); + return NULL; + } + + /* get a global reference to the newly created host */ + jhost = jhost_ref(env, jhost); + + if (!jhost) { + jxbt_throw_jni(env, "new global ref allocation failed"); + return NULL; + } + + /* bind the java host and the native host */ + jhost_bind(jhost, host, env); + + /* the native host data field is set with the global reference to the + * java host returned by this function + */ + MSG_host_set_data(host, (void *) jhost); + } + + /* return the global reference to the java host instance */ + return (jobject) MSG_host_get_data(host); +} + +JNIEXPORT jstring JNICALL +Java_simgrid_msg_MsgNative_hostGetName(JNIEnv * env, jclass cls, + jobject jhost) +{ + m_host_t host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return NULL; + } + + return (*env)->NewStringUTF(env, MSG_host_get_name(host)); +} + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_hostGetNumber(JNIEnv * env, jclass cls) +{ + return (jint) MSG_get_host_number(); +} + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_hostSelf(JNIEnv * env, jclass cls) +{ + jobject jhost; + + m_host_t host = MSG_host_self(); + + if (!MSG_host_get_data(host)) { + /* the native host not yet associated with the java host instance */ + + /* instanciate a new java host instance */ + jhost = jhost_new_instance(env); + + if (!jhost) { + jxbt_throw_jni(env, "java host instantiation failed"); + return NULL; + } + + /* get a global reference to the newly created host */ + jhost = jhost_ref(env, jhost); + + if (!jhost) { + jxbt_throw_jni(env, "global ref allocation failed"); + return NULL; + } + + /* Bind & store it */ + jhost_bind(jhost, host, env); + MSG_host_set_data(host, (void *) jhost); + } else { + jhost = (jobject) MSG_host_get_data(host); + } + + return jhost; +} + +JNIEXPORT jdouble JNICALL +Java_simgrid_msg_MsgNative_hostGetSpeed(JNIEnv * env, jclass cls, + jobject jhost) +{ + m_host_t host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return -1; + } + + return (jdouble) MSG_get_host_speed(host); +} + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls, + jobject jhost) +{ + m_host_t host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return -1; + } + + return (jint) MSG_get_host_msgload(host); +} + + +JNIEXPORT jboolean JNICALL +Java_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls, + jobject jhost) +{ + m_host_t host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return 0; + } + + return (jboolean) MSG_host_is_avail(host); +} + + +/*************************************************************************************** + * The MSG task connected functions implementation. * + ***************************************************************************************/ + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskCreate(JNIEnv * env, jclass cls, + jobject jtask, jstring jname, + jdouble jcomputeDuration, + jdouble jmessageSize) +{ + m_task_t task; /* the native task to create */ + const char *name = NULL; /* the name of the task */ + + if (jcomputeDuration < 0) { + jxbt_throw_illegal(env, + bprintf + ("Task ComputeDuration (%f) cannot be negative", + (double) jcomputeDuration)); + return; + } + + if (jmessageSize < 0) { + jxbt_throw_illegal(env, + bprintf("Task MessageSize (%f) cannot be negative", + (double) jmessageSize)); + return; + } + + if (jname) { + /* get the C string from the java string */ + name = (*env)->GetStringUTFChars(env, jname, 0); + } + + + /* create the task */ + task = + MSG_task_create(name, (double) jcomputeDuration, + (double) jmessageSize, NULL); + + if (jname) + (*env)->ReleaseStringUTFChars(env, jname, name); + + /* bind & store the task */ + jtask_bind(jtask, task, env); + MSG_task_set_data(task, jtask); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls, + jobject jtask, + jstring jname, + jobjectArray jhosts, + jdoubleArray + jcomputeDurations_arg, + jdoubleArray + jmessageSizes_arg) +{ + + m_task_t task; /* the native parallel task to create */ + const char *name; /* the name of the task */ + int host_count; + m_host_t *hosts; + double *computeDurations; + double *messageSizes; + jdouble *jcomputeDurations; + jdouble *jmessageSizes; + + jobject jhost; + int index; + + + if (!jcomputeDurations_arg) { + jxbt_throw_null(env, + xbt_strdup + ("Parallel task compute durations cannot be null")); + return; + } + + if (!jmessageSizes_arg) { + jxbt_throw_null(env, + xbt_strdup + ("Parallel task message sizes cannot be null")); + return; + } + + if (!jname) { + jxbt_throw_null(env, xbt_strdup("Parallel task name cannot be null")); + return; + } + + host_count = (int) (*env)->GetArrayLength(env, jhosts); + + + hosts = xbt_new0(m_host_t, host_count); + computeDurations = xbt_new0(double, host_count); + messageSizes = xbt_new0(double, host_count * host_count); + + jcomputeDurations = + (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0); + jmessageSizes = + (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0); + + for (index = 0; index < host_count; index++) { + jhost = (*env)->GetObjectArrayElement(env, jhosts, index); + hosts[index] = jhost_get_native(env, jhost); + computeDurations[index] = jcomputeDurations[index]; + } + for (index = 0; index < host_count * host_count; index++) { + messageSizes[index] = jmessageSizes[index]; + } + + (*env)->ReleaseDoubleArrayElements(env, jcomputeDurations_arg, + jcomputeDurations, 0); + (*env)->ReleaseDoubleArrayElements(env, jmessageSizes_arg, jmessageSizes, + 0); + + + /* get the C string from the java string */ + name = (*env)->GetStringUTFChars(env, jname, 0); + + task = + MSG_parallel_task_create(name, host_count, hosts, computeDurations, + messageSizes, NULL); + + (*env)->ReleaseStringUTFChars(env, jname, name); + + /* associate the java task object and the native task */ + jtask_bind(jtask, task, env); + + MSG_task_set_data(task, (void *) jtask); + + if (!MSG_task_get_data(task)) + jxbt_throw_jni(env, "global ref allocation failed"); +} + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_taskGetSender(JNIEnv * env, jclass cls, + jobject jtask) +{ + m_process_t process; + + m_task_t task = jtask_to_native_task(jtask, env); + + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return NULL; + } + + process = MSG_task_get_sender(task); + return (jobject) native_to_java_process(process); +} + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls, + jobject jtask) +{ + m_host_t host; + m_task_t task = jtask_to_native_task(jtask, env); + + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return NULL; + } + + host = MSG_task_get_source(task); + + if (!MSG_host_get_data(host)) { + jxbt_throw_jni(env, "MSG_task_get_source() failed"); + return NULL; + } + + return (jobject) MSG_host_get_data(host); +} + + +JNIEXPORT jstring JNICALL +Java_simgrid_msg_MsgNative_taskGetName(JNIEnv * env, jclass cls, + jobject jtask) +{ + m_task_t task = jtask_to_native_task(jtask, env); + + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return NULL; + } + + return (*env)->NewStringUTF(env, MSG_task_get_name(task)); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, + jobject jtask) +{ + m_task_t ptask = jtask_to_native_task(jtask, env); + + if (!ptask) { + jxbt_throw_notbound(env, "task", jtask); + return; + } + + MSG_error_t rv = MSG_task_cancel(ptask); + + jxbt_check_res("MSG_task_cancel()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); +} + +JNIEXPORT jdouble JNICALL +Java_simgrid_msg_MsgNative_taskGetComputeDuration(JNIEnv * env, jclass cls, + jobject jtask) +{ + m_task_t ptask = jtask_to_native_task(jtask, env); + + if (!ptask) { + jxbt_throw_notbound(env, "task", jtask); + return -1; + } + return (jdouble) MSG_task_get_compute_duration(ptask); +} + +JNIEXPORT jdouble JNICALL +Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env, + jclass cls, + jobject jtask) +{ + m_task_t ptask = jtask_to_native_task(jtask, env); + + if (!ptask) { + jxbt_throw_notbound(env, "task", jtask); + return -1; + } + return (jdouble) MSG_task_get_remaining_computation(ptask); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskSetPriority(JNIEnv * env, jclass cls, + jobject jtask, jdouble priority) +{ + m_task_t task = jtask_to_native_task(jtask, env); + + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return; + } + MSG_task_set_priority(task, (double) priority); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskDestroy(JNIEnv * env, jclass cls, + jobject jtask_arg) +{ + + /* get the native task */ + m_task_t task = jtask_to_native_task(jtask_arg, env); + jobject jtask; + + if (!task) { + jxbt_throw_notbound(env, "task", task); + return; + } + jtask = (jobject) MSG_task_get_data(task); + + MSG_error_t rv = MSG_task_destroy(task); + + jxbt_check_res("MSG_task_destroy()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls, + jobject jtask) +{ + m_task_t task = jtask_to_native_task(jtask, env); + + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return; + } + + MSG_error_t rv = MSG_task_execute(task); + + jxbt_check_res("MSG_task_execute()", rv, + MSG_HOST_FAILURE | MSG_TASK_CANCELLED, + bprintf("while executing task %s", + MSG_task_get_name(task))); +} + +/*************************************************************************************** + * Unsortable functions * + ***************************************************************************************/ + + +JNIEXPORT jint JNICALL +Java_simgrid_msg_Msg_getErrCode(JNIEnv * env, jclass cls) +{ + return (jint) MSG_get_errno(); +} + +JNIEXPORT jdouble JNICALL +Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls) +{ + return (jdouble) MSG_get_clock(); +} + + +JNIEXPORT void JNICALL +Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) +{ + char **argv = NULL; + int index; + int argc = 0; + jstring jval; + const char *tmp; + + factory_initializer_to_use = SIMIX_ctx_java_factory_init; + + if (jargs) + argc = (int) (*env)->GetArrayLength(env, jargs); + + argc++; + argv = xbt_new0(char *, argc); + argv[0] = strdup("java"); + + for (index = 0; index < argc - 1; index++) { + jval = (jstring) (*env)->GetObjectArrayElement(env, jargs, index); + tmp = (*env)->GetStringUTFChars(env, jval, 0); + argv[index + 1] = strdup(tmp); + (*env)->ReleaseStringUTFChars(env, jval, tmp); + } + + MSG_global_init(&argc, argv); + + for (index = 0; index < argc; index++) + free(argv[index]); + + free(argv); + + (*env)->GetJavaVM(env, &__java_vm); +} + +JNIEXPORT void JNICALL + JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) +{ + MSG_error_t rv; + int index; //xbt_fifo_item_t item = NULL; + m_host_t *hosts; + jobject jhost; + + /* Run everything */ + rv = MSG_main(); + jxbt_check_res("MSG_main()", rv, MSG_OK, + bprintf + ("unexpected error : MSG_main() failed .. please report this bug ")); + + DEBUG0 + ("MSG_main finished. Bail out before cleanup since there is a bug in this part."); + + DEBUG0("Clean java world"); + /* Cleanup java hosts */ + hosts = MSG_get_host_table(); + for (index = 0; index < MSG_get_host_number() - 1; index++) { + jhost = (jobject) hosts[index]->data; + if (jhost) + jhost_unref(env, jhost); + + } + + DEBUG0("Clean native world"); + /* cleanup native stuff */ + rv = MSG_OK != MSG_clean(); + jxbt_check_res("MSG_clean()", rv, MSG_OK, + bprintf + ("unexpected error : MSG_clean() failed .. please report this bug ")); + +} + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_processKillAll(JNIEnv * env, jclass cls, + jint jresetPID) +{ + return (jint) MSG_process_killall((int) jresetPID); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls, + jstring jplatformFile) +{ + + const char *platformFile = + (*env)->GetStringUTFChars(env, jplatformFile, 0); + + MSG_create_environment(platformFile); + + (*env)->ReleaseStringUTFChars(env, jplatformFile, platformFile); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processExit(JNIEnv * env, jclass cls, + jobject jprocess) +{ + + m_process_t process = jprocess_to_native_process(jprocess, env); + + if (!process) { + jxbt_throw_notbound(env, "process", jprocess); + return; + } + + SIMIX_context_stop(SIMIX_process_self()->context); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js) +{ + const char *s = (*env)->GetStringUTFChars(env, js, 0); + INFO1("%s", s); + (*env)->ReleaseStringUTFChars(env, js, s); +} + +JNIEXPORT jobjectArray JNICALL +Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg) +{ + int index; + jobjectArray jtable; + jobject jhost; + jstring jname; + m_host_t host; + + int count = MSG_get_host_number(); + m_host_t *table = MSG_get_host_table(); + + jclass cls = jxbt_get_class(env, "simgrid/msg/Host"); + + if (!cls) { + return NULL; + } + + jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL); + + if (!jtable) { + jxbt_throw_jni(env, "Hosts table allocation failed"); + return NULL; + } + + for (index = 0; index < count; index++) { + host = table[index]; + jhost = (jobject) (MSG_host_get_data(host)); + + if (!jhost) { + jname = (*env)->NewStringUTF(env, MSG_host_get_name(host)); + + jhost = + Java_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname); + /* FIXME: leak of jname ? */ + } + + (*env)->SetObjectArrayElement(env, jtable, index, jhost); + } + + return jtable; +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls, + jstring jalias, jobject jtask, + jdouble jtimeout) +{ + + MSG_error_t rv; + const char *alias = (*env)->GetStringUTFChars(env, jalias, 0); + + m_task_t task = jtask_to_native_task(jtask, env); + + + if (!task) { + (*env)->ReleaseStringUTFChars(env, jalias, alias); + jxbt_throw_notbound(env, "task", jtask); + return; + } + + /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */ + MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask)); + rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout); + + (*env)->ReleaseStringUTFChars(env, jalias, alias); + + jxbt_check_res("MSG_task_send_with_timeout()", rv, + MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT, + bprintf("while sending task %s to mailbox %s", + MSG_task_get_name(task), alias)); +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls, + jstring jalias, jobject jtask, + jdouble jmaxRate) +{ + m_task_t task = jtask_to_native_task(jtask, env); + MSG_error_t rv; + const char *alias; + + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return; + } + + alias = (*env)->GetStringUTFChars(env, jalias, 0); + + /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */ + MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask)); + rv = MSG_task_send_bounded(task, alias, (double) jmaxRate); + + (*env)->ReleaseStringUTFChars(env, jalias, alias); + + jxbt_check_res("MSG_task_send_bounded()", rv, + MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT, + bprintf + ("while sending task %s to mailbox %s with max rate %f", + MSG_task_get_name(task), alias, (double) jmaxRate)); + +} + +JNIEXPORT jobject JNICALL +Java_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls, + jstring jalias, jdouble jtimeout, + jobject jhost) +{ + MSG_error_t rv; + m_task_t task = NULL; + m_host_t host = NULL; + jobject jtask_global, jtask_local; + const char *alias; + + if (jhost) { + host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return NULL; + } + } + + alias = (*env)->GetStringUTFChars(env, jalias, 0); + + rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host); + jtask_global = MSG_task_get_data(task); + + /* Convert the global ref into a local ref so that the JVM can free the stuff */ + jtask_local = (*env)->NewLocalRef(env, jtask_global); + (*env)->DeleteGlobalRef(env, jtask_global); + MSG_task_set_data(task, NULL); + + (*env)->ReleaseStringUTFChars(env, jalias, alias); + + jxbt_check_res("MSG_task_receive_ext()", rv, + MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT, + bprintf("while receiving from mailbox %s", alias)); + + return (jobject) jtask_local; +} + +JNIEXPORT jboolean JNICALL +Java_simgrid_msg_MsgNative_taskListen(JNIEnv * env, jclass cls, + jstring jalias) +{ + + const char *alias; + int rv; + + alias = (*env)->GetStringUTFChars(env, jalias, 0); + + rv = MSG_task_listen(alias); + + (*env)->ReleaseStringUTFChars(env, jalias, alias); + + return (jboolean) rv; +} + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv * env, jclass cls, + jstring jalias, + jobject jhost) +{ + int rv; + const char *alias; + + m_host_t host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return -1; + } + alias = (*env)->GetStringUTFChars(env, jalias, 0); + + rv = MSG_task_listen_from_host(alias, host); + + (*env)->ReleaseStringUTFChars(env, jalias, alias); + + return (jint) rv; +} + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_taskListenFrom(JNIEnv * env, jclass cls, + jstring jalias) +{ + + int rv; + const char *alias = (*env)->GetStringUTFChars(env, jalias, 0); + + rv = MSG_task_listen_from(alias); + + (*env)->ReleaseStringUTFChars(env, jalias, alias); + + return (jint) rv; +} + +JNIEXPORT void JNICALL +Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, + jstring jdeploymentFile) +{ + + const char *deploymentFile = + (*env)->GetStringUTFChars(env, jdeploymentFile, 0); + + surf_parse_reset_parser(); + + surfxml_add_callback(STag_surfxml_process_cb_list, + japplication_handler_on_begin_process); + + surfxml_add_callback(ETag_surfxml_argument_cb_list, + japplication_handler_on_process_arg); + + surfxml_add_callback(STag_surfxml_prop_cb_list, + japplication_handler_on_property); + + surfxml_add_callback(ETag_surfxml_process_cb_list, + japplication_handler_on_end_process); + + surf_parse_open(deploymentFile); + + japplication_handler_on_start_document(); + + if (surf_parse()) + jxbt_throw_jni(env, "surf_parse() failed"); + + surf_parse_close(); + + japplication_handler_on_end_document(); + + (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile); +} diff --git a/src/jmsg.h b/src/jmsg.h new file mode 100644 index 0000000000..dffe8b987f --- /dev/null +++ b/src/jmsg.h @@ -0,0 +1,344 @@ +/* Java Wrappers to the MSG API. */ + +/* Copyright (c) 2007, 2008, 2009, 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. */ + +#ifndef MSG4JAVA_H +#define MSG4JAVA_H + +#include + +JavaVM *get_java_VM(void); + +JNIEnv *get_current_thread_env(void); + +/* + * Class simgrid_msg_Msg + * Method processCreate + * Signature (Lsimgrid/msg/Process;Lsimgrid/msg/Host;)V + */ +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls, + jobject jprocess, jobject jhost); + + + +/* + * Class simgrid_msg_Msg + * Method processSuspend + * Signature (Lsimgrid/msg/Process;)V + */ +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls, + jobject jprocess); + +/* + * Class simgrid_msg_Msg + * Method processResume + * Signature (Lsimgrid/msg/Process;)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processResume + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method processIsSuspended + * Signature (Lsimgrid/msg/Process;)Z + */ +JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_processIsSuspended + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method processKill + * Signature (Lsimgrid/msg/Process;)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processKill + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method processGetHost + * Signature (Lsimgrid/msg/Process;)Lsimgrid/msg/Host; + */ +JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processGetHost + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method processFromPID + * Signature (I)Lsimgrid/msg/Process; + */ +JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processFromPID + (JNIEnv *, jclass, jint); + +/* + * Class simgrid_msg_Msg + * Method processGetPID + * Signature (Lsimgrid/msg/Process;)I + */ +JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processGetPID + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method processGetPPID + * Signature (Lsimgrid/msg/Process;)I + */ +JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processGetPPID + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method processSelf + * Signature ()Lsimgrid/msg/Process; + */ +JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processSelf + (JNIEnv *, jclass); + +/* + * Class simgrid_msg_Msg + * Method processSelfPID + * Signature ()I + */ +JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processSelfPID + (JNIEnv *, jclass); + +/* + * Class simgrid_msg_Msg + * Method processSelfPPID + * Signature ()I + */ +JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processSelfPPID + (JNIEnv *, jclass); + +/* + * Class simgrid_msg_Msg + * Method processChangeHost + * Signature (Lsimgrid/msg/Process;Lsimgrid/msg/Host;)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processChangeHost + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method processWaitFor + * Signature (D)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processWaitFor + (JNIEnv *, jclass, jdouble); + +/* + * Class simgrid_msg_Msg + * Method hostGetByName + * Signature (Ljava/lang/String;)Lsimgrid/msg/Host; + */ +JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_hostGetByName + (JNIEnv *, jclass, jstring); + +/* + * Class simgrid_msg_Msg + * Method hostGetName + * Signature (Lsimgrid/msg/Host;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_simgrid_msg_MsgNative_hostGetName + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method hostGetNumber + * Signature ()I + */ +JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_hostGetNumber + (JNIEnv *, jclass); + +/* + * Class simgrid_msg_Msg + * Method hostSelf + * Signature ()Lsimgrid/msg/Host; + */ +JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_hostSelf + (JNIEnv *, jclass); + +/* + * Class simgrid_msg_Msg + * Method hostGetSpeed + * Signature (Lsimgrid/msg/Host;)D + */ +JNIEXPORT jdouble JNICALL Java_simgrid_msg_MsgNative_hostGetSpeed + (JNIEnv *, jclass, jobject); + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls, + jobject jhost); + +/* + * Class simgrid_msg_Msg + * Method hostIsAvail + * Signature (Lsimgrid/msg/Host;)Z + */ +JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_hostIsAvail + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method taskCreate + * Signature (Lsimgrid/msg/Task;Ljava/lang/String;DD)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskCreate + (JNIEnv *, jclass, jobject, jstring, jdouble, jdouble); + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv *, jclass, jobject, + jstring, jobjectArray, + jdoubleArray, jdoubleArray); + +/* + * Class simgrid_msg_Msg + * Method taskGetSender + * Signature (Lsimgrid/msg/Task;)Lsimgrid/msg/Process; + */ +JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskGetSender + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method taskGetSource + * Signature (Lsimgrid/msg/Task;)Lsimgrid/msg/Host; + */ +JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskGetSource + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method taskGetName + * Signature (Lsimgrid/msg/Task;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_simgrid_msg_MsgNative_taskGetName + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method taskCancel + * Signature (Lsimgrid/msg/Task;)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskCancel + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method taskGetComputeDuration + * Signature (Lsimgrid/msg/Task;)D + */ +JNIEXPORT jdouble JNICALL Java_simgrid_msg_MsgNative_taskGetComputeDuration + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method taskGetRemainingDuration + * Signature (Lsimgrid/msg/Task;)D + */ +JNIEXPORT jdouble JNICALL +Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv *, jclass, + jobject); + +/* + * Class simgrid_msg_Msg + * Method taskSetPriority + * Signature (Lsimgrid/msg/Task;D)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskSetPriority + (JNIEnv *, jclass, jobject, jdouble); + +/* + * Class simgrid_msg_Msg + * Method taskDestroy + * Signature (Lsimgrid/msg/Task;)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskDestroy + (JNIEnv *, jclass, jobject); + +/* + * Class simgrid_msg_Msg + * Method taskExecute + * Signature (Lsimgrid/msg/Task;)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskExecute + (JNIEnv *, jclass, jobject); + +JNIEXPORT jobject JNICALL + Java_simgrid_msg_MsgNative_taskReceive + (JNIEnv *, jclass, jstring, jdouble, jobject); + +JNIEXPORT void JNICALL + Java_simgrid_msg_MsgNative_taskSend + (JNIEnv *, jclass, jstring, jobject, jdouble); + +/* + * Class simgrid_msg_Msg + * Method getErrCode + * Signature ()I + */ +JNIEXPORT jint JNICALL Java_simgrid_msg_Msg_getErrCode(JNIEnv *, jclass); + +/* + * Class simgrid_msg_Msg + * Method getClock + * Signature ()D + */ +JNIEXPORT jdouble JNICALL Java_simgrid_msg_Msg_getClock(JNIEnv *, jclass); + +JNIEXPORT void JNICALL + JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls); + +JNIEXPORT void JNICALL +Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs); + +/* + * Class simgrid_msg_Msg + * Method processKillAll + * Signature (I)I + */ +JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processKillAll + (JNIEnv *, jclass, jint); + +/* + * Class simgrid_msg_Msg + * Method processExit + * Signature (Lsimgrid/msg/Process;)V + */ +JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processExit + (JNIEnv *, jclass, jobject); + +JNIEXPORT void JNICALL Java_simgrid_msg_Msg_info(JNIEnv *, jclass, + jstring); + +JNIEXPORT jobjectArray JNICALL +Java_simgrid_msg_MsgNative_allHosts(JNIEnv *, jclass); + +JNIEXPORT void JNICALL +Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls, + jstring jplatformFile); + +JNIEXPORT void JNICALL +Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv *, jclass, jstring, + jobject, jdouble); + +JNIEXPORT jboolean JNICALL +Java_simgrid_msg_MsgNative_taskListen(JNIEnv *, jclass, jstring); + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv *, jclass, jstring, + jobject); + +JNIEXPORT jint JNICALL +Java_simgrid_msg_MsgNative_taskListenFrom(JNIEnv *, jclass, jstring); + +JNIEXPORT void JNICALL +Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, + jstring jdeploymentFile); + +#endif /* !MSG4JAVA_H */ diff --git a/src/jmsg_application_handler.c b/src/jmsg_application_handler.c new file mode 100644 index 0000000000..f22746424c --- /dev/null +++ b/src/jmsg_application_handler.c @@ -0,0 +1,110 @@ +/* Upcalls to the Java functions used as callback to the FleXML parser. */ + +/* Copyright (c) 2008, 2009, 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. */ + +#include "jmsg_application_handler.h" + +#include "jmsg.h" + +#include "surf/surfxml_parse.h" +#include "jxbt_utilities.h" +void japplication_handler_on_start_document(void) +{ + jclass cls; + JNIEnv *env = get_current_thread_env(); + jmethodID id = + jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", + "onStartDocument", "()V"); + + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + return; + + (*env)->CallStaticVoidMethod(env, cls, id); +} + +void japplication_handler_on_end_document(void) +{ + jclass cls; + JNIEnv *env = get_current_thread_env(); + jmethodID id = + jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", + "onEndDocument", "()V"); + + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + return; + + (*env)->CallStaticVoidMethod(env, cls, id); +} + +void japplication_handler_on_begin_process(void) +{ + jstring jhostName; + jstring jfunction; + jclass cls; + JNIEnv *env = get_current_thread_env(); + jmethodID id = + jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", + "onBeginProcess", + "(Ljava/lang/String;Ljava/lang/String;)V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + return; + jhostName = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_host); + jfunction = + (jstring) (*env)->NewStringUTF(env, A_surfxml_process_function); + (*env)->CallStaticVoidMethod(env, cls, id, jhostName, jfunction); +} + +void japplication_handler_on_process_arg(void) +{ + jstring jarg; + jclass cls; + JNIEnv *env = get_current_thread_env(); + jmethodID id = + jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", + "onProcessArg", "(Ljava/lang/String;)V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + return; + jarg = (jstring) (*env)->NewStringUTF(env, A_surfxml_argument_value); + + (*env)->CallStaticVoidMethod(env, cls, id, jarg); +} + +void japplication_handler_on_property(void) +{ + jstring jid; + jstring jvalue; + jclass cls; + JNIEnv *env = get_current_thread_env(); + jmethodID id = + jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", + "onProperty", + "(Ljava/lang/String;Ljava/lang/String;)V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + return; + + jid = (jstring) (*env)->NewStringUTF(env, A_surfxml_prop_id); + jvalue = (jstring) (*env)->NewStringUTF(env, A_surfxml_prop_value); + (*env)->CallStaticVoidMethod(env, cls, id, jid, jvalue); +} + +void japplication_handler_on_end_process(void) +{ + JNIEnv *env = get_current_thread_env(); + jclass cls; + jmethodID id = + jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", + "onEndProcess", "()V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + return; + (*env)->CallStaticVoidMethod(env, cls, id); +} diff --git a/src/jmsg_application_handler.h b/src/jmsg_application_handler.h new file mode 100644 index 0000000000..7d3a2159d3 --- /dev/null +++ b/src/jmsg_application_handler.h @@ -0,0 +1,21 @@ +/* Upcalls to the Java functions used as callback to the FleXML parser. */ + +/* Copyright (c) 2008, 2009, 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. */ + +#ifndef MSG_JAPPLICATION_HANDLER_H +#define MSG_JAPPLICATION_HANDLER_H + +#include +#include "msg/msg.h" +void japplication_handler_on_start_document(void); +void japplication_handler_on_end_document(void); +void japplication_handler_on_begin_process(void); +void japplication_handler_on_process_arg(void); +void japplication_handler_on_property(void); +void japplication_handler_on_end_process(void); + +#endif /* !MSG_JAPPLICATION_HANDLER_H */ diff --git a/src/jmsg_host.c b/src/jmsg_host.c new file mode 100644 index 0000000000..26edfa2f6e --- /dev/null +++ b/src/jmsg_host.c @@ -0,0 +1,88 @@ +/* Functions related to the java host instances. */ + +/* Copyright (c) 2007, 2009, 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. */ + +#include "xbt/str.h" +#include "jmsg.h" +#include "jmsg_host.h" +#include "jxbt_utilities.h" + +jobject jhost_new_instance(JNIEnv * env) +{ + + jclass cls = jxbt_get_class(env, "simgrid/msg/Host"); + jmethodID constructor = jxbt_get_jmethod(env, cls, "", "()V"); + + if (!constructor) + return NULL; + + return (*env)->NewObject(env, cls, constructor); +} + +jobject jhost_ref(JNIEnv * env, jobject jhost) +{ + return (*env)->NewGlobalRef(env, jhost); +} + +void jhost_unref(JNIEnv * env, jobject jhost) +{ + (*env)->DeleteGlobalRef(env, jhost); +} + +void jhost_bind(jobject jhost, m_host_t host, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Host", "bind", "J"); + + if (!id) + return; + + (*env)->SetLongField(env, jhost, id, (jlong) (long) (host)); +} + +m_host_t jhost_get_native(JNIEnv * env, jobject jhost) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Host", "bind", "J"); + + if (!id) + return NULL; + + return (m_host_t) (long) (*env)->GetLongField(env, jhost, id); +} + +const char *jhost_get_name(jobject jhost, JNIEnv * env) +{ + m_host_t host = jhost_get_native(env, jhost); + return (const char *) host->name; +} + +void jhost_set_name(jobject jhost, jstring jname, JNIEnv * env) +{ + const char *name; + m_host_t host = jhost_get_native(env, jhost); + + name = (*env)->GetStringUTFChars(env, jname, 0); + + if (host->name) + free(host->name); + + host->name = xbt_strdup(name); + (*env)->ReleaseStringUTFChars(env, jname, name); +} + +jboolean jhost_is_valid(jobject jhost, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Host", "bind", "J"); + + if (!id) + return 0; + + if ((*env)->GetLongField(env, jhost, id)) { + return JNI_TRUE; + } else { + return JNI_FALSE; + } +} diff --git a/src/jmsg_host.h b/src/jmsg_host.h new file mode 100644 index 0000000000..1f40c13f38 --- /dev/null +++ b/src/jmsg_host.h @@ -0,0 +1,110 @@ +/* Functions related to the java host instances. */ + +/* Copyright (c) 2007, 2009, 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. */ + +#ifndef MSG_JHOST_H +#define MSG_JHOST_H + +#include +#include "msg/msg.h" + +/** + * This function returns a new java host instance. + * + * @param env The environment of the current thread + * + * @return A new java host object. + * + * @exception If the class Host is not found the function throws + * the ClassNotFoundException. If the constructor of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +jobject jhost_new_instance(JNIEnv * env); + +/** + * This function returns a global reference to the java host instance + * specified by the parameter jhost. + * + * @param jhost The original java host instance. + * @param env The environment of the current thread + * + * @return The global reference to the original java host + * instance. + */ +jobject jhost_ref(JNIEnv * env, jobject jhost); +/** + * This function delete a global reference to a java host instance. + * + * @param The global refernce to delete. + * @param env The environment of the current thread + */ +void jhost_unref(JNIEnv * env, jobject jhost); + +/** + * This function associated a native host to a java host instance. + * + * @param jhost The java host instance. + * @param host The native host to bind. + * @param env The environment of the current thread + * + * @exception If the class Host is not found the function throws + * the ClassNotFoundException. If the field bind of + * this class is not found the function throws the exception + * NotSuchFieldException. + */ +void jhost_bind(jobject jhost, m_host_t host, JNIEnv * env); + +/** + * This function returns a native host from a java host instance. + * + * @param jhost The java host object from which get the native host. + * @param env The environment of the current thread + * + * @return The function returns the native host associated to the + * java host object. + * + * @exception If the class Host is not found the function throws + * the ClassNotFoundException. If the field bind of + * this class is not found the function throws the exception + * NotSuchFieldException. + */ +m_host_t jhost_get_native(JNIEnv * env, jobject jhost); + +/** + * This function returns the name of a MSG host. + * + * @param jhost A java host object. + * @param env The environment of the current thread + * + * @return The name of the host. + */ +const char *jhost_get_name(jobject jhost, JNIEnv * env); + + +/** + * This function sets the name of a MSG host. + * + * @param host The host concerned by the operation. + * @param jname The new name of the host. + * @param env The environment of the current thread + */ +void jhost_set_name(jobject jhost, jstring jname, JNIEnv * env); + +/** + * This function tests if a java host instance is valid. + * A java host object is valid if it is bind to a native host. + * + * @param jhost The host to test the validity. + * @param env The environment of the current thread + * + * @return If the java host is valid the function returns true. + * Otherwise the function returns false. + */ +jboolean jhost_is_valid(jobject jhost, JNIEnv * env); + +#endif /*!MSG_JHOST_H */ diff --git a/src/jmsg_process.c b/src/jmsg_process.c new file mode 100644 index 0000000000..6ebb133fc8 --- /dev/null +++ b/src/jmsg_process.c @@ -0,0 +1,216 @@ +/* Functions related to the java process instances. */ + +/* Copyright (c) 2007, 2008, 2009, 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. */ + +#include "jmsg_process.h" +#include "jmsg.h" +#include "jxbt_utilities.h" + +#include "simix/smx_context_java.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); + +jobject jprocess_new_global_ref(jobject jprocess, JNIEnv * env) +{ + return (*env)->NewGlobalRef(env, jprocess); +} + +void jprocess_delete_global_ref(jobject jprocess, JNIEnv * env) +{ + (*env)->DeleteGlobalRef(env, jprocess); +} + +jboolean jprocess_is_alive(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "isAlive", "()Z"); + + if (!id) + return 0; + + return (*env)->CallBooleanMethod(env, jprocess, id); +} + +void jprocess_join(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "join", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, jprocess, id); +} + +void jprocess_exit(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "interrupt", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, jprocess, id); +} + +void jprocess_yield(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "switchProcess", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, jprocess, id); +} + +void jprocess_lock_mutex(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "lockMutex", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, jprocess, id); +} + +void jprocess_unlock_mutex(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "unlockMutex", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, jprocess, id); +} + + +void jprocess_signal_cond(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "signalCond", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, jprocess, id); +} + +void jprocess_wait_cond(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "waitCond", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, jprocess, id); +} + + +void jprocess_start(jobject jprocess, JNIEnv * env) +{ + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "start", "()V"); + + if (!id) + return; + + DEBUG2("jprocess_start(jproc=%p,env=%p)", jprocess, env); + (*env)->CallVoidMethod(env, jprocess, id); + DEBUG0("jprocess started"); +} + +m_process_t jprocess_to_native_process(jobject jprocess, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Process", "bind", "J"); + + if (!id) + return NULL; + + return (m_process_t) (long) (*env)->GetLongField(env, jprocess, id); +} + +void jprocess_bind(jobject jprocess, m_process_t process, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Process", "bind", "J"); + + if (!id) + return; + + (*env)->SetLongField(env, jprocess, id, (jlong) (long) (process)); +} + +jlong jprocess_get_id(jobject jprocess, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Process", "id", "J"); + + if (!id) + return 0; + + return (*env)->GetLongField(env, jprocess, id); +} + +jstring jprocess_get_name(jobject jprocess, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Process", "name", + "Ljava/lang/String;"); + jobject jname; + + if (!id) + return NULL; + + jname = (jstring) (*env)->GetObjectField(env, jprocess, id); + + return (*env)->NewGlobalRef(env, jname); + +} + +jboolean jprocess_is_valid(jobject jprocess, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Process", "bind", "J"); + + if (!id) + return JNI_FALSE; + + return (*env)->GetLongField(env, jprocess, id) ? JNI_TRUE : JNI_FALSE; +} + +void jprocess_schedule(smx_context_t context) +{ + JNIEnv *env; + jmethodID id; + + env = get_current_thread_env(); + + id = jxbt_get_smethod(env, "simgrid/msg/Process", "schedule", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, ((smx_ctx_java_t) context)->jprocess, id); +} + + + +void jprocess_unschedule(smx_context_t context) +{ + JNIEnv *env; + jmethodID id; + + env = get_current_thread_env(); + + + id = jxbt_get_smethod(env, "simgrid/msg/Process", "unschedule", "()V"); + + if (!id) + return; + + (*env)->CallVoidMethod(env, ((smx_ctx_java_t) context)->jprocess, id); +} diff --git a/src/jmsg_process.h b/src/jmsg_process.h new file mode 100644 index 0000000000..8d3862a90d --- /dev/null +++ b/src/jmsg_process.h @@ -0,0 +1,242 @@ +/* Functions related to the java process instances. */ + +/* Copyright (c) 2007, 2009, 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. */ + +#ifndef MSG_JPROCESS_H +#define MSG_JPROCESS_H + +#include +#include "msg/msg.h" +#include "simix/simix.h" + +/** + * This function returns a global reference to the java process instance + * specified by the parameter jprocess. + * + * @param jprocess The original java process instance. + * @param env The env of the current thread + * + * @return The global reference to the original java process + * instance. + */ +jobject jprocess_new_global_ref(jobject jprocess, JNIEnv * env); + +/** + * This function delete a global reference to a java process instance. + * If the java process is alive the function joins it and stops it before. + * + * @param The global refernce to delete. + * @param env The env of the current thread + * + * @see jprocess_join() + * @see jprocess_exit() + */ +void jprocess_delete_global_ref(jobject jprocess, JNIEnv * env); + +/** + * + * This function tests if the specified java process instance is alive. + * A java process object is alive if it has been started and has not yet + * terminated. + * + * @param jprocess The java process to test. + * @param env The env of the current thread + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the methos isAlive() of + * this class is not found the function throws the exception + * NotSuchMethodException. + * + * @return If the java process is alive the function returns + * true. Otherwise the function returns false. + */ +jboolean jprocess_is_alive(jobject jprocess, JNIEnv * env); + +/** + * This function waits for a java process to terminate. + * + * @param jprocess The java process ot wait for. + * @param env The env of the current thread + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the methos join() of + * this class is not found the function throws the exception + * NotSuchMethodException. + * + */ +void jprocess_join(jobject jprocess, JNIEnv * env); + +/** + * This function starts the specified java process. + * + * @param jprocess The java process to start. + * @param env The env of the current thread + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the methos start() of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +void jprocess_start(jobject jprocess, JNIEnv * env); + +/** + * This function forces the java process to stop. + * + * @param jprocess The java process to stop. + * @param env The env of the current thread + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the methos stop() of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +void jprocess_exit(jobject jprocess, JNIEnv * env); + +/** + * This function associated a native process to a java process instance. + * + * @param jprocess The java process instance. + * @param process The native process to bind. + * @param env The env of the current thread + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the field bind of + * this class is not found the function throws the exception + * NotSuchFieldException. + */ +void jprocess_bind(jobject jprocess, m_process_t process, JNIEnv * env); + +/** + * This function returns a native process from a java process instance. + * + * @param jprocess The java process object from which get the native process. + * @param env The env of the current thread + * + * @return The function returns the native process associated to the + * java process object. + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the field bind of + * this class is not found the function throws the exception + * NotSuchFieldException. + */ +m_process_t jprocess_to_native_process(jobject jprocess, JNIEnv * env); + +/** + * This function gets the id of the specified java process. + * + * @param jprocess The java process to get the id. + * @param env The env of the current thread + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the field id of + * this class is not found the function throws the exception + * NotSuchFieldException. + * + * @return The id of the specified java process. + */ +jlong jprocess_get_id(jobject jprocess, JNIEnv * env); + +/** + * This function tests if a java process instance is valid. + * A java process object is valid if it is bind to a native + * process. + * + * @param jprocess The java process to test the validity. + * @param env The env of the current thread + * + * @return If the java process is valid the function returns true. + * Otherwise the function returns false. + */ +jboolean jprocess_is_valid(jobject jprocess, JNIEnv * env); + +/** + * This function gets the name of the specified java process. + * + * @param jprocess The java process to get the name. + * @param env The env of the current thread + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the field name of + * this class is not found the function throws the exception + * NotSuchFieldException. + * + * @return The name of the specified java process. + */ +jstring jprocess_get_name(jobject jprocess, JNIEnv * env); + +/** + * This function yields the specified java process. + * + * @param jprocess The java process to yield. + * @param env The env of the current thread. + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the method switchProcess of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +void jprocess_yield(jobject jprocess, JNIEnv * env); + +/** + * This function locks the mutex of the specified java process. + * + * @param jprocess The java process of the mutex to lock. + * @param env The env of the current thread. + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the method lockMutex of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +void jprocess_lock_mutex(jobject jprocess, JNIEnv * env); + +/** + * This function unlocks the mutex of the specified java process. + * + * @param jprocess The java process of the mutex to unlock. + * @param env The env of the current thread. + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the method unlockMutex of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +void jprocess_unlock_mutex(jobject jprocess, JNIEnv * env); + +/** + * This function signals the condition of the mutex of the specified java process. + * + * @param jprocess The java process of the condtion to signal. + * @param env The env of the current thread. + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the method signalCond of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +void jprocess_signal_cond(jobject jprocess, JNIEnv * env); + +/** + * This function waits the condition of the mutex of the specified java process. + * + * @param jprocess The java process of the condtion to wait for. + * @param env The env of the current thread. + * + * @exception If the class Process is not found the function throws + * the ClassNotFoundException. If the method waitCond of + * this class is not found the function throws the exception + * NotSuchMethodException. + */ +void jprocess_wait_cond(jobject jprocess, JNIEnv * env); + +void jprocess_schedule(smx_context_t context); + +void jprocess_unschedule(smx_context_t context); + + +#endif /* !MSG_JPROCESS_H */ diff --git a/src/jmsg_task.c b/src/jmsg_task.c new file mode 100644 index 0000000000..7214d2111a --- /dev/null +++ b/src/jmsg_task.c @@ -0,0 +1,41 @@ +/* Functions related to the java task instances. */ + +/* Copyright (c) 2007, 2009, 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. */ + +#include "jmsg.h" +#include "jmsg_task.h" +#include "jxbt_utilities.h" + +void jtask_bind(jobject jtask, m_task_t task, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Task", "bind", "J"); + + if (!id) + return; + + (*env)->SetLongField(env, jtask, id, (jlong) (long) (task)); +} + +m_task_t jtask_to_native_task(jobject jtask, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Task", "bind", "J"); + + if (!id) + return NULL; + + return (m_task_t) (long) (*env)->GetLongField(env, jtask, id); +} + +jboolean jtask_is_valid(jobject jtask, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Task", "bind", "J"); + + if (!id) + return JNI_FALSE; + + return (*env)->GetLongField(env, jtask, id) ? JNI_TRUE : JNI_FALSE; +} diff --git a/src/jmsg_task.h b/src/jmsg_task.h new file mode 100644 index 0000000000..7b07a55c0d --- /dev/null +++ b/src/jmsg_task.h @@ -0,0 +1,78 @@ +/* Functions related to the java task instances. */ + +/* Copyright (c) 2007, 2009, 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. */ + +#ifndef MSG_JTASK_H +#define MSG_JTASK_H + +#include +#include "msg/msg.h" + +/** + * This function returns a global reference to the java task instance + * specified by the parameter jtask. + * + * @param jtask The original java task instance. + * @param env The environment of the current thread. + * + * @return The global reference to the original java task + * instance. + */ +jobject jtask_new_global_ref(jobject jtask, JNIEnv * env); + +/** + * This function delete a global reference to a java task instance. + * + * @param The global refernce to delete. + * @param env The environment of the current thread. + */ +void jtask_delete_global_ref(jobject jtask, JNIEnv * env); + +/** + * This function associated a native task to a java task instance. + * + * @param jtask The java task instance. + * @param task The native task to bind. + * @param env The environment of the current thread. + * + * @exception If the class Task is not found the function throws + * the ClassNotFoundException. If the field bind of + * this class is not found the function throws the exception + * NotSuchFieldException. + */ +void jtask_bind(jobject jtask, m_task_t task, JNIEnv * env); + +/** + * This function returns a native task from a java task instance. + * + * @param jtask The java task object from which get the native task. + * @param env The environment of the current thread. + * + * @return The function returns the native task associated to the + * java task object. + * + * @exception If the class Task is not found the function throws + * the ClassNotFoundException. If the field bind of + * this class is not found the function throws the exception + * NotSuchFieldException. + */ +m_task_t jtask_to_native_task(jobject jtask, JNIEnv * env); + +/** + * This function tests if a java task instance is valid. + * A java task object is valid if it is bind to a native + * task. + * + * @param jtask The java task to test the validity. + * @param env The environment of the current thread. + * + * @return If the java task is valid the function returns true. + * Otherwise the function returns false. + */ +jboolean jtask_is_valid(jobject jtask, JNIEnv * env); + +#endif /* !MSG_JTASK_H */ diff --git a/src/jxbt_utilities.c b/src/jxbt_utilities.c new file mode 100644 index 0000000000..6b11b8b0c2 --- /dev/null +++ b/src/jxbt_utilities.c @@ -0,0 +1,296 @@ +/* Various JNI helper functions */ + +/* Copyright (c) 2007, 2008, 2009, 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. */ + +#include /* abort */ +#include "xbt/misc.h" +#include "xbt/sysdep.h" +#include "xbt/str.h" +#include "jxbt_utilities.h" + +/* *********** */ +/* JNI GETTERS */ +/* *********** */ + +jclass jxbt_get_class(JNIEnv * env, const char *name) +{ + jclass cls = (*env)->FindClass(env, name); + + if (!cls) { + char *m = bprintf("Class %s not found", name); + jxbt_throw_jni(env, m); + free(m); + return NULL; + } + + return cls; +} + +jmethodID jxbt_get_jmethod(JNIEnv * env, jclass cls, + const char *name, const char *signature) +{ + jmethodID id; + + if (!cls) + return 0; + id = (*env)->GetMethodID(env, cls, name, signature); + + if (!id) { + + jmethodID tostr_id = + (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); + jstring jclassname = + (jstring) (*env)->CallObjectMethod(env, cls, tostr_id, NULL); + const char *classname = (*env)->GetStringUTFChars(env, jclassname, 0); + + char *m = bprintf("Cannot find method %s(%s) in %s", name, signature, + classname); + + (*env)->ReleaseStringUTFChars(env, jclassname, classname); + + jxbt_throw_jni(env, m); + + free(m); + return 0; + } + + return id; +} + +jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls, + const char *name, const char *signature) +{ + jmethodID id; + + if (!cls) + return 0; + id = (*env)->GetStaticMethodID(env, cls, name, signature); + + if (!id) { + + jmethodID tostr_id = + (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); + jstring jclassname = + (jstring) (*env)->CallObjectMethod(env, cls, tostr_id, NULL); + const char *classname = (*env)->GetStringUTFChars(env, jclassname, 0); + + char *m = + bprintf("Cannot find static method %s(%s) in %s", name, signature, + classname); + + (*env)->ReleaseStringUTFChars(env, jclassname, classname); + + jxbt_throw_jni(env, m); + + free(m); + return 0; + } + + return id; +} + +jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname, + const char *name, const char *signature) +{ + + jclass cls; + jmethodID id; + cls = jxbt_get_class(env, classname); + + if (!cls) + return 0; + + id = (*env)->GetStaticMethodID(env, cls, name, signature); + + if (!id) { + char *m = + bprintf("Cannot find static method %s(%s) in %s", name, signature, + classname); + + jxbt_throw_jni(env, m); + + free(m); + return 0; + } + return id; +} + +jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname, + const char *name, const char *signature) +{ + + jclass cls; + jmethodID id; + cls = jxbt_get_class(env, classname); + + if (!cls) + return 0; + + id = (*env)->GetMethodID(env, cls, name, signature); + + if (!id) { + char *m = bprintf("Cannot find method %s(%s) in %s", name, signature, + classname); + + jxbt_throw_jni(env, m); + + free(m); + return 0; + } + return id; +} + +jfieldID jxbt_get_jfield(JNIEnv * env, jclass cls, + const char *name, const char *signature) +{ + jfieldID id; + + if (!cls) + return 0; + + id = (*env)->GetFieldID(env, cls, name, signature); + + if (!id) { + jmethodID getname_id = + (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); + jstring jclassname = + (jstring) (*env)->CallObjectMethod(env, cls, getname_id, NULL); + const char *classname = (*env)->GetStringUTFChars(env, jclassname, 0); + char *m = bprintf("Cannot find field %s %s in %s", signature, name, + classname); + + (*env)->ReleaseStringUTFChars(env, jclassname, classname); + + jxbt_throw_jni(env, m); + + free(m); + return 0; + } + + return id; +} + +jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, + const char *name, const char *signature) +{ + jclass cls = jxbt_get_class(env, classname); + jfieldID id; + + if (!cls) + return 0; + + id = (*env)->GetFieldID(env, cls, name, signature); + + if (!id) { + char *m = bprintf("Cannot find field %s %s in %s", signature, name, + classname); + + jxbt_throw_jni(env, m); + + free(m); + return 0; + } + + return id; +} + +/* ***************** */ +/* EXCEPTION RAISING */ +/* ***************** */ +static void jxbt_throw_by_name(JNIEnv * env, const char *name, char *msg) +{ + jclass cls = (*env)->FindClass(env, name); + + xbt_assert2(cls, "%s (Plus severe error: class %s not found)\n", msg, + name); + + (*env)->ThrowNew(env, cls, msg); + + free(msg); +} + + +/* Errors in MSG */ +void jxbt_throw_jni(JNIEnv * env, const char *msg) +{ + jxbt_throw_by_name(env, + "simgrid/msg/JniException", + bprintf("Internal or JNI error: %s", msg)); +} + +void jxbt_throw_notbound(JNIEnv * env, const char *kind, void *pointer) +{ + jxbt_throw_by_name(env, + "simgrid/msg/JniException", + bprintf("Internal error: %s %p not bound", kind, + pointer)); +} + +void jxbt_throw_native(JNIEnv * env, char *msg) +{ + jxbt_throw_by_name(env, "simgrid/msg/NativeException", msg); +} + +/* *** */ +void jxbt_throw_null(JNIEnv * env, char *msg) +{ + jxbt_throw_by_name(env, "java/lang/NullPointerException", msg); +} + +/* Errors on user side */ +void jxbt_throw_illegal(JNIEnv * env, char *msg) +{ + jxbt_throw_by_name(env, "java/lang/IllegalArgumentException", msg); +} + +void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name) +{ + jxbt_throw_by_name(env, + "simgrid/msg/HostNotFoundException", + bprintf("No such host: %s", invalid_name)); +} + +void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name) +{ + jxbt_throw_by_name(env, + "simgrid/msg/ProcessNotFoundException", + bprintf("No such process: %s", invalid_name)); +} + +// tranfert failure +void jxbt_throw_transfer_failure(JNIEnv * env, char *details) +{ + + jxbt_throw_by_name(env, "simgrid/msg/TransferFailureException", details); + +} + +// host failure Exception +void jxbt_throw_host_failure(JNIEnv * env, char *details) +{ + + jxbt_throw_by_name(env, + "simgrid/msg/HostFailureException", + bprintf("Host Failure %s", details)); + +} + +// time out failure Exception +void jxbt_throw_time_out_failure(JNIEnv * env, char *details) +{ + + jxbt_throw_by_name(env, "simgrid/msg/TimeoutException", details); + +} + +// task Cancelled exception +void jxbt_throw_task_cancelled(JNIEnv * env, char *details) +{ + + jxbt_throw_by_name(env, "simgrid/msg/TaskCancelledException", details); + +} diff --git a/src/jxbt_utilities.h b/src/jxbt_utilities.h new file mode 100644 index 0000000000..08bd391873 --- /dev/null +++ b/src/jxbt_utilities.h @@ -0,0 +1,94 @@ +/* Various JNI helper functions */ + +/* Copyright (c) 2007, 2008, 2009, 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. */ + +#ifndef JXBT_UTILITY_H +#define JXBT_UTILITY_H + +#include + +/* *********** */ +/* JNI GETTERS */ +/* *********** */ + +/* Search a class and throw an exception if not found */ +jclass jxbt_get_class(JNIEnv * env, const char *name); + +/* Search a method in a class and throw an exception if not found + (it's ok to to pass a NULL class: it's a noop) */ +jmethodID jxbt_get_jmethod(JNIEnv * env, jclass class, + const char *name, const char *signature); + +/* Like the jxbt_get_class() but get a static method */ +jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls, + const char *name, const char *signature); + +/* Search a field in a class and throw an exception if not found + (it's ok to to pass a NULL class: it's a noop) */ +jfieldID jxbt_get_jfield(JNIEnv * env, jclass class, + const char *name, const char *signature); + + +/* Search a method in a class and throw an exception if not found + (it's ok to to pass a NULL class: it's a noop) */ +jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname, + const char *name, const char *signature); + +/* Like the jxbt_get_smethod() but get a static method */ +jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname, + const char *name, const char *signature); + +/* Search a field in a class and throw an exception if not found + (it's ok to to pass a NULL class: it's a noop) */ +jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, + const char *name, const char *signature); + + +/* ***************** */ +/* EXCEPTION RAISING */ +/* ***************** */ + +#define jxbt_check_res(fun, res, allowed_exceptions, detail) do {\ + if (res != MSG_OK && res | allowed_exceptions) { \ + xbt_die(bprintf("%s failed with error code %d, which is not an allowed exception. Please fix me.",fun,res)); \ + } else if (res == MSG_HOST_FAILURE) { \ + jxbt_throw_host_failure(env, detail); \ + } else if (res == MSG_TRANSFER_FAILURE) { \ + jxbt_throw_transfer_failure(env,detail); \ + } else if (res == MSG_TIMEOUT) { \ + jxbt_throw_time_out_failure(env,detail); \ + } else if (res == MSG_TASK_CANCELLED){ \ + jxbt_throw_task_cancelled(env,detail); \ + } } while (0) + +/** Thrown on internal error of this layer, or on problem with JNI */ +void jxbt_throw_jni(JNIEnv * env, const char *msg); +/** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */ +void jxbt_throw_notbound(JNIEnv * env, const char *kind, void *pointer); + +/** Thrown on error in native MSG code */ +void jxbt_throw_native(JNIEnv * env, char *msg); + +/** Thrown if NULL gets used */ +void jxbt_throw_null(JNIEnv * env, char *msg); + +/** Thrown on illegal arguments */ +void jxbt_throw_illegal(JNIEnv * env, char *msg); +/** Thrown when looking for an host from name does not lead to anything */ +void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name); +/** Thrown when looking for an host from name does not lead to anything */ +void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name); +/** Thrown when a transfer failure accure while Sending task */ +void jxbt_throw_transfer_failure(JNIEnv * env, char *detail); +/** Thrown when a host failure accures while Sending task*/ +void jxbt_throw_host_failure(JNIEnv * env, char *details); +/** Thrown when a time out accures While Sending task */ +void jxbt_throw_time_out_failure(JNIEnv * env, char *details); +/**Thrown when a task is canceled */ +void jxbt_throw_task_cancelled(JNIEnv * env, char *details); + +#endif /* ! JXBT_UTILITY_H */ -- 2.20.1