Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6402 for branches/MPI


Ignore:
Timestamp:
06/09/11 15:54:37 (13 years ago)
Author:
svonolfe
Message:

Improved efficiency of algorithm execution in the MPI environment (#1542)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3/Program.cs

    r6401 r6402  
    3535namespace HeuristicLab.MPIAlgorithmRunner {
    3636  class Program {
    37     EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
    38 
    3937    private static void SetJobStatus(string address) {
    4038      Console.WriteLine("Started service... at " + address);
     
    124122    }
    125123
     124    private EventWaitHandle waitHandle;
     125
    126126    public void StartAlgorithm(MPI.Communicator communicator) {
    127127      IAlgorithm alg = communicator.Receive<MPITransportWrapper<IAlgorithm>>(0, 0).InnerItem;
     
    130130      Console.WriteLine("Starting algorithm...");
    131131
    132       alg.Stopped += new EventHandler(algorithm_Stopped);
    133       waitHandle.Reset();
    134 
    135132      alg.Prepare(true);
     133      waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
     134      alg.Started += new EventHandler(alg_Started);
    136135      alg.Start();
    137136
    138       Timer t = new Timer(delegate(object state) {
    139         if (alg.ExecutionState == ExecutionState.Started) {
    140           Console.WriteLine("Pausing alg...");
    141           alg.Pause();
     137      waitHandle.WaitOne();
    142138
    143           while (alg.ExecutionState != ExecutionState.Paused) {
    144             Thread.Sleep(100);
    145           }
     139      alg.Started -= new EventHandler(alg_Started);
    146140
    147           communicator.Send<MPITransportWrapper<ResultCollection>>(
    148             new MPITransportWrapper<ResultCollection>(alg.Results), 0, 1);
     141      while (alg.ExecutionState != ExecutionState.Stopped) {
     142        Console.WriteLine("Pausing alg...");
     143        alg.Pause();
    149144
    150           Console.WriteLine("Sending update...");
     145        while (alg.ExecutionState == ExecutionState.Started) {
     146          Thread.Sleep(100);
     147        }
    151148
    152           Console.WriteLine("Resuming alg...");
     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)
    153156          alg.Start();
    154         }
    155       }, null, updateInterval, updateInterval);
    156 
    157       waitHandle.WaitOne();
     157        Thread.Sleep(updateInterval);
     158      }
    158159
    159160      communicator.Send<int>(communicator.Rank, 0, 2);
     
    162163    }
    163164
    164     void algorithm_Stopped(object sender, EventArgs e) {
     165    void alg_Started(object sender, EventArgs e) {
    165166      waitHandle.Set();
    166167    }
Note: See TracChangeset for help on using the changeset viewer.