mirror of
https://github.com/NanXiao/perf-little-book.git
synced 2026-07-17 16:35:13 +00:00
Merge pull request #1 from justanotherdot/topic/fix-typo
Fix typo on DEFINE in sample code
This commit is contained in:
commit
c25de25edf
1 changed files with 6 additions and 6 deletions
|
|
@ -1,22 +1,22 @@
|
||||||
# Record event counts per thread
|
# Record event counts per thread
|
||||||
|
|
||||||
`perf record` can be used to record event counts for every thread when using `-s` option. Check following multi-thread program:
|
`perf record` can be used to record event counts for every thread when using `-s` option. Check following multi-thread program:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cat sum.c
|
$ cat sum.c
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
|
|
||||||
#define N 100000000
|
#define N 100000000
|
||||||
#define THRAED_NUM 8
|
#define THREAD_NUM 8
|
||||||
|
|
||||||
int values[N];
|
int values[N];
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int sum[THRAED_NUM];
|
int sum[THREAD_NUM];
|
||||||
|
|
||||||
#pragma omp parallel for
|
#pragma omp parallel for
|
||||||
for (int i = 0; i < THRAED_NUM; i++)
|
for (int i = 0; i < THREAD_NUM; i++)
|
||||||
{
|
{
|
||||||
int local_sum;
|
int local_sum;
|
||||||
for (int j = 0; j < N; j++)
|
for (int j = 0; j < N; j++)
|
||||||
|
|
@ -30,7 +30,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Build and use `perf record` to note down event counts for every thread:
|
Build and use `perf record` to note down event counts for every thread:
|
||||||
|
|
||||||
```
|
```
|
||||||
# gcc -fopenmp -g sum.c -o sum
|
# gcc -fopenmp -g sum.c -o sum
|
||||||
|
|
@ -39,7 +39,7 @@ Build and use `perf record` to note down event counts for every thread:
|
||||||
[ perf record: Captured and wrote 0.404 MB perf.data (8757 samples) ]
|
[ perf record: Captured and wrote 0.404 MB perf.data (8757 samples) ]
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `perf report` to analyze it (`-T` option means displaying per-thread event counts):
|
Use `perf report` to analyze it (`-T` option means displaying per-thread event counts):
|
||||||
|
|
||||||
```
|
```
|
||||||
# perf report -T
|
# perf report -T
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue