- Timestamp:
- 10/18/11 15:08:14 (13 years ago)
- 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 22 using System; 2 23 using System.Diagnostics; 3 using System.Threading;4 using System.Threading.Tasks;5 24 using HeuristicLab.Common; 6 25 using HeuristicLab.Core; … … 10 29 11 30 namespace HeuristicLab.Algorithms.Benchmarks { 12 [Item("Linpack Algorithm", " A Linpack benchmarkalgorithm.")]31 [Item("Linpack Algorithm", "Linpack benchmarking algorithm.")] 13 32 [Creatable("Benchmarks")] 14 33 [StorableClass] 15 public class Linpack : Algorithm { 16 private DateTime lastUpdateTime; 17 18 [Storable] 19 private ResultCollection results; 34 public class Linpack : Benchmark { 20 35 21 36 #region Benchmark Fields … … 33 48 #endregion 34 49 35 #region Properties36 37 public override ResultCollection Results {38 get { return results; }39 }40 41 #endregion42 43 50 #region Costructors 44 51 45 52 public Linpack() 46 53 : base() { 47 results = new ResultCollection();48 54 } 49 55 50 56 private Linpack(Linpack original, Cloner cloner) 51 57 : base(original, cloner) { 52 results = new ResultCollection();53 58 } 54 59 55 60 #endregion 61 62 #region IDeepClonable Members 56 63 57 64 public override IDeepCloneable Clone(Cloner cloner) { … … 59 66 } 60 67 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 116 69 117 70 #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() { 120 74 int n = DEFAULT_PSIZE; 121 75 int ldaa = DEFAULT_PSIZE; … … 189 143 mflops_result /= 1000; 190 144 191 //System.Console.WriteLine("Mflops/s: " + mflops_result + " Time: " + time_result + " secs" + " Norm Res: " + residn_result + " Precision: " + eps_result);192 193 145 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))); 195 147 } 196 148
Note: See TracChangeset
for help on using the changeset viewer.