我新的MPI和常常看到在MPI代碼以下代碼:
MPI等級確定
if (rank == 0) {
MPI_Send(buf, len, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
}
else {
MPI_Recv(buf, len, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
}
看來,秩確定該方法的發送和該方法的接收。但是 通過調用MPI_Comm_rank(MPI_COMM_WORLD, &rank);
確定進程的級別如何?
它與mpirun
的命令行參數有關嗎?
例如:
mpirun -n 2 -host localhost1,localhost2 ./a.out
(localhost1
是等級0,localhost2
是1級?)
如何在程序將決定誰擁有等級0和誰擁有1級?
有沒有一種方法可以讓我指定某種東西,例如localhost1
正在發送,localhost2
正在接收?