contributed by < etc276
>
嵌入式
yangyang95
double compute_pi_leibniz (size_t N)
{
double pi = 0.0;
int tmp = 1;
for (size_t i = 0; i < N; i++) {
pi += tmp / (2.0 * (double)i + 1.0);
tmp *= (-1);
}
return 4 * pi;
}
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 61
Model name: Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz
Stepping: 4
CPU MHz: 2400.878
CPU max MHz: 3000.0000
CPU min MHz: 500.0000
BogoMIPS: 4788.90
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 4096K
NUMA node0 CPU(s): 0-3
$ make gencsv
以外的輸出機制,預期執行 $ make plot
後,可透過 gnuplot 產生前述多種實做的效能分析比較圖表$ make check
後查看各版本時間$ time ./time_test_baseline
N = 400000000 , pi = 3.141593
real 0m1.388s
user 0m1.376s
sys 0m0.004s
$ time ./time_test_openmp_2
N = 400000000 , pi = 3.141593
real 0m1.324s
user 0m2.632s
sys 0m0.000s
$ time ./time_test_openmp_4
N = 400000000 , pi = 3.141593
real 0m0.770s
user 0m2.768s
sys 0m0.000s
$ time ./time_test_avx
N = 400000000 , pi = 3.141593
real 0m0.922s
user 0m0.920s
sys 0m0.000s
$ time ./time_test_avxunroll
N = 400000000 , pi = 3.141593
real 0m0.721s
user 0m0.712s
sys 0m0.004s
gencsv: default
for i in `seq 100 5000 25000`; do \
printf "%d," $$i;\
./benchmark_clock_gettime $$i; \
done > result_clock_gettime.csv
for (i=100; i<=25000; i+=5000)
compute_pi(i);
查看 Makefile 發現用來產生圖檔的資料 csv 檔是由 benchmark_clock_gettime 輸出,因此修改此 .c 檔,再輸出 error。後改為寫一個 out.pg,並在 Makefile 新增 plot :
以產生兩種圖檔。
產生圖檔的過程遇到一個困難是,csv 檔的資料分隔是用逗號(,)所以一開始想用 "%lf,%lf,%lf,%lf,%lf,%lf"
的方式撰寫 out.pg,後來才發現可以使用 set datafile separator ","
用 gnuplot 畫出來的 error rate
set logscale xy
,看的細一點考慮以下分解:
對兩邊從0到1去做積分
當時,除積分項以外的項收斂到萊布尼茨級數。同時,積分項收斂到0:
所以這便證明了萊布尼茨公式。
double compute_pi_leibniz(size_t N)
{
double pi = 0.0;
int tmp = 1;
for (size_t i =0; i < N; i++) {
pi += tmp / (2.0 * (double)i + 1.0);
tmp *= (-1);
}
pi *= 4;
return pi;
}
其他計算圓周率的方式如 蒙地卡羅、尤拉等等 (待補實作code)
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 | ||
`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.
Do you want to remove this version name and description?
Syncing