Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void method2()
- {
- int i,j;
- struct place *a;
- a=(struct place*)malloc(sizeof(struct place));
- pthread_t threads[rowSize1*colSize2]; /* descriptors of threads */
- for(i = 0; i < rowSize1; i++) /* create threads */
- {
- for(j=0; j<colSize2; j++)
- {
- a->r=i;
- a->c=j;
- if (pthread_create(&threads[i*j], NULL, executeMethod2, (void *)a))
- {
- printf("Can not create a thread\n");
- exit(1);
- }
- }
- }
- for(i = 0; i < rowSize1; i++) /* create threads */
- {
- for(j=0; j<colSize2; j++)
- {
- int value; /* value returned by thread */
- pthread_join(threads[i*j], (void **)&value);
- outputMatrix2[i][j]=value;
- printf("%d ",outputMatrix2[i][j]);
- }
- printf("\n");
- }
- }
- void *executeMethod2(void *a)
- {
- int ans=0;
- struct place *b;
- b=(struct place *)a;
- int n = b->r; /* index of current row in the first matrix*/
- printf("%d current row\n",n);
- int m = b->c;/* index of current column in the second matrix*/
- printf("%d current col\n",m);
- int i,j;
- for(i=0; i<colSize1; i++)
- {
- for(j=0; j<rowSize2; j++)
- {
- ans+=matrix1[n][i]*matrix2[j][m];
- }
- }
- /* terminate a thread and return the ans of multiplication */
- pthread_exit((void*)ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement