From: Samuel Lepetit Date: Tue, 12 Jun 2012 12:05:00 +0000 (+0200) Subject: Add migration example X-Git-Tag: v3_9_90~569^2~19^2~54^2~10 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/371b6b8c9e97b5c836520a36bc450cf513570830?hp=d147d81692db8ae78418b4df9b781e1a8851def1 Add migration example --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c5a9a3027..e58b928ebc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,13 +304,14 @@ ADD_TEST(commTime ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE ADD_TEST(chord ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/chord/chord.tesh) ADD_TEST(kill ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/kill.tesh) ADD_TEST(masterslave ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/masterslave/masterslave.tesh) +ADD_TEST(migration ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/migration/migration.tesh) ADD_TEST(mutualExclusion ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/mutualexclusion.tesh) ADD_TEST(pingPong ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/pingPong/pingpong.tesh) ADD_TEST(priority ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/priority/priority.tesh) ADD_TEST(startKillTime ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/startKillTime/startKillTime.tesh) ADD_TEST(suspend ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/suspend/suspend.tesh) #Don't forget to put new test in this list!!! -set(test_list async bittorrent bypass chord commTime kill masterslave mutualExclusion pingPong priority startKillTime) +set(test_list async bittorrent bypass chord commTime kill masterslave migration mutualExclusion pingPong priority startKillTime) ########################################## # Set the DYLD_LIBRARY_PATH for mac # diff --git a/examples/migration/Emigrant.java b/examples/migration/Emigrant.java new file mode 100644 index 0000000000..c87508125d --- /dev/null +++ b/examples/migration/Emigrant.java @@ -0,0 +1,42 @@ +/* + * 2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ +package migration; + +import org.simgrid.msg.Host; +import org.simgrid.msg.Msg; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.Task; +import org.simgrid.msg.Process; + +public class Emigrant extends Process { + public Emigrant(Host host, String name, String[]args) { + super(host,name,args); + } + public void main(String[] args) throws MsgException { + Migration.mutex.acquire(); + + Msg.info("I'll look for a new job on another machine where the grass is greener."); + migrate(Host.getByName("Boivin")); + + Msg.info("Yeah, found something to do"); + Task task = new Task("job", 98095000, 0); + task.execute(); + waitFor(2); + + Msg.info("Moving back to home after work"); + migrate(Host.getByName("Jacquelin")); + migrate(Host.getByName("Boivin")); + waitFor(4); + + Migration.processToMigrate = this; + Migration.mutex.release(); + suspend(); + + Msg.info("I've been moved on this new host:" + getHost().getName()); + Msg.info("Uh, nothing to do here. Stopping now"); + } +} \ No newline at end of file diff --git a/examples/migration/Migration.java b/examples/migration/Migration.java new file mode 100644 index 0000000000..bcf17ab095 --- /dev/null +++ b/examples/migration/Migration.java @@ -0,0 +1,46 @@ +/* + * $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. + */ +package migration; +import org.simgrid.msg.Msg; +import org.simgrid.msg.Mutex; +import org.simgrid.msg.NativeException; +import org.simgrid.msg.Process; +/** + * Demonstrates the use of Task.setPriority to change + * the computation priority of a task + */ +public class Migration { + public static Mutex mutex; + public static Process processToMigrate = null; + + /* 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 : Priority platform_file deployment_file"); + Msg.info("example : Priority ping_pong_platform.xml ping_pong_deployment.xml"); + System.exit(1); + } + /* Create the mutex */ + mutex = new Mutex(); + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/migration/Policeman.java b/examples/migration/Policeman.java new file mode 100644 index 0000000000..3e01db31c7 --- /dev/null +++ b/examples/migration/Policeman.java @@ -0,0 +1,32 @@ +/* + * 2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ +package migration; + +import org.simgrid.msg.Host; +import org.simgrid.msg.Msg; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.Task; +import org.simgrid.msg.Process; + +public class Policeman extends Process { + public Policeman(Host host, String name, String[]args) { + super(host,name,args); + } + + @Override + public void main(String[] args) throws MsgException { + waitFor(1); + + Msg.info("Wait a bit before migrating the emigrant."); + + Migration.mutex.acquire(); + + Migration.processToMigrate.migrate(Host.getByName("Jacquelin")); + Msg.info("I moved the emigrant"); + Migration.processToMigrate.resume(); + } +} \ No newline at end of file diff --git a/examples/migration/migration.tesh b/examples/migration/migration.tesh new file mode 100644 index 0000000000..869acc592a --- /dev/null +++ b/examples/migration/migration.tesh @@ -0,0 +1,18 @@ +#! ./tesh + +! output sort + +$ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar migration/Migration ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/migration/migrationDeployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (0:@) Ready to run MSG_MAIN +> [ 0.000000] (1:migration.Emigrant@Jacquelin) I'll look for a new job on another machine where the grass is greener. +> [ 0.000000] (1:migration.Emigrant@Boivin) Yeah, found something to do +> [ 1.000000] (2:migration.Policeman@Boivin) Wait a bit before migrating the emigrant. +> [ 3.000000] (1:migration.Emigrant@Boivin) Moving back to home after work +> [ 7.000000] (0:@) Done running MSG_MAIN +> [ 7.000000] (0:@) MSG_main finished +> [ 7.000000] (0:@) Clean java world +> [ 7.000000] (0:@) Clean native world +> [ 7.000000] (1:migration.Emigrant@Jacquelin) I've been moved on this new host:Jacquelin +> [ 7.000000] (1:migration.Emigrant@Jacquelin) Uh, nothing to do here. Stopping now +> [ 7.000000] (2:migration.Policeman@Boivin) I moved the emigrant + diff --git a/examples/migration/migrationDeployment.xml b/examples/migration/migrationDeployment.xml new file mode 100644 index 0000000000..db7c6c0905 --- /dev/null +++ b/examples/migration/migrationDeployment.xml @@ -0,0 +1,6 @@ + + + + + +