Thursday, June 17, 2010

sparse matmul revisited

In we time a (sparse and dense) matrix multiplication of two matrices (parameters). In OPL this can look like:
int N = 250;
{int} I = asSet(1..N);
float A[i in I][j in I] = (i==j)?1:0;
float B[i in I][j in I] = (i==j)?1:0;
//float A[i in I][j in I] = 1;
//float B[i in I][j in I] = 1;
float C[i in I][j in I] = sum(k in I) A[i,k]*B[k,j];
float s = sum(i in I, j in I) C[i,j];

The timings are included in the following table:

Model GNU Mathprog AMPL GAMS OPL
sparse (identity) 50 sec 3 sec 0.1 sec 17 sec
dense (all ones) 50 sec 3 sec 3 sec 17 sec
So in IBM OPL: no sparse processing, and a little bit slower than the other commercial modeling systems (but substantial faster than GNU's Mathprog).