Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Achou.Wang
21st-Century-Examples
提交
f1d5b74c
2
21st-Century-Examples
项目概览
Achou.Wang
/
21st-Century-Examples
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
2
21st-Century-Examples
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f1d5b74c
编写于
9月 22, 2014
作者:
B
Ben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update the threading chapter
上级
a99549a1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
22 addition
and
7 deletion
+22
-7
atomic_factors.c
atomic_factors.c
+1
-0
c_factors.c
c_factors.c
+9
-5
c_primes.c
c_primes.c
+4
-0
mapreduce_wc.c
mapreduce_wc.c
+1
-0
openmp_atoms.c
openmp_atoms.c
+1
-2
openmp_wc.c
openmp_wc.c
+1
-0
pthread_factors.c
pthread_factors.c
+5
-0
未找到文件。
atomic_factors.c
浏览文件 @
f1d5b74c
#include <omp.h>
#include <stdio.h>
#include <stdlib.h> //malloc
#include <string.h> //memset
#include "openmp_getmax.c"
...
...
c_factors.c
浏览文件 @
f1d5b74c
/* Compile with:
export CFLAGS="-g -Wall -O3 --std=c11 -pthread -latomic"
make c_factors
*/
#include <pthread.h>
#include <stdatomic.h>
#include <stdlib.h> //malloc
...
...
@@ -44,7 +48,7 @@ void *mark_factors(void *vin){
}
int
main
(){
long
int
max
=
1e
4
;
long
int
max
=
1e
7
;
_Atomic
(
int
)
*
factor_ct
=
malloc
(
sizeof
(
_Atomic
(
int
))
*
max
);
int
thread_ct
=
4
;
...
...
@@ -58,7 +62,7 @@ int main(){
one_factor_s
x
[
thread_ct
];
for
(
long
int
i
=
2
;
i
<=
max
/
2
;
i
+=
thread_ct
){
for
(
int
t
=
0
;
t
<
thread_ct
&&
t
+
i
<=
max
/
2
;
t
++
){
x
[
t
]
=
(
one_factor_s
){.
i
=
i
+
t
,
.
max
=
max
,
x
[
t
]
=
(
one_factor_s
){.
i
=
i
+
t
,
.
max
=
max
,
.
factor_ct
=
factor_ct
};
pthread_create
(
&
threads
[
t
],
NULL
,
mark_factors
,
x
+
t
);
}
...
...
@@ -67,8 +71,8 @@ int main(){
}
int
max_factors
=
get_max_factors
(
factor_ct
,
max
);
_Atomic
(
long
int
)
tally
[
max_factors
];
memset
(
tally
,
0
,
sizeof
(
long
int
)
*
max_factors
);
_Atomic
(
long
int
)
tally
[
max_factors
+
1
];
memset
(
tally
,
0
,
sizeof
(
long
int
)
*
(
max_factors
+
1
)
);
tally_s
thread_info
[
thread_ct
];
for
(
int
i
=
0
;
i
<
thread_ct
;
i
++
){
...
...
@@ -80,6 +84,6 @@ int main(){
for
(
int
t
=
0
;
t
<
thread_ct
;
t
++
)
pthread_join
(
threads
[
t
],
NULL
);
for
(
int
i
=
0
;
i
<
max_factors
;
i
++
)
for
(
int
i
=
0
;
i
<
max_factors
+
1
;
i
++
)
printf
(
"%i
\t
%li
\n
"
,
i
,
tally
[
i
]);
}
c_primes.c
浏览文件 @
f1d5b74c
/* Compile with:
export CFLAGS="-g -Wall -O3 --std=c11 -pthread -latomic"
make c_primes
*/
#include <stdio.h>
#include <stdatomic.h>
#include <stdlib.h> //malloc
...
...
mapreduce_wc.c
浏览文件 @
f1d5b74c
...
...
@@ -16,6 +16,7 @@ int main(int argc, char **argv){
argv
++
;
Stopif
(
!
argc
,
return
0
,
"Please give some file names on the command line."
);
long
int
total_wc
=
0
;
#pragma omp parallel for \
reduction(+:total_wc)
for
(
int
i
=
0
;
i
<
argc
;
i
++
){
...
...
openmp_atoms.c
浏览文件 @
f1d5b74c
/* Suggested makefile:
----------
P=openmp_atoms
CFLAGS=`pkg-config --cflags glib-2.0` -g -Wall -std=gnu99 -O3 -fopenmp
LDLIBS=`pkg-config --libs glib-2.0` -fopenmp
CFLAGS=-g -Wall -std=gnu99 -O3 -fopenmp
$(P):
----------
...
...
openmp_wc.c
浏览文件 @
f1d5b74c
...
...
@@ -16,6 +16,7 @@ int main(int argc, char **argv){
argv
++
;
Stopif
(
!
argc
,
return
0
,
"Please give some file names on the command line."
);
int
count
[
argc
];
#pragma omp parallel for
for
(
int
i
=
0
;
i
<
argc
;
i
++
){
count
[
i
]
=
wc
(
argv
[
i
]);
...
...
pthread_factors.c
浏览文件 @
f1d5b74c
/* Compile with:
export CFLAGS="-g -Wall -O3 --std=c99 -pthread -fopenmp"
make pthread_factors
*/
#include <omp.h> //get_max is still OpenMP
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h> //malloc
#include <string.h> //memset
#include "openmp_getmax.c"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录