or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
![image alt](https:// "title") | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | Emoji list | ||
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
A07: mergesort-concurrent
contributed by <
snoopy831002
>作業要求
sort -R
處理過code review
ThreadPool:
程式碼內有兩用到threadpool
cut_func()將會被視為一個工作丟入queue
所以基本上切割時都是用threadpool的方式
觀察main函式
流程: cut_func() → merge_sort()→ merge_list() → merge()
cut_func() : 切割輸入的linked list
這裡有比較特別,他有做把資料平均分給每個thread的動作
如果data比thread多就把data平均切割給thread;如果data比thread少那就按照data的數量去切(例如:4個data,切三次就好)
code refactoring
cut_func
與merge_sort
有重複的地方,覺得這兩個地方可以合併ㄛ使用GDB對segmentation fault(core dump)進行偵錯
做這份作業的時候常常會遇到segmentation fault(core dump)的問題。為了解決它,我嘗試使用GDB對它進行偵錯。
使用方法:
gdb sort
run 4 6
←run後面可以加入參數案例分析: mergesort-concurrent
(1)測試
make
./sort [num of thread] [num of input]
(2)修正資料的輸入方式,改由外部引入
(3)資料輸入
uniq words.txt | sort -R > input.txt
uniq
可以去掉資料中重複的部份,而sort
則可以-R
(random)做隨機排序。sort -R
也可用shuf
代替參考資料
使用gdb偵錯segmentation fault