package test;
/**
* @Title: MultiThreadMatrix.java
* @Package matrix
* @Description: 多线程计算矩阵乘法
* @author Aloong
* @date 2010-10-28 下午09:45:56
* @version V1.0
*/
import java.util.Date;
public class MultiThreadMatrix
{
static int[][] matrix1;
static int[][] matrix2;
static int[][] matrix3;
static int m,n,k;
static int index;
static int threadCount;
static long startTime;
public static void main(String[] args) throws InterruptedException
{
//矩阵a高度m=100宽度k=80,矩阵b高度k=80宽度n=50 ==> 矩阵c高度m=100宽度n=50
m = 1024;
n = 1024;
k = 1024;
matrix1 = new int[m][k];
matrix2 = new int[k][n];
matrix3 = new int[m][n];
//随机初始化矩阵a,b
fillRandom(matrix1);
fillRandom(matrix2);
startTime = new Date().getTime();
//输出a,b
// printMatrix(matrix1);
// printMatrix(matrix2);
//创建线程,数量 <= 4
for(int i=0; i<4; i++)
{
if(index < m)
{
Thread t = new Thread(new MyThread());
t.start();
}else
{
break;
}
}
//等待结束后输出
while(threadCount!=0)
{
Thread.sleep(20);
}
// printMatrix(matrix3);
详细解决方案
多线程程序在单核CPU上运行,耗时为0毫秒是什么原因
热度:8161 发布时间:2013-02-26 00:00:00.0
相关解决方案