title: pthreads multi-threaded matrix multiplication
body: <p>I'm currently trying to write a C++ program with pthreads.h for multi-threaded matrix multiplication. </p>
  
  <p>I'm trying to create the threads as follows</p>
  
  <pre><code>int numthreads = (matrix[0].size() * rsize2);//Calculates # of threads needed
  pthread_t *threads;
  threads = (pthread_t*)malloc(numthreads * sizeof(pthread_t));//Allocates memory for threads
  int rc;
  for (int mult = 0; mult &lt; numthreads; mult++)//rsize2
  {
      struct mult_args args;
      args.row = mult;
      args.col = mult;
      cout &lt;&lt; "Creating thread # " &lt;&lt; mult;
      cout &lt;&lt; endl;
      rc = pthread_create(&amp;threads[mult], 0, multiply(&amp;args), 0);
  }
  </code></pre>
  
  <p>This then creates threads that execute my multiply function which is coded as follows</p>
  
  <pre><code>void *multiply(int x, int y)
  {
      int oldprod = 0, prod = 0, sum = 0;
      cout &lt;&lt; "multiply";
  
      for(int i = 0; i &lt; rsize2; i++)//For each row in #ofrows in matrix 2
      {
          prod = matrix[x][i] * matrix2[i][y];//calculates the product
          sum = oldprod + prod; //Running sum starting at 0 + first product
          oldprod = prod; //Updates old product
      }
  </code></pre>
  
  <p>My error lies in my multiply function. I'm trying to find a compatible way to pass in an x and y coordinate for each thread so it knows specifically which summation to calculate but i'm not sure how to do this in a way that is acceptable for the pthreads_create() function.</p>
  
  <p>Update:
  I know that I have to use a struct to accomplish this</p>
  
  <pre><code>struct mult_args {
      int row;
      int col;
  };
  </code></pre>
  
  <p>but I can't get the multiply function to accept the struct</p>