Tushar.bar
Journeyman
HI all , one of my friend was challenged by me that to make a program to multiply two matrix and display result.
but rule is using only one one dimensional array.
he wright the prog in java, but i don't know java(only c,c++)
so can any check that
1>Is the code is working?
2>How many array he takes for it?
3>how many array he use?
but rule is using only one one dimensional array.
he wright the prog in java, but i don't know java(only c,c++)
so can any check that
1>Is the code is working?
2>How many array he takes for it?
3>how many array he use?
void forkJoinMatrixMultiply(
final double[][] a,
final double[][] b,
final double[][] c) {
check(a,b,c);
final int m = a.length;
final int n = b.length;
final ParallelDoubleArray cols = ParallelDoubleArray.createUsingHandoff(b[0],
ParallelDoubleArray.defaultExecutor());
cols.replaceWithMappedIndex(new Ops.IntAndDoubleToDouble() {
public double op(final int j, final double element) {
final double[] Bcolj = new double[n]; // allocated inside the op, not "outside the loop"
for (int k = 0; k < n; k++) {
Bcolj[k] = b[k][j];
}
for (int i = 0; i < m; i++) {
final double[] Arowi = a;
double s = 0;
for (int k = 0; k < n; k++) {
s += Arowi[k] * Bcolj[k];
}
c[j] = s;
}
return element;
}
});
}
Last edited: