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

Slime/Emacs Comint启动MPI进程时挂起问题求助

MPI Program Hangs When Launched via Slime/Emacs Comint, But Works in SBCL REPL

Problem Description

I've written a simple MPI program to reproduce an issue:

#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[]) {
    int rank, csize;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &csize);
    printf("Hello from rank[%d/%d]\n", rank, csize);
    MPI_Finalize();
}

After compiling it successfully, I can launch the executable via mpirun without any issues in the SBCL REPL:

* (uiop:run-program '("mpirun" "-np" "10" "./hello_world") :output :string)

However, when I try to start the MPI process in Slime/Emacs's comint, it hangs indefinitely. I'm looking for help to fix this.


Possible Solutions & Debugging Steps

1. Fix Terminal/TTY Allocation Issues

MPI implementations often rely on proper terminal access to spawn and manage processes. Slime's comint buffer might not provide the full TTY environment mpirun expects. Try these tweaks:

  • Add the --oversubscribe flag (common for OpenMPI) and explicitly redirect input/output to avoid interactive prompts:
    (uiop:run-program '("mpirun" "--oversubscribe" "-np" "10" "./hello_world") 
                      :input nil :output :string :error-output :string)
    
  • For other MPI implementations, use flags like -quiet to suppress interactive behavior.

2. Align Environment Variables

Slime might set different environment variables compared to your standalone SBCL REPL, which can break MPI. Check variables like MPI_HOME, PATH, LD_LIBRARY_PATH, and OMPI_MCA_* (for OpenMPI) in both contexts with:

;; Run this in both SBCL REPL and Slime comint
(uiop:print-environment-variables)

If you spot discrepancies, set the correct variables in your Emacs config or right before launching the MPI process.

3. Run MPI in Batch Mode

Some MPI launchers struggle with interactive terminals. Try detaching the process from comint by redirecting output to a file and running it in the background:

(uiop:run-program '("mpirun" "-np" "10" "./hello_world" "> output.log" "2>&1" "&") 
                  :shell t)

You can later check the output with:

(uiop:read-file-string "output.log")

4. Use Pseudo-Terminal Allocation

Slime's comint might be blocking process I/O. Try allocating a pseudo-terminal to mimic a real terminal environment:

(uiop:run-program '("mpirun" "-np" "10" "./hello_world") 
                  :pty t :output :string)

Note that not all Lisp implementations support the :pty option with uiop:run-program, so test this first.

5. Enable Verbose MPI Logging

Turn on verbose output from mpirun to pinpoint where the hang occurs. For OpenMPI, add -v or --verbose:

(uiop:run-program '("mpirun" "-v" "-np" "10" "./hello_world") 
                  :output :string :error-output :string)

The logs will show if MPI is failing to spawn processes, waiting for input, or hitting network/resource issues specific to the Slime environment.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:18:01