| Home | OR-Objects | Tutorials | Prev |
In this tutorial you will develop an applet to measure the scalability of the matrix multiply in the parallel BLAS implementation. The applet computes the rate of floating point operations for thread counts of '1' to '16'. The rate will scale on Java virtual machines that use native threads and are running on an SMP platform that distributes threads across multiple processors. In the freeware version of OR-Objects, the cache coherency is highest if matrix A is row-major and matrix B is column-major.
For simplicity, the applet details will be skipped. If you would like to see all the details then view the complete source.
public ContiguousMatrixI
buildMatrix(String type, int mChoice, int nChoice)
{
ContiguousMatrixI A = null;
if(type.equals("RowMajor")){
A = new RowMajorMatrix(mChoice,nChoice);
}
else if(type.equals("ColumnMajor")){
A = new ColumnMajorMatrix(mChoice,nChoice);
}
new UniformDistribution().setElements(A);
return A;
}
The first few lines of the method 'test' get the parameters and call 'buildMatrix'
to create the three matrices.
public void
test()
{
int m = new Integer(mChoice.getSelectedItem()).intValue();
int n = new Integer(nChoice.getSelectedItem()).intValue();
int k = new Integer(kChoice.getSelectedItem()).intValue();
double alpha = new Double(alphaChoice.getSelectedItem()).doubleValue();
double beta = new Double(betaChoice.getSelectedItem()).doubleValue();
ContiguousMatrixI A = buildMatrix(typea.getSelectedItem(), m, k);
ContiguousMatrixI B = buildMatrix(typeb.getSelectedItem(), k, n);
ContiguousMatrixI C = buildMatrix(typec.getSelectedItem(), m, n);
values = null; paint(getGraphics()); SmpBLAS3 smp = new SmpBLAS3(); smp.getSmp().setMinWork(0); MatrixBLAS3 blas3 = new MatrixBLAS3(0, smp);
double max=0, min=0;
values = new double[maxBars];
for(int i=0; i<maxBars; i++){
smp.getSmp().setMaxThreads(i+1);
msgLabel.setText("Threads - "+(i+1));
int it = 0;
long time = 0;
while(time < 1000){
Date t1 = new Date();
try{blas3.dgemm(false, false, alpha, A, B, beta, C);}
catch(BlasException e){}
Date t2 = new Date();
time += t2.getTime() - t1.getTime();
it++;
}
double t = 1000.0 * (double)time;
double mflops = ((double)(m*n*(2*k+3)*it))/t;
System.out.println(mflops);
values[i] = mflops;
if(i == 0 || mflops > max) max = mflops;
if(i == 0 || mflops < min) min = mflops;
}
msgLabel.setText("MFLOPS: max = "+(int)(max+0.5)+", min = "+(int)(min+0.5));
paint(getGraphics());
![]() |
|
![]() |