简体   繁体   English

MPI 程序仅在一个进程中执行,而不是在多个进程中请求

[英]MPI program executed in only one process against requested with many processes

I am a beginner trying to learn MPI.我是一个试图学习 MPI 的初学者。 I have tried to run the following program downloaded from internet:我试图运行从互联网下载的以下程序:

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

    int main (argc, argv)
         int argc;
         char *argv[];
    {
      int rank, size;

      MPI_Init (&argc, &argv);  /* starts MPI */
      MPI_Comm_rank (MPI_COMM_WORLD, &rank);    /* get current process id */
      MPI_Comm_size (MPI_COMM_WORLD, &size);    /* get number of processes */
      printf( "Hello world from process %d of %d\n", rank, size );
      MPI_Finalize();
      return 0;
    }

The code has been compiled with mpicc and executed with mpirun .代码已经用mpicc编译并用mpirun执行。

mpicc HelloWorld.c
mpirun -np 4 a.out

The output is as follows:输出如下:

Hello world from process 0 of 1
Hello world from process 0 of 1
Hello world from process 0 of 1
Hello world from process 0 of 1

My question is, why the output has generated only one process and not 4 processes as requested?我的问题是,为什么输出只生成了一个进程而不是按要求生成了 4 个进程?

This problem occurs when mpicc and mpirun are not from the same MPI Implementation.mpiccmpirun不是来自同一个 MPI 实现时会出现此问题。
You can do uninstall openmpi and mpich and install only mpich lib.您可以卸载 openmpi 和 mpich 并仅安装 mpich lib。

Run these commands in your terminal.在终端中运行这些命令。
sudo apt-get remove --auto-remove openmpi-bin
sudo apt-get remove --auto-remove mpich
sudo apt-get install mpich

The following solved my problem:以下解决了我的问题:

sudo apt-get remove --auto-remove openmpi-bin
sudo apt-get remove --auto-remove mpich
sudo apt-get install mpich
sudo apt install lam-runtime     
sudo apt install mpich           
sudo apt install openmpi-bin     
sudo apt install slurm-wlm-torque

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM