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).


  1. hello there,
    would you please give a bit more description what is the machine environment (maybe you gave it but I couldn't find)? on my machine the OPL stuff takes less than 10sec

  2. My PC is somewhat old with a Quad Core Q6700 @ 2.67 Ghz. so these numbers should only be looked at in relative terms.