其他分享
首页 > 其他分享> > openMP makes your cpp parallel grogramming more easy

openMP makes your cpp parallel grogramming more easy

作者:互联网

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