MPI_Gather gives seg fault in the most basic code

后端 未结 2 1751
迷失自我
迷失自我 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
    

提交回复
热议问题