- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
ref MPI_Init 的声明:
This routine must be called by one thread only. That thread is called the main thread and must be the thread that calls MPI_Finalize.
如何做到这一点?我的意思是我见过的每个例子看起来都像 this在我的代码中,我尝试了:
MPI_Comm_rank(MPI_COMM_WORLD, &mpirank);
bool mpiroot = (mpirank == 0);
if(mpiroot)
MPI_Init(&argc, &argv);
但是我得到了:
Attempting to use an MPI routine before initializing MPICH
但是,请注意这会正常工作,如果我像示例中那样保留它,我只需要重新检查,因为我的代码失败了 here .
我在想,因为我们调用了 mpiexec -n 4 ./test
,所以会产生 4 个进程,因此它们都会调用 MPI_Init
。我只是在 main()
的第一行打印了一些东西,它们的打印次数与进程数一样多。
最佳答案
MPI_Init
必须是您的 MPI 程序调用的第一个 MPI 函数。它必须被每个进程调用。请注意,进程与线程不同!如果您继续从进程中生成线程,这些线程不得再次调用 MPI_Init
。
所以你的程序应该是这样的:
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
int mpirank;
MPI_Comm_rank(MPI_COMM_WORLD, &mpirank);
// No more calls to MPI_Init in here
...
MPI_Finalize();
}
关于c - MPI_Init 只能由一个线程调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31833664/
ref MPI_Init 的声明: This routine must be called by one thread only. That thread is called the main thr
我有一个最小的问题示例,我只是启动 4 个进程(在具有 8 个线程的四核 Intel Core i7 cpu 上),并且出于某种原因 MPI_Init 似乎需要非常,很长一段时间。 这是我的代码:
我遇到了关于使用MPI_Init() 的问题。 我只想使用下面上下文中的代码在根处理器上初始化随机数“randv”。为了查看我的目标是否实现,我让程序打印出数组“randv”,方法是在“call RA
假设我有一些如下所示的代码: #include "mpi.h" int main( int argc, char** argv ) { int my_array[10]; //fill
MPICH 和 OpenMPI 的文档都提到,在 MPI_Init 之前或 MPI_Finilize 之后应该完成最少的工作: The MPI standard does not say what a
我遇到了关于使用MPI_Init() 的问题。 我只想使用下面上下文中的代码在根处理器上初始化随机数“randv”。为了查看我的目标是否实现,我让程序打印出数组“randv”,方法是在“call RA
从 std::thread 调用 MPI_Init 是否安全? int main(int argc, char** argv) { std::thread mpi_thread([...]()
有什么区别,应该实际使用哪一个?我找到了这个 IBM链接和这个问题 MPI - one function for MPI_Init and MPI_Init_thread .如果重要的话,我只对 C
是否可以用一个函数来包装MPI_Init和MPI_Init_thread?这样做的目的是拥有更清晰的 API,同时保持向后兼容性。当 MPI 运行时不支持对 MPI_Init_thread 的调用时,
在全新的 Raspberry Pi 4 Ubuntu 上运行干净的 Ubuntu, ubuntu@ubuntu:~/mpi-hello-world/mpitutorial/tutorials/mpi-
我需要在我的项目中使用 MUMPS。我想用求解方程的简单示例(如下)来测试安装。问题是,这段代码在我的个人电脑上可以正常工作,但每次我尝试在我的工作计算机上运行它时都会出现此错误: *** The M
我一直在用下面的代码测试 mpi 究竟是如何工作的 #include #include using namespace std; int main(int argc
这就是我们如何使用 MPI_Init 函数 int main(int argc, char **argv) { MPI_Init(&argc, &argv); … } 为什么 MPI_Init
这就是我们如何使用 MPI_Init 函数 int main(int argc, char **argv) { MPI_Init(&argc, &argv); … } 为什么 MPI_Init
我正在尝试通过 python 使用 OpenMPI 访问共享库,但由于某种原因,我收到以下错误消息: [Geo00433:01196] mca: base: component_find: unabl
我正在尝试在 Windows 中首次使用 Visual Studio 2010 和 Intel Composer XE 2011 SP1 的试用版、ifort visual fortran 编译器编译
我是一名优秀的程序员,十分优秀!