- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有很多从节点,它们可能会也可能不会向主节点发送消息。所以目前主节点无法知道预期有多少 MPI_Recv。出于效率原因,从节点必须向主节点发送最少数量的消息。
我设法找到了 a cool trick ,当不再需要任何消息时,它会发送一条额外的“完成”消息。不幸的是,在我的情况下它似乎不起作用,因为发件人的数量是可变的。关于如何去做的任何想法?谢谢!
if(rank == 0){ //MASTER NODE
while (1) {
MPI_Recv(&buffer, 10, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
if (status.MPI_TAG == DONE) break;
/* Do stuff */
}
}else{ //MANY SLAVE NODES
if(some conditions){
MPI_Send(&buffer, 64, MPI_INT, root, 1, MPI_COMM_WORLD);
}
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Send(NULL, 1, MPI_INT, root, DONE, MPI_COMM_WORLD);
不工作,程序似乎还在等待 MPI_Recv
最佳答案
一个更简单、更优雅的选择是使用 MPI_IBARRIER
。让每个工作人员调用它需要的所有发送,然后在完成后调用 MPI_IBARRIER
。在主机上,您可以在 MPI_ANY_SOURCE
上的 MPI_IRECV
和 MPI_IBARRIER
上循环。当 MPI_IBARRIER
完成时,您知道每个人都已完成,您可以取消 MPI_IRECV
并继续。伪代码看起来像这样:
if (master) {
/* Start the barrier. Each process will join when it's done. */
MPI_Ibarrier(MPI_COMM_WORLD, &requests[0]);
do {
/* Do the work */
MPI_Irecv(..., MPI_ANY_SOURCE, &requests[1]);
/* If the index that finished is 1, we received a message.
* Otherwise, we finished the barrier and we're done. */
MPI_Waitany(2, requests, &index, MPI_STATUSES_IGNORE);
} while (index == 1);
/* If we're done, we should cancel the receive request and move on. */
MPI_Cancel(&requests[1]);
} else {
/* Keep sending work back to the master until we're done. */
while( ...work is to be done... ) {
MPI_Send(...);
}
/* When we finish, join the Ibarrier. Note that
* you can't use an MPI_Barrier here because it
* has to match with the MPI_Ibarrier above. */
MPI_Ibarrier(MPI_COMM_WORLD, &request);
MPI_Wait(&request, MPI_STATUS_IGNORE);
}
关于c - MPI:当预期的 MPI_Recv 数量未知时该怎么办,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30279457/
是否有等级编号对组编号的概括?对于我的代码,我想创建 MPI::COMM_WORLD 的分层分解。假设我们使用 16 个线程。我使用 MPI::COMM_WORLD.Split 创建 4 个通信器,每
能够使用多个节点执行 MPI 作业以加快流程 这是我目前使用的命令: mpirun --hostfile myhost -np 2 --map-by slot Job.x//只在第一个节点执行 mpi
我想创建一个新的通信器,它只保留处理中使用的行列,如果我有 24 个可用处理器而我只需要 10 个,那么该组应该只保留这 10 个,否则它将保留所有他们。出于某种原因,当我尝试创建一个通信器时,一切都
我正在开发一些程序,而不是在每个节点上有 4 个内核的 4 节点集群上运行。我有一个非常快的 OpenMP 版本的程序,它只在一个集群上运行,我正在尝试使用 MPI 扩展它。由于我的经验有限,我想知道
这是我尝试在 MPI 中编写经典平滑像素平均算法的代码。我几乎让它工作了,但是光晕交换发生了一些奇怪的事情,因为可以看到边缘的线条。我似乎找不到错误。我是否正确地交换了光环?我应该收集最终数组的哪一部
我有兴趣使用 MPI(消息传递接口(interface))实现一种事件驱动的调度队列。我要解决的基本问题是:我有一个主进程,它将作业插入全局队列,每个可用的从进程检索队列中的下一个作业(如果有的话)。
当我们在集群上使用命令 say mpirun -np 4 a.out 启动 MPI 程序时,然后MPI 运行时系统如何跨 CPU 分配进程? 我的意思是,假设它在集群中找到一个空闲的四核 CPU,它会
使用 mpirun 启动 MPI 作业时或 mpiexec ,我可以理解人们如何开始每个单独的过程。但是,如果没有任何编译器魔法,这些包装器可执行文件如何将安排(MPI 通信器)传达给 MPI 进程?
MPI 中的等级和进程有什么区别? 最佳答案 Here是我从中学习所有 MPI 的资源,您可能会发现它很有用。 关于你的问题:流程 是正在运行的程序的实际实例。 MPI 允许您创建逻辑 团体进程,并且
MPI 障碍的时间复杂度是多少?它们是否可以扩展到大量核心(>> 10k)? 最佳答案 屏障复杂性与实现高度相关。它可以是线性的,可以是对数的,也可以是更好或更差。某些架构为某些集体操作提供专用网络,
我正在尝试 MPI,想知道这段代码是否会导致死锁。 MPI_Comm_rank (comm, &my_rank); if (my_rank == 0) { MPI_Send (sendbuf,
我有一个简单的 MPI 代码,可以打印出进程的等级,使用 Intel 编译器和 MPI 库进行编译和链接。然后我在集群的主节点上以交互方式运行它:mpiexec -n 50 ./a.out该节点只有
我正在尝试使用 mpi run 使用扭矩调度程序来运行我的程序。虽然在我的 pbs 文件中我通过 加载了所有库 export LD_LIBRARY_PATH=/path/to/library 但它给出
我在所有等级上都有一个相同长度的数组(假设为 10)。数组中的某些值包含处理器的等级。例如 ... Proc 1: [1 0 0 0 0 1 0 0 0 1] Proc 2: [0 2 2 0 0 0
我想在集群中的每台机器上独立地轻松执行集体通信。假设我有 4 台机器,每台机器有 8 个内核,我的 MPI 程序将运行 32 个 MPI 任务。对于给定的功能,我想要的是: 在每个主机上,只有一个任务
我希望能够获得某个通信器的唯一 ID,但是当您通过 MPI_Comm_split() 调用获得此通信器时,这似乎是一项不可能完成的任务。我知道什么时候 MPI_Comm_split() 被集体调用,每
非阻塞发送/接收立即在 MPI 中返回,操作在后台完成。我看到这种情况发生的唯一方法是当前进程/线程调用/创建另一个进程/线程并将发送/接收代码的图像加载到其中并返回。然后这个新进程/线程完成这个操作
冗长的背景 我正在为心脏电生理学模拟并行处理一些代码。由于用户可以使用内置脚本语言指定他们自己的模拟,我无法知道如何在通信与计算之间进行权衡。为了解决这个问题,我正在制作一种运行时分析器,一旦看到要运
我打算做一些并行计算,我完全是这方面的初学者。我将使用 MPI 来完成并行工作,采用 Master-Slave 模型。我现在有四台机器,希望其中一台作为主节点。但是,我不知道如何指定运行该程序的其他机
我可以在我的大学使用 PelicanHPC 访问集群网络,其中运行各种 MPI 程序,但在家里我想练习编写/使用其他 MPI 程序。有没有办法在我自己的系统上运行 MPI 程序? (我在 Ubuntu
我是一名优秀的程序员,十分优秀!