From: Martin Quinson Date: Mon, 22 Aug 2016 22:22:35 +0000 (+0200) Subject: new example, Java implementation of the Token Ring X-Git-Tag: v3_14~507 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7bdff3a31c5d1e6e044b9f23faccf489661a588f new example, Java implementation of the Token Ring --- diff --git a/.gitignore b/.gitignore index 98812d8a7a..95982bbf41 100644 --- a/.gitignore +++ b/.gitignore @@ -973,6 +973,7 @@ examples/java/app/bittorrent/java_app_bittorrent_compiled examples/java/app/centralizedmutex/java_app_centralizedmutex_compiled examples/java/app/masterworker/java_app_masterworker_compiled examples/java/app/pingpong/java_app_pingpong_compiled +examples/java/app/tokenring/java_app_tokenring_compiled examples/java/async/dsend/java_async_dsend_compiled examples/java/dht/chord/java_dht_chord_compiled examples/java/dht/kademlia/java_dht_kademlia_compiled diff --git a/ChangeLog b/ChangeLog index a99902a0d5..6f5ac48dab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,9 @@ SimGrid (3.14) UNRELEASED; urgency=low * Add Exa- and Peta- units such as EiB, EB, Eib, Eb for size, and EiBps, EBps, Eibps, Ebps for bandwidth. They may become useful to some lucky ones. + + Java: + * app_tokenring: new example, very similar to the MSG Token Ring -- $date Da SimGrid team diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index bcc30d75ef..112a950e51 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -14,6 +14,9 @@ set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/app/pingpong) set(app_pingpong_sources ${srcdir}/Main.java ${srcdir}/PingPongTask.java ${srcdir}/Receiver.java ${srcdir}/Sender.java) +set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/app/tokenring) +set(app_tokenring_sources ${srcdir}/Main.java ${srcdir}/RelayRunner.java) + set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/dsend) set(async_dsend_sources ${srcdir}/Main.java ${srcdir}/Receiver.java ${srcdir}/Sender.java) @@ -67,7 +70,7 @@ set(process_suspend_sources ${srcdir}/Main.java ${srcdir}/DreamMaster.java set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/task/priority) set(task_priority_sources ${srcdir}/Main.java ${srcdir}/Test.java) -foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong async_dsend +foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_dsend cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_vm io_file io_storage process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong) string (REPLACE "_" "/" example_dir ${example}) @@ -101,7 +104,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/app/bittorrent/bi ${CMAKE_CURRENT_SOURCE_DIR}/task/priority/priority.xml PARENT_SCOPE) if(enable_java) - foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong async_dsend + foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_dsend cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_vm io_file io_storage process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong) string (REPLACE "_" "/" example_dir ${example}) diff --git a/examples/java/app/tokenring/Main.java b/examples/java/app/tokenring/Main.java new file mode 100644 index 0000000000..d1423aadc5 --- /dev/null +++ b/examples/java/app/tokenring/Main.java @@ -0,0 +1,37 @@ +/* Copyright (c) 2016. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +package app.tokenring; +import org.simgrid.msg.Host; +import org.simgrid.msg.HostNotFoundException; +import org.simgrid.msg.Msg; +import org.simgrid.msg.NativeException; +import org.simgrid.msg.Process; + +class Main { + private Main() { + /* This is just to prevent anyone from creating an instance of this singleton */ + throw new IllegalAccessError("Utility class"); + } + + public static void main(String[] args) throws HostNotFoundException, NativeException { + Msg.init(args); + + String platform = "../platforms/small_platform.xml"; + if(args.length >= 1) + platform = args[0]; + Msg.createEnvironment(platform); + + Host[] hosts = Host.all(); + for (int rank = 0; rank < hosts.length; rank++) { + Process proc = new RelayRunner(hosts[rank], ""+rank, null); + proc.start(); + } + Msg.info("Number of hosts '"+hosts.length+"'"); + Msg.run(); + + Msg.info("Simulation time "+Msg.getClock()); + } +} diff --git a/examples/java/app/tokenring/RelayRunner.java b/examples/java/app/tokenring/RelayRunner.java new file mode 100644 index 0000000000..0f1bf9c1a8 --- /dev/null +++ b/examples/java/app/tokenring/RelayRunner.java @@ -0,0 +1,58 @@ +/* Copyright (c) 2016. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +package app.tokenring; +import org.simgrid.msg.Msg; +import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.NativeException; +import org.simgrid.msg.Host; +import org.simgrid.msg.HostNotFoundException; + +public class RelayRunner extends Process { + + private static final int TASK_COMM_SIZE = 1000000; /* The token is 1MB long*/ + + public RelayRunner(Host host, String name, String[]args) throws HostNotFoundException, NativeException{ + super(host,name,args); + } + + /* This is the function executed by this kind of processes */ + public void main(String[] args) throws MsgException { + // In this example, the processes are given numerical names: "0", "1", "2", and so on + int rank = Integer.parseInt(this.getName()); + + if (rank == 0) { + /* The root (rank 0) first sends the token then waits to receive it back */ + + String mailbox = "1"; + Task token = new Task("Token", 0/* no computation associated*/ , TASK_COMM_SIZE ); + + Msg.info("Host '"+rank+"' send '"+token.getName()+"' to Host '"+mailbox+"'"); + token.send(mailbox); + + token = Task.receive(this.getName()); // Get a message from the mailbox having the same name as the current processor + + Msg.info("Host '"+rank+"' received '"+token.getName()+"'"); + + } else { + /* The others processes receive on their name (coming from their left neighbor -- rank-1) + * and send to their right neighbor (rank+1) */ + Task token = Task.receive(this.getName()); + + Msg.info("Host '"+rank+"' received '"+token.getName()+"'"); + + String mailbox = ""+(rank+1); // Java idiomatic to get the String version of rank+1 + if (rank+1 == Host.getCount()) { + /* The last process has no right neighbor, so it sends the token back to rank 0 */ + mailbox = "0"; + } + + Msg.info("Host '"+rank+"' send '"+token.getName()+"' to Host '"+mailbox+"'"); + token.send(mailbox); + } + } +} \ No newline at end of file diff --git a/examples/java/app/tokenring/app_tokenring.tesh b/examples/java/app/tokenring/app_tokenring.tesh new file mode 100644 index 0000000000..7912ab2bcf --- /dev/null +++ b/examples/java/app/tokenring/app_tokenring.tesh @@ -0,0 +1,156 @@ +#! ./tesh + +$ java -classpath ${classpath:=.} app/tokenring/Main ${srcdir:=.}/../platforms/routing_cluster.xml '--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n' +> [ 0.000000] (0:maestro@) Using regular java threads. +> [ 0.000000] (0:maestro@) Number of hosts '6' +> [ 0.000000] (1:0@host1) Host '0' send 'Token' to Host '1' +> [ 0.017354] (2:1@host2) Host '1' received 'Token' +> [ 0.017354] (2:1@host2) Host '1' send 'Token' to Host '2' +> [ 0.035121] (3:2@host3) Host '2' received 'Token' +> [ 0.035121] (3:2@host3) Host '2' send 'Token' to Host '3' +> [ 0.065898] (4:3@host4) Host '3' received 'Token' +> [ 0.065898] (4:3@host4) Host '3' send 'Token' to Host '4' +> [ 0.083252] (5:4@host5) Host '4' received 'Token' +> [ 0.083252] (5:4@host5) Host '4' send 'Token' to Host '5' +> [ 0.101019] (6:5@host6) Host '5' received 'Token' +> [ 0.101019] (6:5@host6) Host '5' send 'Token' to Host '0' +> [ 0.131796] (1:0@host1) Host '0' received 'Token' +> [ 0.131796] (0:maestro@) MSG_main finished; Cleaning up the simulation... +> [ 0.131796] (0:maestro@) Simulation time 0.13179602061855672 + +$ java -classpath ${classpath:=.} app/tokenring/Main ${srcdir:=.}/../platforms/two_peers.xml --cfg=network/coordinates:yes '--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n' +> [ 0.000000] (0:maestro@) Configuration change: Set 'network/coordinates' to 'yes' +> [ 0.000000] (0:maestro@) Using regular java threads. +> [ 0.000000] (0:maestro@) Number of hosts '2' +> [ 0.000000] (1:0@peer_100030591) Host '0' send 'Token' to Host '1' +> [ 0.637910] (2:1@peer_100036570) Host '1' received 'Token' +> [ 0.637910] (2:1@peer_100036570) Host '1' send 'Token' to Host '0' +> [ 1.275820] (1:0@peer_100030591) Host '0' received 'Token' +> [ 1.275820] (0:maestro@) MSG_main finished; Cleaning up the simulation... +> [ 1.275820] (0:maestro@) Simulation time 1.2758201322136908 + +$ java -classpath ${classpath:=.} app/tokenring/Main ${srcdir:=.}/../platforms/meta_cluster.xml '--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n' +> [ 0.000000] (0:maestro@) Using regular java threads. +> [ 0.000000] (0:maestro@) Number of hosts '60' +> [ 0.000000] (1:0@host-2.cluster1) Host '0' send 'Token' to Host '1' +> [ 0.030364] (2:1@host-2.cluster2) Host '1' received 'Token' +> [ 0.030364] (2:1@host-2.cluster2) Host '1' send 'Token' to Host '2' +> [ 0.060729] (3:2@host-6.cluster1) Host '2' received 'Token' +> [ 0.060729] (3:2@host-6.cluster1) Host '2' send 'Token' to Host '3' +> [ 0.091093] (4:3@host-6.cluster2) Host '3' received 'Token' +> [ 0.091093] (4:3@host-6.cluster2) Host '3' send 'Token' to Host '4' +> [ 0.121458] (5:4@host-21.cluster1) Host '4' received 'Token' +> [ 0.121458] (5:4@host-21.cluster1) Host '4' send 'Token' to Host '5' +> [ 0.138812] (6:5@host-13.cluster1) Host '5' received 'Token' +> [ 0.138812] (6:5@host-13.cluster1) Host '5' send 'Token' to Host '6' +> [ 0.169177] (7:6@host-21.cluster2) Host '6' received 'Token' +> [ 0.169177] (7:6@host-21.cluster2) Host '6' send 'Token' to Host '7' +> [ 0.186531] (8:7@host-13.cluster2) Host '7' received 'Token' +> [ 0.186531] (8:7@host-13.cluster2) Host '7' send 'Token' to Host '8' +> [ 0.216895] (9:8@host-25.cluster1) Host '8' received 'Token' +> [ 0.216895] (9:8@host-25.cluster1) Host '8' send 'Token' to Host '9' +> [ 0.234250] (10:9@host-17.cluster1) Host '9' received 'Token' +> [ 0.234250] (10:9@host-17.cluster1) Host '9' send 'Token' to Host '10' +> [ 0.264614] (11:10@host-25.cluster2) Host '10' received 'Token' +> [ 0.264614] (11:10@host-25.cluster2) Host '10' send 'Token' to Host '11' +> [ 0.281969] (12:11@host-17.cluster2) Host '11' received 'Token' +> [ 0.281969] (12:11@host-17.cluster2) Host '11' send 'Token' to Host '12' +> [ 0.312333] (13:12@host-29.cluster1) Host '12' received 'Token' +> [ 0.312333] (13:12@host-29.cluster1) Host '12' send 'Token' to Host '13' +> [ 0.342697] (14:13@host-29.cluster2) Host '13' received 'Token' +> [ 0.342697] (14:13@host-29.cluster2) Host '13' send 'Token' to Host '14' +> [ 0.373062] (15:14@host-3.cluster1) Host '14' received 'Token' +> [ 0.373062] (15:14@host-3.cluster1) Host '14' send 'Token' to Host '15' +> [ 0.403426] (16:15@host-3.cluster2) Host '15' received 'Token' +> [ 0.403426] (16:15@host-3.cluster2) Host '15' send 'Token' to Host '16' +> [ 0.433791] (17:16@host-7.cluster1) Host '16' received 'Token' +> [ 0.433791] (17:16@host-7.cluster1) Host '16' send 'Token' to Host '17' +> [ 0.464155] (18:17@host-7.cluster2) Host '17' received 'Token' +> [ 0.464155] (18:17@host-7.cluster2) Host '17' send 'Token' to Host '18' +> [ 0.494520] (19:18@host-10.cluster1) Host '18' received 'Token' +> [ 0.494520] (19:18@host-10.cluster1) Host '18' send 'Token' to Host '19' +> [ 0.524884] (20:19@host-10.cluster2) Host '19' received 'Token' +> [ 0.524884] (20:19@host-10.cluster2) Host '19' send 'Token' to Host '20' +> [ 0.555248] (21:20@host-30.cluster1) Host '20' received 'Token' +> [ 0.555248] (21:20@host-30.cluster1) Host '20' send 'Token' to Host '21' +> [ 0.572603] (22:21@host-22.cluster1) Host '21' received 'Token' +> [ 0.572603] (22:21@host-22.cluster1) Host '21' send 'Token' to Host '22' +> [ 0.602967] (23:22@host-30.cluster2) Host '22' received 'Token' +> [ 0.602967] (23:22@host-30.cluster2) Host '22' send 'Token' to Host '23' +> [ 0.633332] (24:23@host-14.cluster1) Host '23' received 'Token' +> [ 0.633332] (24:23@host-14.cluster1) Host '23' send 'Token' to Host '24' +> [ 0.663696] (25:24@host-22.cluster2) Host '24' received 'Token' +> [ 0.663696] (25:24@host-22.cluster2) Host '24' send 'Token' to Host '25' +> [ 0.681051] (26:25@host-14.cluster2) Host '25' received 'Token' +> [ 0.681051] (26:25@host-14.cluster2) Host '25' send 'Token' to Host '26' +> [ 0.711415] (27:26@host-26.cluster1) Host '26' received 'Token' +> [ 0.711415] (27:26@host-26.cluster1) Host '26' send 'Token' to Host '27' +> [ 0.728769] (28:27@host-18.cluster1) Host '27' received 'Token' +> [ 0.728769] (28:27@host-18.cluster1) Host '27' send 'Token' to Host '28' +> [ 0.759134] (29:28@host-26.cluster2) Host '28' received 'Token' +> [ 0.759134] (29:28@host-26.cluster2) Host '28' send 'Token' to Host '29' +> [ 0.776488] (30:29@host-18.cluster2) Host '29' received 'Token' +> [ 0.776488] (30:29@host-18.cluster2) Host '29' send 'Token' to Host '30' +> [ 0.806853] (31:30@host-4.cluster1) Host '30' received 'Token' +> [ 0.806853] (31:30@host-4.cluster1) Host '30' send 'Token' to Host '31' +> [ 0.837217] (32:31@host-4.cluster2) Host '31' received 'Token' +> [ 0.837217] (32:31@host-4.cluster2) Host '31' send 'Token' to Host '32' +> [ 0.867582] (33:32@host-8.cluster1) Host '32' received 'Token' +> [ 0.867582] (33:32@host-8.cluster1) Host '32' send 'Token' to Host '33' +> [ 0.897946] (34:33@host-8.cluster2) Host '33' received 'Token' +> [ 0.897946] (34:33@host-8.cluster2) Host '33' send 'Token' to Host '34' +> [ 0.928310] (35:34@host-11.cluster1) Host '34' received 'Token' +> [ 0.928310] (35:34@host-11.cluster1) Host '34' send 'Token' to Host '35' +> [ 0.958675] (36:35@host-11.cluster2) Host '35' received 'Token' +> [ 0.958675] (36:35@host-11.cluster2) Host '35' send 'Token' to Host '36' +> [ 0.989039] (37:36@host-23.cluster1) Host '36' received 'Token' +> [ 0.989039] (37:36@host-23.cluster1) Host '36' send 'Token' to Host '37' +> [ 1.006394] (38:37@host-15.cluster1) Host '37' received 'Token' +> [ 1.006394] (38:37@host-15.cluster1) Host '37' send 'Token' to Host '38' +> [ 1.036758] (39:38@host-23.cluster2) Host '38' received 'Token' +> [ 1.036758] (39:38@host-23.cluster2) Host '38' send 'Token' to Host '39' +> [ 1.054112] (40:39@host-15.cluster2) Host '39' received 'Token' +> [ 1.054112] (40:39@host-15.cluster2) Host '39' send 'Token' to Host '40' +> [ 1.084477] (41:40@host-27.cluster1) Host '40' received 'Token' +> [ 1.084477] (41:40@host-27.cluster1) Host '40' send 'Token' to Host '41' +> [ 1.101831] (42:41@host-19.cluster1) Host '41' received 'Token' +> [ 1.101831] (42:41@host-19.cluster1) Host '41' send 'Token' to Host '42' +> [ 1.132196] (43:42@host-27.cluster2) Host '42' received 'Token' +> [ 1.132196] (43:42@host-27.cluster2) Host '42' send 'Token' to Host '43' +> [ 1.149550] (44:43@host-19.cluster2) Host '43' received 'Token' +> [ 1.149550] (44:43@host-19.cluster2) Host '43' send 'Token' to Host '44' +> [ 1.179915] (45:44@host-1.cluster1) Host '44' received 'Token' +> [ 1.179915] (45:44@host-1.cluster1) Host '44' send 'Token' to Host '45' +> [ 1.210279] (46:45@host-1.cluster2) Host '45' received 'Token' +> [ 1.210279] (46:45@host-1.cluster2) Host '45' send 'Token' to Host '46' +> [ 1.240643] (47:46@host-5.cluster1) Host '46' received 'Token' +> [ 1.240643] (47:46@host-5.cluster1) Host '46' send 'Token' to Host '47' +> [ 1.271008] (48:47@host-5.cluster2) Host '47' received 'Token' +> [ 1.271008] (48:47@host-5.cluster2) Host '47' send 'Token' to Host '48' +> [ 1.301372] (49:48@host-9.cluster1) Host '48' received 'Token' +> [ 1.301372] (49:48@host-9.cluster1) Host '48' send 'Token' to Host '49' +> [ 1.331737] (50:49@host-9.cluster2) Host '49' received 'Token' +> [ 1.331737] (50:49@host-9.cluster2) Host '49' send 'Token' to Host '50' +> [ 1.362101] (51:50@host-20.cluster1) Host '50' received 'Token' +> [ 1.362101] (51:50@host-20.cluster1) Host '50' send 'Token' to Host '51' +> [ 1.379456] (52:51@host-12.cluster1) Host '51' received 'Token' +> [ 1.379456] (52:51@host-12.cluster1) Host '51' send 'Token' to Host '52' +> [ 1.409820] (53:52@host-20.cluster2) Host '52' received 'Token' +> [ 1.409820] (53:52@host-20.cluster2) Host '52' send 'Token' to Host '53' +> [ 1.427174] (54:53@host-12.cluster2) Host '53' received 'Token' +> [ 1.427174] (54:53@host-12.cluster2) Host '53' send 'Token' to Host '54' +> [ 1.457539] (55:54@host-24.cluster1) Host '54' received 'Token' +> [ 1.457539] (55:54@host-24.cluster1) Host '54' send 'Token' to Host '55' +> [ 1.474893] (56:55@host-16.cluster1) Host '55' received 'Token' +> [ 1.474893] (56:55@host-16.cluster1) Host '55' send 'Token' to Host '56' +> [ 1.505258] (57:56@host-24.cluster2) Host '56' received 'Token' +> [ 1.505258] (57:56@host-24.cluster2) Host '56' send 'Token' to Host '57' +> [ 1.522612] (58:57@host-16.cluster2) Host '57' received 'Token' +> [ 1.522612] (58:57@host-16.cluster2) Host '57' send 'Token' to Host '58' +> [ 1.552977] (59:58@host-28.cluster1) Host '58' received 'Token' +> [ 1.552977] (59:58@host-28.cluster1) Host '58' send 'Token' to Host '59' +> [ 1.583341] (60:59@host-28.cluster2) Host '59' received 'Token' +> [ 1.583341] (60:59@host-28.cluster2) Host '59' send 'Token' to Host '0' +> [ 1.613705] (1:0@host-2.cluster1) Host '0' received 'Token' +> [ 1.613705] (0:maestro@) MSG_main finished; Cleaning up the simulation... +> [ 1.613705] (0:maestro@) Simulation time 1.6137053608247407