简体   繁体   English

c ++ 11多线程与boost_thread

[英]c++11 multi threading vs boost_thread

I am a beginner of c++ parallel computing. 我是c ++并行计算的初学者。 However, my project requires that I would need to use c++98 (stdlibc++) for it. 但是,我的项目要求我需要为此使用c ++ 98(stdlibc ++)。 I search online and it seems most of the tutorials is based on c++11 thread. 我在网上搜索,似乎大多数教程都基于c ++ 11线程。 I noted that boost_thread is an implementation for c++98 but there seems to be much less available tutorial. 我注意到boost_thread是c ++ 98的实现,但是可用的教程似乎少得多。 So I would like to ask what is the best way for me to learn and implement parallel computing for my project. 因此,我想问一问,对于我的项目而言,学习和实现并行计算的最佳方法是什么?

Eventually, my project would require calculations based on hundreds of cores and computing nodes. 最终,我的项目将需要基于数百个内核和计算节点的计算。 Would multi-threading be sufficient or do I have to use Boost_MPI? 多线程是否足够?还是必须使用Boost_MPI? Thank you. 谢谢。

If you are limited to c++98 that means that you won't have all the thread managing and locking mechanisms as part of the language. 如果限于c ++ 98,则意味着您不会将所有线程管理和锁定机制作为语言的一部分。 Therefore you will have to implement them by yourself based on available OS APIs. 因此,您将必须根据可用的OS API自行实现它们。 There are different APIs for Windows and Linux. Windows和Linux有不同的API。 Here is an example of C++ wrapper for Linux pthread library . 这是Linux pthread库C ++包装器的示例。 And this is an example of C++ wrapper for Windows Threads . 这是Windows线程C ++包装器的示例。 So your project won't be portable unless you create (or find somewhere) a class which hides these libraries behind a common interface under which it implements the same logic for Windows and Linux differed by #ifdef WINDOWS / #ifdef LINUX . 因此,除非您创建(或在某处找到)一个类将这些库隐藏在一个通用接口下,否则该项目将不可移植。在该接口下,该类可以为Windows和Linux实现相同的逻辑,区别在于#ifdef WINDOWS / #ifdef LINUX

Regarding 关于

what is the best way for me to learn and implement parallel computing for my project. 对我的项目而言,学习和实现并行计算的最佳方法是什么?

There is no a correct answer for this. 没有正确的答案。 Look for some basic Multi Threading tutorials. 寻找一些基本的多线程教程。 Try to implement few simple programs (before you move to a big project) and come back when you face difficulties with more specific questions. 尝试实施一些简单的程序(在转到大项目之前),然后在遇到更具体的问题的困难时返回。

I have heard about boost but never used it so I can't provide any feedback on that. 我听说过Boost,但从未使用过,所以我无法提供任何反馈。 But again, you need to ask specific question. 但是同样,您需要提出具体问题。 You can provide some specific requirements from your project and ask question based on them. 您可以从项目中提供一些特定需求,并根据这些需求提出问题。 Anyway dive into boost documentation , you can find there threads related libraries (also pay attention for boost usage license). 无论如何,进入boost文档 ,您都可以在其中找到与线程相关的库(也要注意boost使用许可证)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM