- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
(初学者问题)我尝试使用 MPI_Comm_Spawn 动态生成进程,然后向子进程广播消息,但程序在从根进程向子进程广播时停止。我正在关注 http://www.mpi-forum.org/docs/docs.html 中的文档但我无法让它发挥作用。有人可以帮帮我吗?
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
MPI_Comm parentcomm;
MPI_Comm_get_parent( &parentcomm );
if (parentcomm == MPI_COMM_NULL) {
MPI_Comm intercomm;
MPI_Status status;
char msg_rec[1024];
char msg_send[1024];
int size, i;
int np = (argc > 0) ? atoi(argv[1]) : 3;
printf("Spawner will spawn %d processes\n", np);
MPI_Comm_spawn( argv[0], MPI_ARGV_NULL, np, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm, MPI_ERRCODES_IGNORE );
MPI_Comm_size(intercomm, &size);
sprintf(msg_send, "Hello!");
printf("Spawner will broadcast '%s'\n", msg_send);
MPI_Bcast( (void*)msg_send, 1024, MPI_CHAR, 0, intercomm);
printf("Spawner will receive answers\n");
for (i=0; i < size; i++) {
MPI_Recv( (void*)msg_rec, 1024, MPI_CHAR, i, MPI_ANY_TAG, intercomm, &status);
printf("Spawner received '%s' from rank %d\n", msg_rec, i);
};
} else {
int rank, size;
char msg_rec[1024];
char msg_send[1024];
MPI_Comm_rank(parentcomm, &rank);
MPI_Comm_size(parentcomm, &size);
printf(" Rank %d ready\n", rank);
MPI_Bcast( (void*)msg_rec, 1024, MPI_CHAR, 0, parentcomm);
printf(" Rank %d received '%s' from broadcast!\n", rank, msg_rec);
sprintf(msg_send, "Hi there from rank %d!\n", rank);
MPI_Send( (void*)msg_send, 1024, MPI_CHAR, 0, rank, parentcomm);
};
MPI_Finalize();
return 0;
};
我不知道这是否重要,但我使用的是 ubuntu 11.10 和 Hidra Process Manager。
最佳答案
正如@suszterpatt 所指出的,您正在使用“Intercommunicator”(而不是“Intracommunicator”)。了解这一点并查看MPI_Bcast ,我们看到:
If comm is an intercommunicator, then the call involves all processes in the intercommunicator, but with one group (group A) defining the root process. All processes in the other group (group B) pass the same value in argument root, which is the rank of the root in group A. The root passes the value MPI_ROOT in root. All other processes in group A pass the value MPI_PROC_NULL in root. Data is broadcast from the root to all processes in group B. The receive buffer arguments of the processes in group B must be consistent with the send buffer argument of the root.
这意味着您只需将父级中的广播调用替换为:
MPI_Bcast( (void*)msg_send, 1024, MPI_CHAR, MPI_ROOT, intercomm);
其他一些错误:
argc > 1
。MPI_Comm_size(intercomm, &size)
将返回 1
。您需要改用 MPI_Comm_remote_size(intercomm, &size)
。关于c - MPI 生成 : root process does not communicate to child processes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9970409/
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 5年前关闭。 Improve t
我是一名设计老师,试图帮助学生应对编程挑战,所以我编码是为了好玩,但我不是专家。 她需要找到 mode (最常见的值)在使用耦合到 Arduino 的传感器的数据构建的数据集中,然后根据结果激活一些功
我正在开发一个应用程序,该应用程序提供 CPU 使用率最高的 5 个应用程序名称。目前,我通过以下代码获得了排名前 5 的应用程序: var _ = require('lodash');
互联网上很少有例子涉及这个问题的所有三个问题——即 set-process-sentinel ; set-process-filter ;和 start-process . 我尝试了几种不同的方法来微
如 this post 中所述,在 C# 中有两种调用另一个进程的方法。 Process.Start("hello"); 和 Process p = new Process(); p.StartInf
我试图让我的桨从白色变为渐变(线性),并使球具有径向渐变。感谢您的帮助!您可以在 void drawPaddle 中找到桨的代码。 这是我的目标: 这是我的代码: //球 int ballX = 50
考虑:流程(a)根据我的文字: A process is first entered at the time of simulation, at which time it is executed u
我真的希望 Processing 有用于处理数组的 push 和 pop 方法,但由于它没有,我不得不试图找出删除数组中特定位置的对象的最佳方法。我相信这对很多人来说都是基本的,但我可以使用一些帮助,
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
以编程方式,我如何确定 Windows 10 中的 3 个类别 应用 后台进程 Windows 服务 就像任务管理器一样? 即我需要一些 C# 代码,我可以确定应用程序列表与后台进程列表。检查 Win
当我导入 node:process它工作正常。但是,当我尝试要求相同时,它会出错。 这工作正常: import process from 'node:process'; 但是当我尝试要求相同时,它会引
我正在上一门使用处理的类(class)。 我在理解 map() 函数时遇到问题。 根据它的文档( http://www.processing.org/reference/map_.html ): Re
我试图执行: composer.phar update 并收到: Fatal error: Allowed memory size of 94371840 bytes exhausted (tried
给定一堆二维图像,如何使用 Processing/Processing.js 产生体积渲染效果? 目前我的想法是使用 java(类似于 imageJ)进行体积渲染 -> 获取体积渲染图像的面作为单独的
这是代码示例 var startInfo = new ProcessStartInfo { Arguments = commandStr, FileName = @"C:\Window
当我在 Processing(草图 > 导入库 > 添加库)中添加库时,它安装在哪里? 最佳答案 它们安装在您的 中速写本位置 . 您可以通过转到"file">“首选项”来查看和更改您的速写本位置。草
无聊的好奇... 我正在查看当前进程的一些属性: using(Process p = Process.GetCurrentProcess()) { // Inspect properties
我正在尝试在同一页面上运行多个草图。 初始化脚本指定: /* * This code searches for all the * in your page and loads each scrip
Process.Kill 后是否需要使用 Process.WaitForExit? 如果调用进程在调用 Process.Kill 后立即退出怎么办? 这会导致 Process.Kill 失败吗? 编辑
我尝试使用处理从麦克风获取频率。我混合了文档中的两个示例,但“最高”并不是真正的赫兹(a 是 440 赫兹)。 你知道如何拥有比这更好的东西吗? import ddf.minim.*; import
我是一名优秀的程序员,十分优秀!