【问题标题】:MPI_REDUCE errorMPI_REDUCE 错误
【发布时间】:2013-03-16 19:08:34
【问题描述】:

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

谢谢

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

计算.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

【问题讨论】:

    标签: fortran mpi


    【解决方案1】:

    取自 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 用作rootierror 用作MPI_Comm。您的意思是使用不需要根参数的MPI_Allreduce

    哦,如果可能,请尝试使用use mpi 而不是include 'mpif.h',这甚至可能会捕获当前错误。

    【讨论】:

      猜你喜欢
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 2013-01-21
      • 1970-01-01
      • 2014-01-25
      • 1970-01-01
      相关资源
      最近更新 更多