Recently I've tried to write some parallel code using openMP as supported by Microsoft Visual Studio 2008.

The first test I've done is about the matrix product, but I wonder about the strange performances I've obtained.

I've measured the time spent in evaluation and obtained the following results:

A. Product of square matrices (700x700 sized)

1.[Debug] Sequential_time_spent = 8600 ms (mean value) (no relevant percentual changes if size changes)

Parallel_time_spent = 7300 ms (mean value)

1.[Release] Sequential_time_spent = 3900 ms (mean value) (no relevant percentual changes if size changes)

Parallel_time_spent = 5000 ms (mean value)

Strange!!! Maybe I'm wrong with the use of parallel clauses of openMP.

Someone has suggestions or knows 'something' about this behaviour?

Every matrix is created in the heap.

The code is really simple:

- Code: Select all
`typedef struct _Matrix`

{

int r;

int c;

double **m;

} Matrix;

/////////////////////////////

//Sequential product

/////////////////////////////

void product(Matrix* m1, Matrix* m2, Matrix* m3)

{

for(int i=0; i<m1->r; i++)

{

for(int j=0; j<m2->c; j++)

{

m3->m[i][j] = 0.0;

for(int k=0; k<m1->c; k++)

{

//Sleep(1);

m3->m[i][j] += m1->m[i][k] * m2->m[k][j];

}

}

}

}

/////////////////////////////

//Parallel product

/////////////////////////////

void product_p(Matrix* m1, Matrix* m2, Matrix* m3)

{

#pragma omp parallel for

for(int i=0; i<m1->r; i++)

{

for(int j=0; j<m2->c; j++)

{

m3->m[i][j] = 0.0;

for(int k=0; k<m1->c; k++)

{

//Sleep(1);

m3->m[i][j] += m1->m[i][k] * m2->m[k][j];

}

}

}//end parallel for

}