1 /* ***** BEGIN LICENSE BLOCK ***** 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 * 4 * The contents of this file are subject to the Mozilla Public License Version 5 * 1.1 (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * http://www.mozilla.org/MPL/ 8 * 9 * Software distributed under the License is distributed on an "AS IS" basis, 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 * for the specific language governing rights and limitations under the 12 * License. 13 * 14 * The Original Code is JTransforms. 15 * 16 * The Initial Developer of the Original Code is 17 * Piotr Wendykier, Emory University. 18 * Portions created by the Initial Developer are Copyright (C) 2007-2009 19 * the Initial Developer. All Rights Reserved. 20 * 21 * Alternatively, the contents of this file may be used under the terms of 22 * either the GNU General Public License Version 2 or later (the "GPL"), or 23 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 24 * in which case the provisions of the GPL or the LGPL are applicable instead 25 * of those above. If you wish to allow use of your version of this file only 26 * under the terms of either the GPL or the LGPL, and not to allow others to 27 * use your version of this file under the terms of the MPL, indicate your 28 * decision by deleting the provisions above and replace them with the notice 29 * and other provisions required by the GPL or the LGPL. If you do not delete 30 * the provisions above, a recipient may use your version of this file under 31 * the terms of any one of the MPL, the GPL or the LGPL. 32 * 33 * ***** END LICENSE BLOCK ***** */ 34 35 package edu.emory.mathcs.jtransforms.dht; 36 37 import java.util.Arrays; 38 39 import edu.emory.mathcs.utils.ConcurrencyUtils; 40 import edu.emory.mathcs.utils.IOUtils; 41 42 /** 43 * Benchmark of double precision DHT's 44 * 45 * @author Piotr Wendykier (piotr.wendykier@gmail.com) 46 * 47 */ 48 public class BenchmarkDoubleDHT { 49 50 private static int nthread = 8; 51 52 private static int niter = 200; 53 54 private static int nsize = 16; 55 56 private static int threadsBegin2D = 65636; 57 58 private static int threadsBegin3D = 65636; 59 60 private static boolean doWarmup = true; 61 62 private static int[] sizes1D = new int[] { 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 10368, 27000, 75600, 165375, 362880, 1562500, 3211264, 6250000 }; 63 64 private static int[] sizes2D = new int[] { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 260, 520, 1050, 1458, 1960, 2916, 4116, 5832 }; 65 66 private static int[] sizes3D = new int[] { 8, 16, 32, 64, 128, 256, 512, 1024, 5, 17, 30, 95, 180, 270, 324, 420 }; 67 68 private static boolean doScaling = false; 69 BenchmarkDoubleDHT()70 private BenchmarkDoubleDHT() { 71 72 } 73 parseArguments(String[] args)74 public static void parseArguments(String[] args) { 75 if (args.length > 0) { 76 nthread = Integer.parseInt(args[0]); 77 threadsBegin2D = Integer.parseInt(args[1]); 78 threadsBegin3D = Integer.parseInt(args[2]); 79 niter = Integer.parseInt(args[3]); 80 doWarmup = Boolean.parseBoolean(args[4]); 81 doScaling = Boolean.parseBoolean(args[5]); 82 nsize = Integer.parseInt(args[6]); 83 sizes1D = new int[nsize]; 84 sizes2D = new int[nsize]; 85 sizes3D = new int[nsize]; 86 for (int i = 0; i < nsize; i++) { 87 sizes1D[i] = Integer.parseInt(args[7 + i]); 88 } 89 for (int i = 0; i < nsize; i++) { 90 sizes2D[i] = Integer.parseInt(args[7 + nsize + i]); 91 } 92 for (int i = 0; i < nsize; i++) { 93 sizes3D[i] = Integer.parseInt(args[7 + nsize + nsize + i]); 94 } 95 } else { 96 System.out.println("Default settings are used."); 97 } 98 ConcurrencyUtils.setNumberOfThreads(nthread); 99 ConcurrencyUtils.setThreadsBeginN_2D(threadsBegin2D); 100 ConcurrencyUtils.setThreadsBeginN_3D(threadsBegin3D); 101 System.out.println("nthred = " + nthread); 102 System.out.println("threadsBegin2D = " + threadsBegin2D); 103 System.out.println("threadsBegin3D = " + threadsBegin3D); 104 System.out.println("niter = " + niter); 105 System.out.println("doWarmup = " + doWarmup); 106 System.out.println("doScaling = " + doScaling); 107 System.out.println("nsize = " + nsize); 108 System.out.println("sizes1D[] = " + Arrays.toString(sizes1D)); 109 System.out.println("sizes2D[] = " + Arrays.toString(sizes2D)); 110 System.out.println("sizes3D[] = " + Arrays.toString(sizes3D)); 111 } 112 benchmarkForward_1D()113 public static void benchmarkForward_1D() { 114 double[] times = new double[nsize]; 115 double[] x; 116 for (int i = 0; i < nsize; i++) { 117 System.out.println("Forward DHT 1D of size " + sizes1D[i]); 118 DoubleDHT_1D dht = new DoubleDHT_1D(sizes1D[i]); 119 x = new double[sizes1D[i]]; 120 if (doWarmup) { // call the transform twice to warm up 121 IOUtils.fillMatrix_1D(sizes1D[i], x); 122 dht.forward(x); 123 IOUtils.fillMatrix_1D(sizes1D[i], x); 124 dht.forward(x); 125 } 126 double av_time = 0; 127 long elapsedTime = 0; 128 for (int j = 0; j < niter; j++) { 129 IOUtils.fillMatrix_1D(sizes1D[i], x); 130 elapsedTime = System.nanoTime(); 131 dht.forward(x); 132 elapsedTime = System.nanoTime() - elapsedTime; 133 av_time = av_time + elapsedTime; 134 } 135 times[i] = (double) av_time / 1000000.0 / (double) niter; 136 System.out.println("Average execution time: " + String.format("%.2f", av_time / 1000000.0 / (double) niter) + " msec"); 137 x = null; 138 dht = null; 139 System.gc(); 140 ConcurrencyUtils.sleep(5000); 141 } 142 IOUtils.writeFFTBenchmarkResultsToFile("benchmarkDoubleForwardDHT_1D.txt", nthread, niter, doWarmup, doScaling, sizes1D, times); 143 } 144 benchmarkForward_2D_input_1D()145 public static void benchmarkForward_2D_input_1D() { 146 double[] times = new double[nsize]; 147 double[] x; 148 for (int i = 0; i < nsize; i++) { 149 System.out.println("Forward DHT 2D (input 1D) of size " + sizes2D[i] + " x " + sizes2D[i]); 150 DoubleDHT_2D dht2 = new DoubleDHT_2D(sizes2D[i], sizes2D[i]); 151 x = new double[sizes2D[i] * sizes2D[i]]; 152 if (doWarmup) { // call the transform twice to warm up 153 IOUtils.fillMatrix_2D(sizes2D[i], sizes2D[i], x); 154 dht2.forward(x); 155 IOUtils.fillMatrix_2D(sizes2D[i], sizes2D[i], x); 156 dht2.forward(x); 157 } 158 double av_time = 0; 159 long elapsedTime = 0; 160 for (int j = 0; j < niter; j++) { 161 IOUtils.fillMatrix_2D(sizes2D[i], sizes2D[i], x); 162 elapsedTime = System.nanoTime(); 163 dht2.forward(x); 164 elapsedTime = System.nanoTime() - elapsedTime; 165 av_time = av_time + elapsedTime; 166 } 167 times[i] = (double) av_time / 1000000.0 / (double) niter; 168 System.out.println("Average execution time: " + String.format("%.2f", av_time / 1000000.0 / (double) niter) + " msec"); 169 x = null; 170 dht2 = null; 171 System.gc(); 172 ConcurrencyUtils.sleep(5000); 173 } 174 IOUtils.writeFFTBenchmarkResultsToFile("benchmarkDoubleForwardDHT_2D_input_1D.txt", nthread, niter, doWarmup, doScaling, sizes2D, times); 175 176 } 177 benchmarkForward_2D_input_2D()178 public static void benchmarkForward_2D_input_2D() { 179 double[] times = new double[nsize]; 180 double[][] x; 181 for (int i = 0; i < nsize; i++) { 182 System.out.println("Forward DHT 2D (input 2D) of size " + sizes2D[i] + " x " + sizes2D[i]); 183 DoubleDHT_2D dht2 = new DoubleDHT_2D(sizes2D[i], sizes2D[i]); 184 x = new double[sizes2D[i]][sizes2D[i]]; 185 if (doWarmup) { // call the transform twice to warm up 186 IOUtils.fillMatrix_2D(sizes2D[i], sizes2D[i], x); 187 dht2.forward(x); 188 IOUtils.fillMatrix_2D(sizes2D[i], sizes2D[i], x); 189 dht2.forward(x); 190 } 191 double av_time = 0; 192 long elapsedTime = 0; 193 for (int j = 0; j < niter; j++) { 194 IOUtils.fillMatrix_2D(sizes2D[i], sizes2D[i], x); 195 elapsedTime = System.nanoTime(); 196 dht2.forward(x); 197 elapsedTime = System.nanoTime() - elapsedTime; 198 av_time = av_time + elapsedTime; 199 } 200 times[i] = (double) av_time / 1000000.0 / (double) niter; 201 System.out.println("Average execution time: " + String.format("%.2f", av_time / 1000000.0 / (double) niter) + " msec"); 202 x = null; 203 dht2 = null; 204 System.gc(); 205 ConcurrencyUtils.sleep(5000); 206 } 207 IOUtils.writeFFTBenchmarkResultsToFile("benchmarkDoubleForwardDHT_2D_input_2D.txt", nthread, niter, doWarmup, doScaling, sizes2D, times); 208 209 } 210 benchmarkForward_3D_input_1D()211 public static void benchmarkForward_3D_input_1D() { 212 double[] times = new double[nsize]; 213 double[] x; 214 for (int i = 0; i < nsize; i++) { 215 System.out.println("Forward DHT 3D (input 1D) of size " + sizes3D[i] + " x " + sizes3D[i] + " x " + sizes3D[i]); 216 DoubleDHT_3D dht3 = new DoubleDHT_3D(sizes3D[i], sizes3D[i], sizes3D[i]); 217 x = new double[sizes3D[i] * sizes3D[i] * sizes3D[i]]; 218 if (doWarmup) { // call the transform twice to warm up 219 IOUtils.fillMatrix_3D(sizes3D[i], sizes3D[i], sizes3D[i], x); 220 dht3.forward(x); 221 IOUtils.fillMatrix_3D(sizes3D[i], sizes3D[i], sizes3D[i], x); 222 dht3.forward(x); 223 } 224 double av_time = 0; 225 long elapsedTime = 0; 226 for (int j = 0; j < niter; j++) { 227 IOUtils.fillMatrix_3D(sizes3D[i], sizes3D[i], sizes3D[i], x); 228 elapsedTime = System.nanoTime(); 229 dht3.forward(x); 230 elapsedTime = System.nanoTime() - elapsedTime; 231 av_time = av_time + elapsedTime; 232 } 233 times[i] = (double) av_time / 1000000.0 / (double) niter; 234 System.out.println("Average execution time: " + String.format("%.2f", av_time / 1000000.0 / (double) niter) + " msec"); 235 x = null; 236 dht3 = null; 237 System.gc(); 238 ConcurrencyUtils.sleep(5000); 239 } 240 IOUtils.writeFFTBenchmarkResultsToFile("benchmarkDoubleForwardDHT_3D_input_1D.txt", nthread, niter, doWarmup, doScaling, sizes3D, times); 241 242 } 243 benchmarkForward_3D_input_3D()244 public static void benchmarkForward_3D_input_3D() { 245 double[] times = new double[nsize]; 246 double[][][] x; 247 for (int i = 0; i < nsize; i++) { 248 System.out.println("Forward DHT 3D (input 3D) of size " + sizes3D[i] + " x " + sizes3D[i] + " x " + sizes3D[i]); 249 DoubleDHT_3D dht3 = new DoubleDHT_3D(sizes3D[i], sizes3D[i], sizes3D[i]); 250 x = new double[sizes3D[i]][sizes3D[i]][sizes3D[i]]; 251 if (doWarmup) { // call the transform twice to warm up 252 IOUtils.fillMatrix_3D(sizes3D[i], sizes3D[i], sizes3D[i], x); 253 dht3.forward(x); 254 IOUtils.fillMatrix_3D(sizes3D[i], sizes3D[i], sizes3D[i], x); 255 dht3.forward(x); 256 } 257 double av_time = 0; 258 long elapsedTime = 0; 259 for (int j = 0; j < niter; j++) { 260 IOUtils.fillMatrix_3D(sizes3D[i], sizes3D[i], sizes3D[i], x); 261 elapsedTime = System.nanoTime(); 262 dht3.forward(x); 263 elapsedTime = System.nanoTime() - elapsedTime; 264 av_time = av_time + elapsedTime; 265 } 266 times[i] = (double) av_time / 1000000.0 / (double) niter; 267 System.out.println("Average execution time: " + String.format("%.2f", av_time / 1000000.0 / (double) niter) + " msec"); 268 x = null; 269 dht3 = null; 270 System.gc(); 271 ConcurrencyUtils.sleep(5000); 272 } 273 IOUtils.writeFFTBenchmarkResultsToFile("benchmarkDoubleForwardDHT_3D_input_3D.txt", nthread, niter, doWarmup, doScaling, sizes3D, times); 274 } 275 main(String[] args)276 public static void main(String[] args) { 277 parseArguments(args); 278 benchmarkForward_1D(); 279 benchmarkForward_2D_input_1D(); 280 benchmarkForward_2D_input_2D(); 281 benchmarkForward_3D_input_1D(); 282 benchmarkForward_3D_input_3D(); 283 System.exit(0); 284 285 } 286 } 287