gpt4 book ai didi

c - MPI简单数据传输程序

转载 作者:行者123 更新时间:2023-12-04 05:13:30 25 4
gpt4 key购买 nike

我应该将一些整数从一个处理器发送到另一个处理器,这将在我大学的 shell 服务器上完成...

首先我创建了我的解决方案代码,它看起来像(至少我是这么认为的......)

#include <stdio.h>
#include <mpi.h>

int main(int argc, char **argv)
{
int currentRank = -1;

MPI_Init(&argc, &argv);

MPI_Comm_rank(MPI_COMM_WORLD, &currentRank);

if(currentRank == 0) {
int numberToSend = 1;
MPI_Send(&numberToSend , 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
else if(currentRank == 1) {
int recivedNumber;
MPI_Recv(&recivedNumber, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Recived number = %d\n", recivedNumber);
}

MPI_Finalize();

return 0;
}

比我应该创建一些 name.pbs 文件...并运行它。而且我无法理解如何指定这个处理器数量......我尝试如下:
#PBS -l nodes=2:ppn=2 
#PBS -N cnt
#PBS -j oe
mpiexec ~/mpi1

但后来仍然不知道如何处理腻子。 qstat comamnd 似乎什么都不做...只有当 qstat -Qq它向我展示了一些“统计数据”,但到处都是 0 值……这是我在 mpi 中的第一个程序,我真的一点也不明白……

当我尝试运行我的程序时,我得到:
164900@halite:~$ ./transfer1
Fatal error in MPI_Send: Invalid rank, error stack:
MPI_Send(174): MPI_Send(buf=0x7fffd28ec640, count=1, MPI_INT, dest=1, tag=0, MPI_COMM_WORLD) failed
MPI_Send(99).: Invalid rank has value 1 but must be nonnegative and less than 1

谁能解释我如何在服务器上运行它?

最佳答案

示例代码在这里工作正常,使用 OpenMPI 和 GCC 进行测试,

问题是,当您运行代码时,您需要通过 mpirun 实例指定内核数,您可能已经使用扭矩或正在使用的任何调度程序正确分配了它们,但是您正在运行编译后的代码,就好像它是您需要的串行代码一样使用 mpi heres 运行它,并使用相关输出的示例运行它

mpirun -np 2 ./example
Recived number = 1

使用不同的调度程序 hydra、PBS 或不同的 MPI 版本,您需要遵循与上述相同的模式,并且特定于您的 mpi 运行命令的核心数

关于c - MPI简单数据传输程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14596186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com