我有以下代码,当使用 eclipse 2020.12 执行时,输出是这样的:“Hello from rank 0 out of 1”
#include <iostream>
#include <mpi.h>
using namespace std;
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
int data;
if (rank > 0) {
MPI_Recv(&data, 1, MPI_INT, rank-1, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);
cout << "Rank "<< rank<< " has received message with data " << data
<< " from rank " << rank-1
<< endl;
}
cout << "Hello from rank " << rank<< " out of " << size<< endl;
if (rank < size-1) {
data = rank*rank;
MPI_Send(&data, 1, MPI_INT, rank+1, 0, MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}
但是,当我通过命令行使用以下命令执行此操作时,它按预期工作
mpic++ -o name name.cpp
mpiexec -np 4 ./name
它显示 4 hello ,这是我的核心数。我想知道为什么 eclipse 无法识别,但是具有另一种执行方式的 sampe cpp 文件可以正常工作!输出将是:
Hello from rank 0 out of 4
Rank 1 has received message with data 0 from rank 0
Hello from rank 1 out of 4
Rank 2 has received message with data 1 from rank 1
Hello from rank 2 out of 4
Rank 3 has received message with data 4 from rank 2
Hello from rank 3 out of 4