package jicos.examples.pieceworkmatrixproduct; import jicos.examples.pieceworkmatrixproduct.*; import jicos.services.*; import java.rmi.*; final class Application { final static int BLOCKSIZE = 4; public static void main ( String args[] ) throws RemoteException, InterruptedException { String hspDomainName = args[ 0 ]; // get a remote reference to an Hsp HspAgent agent = new HspAgent( hspDomainName ); Client2Hsp hsp = agent.getClient2Hsp(); // register with HSP int n = Integer.parseInt( args[1] ); Matrix matrix = Matrix.makeMatrix( n ); Object[] matrices = { matrix, matrix }; Environment environment = new Environment( matrices, null ); hsp.login( environment ); // construct, spawn submatrix product tasks for( int i = 0; i < n; i += BLOCKSIZE ) for( int j = 0; j < n; j += BLOCKSIZE ) for( int k = 0; k < n; k += BLOCKSIZE ) { short compId = (short) ( i*BLOCKSIZE + j + k/BLOCKSIZE ); Task t = new MatrixProduct( i, k, j, BLOCKSIZE ); hsp.compute( t, compId ); } // initialize product Matrix p = new Matrix( n ); // retrieve, process Results int $results = ( n/BLOCKSIZE ) * ( n/BLOCKSIZE ) * ( n/BLOCKSIZE ); for( int l = 0; l < $results; l ++ ) { Result result = hsp.getResult(); int compId = result.getId(); compId /= BLOCKSIZE; int row = ( compId / BLOCKSIZE ) * BLOCKSIZE; int col = ( compId % BLOCKSIZE ) * BLOCKSIZE; Matrix d = (Matrix) result.getValue(); p.addSubMatrix( d, row, col, d.m.length, d.m[0].length ); } // unregister from HSP, print product hsp.logout(); p.print(); } }