Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/11 17:37:05 (13 years ago)
Author:
svonolfe
Message:

Added first version of the MPIEngine (#1542)

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  
    120120  </ItemGroup>
    121121  <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>
    122126    <ProjectReference Include="..\..\..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    123127      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     
    127131      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
    128132      <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>
    129137    </ProjectReference>
    130138    <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  
    3030  [PluginDependency("HeuristicLab.Common", "3.3")]
    3131  [PluginDependency("HeuristicLab.Core", "3.3")]
     32  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3233  [PluginDependency("HeuristicLab.MPInet", "1.0.0")]
    3334  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3435  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     36  [PluginDependency("HeuristicLab.Operators.MPISupport", "3.3")]
    3537  public class HeuristicLabProblemsVehicleRoutingPlugin : PluginBase {
    3638  }
  • branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/Program.cs

    r6348 r6354  
    2727using HeuristicLab.Persistence.Default.Xml;
    2828using System.Threading;
     29using HeuristicLab.Operators.MPISupport;
     30using HeuristicLab.Core;
    2931
    3032namespace HeuristicLab.MPIAlgorithmRunner {
     
    3335
    3436    static void Main(string[] args) {
    35       if (args.Length != 2) {
     37      if (args.Length != 3) {
    3638        Console.WriteLine("Args:" + args.Length);
    3739
    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)");
    3941      }
    4042
    4143      string fileName = args[0];
    4244      string resultName = args[1];
     45      int updateInterval = int.Parse(args[2]);
    4346
    4447      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        }
    4799      }
    48100    }
    49101
    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...");
    52106
    53107      alg.Stopped += new EventHandler(algorithm_Stopped);
     
    57111      alg.Start();
    58112
     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
    59132      waitHandle.WaitOne();
    60133
    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);
    62137    }
    63138
Note: See TracChangeset for help on using the changeset viewer.