MPI_REDUCE错误

时间:2013-03-16 06:47:05

标签: fortran mpi

我不明白为什么以下程序无效。当我使用“mpirun -np 2 a.out”运行它时,我希望它打印“N:2”,但它却给了我一个seg错误。

谢谢

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

1 个答案:

答案 0 :(得分:3)

取自mpich2文件:

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

您没有为root指定mpi_reduce。因此,mpi_comm_world用作rootierror用作MPI_Comm。你的意思是使用MPI_Allreduce,它不需要根参数吗?

哦,如果可能的话,尽量使用use mpi而不是include 'mpif.h',这可能会抓住当前的错误。