Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/18/11 15:08:14 (13 years ago)
Author:
ascheibe
Message:

on behalf of spimming:
#1659

  • implemented abstract base class for benchmarking algorithms
  • added License information
  • corrected plugin dependencies
  • corrected descriptions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Linpack.cs

    r6920 r6934  
    1 using System;
     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;
    223using System.Diagnostics;
    3 using System.Threading;
    4 using System.Threading.Tasks;
    524using HeuristicLab.Common;
    625using HeuristicLab.Core;
     
    1029
    1130namespace HeuristicLab.Algorithms.Benchmarks {
    12   [Item("Linpack Algorithm", "A Linpack benchmark algorithm.")]
     31  [Item("Linpack Algorithm", "Linpack benchmarking algorithm.")]
    1332  [Creatable("Benchmarks")]
    1433  [StorableClass]
    15   public class Linpack : Algorithm {
    16     private DateTime lastUpdateTime;
    17 
    18     [Storable]
    19     private ResultCollection results;
     34  public class Linpack : Benchmark {
    2035
    2136    #region Benchmark Fields
     
    3348    #endregion
    3449
    35     #region Properties
    36 
    37     public override ResultCollection Results {
    38       get { return results; }
    39     }
    40 
    41     #endregion
    42 
    4350    #region Costructors
    4451
    4552    public Linpack()
    4653      : base() {
    47       results = new ResultCollection();
    4854    }
    4955
    5056    private Linpack(Linpack original, Cloner cloner)
    5157      : base(original, cloner) {
    52       results = new ResultCollection();
    5358    }
    5459
    5560    #endregion
     61
     62    #region IDeepClonable Members
    5663
    5764    public override IDeepCloneable Clone(Cloner cloner) {
     
    5966    }
    6067
    61     public override void Prepare() {
    62       results.Clear();
    63       OnPrepared();
    64     }
    65 
    66     public override void Start() {
    67       var cancellationTokenSource = new CancellationTokenSource();
    68       OnStarted();
    69       Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token);
    70       task.ContinueWith(t => {
    71         try {
    72           t.Wait();
    73         }
    74         catch (AggregateException ex) {
    75           try {
    76             ex.Flatten().Handle(x => x is OperationCanceledException);
    77           }
    78           catch (AggregateException remaining) {
    79             if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
    80             else OnExceptionOccurred(remaining);
    81           }
    82         }
    83         cancellationTokenSource.Dispose();
    84         cancellationTokenSource = null;
    85         OnStopped();
    86       });
    87     }
    88 
    89     private void Run(object state) {
    90       CancellationToken cancellationToken = (CancellationToken)state;
    91       lastUpdateTime = DateTime.Now;
    92       System.Timers.Timer timer = new System.Timers.Timer(250);
    93       timer.AutoReset = true;
    94       timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    95       timer.Start();
    96       try {
    97         RunBenchmark();
    98       }
    99       finally {
    100         timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed);
    101         timer.Stop();
    102         ExecutionTime += DateTime.Now - lastUpdateTime;
    103       }
    104 
    105       cancellationToken.ThrowIfCancellationRequested();
    106     }
    107 
    108     private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
    109       System.Timers.Timer timer = (System.Timers.Timer)sender;
    110       timer.Enabled = false;
    111       DateTime now = DateTime.Now;
    112       ExecutionTime += now - lastUpdateTime;
    113       lastUpdateTime = now;
    114       timer.Enabled = true;
    115     }
     68    #endregion
    11669
    11770    #region Linpack Benchmark
    118 
    119     private void RunBenchmark() {
     71    // implementation based on Java version: http://www.netlib.org/benchmark/linpackjava/
     72
     73    protected override void RunBenchmark() {
    12074      int n = DEFAULT_PSIZE;
    12175      int ldaa = DEFAULT_PSIZE;
     
    189143      mflops_result /= 1000;
    190144
    191       //System.Console.WriteLine("Mflops/s: " + mflops_result + "  Time: " + time_result + " secs" + "  Norm Res: " + residn_result + "  Precision: " + eps_result);
    192 
    193145      Results.Add(new Result("Mflops/s", new DoubleValue(mflops_result)));
    194       //Results.Add(new Result("ca. Mflops/s", new DoubleValue(mflops_result * Environment.ProcessorCount)));
     146      Results.Add(new Result("total Mflops/s", new DoubleValue(mflops_result * Environment.ProcessorCount)));
    195147    }
    196148
Note: See TracChangeset for help on using the changeset viewer.