我正试图用C++语言使用MPI库来理解并行代码和顺序代码之间的区别
I am trying to understand the difference between parallel and sequential code using MPI library with C++ language
这是代码"expl.cpp":
#include <iostream>
#include "mpi.h"
using namespace std;
int main (int argc,char **argv)
{
cout << "this line of code is executed in sequential mode " << endl ;
MPI::Init();
cout << "hello MPI world!" << endl ;
MPI::Finalize();
return 0;
}
使用编译上述代码后
mpicc -o expl expl.cpp
并用这个命令执行二进制文件
mpirun -np 4 ./expl
我的预期输出为:
this line of code is executed in sequential mode
hello MPI world!
hello MPI world!
hello MPI world!
hello MPI world!
但我得到了这个输出:
this line of code is executed in sequential mode
this line of code is executed in sequential mode
this line of code is executed in sequential mode
this line of code is executed in sequential mode
hello MPI world!
hello MPI world!
hello MPI world!
hello MPI world!
我想要一个简单的澄清。
如果你阅读文档,它会显示
这将在当前运行时环境中运行的X个副本
这正是发生的事情。
相关文章:
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 以下两个代码段有什么区别?
- 两个代码段之间有什么区别?
- 当我使用按引用返回时,我不知道这些代码之间的区别
- 给定的两个代码有什么区别.一个在 ideone 上运行时超出时间限制,另一个工作正常
- 为不同目标MCU开发C/C++代码的区别
- 这两行代码有什么区别
- (C++)比较两段代码,一段有效,一段无效,无法找出区别
- C++ 构造函数和初始值设定项行为。这 5 个代码有什么区别?
- 这些代码之间的区别在哪里?输出不应该是一样的吗?
- 框架代码和普通代码之间的区别
- 有人可以解释一下这个 c++ 代码的区别吗?
- 这两个版本的代码有什么区别
- 这两个指针代码有什么区别
- 告诉我两者之间的区别.它是在树上插入的C 代码
- 当我<limits>在 c++ 代码中包含或<limit.h>时有什么区别
- 这些C++代码之间有什么区别
- 无法理解工作代码和损坏代码之间的区别
- 以下C++代码中的 += 和常规总和有什么区别
- 以下代码段的区别