MOdify the program below to do 3×3 matrix mutiplications: #include #include #include using…

Homework Help Question & Answers

MOdify the program below to do 3×3 matrix mutiplications: #include #include #include using…

MOdify the program below to do 3×3 matrix mutiplications:

#include

#include

#include

using namespace std;

int A[3] [3] = {{1,2},{3,4}};

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

int C[3] [3];

struct Position{

    int row;

    int col;

};

void *CalculateElement(void *pos){

    Position *p = (Position *)pos;

    C[p->row][p->col] = 0;

    for(int i = 0; i

        C[p->row][p->col] += A[p->row][i]*B[i][p->col];

    }

    pthread_exit(NULL);

}

const int NUM_THREADS = 4;

int main()

{

    pthread_t threads[NUM_THREADS];

    for(int i = 0; i

        Position *p = new Position;

        p->row = i/NUM_THREADS;

        p->col = i%NUM_THREADS;

        pthread_create(&threads[i], NULL, CalculateElement, (void *)p);

    }

   for(int i = 0; i

        pthread_join(threads[i], NULL);

    }

    cout

    for(int i = 0; i

        for(int j = 0; j

            cout

        }

        cout

    }

}

0 0
Add a comment
Reference no: EM132069492

GET HELP WITH YOUR PAPERS

GET THIS ANSWER FROM EXPERTS NOW

WhatsApp
Hello! Need help with your assignments? We are here
Don`t copy text!