今天来分享“MPICH:MPII_Init_thread(222): gpu_init failed”这个问题的解决方式

前言 #

如果在安装 MPICH 的时候没有注意要一些选项,那么当使用mpicxx mpi_send.cpp -o send && mpirun -n 2 ./send进行编译输出的时候,就会得到一段报错:MPICH:MPII_Init_thread(222): gpu_init failed这个问题在国内外没有一个人指出答案,希望后续有人搜到,能够帮助到你。

问题原因 #

这个问题在于,我们在安装 MPICH 的时候,如果我们安装了 CUDA 或者 HIP,那么 MPICH 它对于 GPU 是默认自动启动支持的。

回顾文档,重要的安装细节包括:

GPU support is automatically enabled if CUDA, ZE, or HIP runtime is detected during configure. To specify where your GPU runtime is installed, use:--with-cuda=<path> or --with-ze=<path> or --with-hip=<path>

(我认为在这要指定是因为 cuda 这些安装不是正常位置,安装程序没有找到)

If the lib/ and include/ are not in the same path, both can be specified separately, for example: --with-cuda-include= and --with-cuda-lib=

In addition, GPU support can be explicitly disabled by using:--without-cuda or --without-ze or --without-hip

(如果当初加了这个指令,那么安装后就不会自动启用 GPU 支持了。这里是产生问题的根本原因)

解决方案 #

如果没有注意到上面,默认就启动了 GPU 支持。只要程序没有关于 GPU 相关的调用函数,就会报错。那么如何挽救呢?难道重装吗? 不用不用,只要设置一个环境变量即可:MPIR_CVAR_ENABLE_GPU=0