edu.mines.jtk.bench.MtMatMulBench Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edu-mines-jtk Show documentation
Show all versions of edu-mines-jtk Show documentation
Java packages for science and engineering
The newest version!
/****************************************************************************
Copyright 2006, Colorado School of Mines and others.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
****************************************************************************/
package edu.mines.jtk.bench;
import static java.lang.Math.min;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import edu.mines.jtk.util.*;
import static edu.mines.jtk.util.ArrayMath.*;
/**
* Benchmark single- and multi-threaded matrix multiplication.
* @author Dave Hale, Colorado School of Mines
* @version 2006.07.02
*/
public class MtMatMulBench {
public static final int NTHREAD =
Runtime.getRuntime().availableProcessors();
public static void main(String[] args) {
int m = 1001;
int n = 1002;
float[][] a = randfloat(n,m);
float[][] b = randfloat(m,n);
float[][] c1 = zerofloat(m,m);
float[][] c2 = zerofloat(m,m);
float[][] c3 = zerofloat(m,m);
float[][] c4 = zerofloat(m,m);
float[][] c5 = zerofloat(m,m);
Stopwatch s = new Stopwatch();
double mflops = 2.0e-6*m*m*n;
double maxtime = 5.0;
System.out.println("Matrix multiply benchmark");
System.out.println("m="+m+" n="+n+" nthread="+NTHREAD);
System.out.println("Methods:");
System.out.println("mul1 = single-threaded");
System.out.println("mul2 = multi-threaded (equal chunks)");
System.out.println("mul3 = multi-threaded (atomic-integer)");
System.out.println("mul4 = multi-threaded (thread-pool)");
System.out.println("mul5 = multi-threaded (fork-join)");
for (int ntrial=0; ntrial<3; ++ntrial) {
System.out.println();
int nmul;
s.restart();
for (nmul=0; s.time() cs = new ExecutorCompletionService(es);
for (int j=0; j
© 2015 - 2025 Weber Informatics LLC | Privacy Policy