2013-03-16 50 views
0

我不明白爲什麼下面的程序不工作。當我用「mpirun -np 2 a.out」運行它時,我期望它打印出「N:2」,但是它會給我一個seg故障。MPI_REDUCE錯誤

謝謝

main.f

program main 

    implicit none 

    include 'mpif.h' 

    integer me, ngs,ierror 

    call inimpi(me, ngs) 

    call calc 

    call mpi_finalize(ierror) 

    stop 
    end 

inimpi.f

subroutine inimpi(me, ngs) 

    include 'mpif.h' 

    integer me, ngs, ierror 

    call mpi_init(ierror) 
    call mpi_comm_rank(mpi_comm_world, me, ierror) 
    call mpi_comm_size(mpi_comm_world, ngs, ierror) 

    return 
    end 

calc.f

subroutine calc 

    include 'mpif.h' 

    integer p, e, ierror 

    p = 1 

    call mpi_reduce(p, e, 1, mpi_integer, 
&  mpi_sum, mpi_comm_world, ierror) 

    print *, "N: ", e 
    return 
    end 

回答

3

從MPICH2資料爲準:

int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, 
       MPI_Op op, int root, MPI_Comm comm) 

您沒有爲mpi_reduce指定root。因此,使用mpi_comm_world作爲root,使用ierror作爲MPI_Comm。你的意思是使用MPI_Allreduce,它不需要根參數?

噢,如果可能的話,儘量使用use mpi而不是include 'mpif.h',這可能甚至會引發當前的錯誤。

+0

謝謝你指出。 – jhaprade 2013-03-18 01:32:51