Advertisement
Guest User

method 2 error

a guest
Oct 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. void method2()
  2. {
  3. int i,j;
  4. struct place *a;
  5. a=(struct place*)malloc(sizeof(struct place));
  6.  
  7. pthread_t threads[rowSize1*colSize2]; /* descriptors of threads */
  8. for(i = 0; i < rowSize1; i++) /* create threads */
  9. {
  10. for(j=0; j<colSize2; j++)
  11. {
  12. a->r=i;
  13. a->c=j;
  14. if (pthread_create(&threads[i*j], NULL, executeMethod2, (void *)a))
  15. {
  16. printf("Can not create a thread\n");
  17. exit(1);
  18. }
  19.  
  20. }
  21.  
  22. }
  23. for(i = 0; i < rowSize1; i++) /* create threads */
  24. {
  25. for(j=0; j<colSize2; j++)
  26. {
  27. int value; /* value returned by thread */
  28. pthread_join(threads[i*j], (void **)&value);
  29. outputMatrix2[i][j]=value;
  30. printf("%d ",outputMatrix2[i][j]);
  31. }
  32. printf("\n");
  33. }
  34. }
  35. void *executeMethod2(void *a)
  36. {
  37. int ans=0;
  38. struct place *b;
  39. b=(struct place *)a;
  40. int n = b->r; /* index of current row in the first matrix*/
  41. printf("%d current row\n",n);
  42. int m = b->c;/* index of current column in the second matrix*/
  43. printf("%d current col\n",m);
  44.  
  45. int i,j;
  46. for(i=0; i<colSize1; i++)
  47. {
  48. for(j=0; j<rowSize2; j++)
  49. {
  50. ans+=matrix1[n][i]*matrix2[j][m];
  51. }
  52. }
  53. /* terminate a thread and return the ans of multiplication */
  54. pthread_exit((void*)ans);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement