Your Location is: Home > Linux

Debugging mpi with gdb has problems [closed]

From: Vanuatu View: 1107 jason-lin 


I have installed a virtual machine (VM) on my computer, and the linux system is debian. I use the vscode plugin for remote connection, and I want to debug the mpi program via gdb. But I encountered some difficulties

 mpiexec -np 3 xterm -e gdb -ex=run ./1

1 is my executable program。 This time the virtual machine will appear with 3 xterm windows, which is good。 I still have no problem when I add breakpoints, when I run the program it gets stuck

Starting program: /home/mpi1/mpi/mpitutorial/tutorials/mpi-hello-world/code/1 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/"

only using ctrl+c to force stop the program.The error message is as follows:

Program received signal SIGINT, Interrupt.
0x00007ffff7b7e461 in __GI___libc_read (fd=6, buf=0x7ffff7f9bf20, nbytes=1023)
    at ../sysdeps/unix/sysv/linux/read.c:26
(gdb) 26        ../sysdeps/unix/sysv/linux/read.c: Without that file or directory.

This has bothered me for a long time, please help me

Source Code:

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

int main(int argc, char *argv[])
    int rank, value, size;
    MPI_Status status;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank); 
    MPI_Comm_size(MPI_COMM_WORLD, &size); 
    do {
        if (rank==0) {
            fprintf(stderr, "\nPlease give new value=");
            fprintf(stderr, "%d read <-<- (%d)\n",rank,value);
            /*There must be at least two processes before data can be passed*/
            if (size>1) {
                MPI_Send(&value, 1, MPI_INT, rank+1, 0, MPI_COMM_WORLD);
                fprintf(stderr, "%d send (%d)->-> %d\n", rank,value,rank+1);
        else {
            MPI_Recv(&value, 1, MPI_INT, rank-1, 0, MPI_COMM_WORLD, &status);
            fprintf(stderr, "%d receive(%d)<-<- %d\n",rank, value, rank-1);
            if (rank<size-1) {
                MPI_Send(&value, 1, MPI_INT, rank+1, 0, MPI_COMM_WORLD);
                fprintf(stderr, "%d send (%d)->-> %d\n", rank, value, rank+1);

This program implements the relay transfer of data between processes

Running results

picture 2

Best answer