60 likes | 160 Views
矩陣乘法. 實作矩陣 乘法 利用 threads 來 加速運算速度 Matrix1 row x Matrix2 column = Ans ( x,y ). Matrix 1. Matrix 2. Answer. 要求說明. 不限制 threads 多少 , 但一定要開 2 個以上 . 主程式也可以做運算 . Bonus(+10%) 可利用其他方法來加速矩陣乘法的速度 速度越 快 會有額外加分. The Sleeping-Barber Problem.
E N D
矩陣乘法 • 實作矩陣乘法 • 利用threads來加速運算速度 • Matrix1row xMatrix2column = Ans(x,y) Matrix 1 Matrix 2 Answer
要求說明 • 不限制threads多少, 但一定要開2個以上. • 主程式也可以做運算. • Bonus(+10%) • 可利用其他方法來加速矩陣乘法的速度 • 速度越快會有額外加分
The Sleeping-Barber Problem. • A barbershop consists of a waiting room with s seats and a barber room with one barber chair. • There are c customers and one barber. Customers alternate between growing hair and getting ahaircut. The barber sleeps and cuts hair. If there are no customers to be served, the barber sleeps. • If a customer wants a haircut and all chairs are occupied, then the customer leaves the shop andskips the haircut. If chairs are available but the barber is busy, then the customer waits in one of theavailable chairs until the barber is free. If the barber is asleep, the customer wakes up the barber.
要求說明 • 利用以下條件來實作Sleeping-Barber problem的方法 • 5個學生(customers c) • 1個管理員(Barber b) • 每次預約限制2個學生(chairs) • 5台的機器(buffer) • 學生利用機器的時間(wait time) • 假設每個學生都要找管理員預約機器來做作業, 但機器只有5台, 每個學生要使用機器的數目在1-5台內, 管理員要負責登記機器的使用狀況, 隨機或連續選擇機器都可以.
範例 • 學生A,B,C,D,E 管理員admin 機器0-4使用人數K=2 • A學生要用2台機器做作業 • A學生找admin登記要用2台機器(1,2),需要1hr, K=2-1 • B學生要用2台機器做作業 • B學生找admin登記要用2台機器(3,4),需要2hr , K=1-1 • A學生作業完成 • A學生找admin登記使用完成,release(1,2), K=0+1 • C學生要用2台機器做作業 • C學生找admin登記要用2台機器(1,3),需要1hr, K=1-1. 因為B學生在使用第3台機器, 因此C學生要等B學生釋放第3台機器才開始做作業 • …
範例(bonus) • 學生A,B,C,D,E 管理員admin 機器0-4 使用人數K=2 • A學生要用2台機器做作業 • A學生找admin登記要用2台機器(1,2),需要1hr, K=2-1 • B學生要用2台機器做作業 • B學生找admin登記要用2台機器(3,4),需要2hr , K=1-1 • A學生作業完成 • A學生找admin登記使用完成,release(1,2), K=0+1 • C學生要用2台機器做作業 • C學生找admin登記要用2台機器(1,3),需要1hr, K=1-1. 因為B學生在使用第3台機器, 但第1台機器並不在使用中, 所以C學生可以先利用第1台機器, 等到第3台機器可以使用再使用第3台機器. • …