Changeset 6354 for branches/MPI/HeuristicLab.ExtLibs
- Timestamp:
- 06/01/11 17:37:05 (14 years ago)
- Location:
- branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/HeuristicLab.MPIAlgorithmRunner-3.3.csproj
r6348 r6354 120 120 </ItemGroup> 121 121 <ItemGroup> 122 <ProjectReference Include="..\..\..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 123 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> 124 <Name>HeuristicLab.Collections-3.3</Name> 125 </ProjectReference> 122 126 <ProjectReference Include="..\..\..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj"> 123 127 <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project> … … 127 131 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> 128 132 <Name>HeuristicLab.Core-3.3</Name> 133 </ProjectReference> 134 <ProjectReference Include="..\..\..\..\HeuristicLab.Operators.MPISupport\3.3\HeuristicLab.Operators.MPISupport-3.3.csproj"> 135 <Project>{6BD69CDA-4875-4045-8B35-6FD4602854F5}</Project> 136 <Name>HeuristicLab.Operators.MPISupport-3.3</Name> 129 137 </ProjectReference> 130 138 <ProjectReference Include="..\..\..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> -
branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/HeuristicLabMPIAlgorithmRunnerPlugin.cs.frame
r6348 r6354 30 30 [PluginDependency("HeuristicLab.Common", "3.3")] 31 31 [PluginDependency("HeuristicLab.Core", "3.3")] 32 [PluginDependency("HeuristicLab.Collections", "3.3")] 32 33 [PluginDependency("HeuristicLab.MPInet", "1.0.0")] 33 34 [PluginDependency("HeuristicLab.Optimization", "3.3")] 34 35 [PluginDependency("HeuristicLab.Persistence", "3.3")] 36 [PluginDependency("HeuristicLab.Operators.MPISupport", "3.3")] 35 37 public class HeuristicLabProblemsVehicleRoutingPlugin : PluginBase { 36 38 } -
branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/Program.cs
r6348 r6354 27 27 using HeuristicLab.Persistence.Default.Xml; 28 28 using System.Threading; 29 using HeuristicLab.Operators.MPISupport; 30 using HeuristicLab.Core; 29 31 30 32 namespace HeuristicLab.MPIAlgorithmRunner { … … 33 35 34 36 static void Main(string[] args) { 35 if (args.Length != 2) {37 if (args.Length != 3) { 36 38 Console.WriteLine("Args:" + args.Length); 37 39 38 throw new ArgumentException("You must provide two arguments - the algorithm file and the result file");40 throw new ArgumentException("You must provide 3 arguments - the algorithm file, the result file and the update interval (in ms)"); 39 41 } 40 42 41 43 string fileName = args[0]; 42 44 string resultName = args[1]; 45 int updateInterval = int.Parse(args[2]); 43 46 44 47 using (new MPI.Environment(ref args)) { 45 Program p = new Program(); 46 p.StartAlgorithm(fileName, resultName + MPI.Communicator.world.Rank + ".hl"); 48 MPI.Communicator communicator = MPI.Communicator.world.Clone() as MPI.Communicator; 49 50 if (communicator.Rank == 0) { 51 IAlgorithm alg = XmlParser.Deserialize<IAlgorithm>(fileName); 52 MPITransportWrapper<IAlgorithm> transport = new MPITransportWrapper<IAlgorithm>(alg); 53 54 int clients = communicator.Size - 1; 55 Console.WriteLine("Sending alg to " + clients + " clients"); 56 for (int i = 0; i < clients; i++) { 57 int client = i + 1; 58 communicator.Send(transport, client, 0); 59 } 60 61 ItemList<ResultCollection> results = new ItemList<ResultCollection>(); 62 63 bool[] finished = new bool[clients]; 64 int finishedCount = 0; 65 66 while (finishedCount != clients) { 67 for (int i = 0; i < clients; i++) { 68 if (!finished[i]) { 69 int client = i + 1; 70 ResultCollection result = communicator.Receive<MPITransportWrapper<ResultCollection>>(client, 1).InnerItem; 71 72 Console.WriteLine("Received result " + result); 73 74 if (results.Count != clients) { 75 results.Add(result); 76 } else { 77 results[i] = result; 78 } 79 80 Console.WriteLine("Probing..."); 81 if (communicator.ImmediateProbe(client, 2) != null) { 82 finished[i] = true; 83 finishedCount++; 84 } 85 } 86 } 87 88 Console.WriteLine("Update results"); 89 lock (resultName) { 90 XmlGenerator.Serialize(results, resultName); 91 } 92 } 93 94 Console.WriteLine("Finished."); 95 } else { 96 Program p = new Program(); 97 p.StartAlgorithm(updateInterval, communicator); 98 } 47 99 } 48 100 } 49 101 50 public void StartAlgorithm(string fileName, string resultName) { 51 IAlgorithm alg = XmlParser.Deserialize<HeuristicLab.Optimization.IAlgorithm>(fileName); 102 public void StartAlgorithm(int updateInterval, MPI.Communicator communicator) { 103 IAlgorithm alg = communicator.Receive<MPITransportWrapper<IAlgorithm>>(0, 0).InnerItem; 104 105 Console.WriteLine("Starting algorithm..."); 52 106 53 107 alg.Stopped += new EventHandler(algorithm_Stopped); … … 57 111 alg.Start(); 58 112 113 Timer t = new Timer(delegate(object state) { 114 if (alg.ExecutionState == ExecutionState.Started) { 115 Console.WriteLine("Pausing alg..."); 116 alg.Pause(); 117 118 while (alg.ExecutionState != ExecutionState.Paused) { 119 Thread.Sleep(100); 120 } 121 122 communicator.Send<MPITransportWrapper<ResultCollection>>( 123 new MPITransportWrapper<ResultCollection>(alg.Results), 0, 1); 124 125 Console.WriteLine("Sending update..."); 126 127 Console.WriteLine("Resuming alg..."); 128 alg.Start(); 129 } 130 }, null, updateInterval, updateInterval); 131 59 132 waitHandle.WaitOne(); 60 133 61 XmlGenerator.Serialize(alg, resultName); 134 communicator.Send<int>(communicator.Rank, 0, 2); 135 communicator.Send<MPITransportWrapper<ResultCollection>>( 136 new MPITransportWrapper<ResultCollection>(alg.Results), 0, 1); 62 137 } 63 138
Note: See TracChangeset
for help on using the changeset viewer.