Simple and short:

I wrote 2 programs.

1 was single threaded and multiplied 2 matrices together.

This program below is the same as the first but using multiple threads.

Correct me if I'm wrong, but shouldnt the multithreaded version take less time to perform the matrix multiplication computation?

When I run both, the single threaded version takes less time to compute the multiplication.

can someone make sure im using thread.join() correctly - maybe iv used it in the wrong place/way?

btw, this is my first time using threads..

import java.io.*; import java.util.*; /** * * @author Ryan Davis * * Multi Thread * This program will read a matrix from a data file, transpose it, and then * multiply them. The program will output the time it took to multiply the * matrices. */ public class MatrixMultiThread { private static String file = "C:\\data1.txt"; private static final int rows = getRows(file); private static final int columns = getColumns(file); private static int[] temp = new int[rows*columns]; private static int[][] matrix = new int[rows][columns]; private static int[][] transpose = new int[columns][rows]; private static int[][] result = new int[rows][rows]; private static myThread[] threadPool; public static void main(String[] args){ System.out.println("rows: " + rows); System.out.println("columns: " + columns); readFile(file); buildMatrices(); multiply(); } private static int getColumns(String f){...} private static int getRows(String f){...} private static void readFile(String f){...} private static void buildMatrices(){...} /** * this method multiplies matrix and transpose together. the result matrix * is printed to the screen as well as the time in MS that it took to * perform the multiplication. note: the time of printing to the screen is * not included - strictly the computation time. */ private static void multiply(){ threadPool = new myThread[rows]; long start = System.nanoTime();//computation begins for(int i=0; i<rows; i++){ threadPool[i] = new myThread(i); threadPool[i].start(); try{ threadPool[i].join(); }catch (InterruptedException e){ //thread was interrupted } } long end = System.nanoTime();//computation ends double time = (end-start)/1000000.0; //print result matrix for(int i=0; i<rows; i++){ for(int j=0; j<rows; j++){ System.out.print(result[i][j] + " "); } System.out.println(); } System.out.println();//blank line System.out.println("Multiplication took " + time + " milliseconds."); } private static class myThread extends Thread{ int index; myThread(int index){ this.index = index; } public void run(){ for(int i=0; i<rows; i++){ for(int j=0; j<columns; j++){ result[index][i] += matrix[index][j] * transpose[j][i]; } } } } }