Can anyone tell me what is wrong with this code?
I found it on Wikipedia
When I compile it it gives me a lot of errors

void parallel(int num_threads,int matrix_demention)
 int i;
 for(i=0;i<num_threads;i++)
   create_thread(&threads[i],i);
 pthread_attr_destroy(&attr); // Free attribute and wait for the other threads 
 for(i=0;i<p;i++)
   pthread_join(threads[i],NULL);

void *gauss(int thread_id)
 int i,k,j;
 for(k=0;k<matrix_demention-1;k++)
   if(thread_id==(k%num_thread))  //interleaved-row work distribution
 for(j=k+1;j<matrix_demention;j++)
     M[k][j]=M[k][j]/M[k][k];
     M[k][k]=1;
 barrier(num_thread,&mybarrier);      //wait for other thread finishing this round
   for(i=k+1;i<matrix_demention;i=i+1)
       if(i%p==thread_id)
          for(j=k+1;j<matrix_demention;j++)
          M[i][j]=M[i][j]-M[i][k]*M[k][j];
          M[i][k]=0;}
 barrier(num_thread,&mybarrier);
 return NULL;

void barrier(int num_thread, barrier_t * mybarrier)
  pthread_mutex_lock(&(mybarrier->barrier_mutex));
  mybarrier->cur_count++;
  if(mybarrier->cur_count!=num_thread)
       pthread_cond_wait(&(mybarrier->barrier_cond),&(mybarrier->barrier_mutex));
  else
      mybarrier->cur_count=0;
      pthread_cond_broadcast(&(mybarrier->barrier_cond));
  pthread_mutex_unlock(&(mybarrier->barrier_mutex));

What you have there appears to be the makings of 3 functions: parallel(), gauss(), and barrier().

The code does not adhere to the proper format of a c++ function.

Additionally, the functions are not associated with any main() driver or WinMain() entry point.

What you have there appears to be a code snippet taken out the context of a working program used as an example to teach some sort of algorithmic concept(s).

So.. if you wanted to actually use this code, it appears that you would have to code up some sort of multi-threaded program, format the above code as proper functions, and pass in the appropriate arguments.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.