Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MPI/HeuristicLab.ExtLibs/HeuristicLab.MPInet/MPIAlgorithmRunner/3.3/Program.cs @ 6349

Last change on this file since 6349 was 6348, checked in by svonolfe, 14 years ago

Created plugin for the MPIAlgorithmRunner (#1542)

File size: 2.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Optimization;
27using HeuristicLab.Persistence.Default.Xml;
28using System.Threading;
29
30namespace HeuristicLab.MPIAlgorithmRunner {
31  class Program {
32    EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
33
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
44      using (new MPI.Environment(ref args)) {
45        Program p = new Program();
46        p.StartAlgorithm(fileName, resultName + MPI.Communicator.world.Rank + ".hl");
47      }
48    }
49
50    public void StartAlgorithm(string fileName, string resultName) {
51      IAlgorithm alg = XmlParser.Deserialize<HeuristicLab.Optimization.IAlgorithm>(fileName);
52
53      alg.Stopped += new EventHandler(algorithm_Stopped);
54      waitHandle.Reset();
55
56      alg.Prepare(true);
57      alg.Start();
58
59      waitHandle.WaitOne();
60
61      XmlGenerator.Serialize(alg, resultName);
62    }
63
64    void algorithm_Stopped(object sender, EventArgs e) {
65      waitHandle.Set();
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.