Matrix multiplication with OpenMP parallel for loop I tried implementing matrix multiplication with parallel for loop in OpenMP as follows. It runs correctly but I want to make sure if I'm missing anything. How does this determine the number of threads to run?

Matrix is a class for square matrices. 

#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;vector&gt;
# include &lt;omp.h&gt;

Matrix parallel_mat_mul(Matrix a, Matrix b)
{
    int n =a.getSize();
    Matrix c(n); 
    clock_t begin_time = clock();
    # pragma omp parallel shared ( a, b, c, n  ) // private ( i, j, k )
    {
        # pragma omp for
        for ( int i = 0; i &lt; n; i++ )
        {
            for (int j = 0; j &lt; n; j++ )
            {
                double local_sum=0;
                for ( int k = 0; k &lt; n; k++ )
                {
                    local_sum+= (a(i,k)*b(k,j));
                }
                c(i,j)=local_sum;
            }
        }

    }
    cout &lt;&lt; "Parallel time: "&lt;&lt;float( clock () - begin_time ) / CLOCKS_PER_SEC  &lt;&lt;"\n";
    return c;
}
There is a real problem with your code in that you pass the matrices by copy.

Matrix parallel_mat_mul(Matrix a, Matrix b)


This should really be either passed by reference

Matrix parallel_mat_mul(const Matrix&amp; a, const Matrix&amp; b)


Or implemented through an operator of the Matrix class

operator+(const Matrix&amp; other) const


Nevertheless to better judge this function one would need the implementation of Matrix