Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/19/11 11:08:33 (13 years ago)
Author:
svonolfe
Message:

Refactored solution (#1542)

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  
    3636  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    3737    <DebugSymbols>true</DebugSymbols>
    38     <OutputPath>bin\Debug\</OutputPath>
     38    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    3939    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4040    <DebugType>full</DebugType>
     
    103103  </PropertyGroup>
    104104  <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>
    107108    </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>
    110112    </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>
    113116    </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>
    116120    </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>
    119124    </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>
    122128    </Reference>
    123129    <Reference Include="Microsoft.Hpc.Scheduler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
     
    139145  <ItemGroup>
    140146    <Compile Include="AlgorithmBroker.cs" />
    141     <Compile Include="HeuristicLabMPIAlgorithmRunnerPlugin.cs" />
    142147    <Compile Include="IAlgorithmBroker.cs" />
    143148    <Compile Include="Program.cs" />
     
    145150  </ItemGroup>
    146151  <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>
    147160    <ProjectReference Include="..\..\HeuristicLab.Operators.MPISupport\3.3\HeuristicLab.Operators.MPISupport-3.3.csproj">
    148161      <Project>{6BD69CDA-4875-4045-8B35-6FD4602854F5}</Project>
    149162      <Name>HeuristicLab.Operators.MPISupport-3.3</Name>
     163      <Private>False</Private>
    150164    </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" />
    160165  </ItemGroup>
    161166  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
     
    166171set Outdir=$(Outdir)
    167172
    168 call PreBuildEvent.cmd
    169 SubWCRev "%25ProjectDir%25\" "%25ProjectDir%25\HeuristicLabMPIAlgorithmRunnerPlugin.cs.frame" "%25ProjectDir%25\HeuristicLabMPIAlgorithmRunnerPlugin.cs"</PreBuildEvent>
     173call PreBuildEvent.cmd</PreBuildEvent>
    170174  </PropertyGroup>
    171175  <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>
    179178  </PropertyGroup>
    180179  <!-- 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  
    2727using HeuristicLab.Persistence.Default.Xml;
    2828using System.Threading;
    29 using HeuristicLab.Operators.MPISupport;
    30 using HeuristicLab.Core;
    31 using Microsoft.Hpc.Scheduler;
    32 using System.ServiceModel;
    33 using System.Net;
    3429
    3530namespace HeuristicLab.MPIAlgorithmRunner {
    3631  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);
    6233
    6334    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
    6444      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");
    12147      }
    12248    }
    12349
    124     private EventWaitHandle waitHandle;
     50    public void StartAlgorithm(string fileName, string resultName) {
     51      IAlgorithm alg = XmlParser.Deserialize<HeuristicLab.Optimization.IAlgorithm>(fileName);
    12552
    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();
    13155
    13256      alg.Prepare(true);
    133       waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
    134       alg.Started += new EventHandler(alg_Started);
    13557      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();
    13685
    13786      waitHandle.WaitOne();
    13887
    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);
    16389    }
    16490
    165     void alg_Started(object sender, EventArgs e) {
     91    void algorithm_Stopped(object sender, EventArgs e) {
    16692      waitHandle.Set();
    16793    }
Note: See TracChangeset for help on using the changeset viewer.