Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computer-Science This is done in ubuntu using text editor. The goal is to have d

ID: 3669787 • Letter: C

Question

Computer-Science

This is done in ubuntu using text editor. The goal is to have different threads calculate the result matrix c (calculate the rows) and output that matrix c. These are my values, but i dont know where to go from here.

Your overall goal is to write a matrix multiplication program where the work of calculating the product matrix is distributed among multiple threads created using the pthread library. To this end, your program must do the followin g: 1. Define two global matrices AKITY] & BYM[Z] to store the two matrices to be multiplied. X and Y must be set using a #define directive. Define a global matrix C[XZ] to store the product of matrices A and B. Once again, Z must be set using a #denne directive. 2. Define a pthread function called pthread multiply to perform the actual matrix multiplication operation (Note: Recall that a pthread function must have a very specific prototype). As a starting point, a regular (non-threaded) function for matrix multiplication, called multiply, has been provided below 3. xoid multiplyO int row.colinner: for (row = 0; row x; row++) { for (col = o; col

Explanation / Answer

# include <stdio.h>

# include <pthread.h>

//declaring A,B,C global matrixs

int A [X][Y] = { {1,4}, {2,5}, {3,6} };

int B [Y][Z] = { {8,7,6}, {5,4,3} };

int C [X][Z];

int r1=3,c1=2,r2=2,c2=3;

void *thread_Multiply_Matrix(void *);

int main()

{

    pthread_t tid;   

    int iCount,jCount,kCount;

    //checking whteher multiplication is possible or not

   

    if(c1!=r2)

    {

        printf("Multipication of Matrix not Possible !!!");

    }

    else

    {

        for(iCount=0;iCount<r1;iCount=iCount+2)

        {

            for(jCount=0;jCount<c2;jCount=jCount+2)

            {

                C [X][Z]=0;

            }

        }

        //creating thread using pthread_create() in thread_Multiply_Matrix method

        pthread_create(&tid,NULL,thread_Multiply_Matrix,NULL);

       

        for(iCount=0;iCount<r1;iCount=iCount+2)

        {

            for(jCount=0;jCount<c2;jCount++)

            {

                for(kCount=0;kCount<c1;kCount++)

                {

                    C [iCount][jCount]+=A[iCount][kCount] * B[kCount][jCount];

                }

            }

        }

       

        pthread_join(tid,NULL);

    }

   

    printf(" Matrix 1 ");

   

    for(iCount=0;iCount<r1;iCount++)

    {

        for(jCount=0;jCount<c1;jCount++)

        {

            printf("%d ",A[iCount][jCount]);

        }

        printf(" ");

    }   

   

    printf(" Matrix 2 ");

   

    for(iCount=0;iCount<r2;iCount++)

    {

        for(jCount=0;jCount<c2;jCount++)

        {

            printf("%d ",B[iCount][jCount]);

        }

        printf(" ");

    }   

   

    printf(" Multipication of Matrix ... ");

   

    for(iCount=0;iCount<r1;iCount++)

    {

        for(jCount=0;jCount<c2;jCount++)

        {

            printf("%d ",C[iCount][jCount]);

        }

        printf(" ");

    }   

    return 0;

}

void *thread_Multiply_Matrix(void *para)

{

    int iCount,jCount,kCount;

    for(iCount=1;iCount<r1;iCount=iCount+2)

        {

            for(jCount=0;jCount<c2;jCount++)

            {

                for(kCount=0;kCount<c1;kCount++)

                {                   

                    MAT3[iCount][jCount]+=MAT1[iCount][kCount] * MAT2[kCount][jCount];

                }

            }

        }

       

    printf("thread finished ...");

    pthread_exit(NULL);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote