c++ - 并行位置

标签 c++ parallel-processing hpx

并行性新手,正在学习使用 C++ 来了解 HPX。我正在查看一个特定的 hello-word 示例,它将在每个位置的每个操作系统线程上打印 hello world,一些输出如下所示:

hello world from OS-thread 1 on locality 0
hello world from OS-thread 1 on locality 1
hello world from OS-thread 0 on locality 0
hello world from OS-thread 0 on locality 1

我的问题是,当程序输出在位置x时,位置到底意味着什么?我理解操作系统线程,但我不太确定程序是什么表示哪个地方。

HPX main 中的一些代码示例,这不一定是我的问题所必需的,但它确实包含多次调用来查找与主题相关的位置。

int hpx_main()
{
    {
        // Get a list of all available localities.
        std::vector<hpx::naming::id_type> localities =
            hpx::find_all_localities();

        // Reserve storage space for futures, one for each locality.
        std::vector<hpx::lcos::future<void> > futures;
        futures.reserve(localities.size());

        BOOST_FOREACH(hpx::naming::id_type const& node, localities)
        {
            // Asynchronously start a new task. The task is encapsulated in a
            // future, which we can query to determine if the task has
            // completed.
            typedef hello_world_foreman_action action_type;
            futures.push_back(hpx::async<action_type>(node));
        }

        // The non-callback version of hpx::lcos::wait takes a single parameter,
        // a future of vectors to wait on. hpx::lcos::wait only returns when
        // all of the futures have finished.
        hpx::lcos::wait(futures);
    }

    // Initiate shutdown of the runtime system.
    return hpx::finalize();
}

最佳答案

据我从他们的文档中了解到 - 您可以将位置视为执行应用程序的进程数。
假设有 2 个服务器执行您的程序,第一个服务器将执行位置 0,第二个服务器将执行位置 1。
这样您就可以知道执行相同代码的哪个进程是服务器(位置 0),哪个是客户端(位置 1)。

此外,每个进程可以运行多个线程,这通过os_threads的数量可见。

按照这个例子: http://stellar.cct.lsu.edu/files/hpx_0.8.1/docs/hpx/tutorial/examples/hello_world.html

以及这些命令行选项:http://stellar.cct.lsu.edu/files/hpx_0.8.1/docs/hpx/tutorial/getting_started/commandline.html

这是如何使用多个位置的说明: http://stellar.cct.lsu.edu/files/hpx_0.8.1/docs/hpx/tutorial/getting_started/unix_pbs.html

我认为理解它的最好方法是使用 --hpx:node 和 --hpx:threads 的值。

此外 - 我认为 openmpi 文档更适合理解这些术语......

虽然不确定我是否有所帮助,但我希望我有所帮助。

关于c++ - 并行位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23070413/

相关文章:

c++ - C++ 中的二进制补码 - 数组下标的无效类型 'int[int]'

c++ 运算符重载 += 有效但 << 无效

c++ - Arduino 类中的 Serial.println

python - 并行计算-将每个进程输出到文件

c++ - HPX 是否提供具有粒度控制的基于任务的并行迭代功能?

c++ - 在 C++ 中正确使用构造函数

r - 在 Linux 中使用 mclapply 时 R 中出现奇怪的段错误

r - 并行 R 中每个子进程的唯一名称

c++ - 设计一个迭代器以在取消引用时抛出异常

c++ - 是否可以编写可以在 HPX 和 C++1x 线程之间切换的代码?