From f229c326ce7a55889bb47801615cf6468c8c6a73 Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 3 May 2010 10:04:30 +0000 Subject: [PATCH] Reindent, and use default platf and deploy if none is passed git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7661 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- examples/java/basic/BasicTest.java | 12 +++++-- examples/java/basic/Master.java | 58 +++++++++++++++--------------- examples/java/basic/Slave.java | 57 +++++++++++++++-------------- 3 files changed, 69 insertions(+), 58 deletions(-) diff --git a/examples/java/basic/BasicTest.java b/examples/java/basic/BasicTest.java index 89921ae918..e6c6a8f672 100644 --- a/examples/java/basic/BasicTest.java +++ b/examples/java/basic/BasicTest.java @@ -19,17 +19,23 @@ public class BasicTest { /* initialize the MSG simulation. Must be done before anything else (even logging). */ Msg.init(args); - if(args.length < 2) { + 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/java/basic/Master.java b/examples/java/basic/Master.java index eab3bf5f95..021220c85f 100644 --- a/examples/java/basic/Master.java +++ b/examples/java/basic/Master.java @@ -10,33 +10,33 @@ 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!"); - } + 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/java/basic/Slave.java b/examples/java/basic/Slave.java index 6d8eb6cc30..d55ae0a224 100644 --- a/examples/java/basic/Slave.java +++ b/examples/java/basic/Slave.java @@ -5,33 +5,38 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ -import simgrid.msg.*; +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); - } + 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!"); - } + 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 -- 2.20.1