标签:clustering https kmeans grogramming aditya1601 easy cpp OpenMP
Recently, I want to learn some cpp implementations of the statistical learning
algorithms, kNN, k-Means, etc. There are so many implementations enlightened me.
What suprised me, is I find a line saying #include <omp.h>
, in github repository aditya1601/kmeans-clustering-cpp
. After some search, I found it's a header for OpenMP
, which is a multi-threading implementation API
.
By applying OpenMP
, you just need to add a #gragma omp parallel ...
line to parallelize your code.
test code
void Test(int n)
{
for (int i = 0; i < 10000; ++i) {
//do nothing, just waste time
}
stringstream ss;
ss << this_thread::get_id() << " ";
ss << n << " : \n";
printf(ss.str().c_str());
}
int main(int argc, char* argv[])
{
#pragma omp parallel for
for (int i = 0; i < 100; ++i)
Test(i);
system("pause");
return 0;
}
reference
aditya1601/kmeans-clustering-cpp: A C++ implementation of simple k-means clustering algorithm.
https://github.com/aditya1601/kmeans-clustering-cpp
OpenMP - Wikipedia
https://en.wikipedia.org/wiki/OpenMP
OpenMP教程——从0开始一小时写出并行程序! - 知乎
https://zhuanlan.zhihu.com/p/397670985
ヾ(▽*)))欢迎回来~
http://home.ustc.edu.cn/~shaojiemike/posts/openmpreductions/
标签:clustering,https,kmeans,grogramming,aditya1601,easy,cpp,OpenMP 来源: https://www.cnblogs.com/yusisc/p/16391981.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。