首页 > 解决方案 > 当我运行 mpi 时,我得到“系统中没有足够的可用插槽”

问题描述

我是一名高中生。学习和编写mpi基础理论时出现错误。我在互联网上搜索并尝试了所有内容,但我无法很好地理解它。

代码真的很简单。代码没有问题,我理解得很好。

#include <stdio.h>

#include <mpi.h>

int main(int argc, char *argv[])

{   

   int num_procs, my_rank;

   MPI_Init(&argc, &argv);

   MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

   MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

   printf("Hello world! I'm rank %d among %d processes.\n", my_rank, num_procs);

   MPI_Finalize();

   return 0;

}

但是运行mpi有问题。当我这样输入时效果很好。

mpirun -np 2 ./hello

Hello world! I'm rank 1 among 2 processes.

Hello world! I'm rank 0 among 2 processes.

此错误发生在 -np 3。

mpirun -np 3 ./hello

`There are not enough slots available in the system to satisfy the 3
slots that were requested by the application:

./hello

  Either request fewer slots for your application, or make more slots
  available for use.

   A "slot" is the Open MPI term for an allocatable unit where we can
   launch a process.  The number of slots available are defined by the
   environment in which Open MPI processes are run:

  1. Hostfile, via "slots=N" clauses (N defaults to number of
     processor cores if not provided)
  2. The --host command line parameter, via a ":N" suffix on the
     hostname (N defaults to 1 if not provided)
  3. Resource manager (e.g., SLURM, PBS/Torque, LSF, etc.)
  4. If none of a hostfile, the --host command line parameter, or an
     RM is present, Open MPI defaults to the number of processor cores

In all the above cases, if you want Open MPI to default to the number
of hardware threads instead of the number of processor cores, use the
--use-hwthread-cpus option.

Alternatively, you can use the --oversubscribe option to ignore the
number of available slots when deciding the number of processes to
launch.

我的笔记本电脑是 Intel i5,cpu 核心是 2 和 4 线程。是否因为只有 2 个核心而发生这样的问题?我不完全理解这部分。

韩国关于mpi的资料不多,所以我一直在google和研究。如果是这个原因,有没有办法增加进程的数量?其他人写的是-np 17有错误,他们是如何将进程增加到两位数的?电脑有能力吗?请简单解释一下,以便我能很好地理解它。

标签: mpi

解决方案


我的笔记本电脑是 Intel i5,cpu 核心是 2 和 4 线程。是否因为只有 2 个核心而发生这样的问题?

是的。默认情况下,Open MPI 使用核心数作为插槽。因此,由于您只有 2 个内核,因此您最多只能启动 2 个进程。

如果是这个原因,有没有办法增加进程的数量?

是的,如果你使用--use-hwthread-cpus你的mpirun命令,你可以在你的笔记本电脑中使用多达 4 个 mpi 进程,因为你的笔记本电脑中有 4 个线程。尝试运行命令, mpirun -np 4 --use-hwthread-cpus a.out

此外,您可以使用--oversubscribe选项来增加大于可用内核/线程的进程数。例如试试这个mpirun -np 10 --oversubscribe a.out


推荐阅读