From: mquinson Date: Sat, 27 Feb 2010 23:05:51 +0000 (+0000) Subject: rewrite to use send/recv instead of put/get (+ add READMEs) X-Git-Tag: SVN~606 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/373eb2a4dce0450662a2d545ff4db464ff8d05a9 rewrite to use send/recv instead of put/get (+ add READMEs) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7132 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/examples/java/comm_time/CommTimeTest.java b/examples/java/comm_time/CommTimeTest.java index 326985deb9..4ff274af48 100644 --- a/examples/java/comm_time/CommTimeTest.java +++ b/examples/java/comm_time/CommTimeTest.java @@ -1,8 +1,7 @@ /* * $Id$ * - * Copyright 2006,2007 Martin Quinson, Malek Cherier - * All right reserved. + * Copyright 2006,2007,2010 The SimGrid Team. All right reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. @@ -23,16 +22,12 @@ public class CommTimeTest { /* initialize the MSG simulation. Must be done before anything else (even logging). */ Msg.init(args); - if(args.length < 2) { - + if(args.length < 2) { Msg.info("Usage : CommTime platform_file deployment_file"); Msg.info("example : CommTime comm_time_platform.xml comm_time_deployment.xml"); System.exit(1); } - /* specify a paje output file. */ - Msg.pajeOutput("comm_time.trace"); - /* construct the platform and deploy the application */ Msg.createEnvironment(args[0]); Msg.deployApplication(args[1]); diff --git a/examples/java/comm_time/Makefile.am b/examples/java/comm_time/Makefile.am index c469a012b4..10b4b5b217 100644 --- a/examples/java/comm_time/Makefile.am +++ b/examples/java/comm_time/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST=comm_time_deployment.xml comm_time_platform.xml # Declare sources: JAVA_SRC=Master.java Slave.java CommTimeTest.java \ - CommTimeTask.java FinalizeTask.java + MyTask.java FinalizeTask.java JAVA_TESTS=CommTimeTest.class TESTS=$(JAVA_TESTS) diff --git a/examples/java/comm_time/Master.java b/examples/java/comm_time/Master.java index 488dc3dece..8343873054 100644 --- a/examples/java/comm_time/Master.java +++ b/examples/java/comm_time/Master.java @@ -1,8 +1,7 @@ /* - * $Id$ + * Master of a basic master/slave example in Java * - * Copyright 2006,2007 Martin Quinson, Malek Cherier - * All rights reserved. + * Copyright 2006,2007,2010 The SimGrid Team. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. @@ -11,50 +10,34 @@ import simgrid.msg.*; public class Master extends simgrid.msg.Process { - public void main(String[] args) throws JniException, NativeException { + if (args.length < 4) { + Msg.info("Master needs 4 arguments"); + System.exit(1); + } - Msg.info("Hello i'm the master"); - - int numberoftasks = Integer.valueOf(args[0]).intValue(); + int tasksCount = Integer.valueOf(args[0]).intValue(); double taskComputeSize = Double.valueOf(args[1]).doubleValue(); double taskCommunicateSize = Double.valueOf(args[2]).doubleValue(); - - int slavecount = args.length - 3; - Host[] slaves = new Host[slavecount] ; - - for (int i = 3; i < args.length; i++) { - try { - slaves[i-3] = Host.getByName(args[i]); - } catch(HostNotFoundException e) { - Msg.info(e.toString()); - Msg.info("Unknown host " + args[i] +". Stopping Now! " ); - System.exit(1); - } - } - - Msg.info("Got " + slavecount + " slave(s):"); - for (int i = 0; i < slavecount; i++) - Msg.info("\t " + slaves[i].getName()); - Msg.info("Got "+numberoftasks+" task(s) to process."); + int slavesCount = Integer.valueOf(args[3]).intValue(); - for (int i = 0; i < numberoftasks; i++) { - CommTimeTask task = new CommTimeTask("Task_" + i ,taskComputeSize,taskCommunicateSize); - task.setTime(Msg.getClock()); - slaves[i % slavecount].put(0,task); - -// Msg.info("Send completed for the task " + task.getName() + " on the host " + slaves[i % slavecount].getName() + " [" + (i % slavecount) + "]"); + Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process"); + + for (int i = 0; i < tasksCount; i++) { + MyTask task = new MyTask("Task_" + i, taskComputeSize, taskCommunicateSize); + if (i%1000==0) + Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\""); + task.send("slave_"+(i%slavesCount)); } - + Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over."); - - for (int i = 0; i < slavecount; i++) { - - Msg.info("Finalize host " + slaves[i].getName() + " [" + i + "]"); - slaves[i].put(0, new FinalizeTask()); + + for (int i = 0; i < slavesCount; i++) { + FinalizeTask task = new FinalizeTask(); + task.send("slave_"+(i%slavesCount)); } - Msg.info("All finalize messages have been dispatched. Goodbye now!"); - } -} \ No newline at end of file + Msg.info("Goodbye now!"); + } +} diff --git a/examples/java/comm_time/MyTask.java b/examples/java/comm_time/MyTask.java new file mode 100644 index 0000000000..633ab004a5 --- /dev/null +++ b/examples/java/comm_time/MyTask.java @@ -0,0 +1,28 @@ +/* + * $Id$ + * + * Copyright 2006,2007,2010 The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +import simgrid.msg.*; + +public class MyTask extends Task { + + private double timeVal; + + public MyTask(String name, double computeDuration, double messageSize) throws JniException, NativeException{ + super(name,computeDuration,messageSize); + } + + public void setTime(double timeVal){ + this.timeVal = timeVal; + } + + public double getTime() { + return this.timeVal; + } +} + \ No newline at end of file diff --git a/examples/java/comm_time/README b/examples/java/comm_time/README new file mode 100644 index 0000000000..6512acd7fe --- /dev/null +++ b/examples/java/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/java/comm_time/Slave.java b/examples/java/comm_time/Slave.java index 6fc7828801..7a7ace7e21 100644 --- a/examples/java/comm_time/Slave.java +++ b/examples/java/comm_time/Slave.java @@ -11,30 +11,26 @@ import simgrid.msg.*; public class Slave extends simgrid.msg.Process { - public void main(String[] args) throws JniException, NativeException { + if (args.length < 1) { + Msg.info("Slave needs 1 argument (its number)"); + System.exit(1); + } + + int num = Integer.valueOf(args[0]).intValue(); + Msg.info("Receiving on 'slave_"+num+"'"); - Msg.info("Hello i'm a slave"); - - while(true) { - double time1 = Msg.getClock(); - Task t = Task.get(0); - + while(true) { + Task t = Task.receive("slave_"+num); + if (t instanceof FinalizeTask) { break; } - CommTimeTask task = (CommTimeTask)t; - - if(time1 < task.getTime()) - time1 = task.getTime(); - -/* double time2 = Msg.getClock(); - Msg.info("Processing \"" + task.getName() + "\" " + getHost().getName() + - " (Communication time : " + (time2 - time1) + ")"); -*/ + MyTask task = (MyTask)t; task.execute(); - } +// Msg.info("\"" + task.getName() + "\" done "); + } Msg.info("Received Finalize. I'm done. See you!"); - } + } } \ No newline at end of file diff --git a/examples/java/comm_time/comm_time_deployment.xml b/examples/java/comm_time/comm_time_deployment.xml index bd29ebd01e..917190d502 100644 --- a/examples/java/comm_time/comm_time_deployment.xml +++ b/examples/java/comm_time/comm_time_deployment.xml @@ -2,48 +2,54 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/java/ping_pong/README b/examples/java/ping_pong/README new file mode 100644 index 0000000000..aa16de9c89 --- /dev/null +++ b/examples/java/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