矩陣乘法的多執行緒實現(C 語言)

2021-10-01 22:41:11 字數 2394 閱讀 9512

多執行緒矩陣的乘法,禁止不加改動用於課設,僅供參考。

// multhread_martix_mul.cpp : 此檔案包含 "main" 函式。程式執行將在此處開始並結束。

//#include "pch.h"

#include #include #include "windows.h"

#include #include #include template class martix

martix(const int size)}}

const t &get_x_y(const int i, const int j) const

t &get_x_y(const int i, const int j)

void serial_mul(const martix&a, const martix&b)

}void accelerate_serial_mul(const martix&a, const martix&b)

}void line_parall_mul_block(const martix&a, const martix&b, const int star, const int end)

}void line_parall_mul(const martix&a, const martix&b, cosnt int thread_num)

thread_s.push_back(std::thread(&martix::line_parall_mul_block, this, std::cref(a), std::cref(b), cur_end + 1, p_size)); //最後乙個核心是餘數

for (auto &t : thread_s)

t.join();

}void accelerate_line_parall_mul_block(const martix&a, const martix&b, const int star, const int end)

}void accelerate_line_parall_mul(const martix&a, const martix&b, cosnt int thread_num)

thread_s.push_back(std::thread(&martix::accelerate_line_parall_mul_block, this, std::cref(a), std::cref(b), cur_end + 1, p_size)); //最後乙個核心是餘數

for (auto &t : thread_s)

t.join();

}~martix() {}

};int main()

mini;

mini.spend_time = int_max;

mini.thread_num = 0;

const int size = 6400;

martixa(size);

martixb(size);

martixc(size);

int star, end;

/* int thread_num;

double serial_time;

double acc_serial_time; */

std::vectoracc_para_time;

std::cout << "(double)矩陣大小為:" << size << std::endl;

/* std::cout << "快取不友好序列用時(ms):";

star = clock();

c.serial_mul(a, b);

end = clock();

std::cout << end - star << std::endl;

serial_time = static_cast(end - star);

std::cout<<"系統暫停60s"<(end - star);

if (end - star < mini.spend_time)

std::cout<<"系統暫停60s"<(end - star));

if (end - star < mini.spend_time)

std::cout<<"系統暫停60s"<「開始執行(不除錯)」選單

// 除錯程式: f5 或除錯 >「開始除錯」選單

// 1. 使用解決方案資源管理器視窗新增/管理檔案

// 2. 使用團隊資源管理器視窗連線到源**管理

// 3. 使用輸出視窗檢視生成輸出和其他訊息

// 4. 使用錯誤列表視窗檢視錯誤

// 5. 轉到「專案」>「新增新項」以建立新的**檔案,或轉到「專案」>「新增現有項」以將現有**檔案新增到專案

// 6. 將來,若要再次開啟此專案,請轉到「檔案」>「開啟」>「專案」並選擇 .sln 檔案

C語言實現矩陣乘法

產生a 5行4列 b 4行3列 兩個隨機矩陣,每個元素是 10,10 之間的隨機整數並列印出來,列印出它們的乘積c矩陣。要求矩陣用 分隔開,以a,b,c的順序列印,各行對齊。include stdafx.h include include include include pragma warning...

矩陣乘法的c語言實現

矩陣乘法的c語言程式 include int main 賦值使陣列s元素初值全部為零 printf 請輸入矩陣a行數m1,列數n1 輸入矩陣a行數,列數 scanf d,d m1,n1 printf 請輸入矩陣b行數m2,列數n2 輸入矩陣b行數,列數 scanf d,d m2,n2 printf ...

C語言 矩陣乘法

問題描述 給定乙個n階矩陣a,輸出a的m次冪 m是非負整數 例如 a 1 23 4 a的2次冪 7 10 15 22 輸入格式 第一行是乙個正整數n m 1 n 30,0 m 5 表示矩陣a的階數和要求的冪數 接下來n行,每行n個絕對值不超過10的非負整數,描述矩陣a的值 輸出格式 輸出共n行,每行...