You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu终端运行C语言MPI代码报错:无法连接本地mpd的解决咨询

Fixing "mpiexec_karim: cannot connect to local mpd" Error in Ubuntu MPI

The error you're seeing points to a problem with the MPI Process Daemon (MPD)—a component used in older MPI implementations like MPICH2—either not running at all or missing the required console mode flag. Here's how to resolve this:

Option 1: Properly Configure and Start MPD (For MPICH2)

If you're sticking with MPICH2, follow these steps to get the daemon working correctly:

  1. Create the MPD secret file
    MPD requires a password file to operate. Create a .mpd.conf in your home directory with a simple secret string (replace your_secret with any value you like):
echo "secretword=your_secret" > ~/.mpd.conf
chmod 600 ~/.mpd.conf

The chmod 600 ensures only your user can access this sensitive file.

  1. Start MPD in console mode
    Use the -n flag (console mode) mentioned in the error message to launch the daemon:
mpd -n

This will create the required socket at /tmp/mpd2.console_karim that mpirun needs to connect to.

  1. Verify MPD is running
    Check if the daemon is active with:
ps aux | grep mpd

You should see an mpd process listed in the output.

  1. Run your MPI program again
    Now execute your compiled program as before:
mpirun -np 3 test

Option 2: Switch to OpenMPI (Modern, Daemon-Free Alternative)

MPD is deprecated in newer MPI ecosystems. OpenMPI is a more user-friendly, modern alternative that doesn't require a background daemon. Here's how to set it up:

  1. Install OpenMPI
    If you don't have it installed already, run:
sudo apt update
sudo apt install openmpi-bin libopenmpi-dev
  1. Recompile your code
    The mpicc wrapper will now point to OpenMPI's compiler. Recompile your code:
mpicc main.c -o test
  1. Run the program directly
    No daemon setup is needed—just execute your program:
mpirun -np 3 test

This should produce your expected output:

Greetings from process 1 !
Greetings from process 2 !
Greetings from process 3 !

Quick Note on Your Code

Your MPI code is correctly structured—it follows standard MPI initialization, rank/size checks, and message passing logic. The issue is purely with the runtime environment setup, not the code itself.

内容的提问来源于stack exchange,提问作者Kareem Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:17:15