Changeset 7205 for branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3
- Timestamp:
- 12/19/11 11:08:33 (13 years ago)
- Location:
- branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3/HeuristicLab.MPIAlgorithmRunner-3.3.csproj
r6394 r7205 36 36 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> 37 37 <DebugSymbols>true</DebugSymbols> 38 <OutputPath> bin\Debug\</OutputPath>38 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 39 39 <DefineConstants>DEBUG;TRACE</DefineConstants> 40 40 <DebugType>full</DebugType> … … 103 103 </PropertyGroup> 104 104 <ItemGroup> 105 <Reference Include="HeuristicLab.Collections-3.3"> 106 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Collections-3.3.dll</HintPath> 105 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 106 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath> 107 <Private>False</Private> 107 108 </Reference> 108 <Reference Include="HeuristicLab.Common-3.3"> 109 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath> 109 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 110 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 111 <Private>False</Private> 110 112 </Reference> 111 <Reference Include="HeuristicLab.Core-3.3"> 112 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath> 113 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 114 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath> 115 <Private>False</Private> 113 116 </Reference> 114 <Reference Include="HeuristicLab.Optimization-3.3"> 115 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization-3.3.dll</HintPath> 117 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 118 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 119 <Private>False</Private> 116 120 </Reference> 117 <Reference Include="HeuristicLab.Persistence-3.3"> 118 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Persistence-3.3.dll</HintPath> 121 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 122 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath> 123 <Private>False</Private> 119 124 </Reference> 120 <Reference Include="HeuristicLab.PluginInfrastructure-3.3"> 121 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 125 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 126 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 127 <Private>False</Private> 122 128 </Reference> 123 129 <Reference Include="Microsoft.Hpc.Scheduler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> … … 139 145 <ItemGroup> 140 146 <Compile Include="AlgorithmBroker.cs" /> 141 <Compile Include="HeuristicLabMPIAlgorithmRunnerPlugin.cs" />142 147 <Compile Include="IAlgorithmBroker.cs" /> 143 148 <Compile Include="Program.cs" /> … … 145 150 </ItemGroup> 146 151 <ItemGroup> 152 <None Include="HeuristicLab.snk" /> 153 </ItemGroup> 154 <ItemGroup> 155 <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.MPInet\1.0.0\HeuristicLab.MPInet-1.0.0.csproj"> 156 <Project>{C47EEE60-DF91-46DB-9B78-F2C2301D6FE7}</Project> 157 <Name>HeuristicLab.MPInet-1.0.0</Name> 158 <Private>False</Private> 159 </ProjectReference> 147 160 <ProjectReference Include="..\..\HeuristicLab.Operators.MPISupport\3.3\HeuristicLab.Operators.MPISupport-3.3.csproj"> 148 161 <Project>{6BD69CDA-4875-4045-8B35-6FD4602854F5}</Project> 149 162 <Name>HeuristicLab.Operators.MPISupport-3.3</Name> 163 <Private>False</Private> 150 164 </ProjectReference> 151 <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.MPInet\1.0.0\HeuristicLab.MPInet-1.0.0.csproj">152 <Project>{C47EEE60-DF91-46DB-9B78-F2C2301D6FE7}</Project>153 <Name>HeuristicLab.MPInet-1.0.0</Name>154 </ProjectReference>155 </ItemGroup>156 <ItemGroup>157 <None Include="HeuristicLab.snk" />158 <None Include="HeuristicLabMPIAlgorithmRunnerPlugin.cs.frame" />159 <None Include="Properties\AssemblyInfo.frame" />160 165 </ItemGroup> 161 166 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> … … 166 171 set Outdir=$(Outdir) 167 172 168 call PreBuildEvent.cmd 169 SubWCRev "%25ProjectDir%25\" "%25ProjectDir%25\HeuristicLabMPIAlgorithmRunnerPlugin.cs.frame" "%25ProjectDir%25\HeuristicLabMPIAlgorithmRunnerPlugin.cs"</PreBuildEvent> 173 call PreBuildEvent.cmd</PreBuildEvent> 170 174 </PropertyGroup> 171 175 <PropertyGroup> 172 <PostBuildEvent>set ProjectName=$(ProjectName) 173 set Source=$(TargetPath) 174 set Configuration=$(ConfigurationName) 175 set Platform=$(PlatformName) 176 set SolutionDir=$(SolutionDir) 177 178 if exist "$(SolutionDir)CustomPostBuild.cmd" call "$(SolutionDir)CustomPostBuild.cmd"</PostBuildEvent> 176 <PostBuildEvent> 177 </PostBuildEvent> 179 178 </PropertyGroup> 180 179 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3/Program.cs
r6402 r7205 27 27 using HeuristicLab.Persistence.Default.Xml; 28 28 using System.Threading; 29 using HeuristicLab.Operators.MPISupport;30 using HeuristicLab.Core;31 using Microsoft.Hpc.Scheduler;32 using System.ServiceModel;33 using System.Net;34 29 35 30 namespace HeuristicLab.MPIAlgorithmRunner { 36 31 class Program { 37 private static void SetJobStatus(string address) { 38 Console.WriteLine("Started service... at " + address); 39 40 // Discover the job's context from the environment 41 String headNodeName = System.Environment.GetEnvironmentVariable("CCP_SCHEDULER"); 42 int jobId = System.Convert.ToInt32(System.Environment.GetEnvironmentVariable("CCP_JOBID")); 43 44 Console.WriteLine(jobId + "@" + headNodeName); 45 46 // Connect to the head node and get the job 47 IScheduler scheduler = new Scheduler(); 48 scheduler.Connect(headNodeName); 49 ISchedulerJob job = scheduler.OpenJob(jobId); 50 51 job.SetCustomProperty("address", address); 52 53 job.Commit(); 54 } 55 56 private static string GetAddress(ServiceHost service) { 57 IPHostEntry IPHost = Dns.GetHostByName(Dns.GetHostName()); 58 string address = "net.tcp://" + IPHost.AddressList[0].ToString() + ":" + service.ChannelDispatchers[0].Listener.Uri.Port + "/AlgorithmBroker"; 59 60 return address; 61 } 32 EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); 62 33 63 34 static void Main(string[] args) { 35 if (args.Length != 2) { 36 Console.WriteLine("Args:" + args.Length); 37 38 throw new ArgumentException("You must provide two arguments - the algorithm file and the result file"); 39 } 40 41 string fileName = args[0]; 42 string resultName = args[1]; 43 64 44 using (new MPI.Environment(ref args)) { 65 int clients = MPI.Communicator.world.Group.Size - 1; 66 Console.WriteLine("Clients: " + clients); 67 68 MPI.Communicator communicator = MPI.Communicator.world.Clone() as MPI.Communicator; 69 70 if (communicator.Rank == 0) { 71 ServiceHost service = AlgorithmBroker.StartService(communicator); 72 AlgorithmBroker broker = (service.SingletonInstance as AlgorithmBroker); 73 74 string address = GetAddress(service); 75 SetJobStatus(address); 76 77 bool[] finished = new bool[clients]; 78 int finishedCount = 0; 79 80 while (finishedCount != clients) { 81 ItemList<ResultCollection> results = new ItemList<ResultCollection>(); 82 83 for (int i = 0; i < clients; i++) { 84 if (!finished[i]) { 85 int client = i + 1; 86 ResultCollection result = communicator.Receive<MPITransportWrapper<ResultCollection>>(client, 1).InnerItem; 87 88 Console.WriteLine("Received result " + result); 89 90 if (results.Count != clients) { 91 results.Add(result); 92 } else { 93 results[i] = result; 94 } 95 96 Console.WriteLine("Probing..."); 97 if (communicator.ImmediateProbe(client, 2) != null) { 98 finished[i] = true; 99 finishedCount++; 100 } 101 } 102 } 103 104 Console.WriteLine("Update results"); 105 lock (broker.resultLocker) 106 broker.Results = results; 107 } 108 109 lock (broker.ExitWaitHandle) { 110 broker.Terminated = true; 111 } 112 113 broker.ExitWaitHandle.WaitOne(); 114 Console.WriteLine("Finished."); 115 Thread.Sleep(1000); 116 service.Close(); 117 } else { 118 Program p = new Program(); 119 p.StartAlgorithm(communicator); 120 } 45 Program p = new Program(); 46 p.StartAlgorithm(fileName, resultName + MPI.Communicator.world.Rank + ".hl"); 121 47 } 122 48 } 123 49 124 private EventWaitHandle waitHandle; 50 public void StartAlgorithm(string fileName, string resultName) { 51 IAlgorithm alg = XmlParser.Deserialize<HeuristicLab.Optimization.IAlgorithm>(fileName); 125 52 126 public void StartAlgorithm(MPI.Communicator communicator) { 127 IAlgorithm alg = communicator.Receive<MPITransportWrapper<IAlgorithm>>(0, 0).InnerItem; 128 int updateInterval = communicator.Receive<int>(0, 1); 129 130 Console.WriteLine("Starting algorithm..."); 53 alg.Stopped += new EventHandler(algorithm_Stopped); 54 waitHandle.Reset(); 131 55 132 56 alg.Prepare(true); 133 waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);134 alg.Started += new EventHandler(alg_Started);135 57 alg.Start(); 58 59 Thread.Sleep(10000); 60 Thread t = new Thread(delegate() { 61 while (true) { 62 if (alg.ExecutionState == Core.ExecutionState.Started) { 63 alg.Pause(); 64 65 while (alg.ExecutionState == Core.ExecutionState.Started) 66 Thread.Sleep(100); 67 68 if (alg.Results.ContainsKey("Best valid Solution Distance")) { 69 Console.WriteLine("BestDistance: " + alg.Results["Best valid Solution Distance"].Value.ToString()); 70 } 71 72 if (alg.Results.ContainsKey("Best valid Solution Vehicles")) { 73 Console.WriteLine("BestVehicles: " + alg.Results["Best valid Solution Vehicles"].Value.ToString()); 74 } 75 76 XmlGenerator.Serialize(alg, resultName); 77 alg.Start(); 78 } 79 80 Thread.Sleep(300000); 81 } 82 }); 83 t.IsBackground = true; 84 t.Start(); 136 85 137 86 waitHandle.WaitOne(); 138 87 139 alg.Started -= new EventHandler(alg_Started); 140 141 while (alg.ExecutionState != ExecutionState.Stopped) { 142 Console.WriteLine("Pausing alg..."); 143 alg.Pause(); 144 145 while (alg.ExecutionState == ExecutionState.Started) { 146 Thread.Sleep(100); 147 } 148 149 communicator.Send<MPITransportWrapper<ResultCollection>>( 150 new MPITransportWrapper<ResultCollection>(alg.Results), 0, 1); 151 152 Console.WriteLine("Sending update..."); 153 154 Console.WriteLine("Resuming alg..."); 155 if (alg.ExecutionState == ExecutionState.Paused) 156 alg.Start(); 157 Thread.Sleep(updateInterval); 158 } 159 160 communicator.Send<int>(communicator.Rank, 0, 2); 161 communicator.Send<MPITransportWrapper<ResultCollection>>( 162 new MPITransportWrapper<ResultCollection>(alg.Results), 0, 1); 88 XmlGenerator.Serialize(alg, resultName); 163 89 } 164 90 165 void alg _Started(object sender, EventArgs e) {91 void algorithm_Stopped(object sender, EventArgs e) { 166 92 waitHandle.Set(); 167 93 }
Note: See TracChangeset
for help on using the changeset viewer.