MPI_Gather gives seg fault in the most basic code

后端 未结 2 1742
迷失自我
迷失自我 2020-12-04 03:31

I am working on a much bigger program where I struggle with MPI_Gather.

I wrote a minimal example code, see below.

 program test
  use MPI
  integer          


        
相关标签:
2条回答
  • 2020-12-04 03:33

    The big problem is that you did not include the last arg ierr in the call to MPI_Gather. The doc said

    All MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list.

    In addition to that, my advise is to always stick to good practice: Do not use intrinsic funtion names for your variable, example of size.

    program test
        use MPI
        integer :: ierr, rank, nProc
        double precision, allocatable, dimension(:) :: send, recv
    
        call MPI_Init(ierr)
        if (ierr /= 0) print *, 'Error in MPI_Init'
    
        call MPI_Comm_size(MPI_COMM_WORLD, nProc, ierr)
        if (ierr /= 0) print *, 'Error in MPI_Comm_size'
        call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
        if (ierr /= 0) print *, 'Error in MPI_Comm_size'
    
        allocate(send(1), recv(nProc))
    
        send(1) = rank
    
        call MPI_Gather(send, 1, MPI_DOUBLE_PRECISION, &
                        recv, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)
        if (ierr /= 0) print *, 'Error in MPI_Gather'
        print *, recv
        call MPI_Finalize(ierr)
    end program test
    
    0 讨论(0)
  • 2020-12-04 03:38

    You have forgotten to add the return error code to the call to MPI_Gather as the last argument. The value of the return code is being written to an unmapped address.

    It should read

    call MPI_Gather(send, 1, MPI_DOUBLE_PRECISION, &
                    recv, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)
    

    ifort catches this at the compilation stage. It looks like your compiler (gfortran?) doesn't

    0 讨论(0)
提交回复
热议问题