Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6388


Ignore:
Timestamp:
06/08/11 11:07:33 (13 years ago)
Author:
svonolfe
Message:

Worked on the MPIEngine (#1542)

Location:
branches/MPI
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/HeuristicLab.MPIAlgorithmRunner-3.3.csproj

    r6354 r6388  
    103103  </PropertyGroup>
    104104  <ItemGroup>
     105    <Reference Include="Microsoft.Hpc.Scheduler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
     106      <HintPath>Microsoft.Hpc.Scheduler.dll</HintPath>
     107    </Reference>
    105108    <Reference Include="MPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=29b4a045737654fe, processorArchitecture=MSIL">
    106109      <HintPath>..\HeuristicLab.ExtLibs\HeuristicLab.MPInet\1.0.0\MPI.dll</HintPath>
     
    108111    <Reference Include="System" />
    109112    <Reference Include="System.Core" />
     113    <Reference Include="System.ServiceModel" />
    110114    <Reference Include="System.Xml.Linq" />
    111115    <Reference Include="System.Data.DataSetExtensions" />
     
    115119  </ItemGroup>
    116120  <ItemGroup>
     121    <Compile Include="AlgorithmBroker.cs" />
    117122    <Compile Include="HeuristicLabMPIAlgorithmRunnerPlugin.cs" />
     123    <Compile Include="IAlgorithmBroker.cs" />
    118124    <Compile Include="Program.cs" />
    119125    <Compile Include="Properties\AssemblyInfo.cs" />
  • branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/HeuristicLabMPIAlgorithmRunnerPlugin.cs.frame

    r6354 r6388  
    2828  [Plugin("HeuristicLab.MPIAlgorithmRunner", "3.3.4.$WCREV$")]
    2929  [PluginFile("HeuristicLab.MPIAlgorithmRunner-3.3.exe", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3031  [PluginDependency("HeuristicLab.Common", "3.3")]
    3132  [PluginDependency("HeuristicLab.Core", "3.3")]
    32   [PluginDependency("HeuristicLab.Collections", "3.3")]
    3333  [PluginDependency("HeuristicLab.MPInet", "1.0.0")]
     34  [PluginDependency("HeuristicLab.Operators.MPISupport", "3.3")]
    3435  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3536  [PluginDependency("HeuristicLab.Persistence", "3.3")]
  • branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/Program.cs

    r6354 r6388  
    2929using HeuristicLab.Operators.MPISupport;
    3030using HeuristicLab.Core;
     31using Microsoft.Hpc.Scheduler;
     32using System.ServiceModel;
     33using System.Net;
    3134
    3235namespace HeuristicLab.MPIAlgorithmRunner {
     
    3437    EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
    3538
     39    private static void SetJobStatus(string address) {
     40      Console.WriteLine("Started service... at " + address);
     41
     42      // Discover the job's context from the environment
     43      String headNodeName = System.Environment.GetEnvironmentVariable("CCP_CLUSTER_NAME");
     44      int jobId = System.Convert.ToInt32(System.Environment.GetEnvironmentVariable("CCP_JOBID"));
     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    }
     62
    3663    static void Main(string[] args) {
    37       if (args.Length != 3) {
    38         Console.WriteLine("Args:" + args.Length);
     64      using (new MPI.Environment(ref args)) {
     65        int clients = MPI.Communicator.world.Group.Size;
     66        int updateInterval = 5000;
    3967
    40         throw new ArgumentException("You must provide 3 arguments - the algorithm file, the result file and the update interval (in ms)");
    41       }
    42 
    43       string fileName = args[0];
    44       string resultName = args[1];
    45       int updateInterval = int.Parse(args[2]);
    46 
    47       using (new MPI.Environment(ref args)) {
    4868        MPI.Communicator communicator = MPI.Communicator.world.Clone() as MPI.Communicator;
    4969
    5070        if (communicator.Rank == 0) {
    51           IAlgorithm alg = XmlParser.Deserialize<IAlgorithm>(fileName);
    52           MPITransportWrapper<IAlgorithm> transport = new MPITransportWrapper<IAlgorithm>(alg);
     71          ServiceHost service = AlgorithmBroker.StartService(communicator);
     72          AlgorithmBroker broker = (service.SingletonInstance as AlgorithmBroker);
    5373
    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           }
     74          string address = GetAddress(service);
     75          SetJobStatus(address);
    6076
    6177          ItemList<ResultCollection> results = new ItemList<ResultCollection>();
     
    87103
    88104            Console.WriteLine("Update results");
    89             lock (resultName) {
    90               XmlGenerator.Serialize(results, resultName);
    91             }
     105            broker.Results = results;
    92106          }
    93107
     108          lock (broker.ExitWaitHandle) {
     109            broker.Terminated = true;
     110          }
     111
     112          broker.ExitWaitHandle.WaitOne();
    94113          Console.WriteLine("Finished.");
     114          service.Close();
    95115        } else {
    96116          Program p = new Program();
  • branches/MPI/HeuristicLab.MPIEngine/3.3/HeuristicLab.MPIEngine-3.3.csproj

    r6354 r6388  
    104104  </PropertyGroup>
    105105  <ItemGroup>
     106    <Reference Include="Microsoft.Hpc.Scheduler, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
     107      <HintPath>..\..\HeuristicLab.ExtLibs\HeuristicLab.MPInet\MPIAlgorithmRunner\3.3\Microsoft.Hpc.Scheduler.dll</HintPath>
     108    </Reference>
    106109    <Reference Include="System" />
    107110    <Reference Include="System.Core" />
     111    <Reference Include="System.ServiceModel" />
    108112    <Reference Include="System.Xml.Linq" />
    109113    <Reference Include="System.Data.DataSetExtensions" />
     
    133137      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
    134138      <Name>HeuristicLab.Core-3.3</Name>
     139    </ProjectReference>
     140    <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.MPInet\MPIAlgorithmRunner\3.3\HeuristicLab.MPIAlgorithmRunner-3.3.csproj">
     141      <Project>{62C3B458-430E-4EF4-8250-C50BCF94D035}</Project>
     142      <Name>HeuristicLab.MPIAlgorithmRunner-3.3</Name>
     143    </ProjectReference>
     144    <ProjectReference Include="..\..\HeuristicLab.Operators.MPISupport\3.3\HeuristicLab.Operators.MPISupport-3.3.csproj">
     145      <Project>{6BD69CDA-4875-4045-8B35-6FD4602854F5}</Project>
     146      <Name>HeuristicLab.Operators.MPISupport-3.3</Name>
    135147    </ProjectReference>
    136148    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
  • branches/MPI/HeuristicLab.MPIEngine/3.3/HeuristicLabMPIEnginePlugin.cs.frame

    r6349 r6388  
    3131  [Plugin("HeuristicLab.MPIEngine", "3.3.4.$WCREV$")]
    3232  [PluginFile("HeuristicLab.MPIEngine-3.3.dll", PluginFileType.Assembly)]
     33  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3334  [PluginDependency("HeuristicLab.Common", "3.3")]
    3435  [PluginDependency("HeuristicLab.Core", "3.3")]
    3536  [PluginDependency("HeuristicLab.MPInet", "1.0.0")]
    3637  [PluginDependency("HeuristicLab.MPIAlgorithmRunner", "3.3")]
     38  [PluginDependency("HeuristicLab.Operators.MPISupport", "3.3")]
     39  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3740  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     41  [PluginDependency("HeuristicLab.SequentialEngine", "3.3")]
    3842  public class HeuristicLabMPIEnginePlugin : PluginBase {
    3943  }
  • branches/MPI/HeuristicLab.MPIEngine/3.3/MPIEngine.cs

    r6354 r6388  
    3131using HeuristicLab.Optimization;
    3232using System.Linq;
     33using Microsoft.Hpc.Scheduler;
     34using System.ServiceModel;
     35using HeuristicLab.MPIAlgorithmRunner;
     36using HeuristicLab.Operators.MPISupport;
    3337
    3438namespace HeuristicLab.MPIEngine {
     
    4953    }
    5054
    51     private string algFile;
     55    private IAlgorithm algorithm;
    5256
    5357    public override void Start() {
     
    6468        alg.Engine = new SequentialEngine.SequentialEngine();
    6569
    66         algFile = Path.GetTempFileName();
    67         XmlGenerator.Serialize(alg, algFile);
     70        algorithm = alg;
    6871      }
    6972
     
    7780        IScope globalScope = context.Scope;
    7881
    79         string resultFile = Path.GetTempFileName();
    80         ItemList<ResultCollection> empty = new ItemList<ResultCollection>();
    81         XmlGenerator.Serialize(empty, resultFile);
     82        string exec = @"mpiexec";
     83        string args = @"-c 3 C:\public\MPISupport\HeuristicLab.MPIAlgorithmRunner-3.3.exe ";
    8284
    83         string exec = @"C:\Program Files\Microsoft Compute Cluster Pack\Bin\mpiexec.exe";
    84         string args = @"-n 3 HeuristicLab.MPIAlgorithmRunner-3.3.exe " + algFile + " " + resultFile + " 5000";
     85        IScheduler scheduler = new Scheduler();
     86        scheduler.Connect("blade00.hpc.fh-hagenberg.at");
    8587
    86         System.Threading.Thread pollThread = new System.Threading.Thread(delegate(object state) {
    87           while (true) {
    88             System.Threading.Thread.Sleep(5000);
     88        ISchedulerJob job = scheduler.CreateJob();
     89        job.Name = "HeuristicLab.MPIEngine";
     90        job.RequestedNodes.Add("BLADE03");
     91        ISchedulerTask task = job.CreateTask();
     92        task.Name = "HeuristicLab.MPIAlgorithmRunner";
     93        task.CommandLine = exec + " " + args;
     94        task.StdOutFilePath = "stdout.txt";
     95        task.StdErrFilePath = "stderr.txt";
     96        task.MinimumNumberOfCores = task.MaximumNumberOfCores = 3;
     97        job.AddTask(task);
    8998
    90             lock (resultFile) {
    91               object results = XmlParser.Deserialize(resultFile);
    92               ResultCollection resultCollection = (globalScope.Variables["Results"].Value as ResultCollection);
     99        scheduler.SubmitJob(job, @"HPC\svonolfe", @"Vunkopf!3");
    93100
    94               if (resultCollection != null) {
    95                 if (!resultCollection.ContainsKey("MPIResults"))
    96                   resultCollection.Add(new Result("MPIResults", results as IItem));
     101        try {
     102          string address = null;
     103          int timeout = 10;
    97104
    98                 resultCollection["MPIResults"].Value = results as IItem;
     105          while (address == null && timeout > 0) {
     106            ISchedulerJob schedulerJob = scheduler.OpenJob(job.Id);
     107            if (schedulerJob != null) {
     108              INameValueCollection properties = schedulerJob.GetCustomProperties();
     109              NameValue item = properties.FirstOrDefault(i => i.Name == "address");
     110              if (item != null) {
     111                address = item.Value;
     112              } else {
     113                System.Threading.Thread.Sleep(1000);
     114                timeout--;
    99115              }
    100 
    101116            }
    102117          }
    103         });
    104         pollThread.Start();
    105118
    106         Process p = Process.Start(exec, args);
    107         p.WaitForExit();
     119          if (address == null) {
     120            throw new Exception("A timeout occurred when starting the MPIAlgorithmRunner");
     121          }
    108122
    109         pollThread.Abort();
    110         File.Delete(algFile);
    111         File.Delete(resultFile);
     123          NetTcpBinding netTCPBinding = new NetTcpBinding(SecurityMode.None);
     124          ChannelFactory<IAlgorithmBroker> factory = new ChannelFactory<IAlgorithmBroker>(netTCPBinding, address);
     125          IAlgorithmBroker proxy = factory.CreateChannel();
     126
     127          proxy.TransmitAlgorithm(new MPITransportWrapper<IAlgorithm>(algorithm));
     128
     129          while (!proxy.IsAlgorithmTerminated()) {
     130            ItemList<ResultCollection> results = proxy.GetResults().InnerItem;
     131
     132            ResultCollection resultCollection = (globalScope.Variables["Results"].Value as ResultCollection);
     133
     134            if (resultCollection != null && results != null) {
     135              if (!resultCollection.ContainsKey("MPIResults"))
     136                resultCollection.Add(new Result("MPIResults", results));
     137
     138              resultCollection["MPIResults"].Value = results;
     139            }
     140
     141            System.Threading.Thread.Sleep(5000);
     142          }
     143        }
     144        catch (Exception e) {
     145          scheduler.CancelJob(job.Id, "Exception: " + e.Message);
     146          throw e;
     147        }
    112148      }
    113149    }
Note: See TracChangeset for help on using the changeset viewer.