Piecework Matrix Product

In this program, the JICOS  client:
  1. dispatches multiple concurrent computations, using the setComputation method;
  2. gets the result of each computation as it becomes available, using the getResult method;
  3. composes the results of these computations into an overall result.
This is illustrated in a simple way, using a matrix product computation. The JICOS  client actually computes  B = A2, where matrix A is square. The size of A is the product of 2 parameters:
  1. blocksize
  2. number of blocks.
The client is passed these 2 parameters through the command line.

If the operand matrices are of dimension n, and the blocksize is b, then each matrix decomposes into n/b x n/b blocks (i.e. submatrices): There are (n/b)3 submatrix product tasks. When the result of a submatrix product task is returned to the client, the submatrix is added to the appropriate submatrix of the product matrix.

We use the Jicos's input capability to transmit the operand matrices to the hosts: Each submatrix product task is small because it is characterized by only 4 int values:

  • the starting row block of the left matrix
  • the starting column block of the left matrix
  • the starting column block of the right matrix
  • the block size.
The return type of a SubMatrixProductTask is a SubMatrixProduct, which contains:
  • the destination within the product matrix of the submatrix product. This is given as a row block and column block in the product matrix.
  • The submatrix product, which has (blocksize x blocksize) entries.

The classes

This program comprises the following classes:
  • Application.java: the class whose main method creates the input matrices, dispatches the submatrix product tasks, and composes the matrix product from the submatrix products.
  • SubMatrixProductTask.java: the class whose execute method encapsulates the submatrix product computation.
  • SubMatrixProduct: a container class, that has which submatrix product it is, and its value.
  • Matrix.java: a class, which, besides its constructors, has the following other methods:
    • oneMatrix, which makes a matrix of all 1's
    • addSubMatrix, which adds a submatrix to this.

Output

With a block size of  4 and the number of blocks = 5, the client produces 2 matrices of size 20 whose entries are all 1. The product of these matrices is a 20 x 20 matrix use entries are all 20. The client produces the following output:

row 0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 1: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 2: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 3: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 4: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 5: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 6: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 7: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 8: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 9: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 11: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 12: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 13: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 14: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 15: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 16: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 17: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 18: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 row 19: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20