0% found this document useful (0 votes)
5 views1 page

Daa 7

This C++ code defines 2 matrices A and B of size 3x3 and multiplies them to calculate the resultant matrix C using multiple threads, with each thread calculating one row of the result matrix.

Uploaded by

subhamkale4311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Daa 7

This C++ code defines 2 matrices A and B of size 3x3 and multiplies them to calculate the resultant matrix C using multiple threads, with each thread calculating one row of the result matrix.

Uploaded by

subhamkale4311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

#include <thread>
#include <vector>
#define SIZE 3
Int A[SIZE][SIZE] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
Int B[SIZE][SIZE] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
Int C[SIZE][SIZE] = {0};
Void multiply(int row) {
For (int col = 0; col < SIZE; col++) {
For (int k = 0; k < SIZE; k++) {
C[row][col] += A[row][k] * B[k][col]; } }}
Int main() {
Std::vector<std::thread> threads;
For (int I = 0; I < SIZE; i++) {
Threads.push_back(std::thread(multiply, i)); }
For (auto &t : threads) {
t.join(); }
Std::cout << “Resultant Matrix after multiplication:” << std::endl;
For (int I = 0; I < SIZE; i++) {
For (int j = 0; j < SIZE; j++) {
Std::cout << C[i][j] << “ “; }
Std::cout << std::endl; }
Return 0;
}

You might also like