[英]MPI only recognising 1 process in C?
I am learning MPI for parallel programming in C and I am using a processor with 4 cores. 我正在学习C语言中用于并行编程的MPI,并且正在使用具有4个内核的处理器。 I am trying to do an example from a tutorial in which the output should be: 我正在尝试从教程中输出一个示例:
Hello world! I'm process 0 out of 4 processes
Hello world! I'm process 2 out of 4 processes
Hello world! I'm process 1 out of 4 processes
Hello world! I'm process 3 out of 4 processes
In whatever order. 以任何顺序。
Here is my code: 这是我的代码:
#include <stdio.h>
#include <mpi.h>
int main(int argc, char** argv)
{
int ierr, num_procs, my_id;
ierr = MPI_Init(&argc, &argv);
ierr = MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
ierr = MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
printf("Hello world! I'm process %i out of %i processes\n", my_id, num_procs);
ierr = MPI_Finalize();
}
I compile it using: 我使用以下命令进行编译:
mpicc helloworld.c -o helloworld
And I run it using: 我使用以下命令运行它:
mpirun -np 4 helloworld
This is what is outputted: 这是输出的内容:
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
It's outputting it 4 times which is relatively good news I guess but the program isn't recognising the number of threads and each thread ID. 它输出了4次,我猜这是一个相对不错的消息,但是该程序无法识别线程数和每个线程ID。
Is it even running in parallel or is it just running 4 times in serial? 它甚至并行运行还是仅连续运行4次? How can I get the program to recognise the amount of threads and the thread ID properly? 如何使程序正确识别线程数量和线程ID?
Thanks in advance! 提前致谢!
mpicc helloworld.c -o helloworld
mpirun -np 4 helloworld
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
This sequence clearly shows us that your MPI runtime was unable to detect parallel start, it probably from misconfiguration: your mpicc
is from one MPI implementation and your mpirun
is from other. 此序列清楚地向我们表明,您的MPI运行时无法检测到并行启动,这可能是由于配置错误:您的mpicc
来自一个MPI实现,而mpirun
来自另一个。 For example, both MPICH and OpenMPI have mpicc
scripts for compiling MPI programs, but their mpiexec
/ mpirun
programs are incompatible. 例如,MPICH和OpenMPI都具有用于编译MPI程序的mpicc
脚本,但是它们的mpiexec
/ mpirun
程序不兼容。 Compile with MPICH, start with OpenMPI starter and MPICH runtime will not receive needed environment variables to figure out parallel run and its parameters. 使用MPICH进行编译,从OpenMPI启动程序开始,MPICH运行时将不会收到需要的环境变量来确定并行运行及其参数。
You should revisit list of installed packages ( dpkg -l|egrep 'mpich|openmpi'
) and check which file is from which library ( dpkg -L mpich
, dpkg -L openmpi-bin
; dpkg -L libmpich-dev
, dpkg -L libopenmpi-dev
). 您应该重新访问已安装软件包的列表( dpkg -l|egrep 'mpich|openmpi'
),并检查哪个文件来自哪个库( dpkg -L mpich
, dpkg -L openmpi-bin
; dpkg -L libmpich-dev
, dpkg -L libopenmpi-dev
)。 Ubuntu/debian also have system of "alternatives" which will install symbolic links mpicc
and mpirun
to actual scripts (do ls -l /usr/bin/mpicc /usr/bin/mpirun
to see current state of the links). Ubuntu / debian也有“替代”系统,该系统将安装符号链接mpicc
和mpirun
到实际脚本(执行ls -l /usr/bin/mpicc /usr/bin/mpirun
可以查看链接的当前状态)。 Check update-alternatives
tool, its man page and docs to learn how to reset all mpi-named scripts to one implementation (and there is galternatives
GUI for it). 检查update-alternatives
工具,其手册页和文档,以了解如何将所有以mpi命名的脚本重置为一个实现(并且具有galternatives
GUI)。
According to file lists in packages, mpich and openmpi have variants of mpirun/mpiexec with suffixes http://packages.ubuntu.com/yakkety/amd64/openmpi-bin/filelist http://packages.ubuntu.com/yakkety/amd64/mpich/filelist : 根据软件包中的文件列表,mpich和openmpi具有mpirun / mpiexec变体,后缀为http://packages.ubuntu.com/yakkety/amd64/openmpi-bin/filelist http://packages.ubuntu.com/yakkety/amd64 / mpich / filelist :
/usr/bin/mpiexec.openmpi
/usr/bin/mpirun.openmpi
/usr/bin/mpiexec.hydra
/usr/bin/mpiexec.mpich
/usr/bin/mpirun.mpich
Same situation for mpicc scripts: http://packages.ubuntu.com/yakkety/amd64/libopenmpi-dev/filelist http://packages.ubuntu.com/yakkety/amd64/libmpich-dev/filelist mpicc脚本的情况相同: http : //packages.ubuntu.com/yakkety/amd64/libopenmpi-dev/filelist http://packages.ubuntu.com/yakkety/amd64/libmpich-dev/filelist
/usr/bin/mpicc.openmpi
/usr/bin/mpicc.mpich
Always use mpicc and mpirun (or mpiexec) from the same implementation. 始终从同一实现中使用mpicc和mpirun(或mpiexec)。 You may also use variants with suffix to be sure: mpicc.openmpi
& mpiexec.openmpi
pair or mpicc.mpich
& mpiexec.mpich
pair. 您也可以使用带有后缀的变体来确保: mpicc.openmpi
和mpiexec.openmpi
对或mpicc.mpich
和mpiexec.mpich
对。
And to use some MPI implementation, you should have it fully installed, both for bin, lib and dev packages. 要使用某些MPI实施,您应该针对bin,lib和dev软件包完全安装它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.