我開始了與MPI和已經寫了一個快速演示程序:爲什麼我所有的mpi線程都是主人?
int main(int argc, char** argv)
{
MPI_Init(&argc, &argv);
int myRank = MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
if (myRank) {
cout << "slave" << endl;
}
else {
cout << "master" << endl;
}
MPI_Finalize();
return 0;
}
我用下面的命令來運行它:
aprun -n 4 test
我的輸出是
master
master
master
master
我期待類似
slave
master
slave
slave
這是怎麼發生的?爲什麼我所有的線程都是主人?
「If」只對「0」爲真,對於其他整數值爲false? 嘗試檢查MPI_SUCCESS和MPI_ERR_COMM? – phantasmagoria
MPI_Comm_rank函數的返回值不是您認爲的那樣。返回的值是一個錯誤代碼。大多數MPI *功能都是如此。 –