Fortran 减少错误
我不明白为什么下面的程序不起作用。当我使用“mpirun-np 2 a.out”运行它时,我希望它打印“N:2”,但它给了我一个seg错误 多谢各位 main.fFortran 减少错误,fortran,mpi,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
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
计算
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
摘自mpich2文档:
int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, int root, MPI_Comm comm)
您没有为mpi\u reduce
指定根目录。因此,mpi\u comm\u world
用作root
,而ierror
用作mpi\u comm
。您的意思是使用不需要根参数的MPI\u Allreduce
哦,如果可能的话,尝试使用使用mpi
而不是包括“mpif.h”
,这甚至可能捕获到当前错误。摘自mpich2文档:
int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, int root, MPI_Comm comm)
您没有为mpi\u reduce
指定根目录。因此,mpi\u comm\u world
用作root
,而ierror
用作mpi\u comm
。您的意思是使用不需要根参数的MPI\u Allreduce
哦,如果可能的话,尝试使用使用mpi
而不是包含“mpif.h”
,这甚至可能捕获到当前错误