【发布时间】:2015-10-09 16:32:25
【问题描述】:
我有一个基本程序,它在线程之间发送消息并每次替换一个字符。我的问题是每个线程中生成的随机数总是相同的。这是我的代码:
if (me+1 == npe) then
a = 0
else
a = me + 1
end if
if (me == 0) then
b = npe-1
else
b = me-1
end if
if (me == 0) then
call MPI_Send(msg, len(msg), MPI_CHARACTER, a, tag, comm, ierr)
else
call MPI_Recv(msg, len(msg), MPI_CHARACTER, b, tag, comm, stat, ierr)
call random_number(u)
j = FLOOR(14*u)
msg(j:j) = "?"
call MPI_Send(msg, len(msg), MPI_CHARACTER, a, tag, comm, ierr)
end if
if (me == 0) then
call MPI_Recv(msg, len(msg), MPI_CHARACTER, b, tag, comm, stat, ierr)
end if
me = 线程数,npe = 线程总数
除了随机生成的数字外,一切正常。我尝试使用 call random_seed(me) 但它不起作用。
【问题讨论】:
-
为什么要让每个数字都不一样? mpi 的部分优势在于沟通者在相同的进程上工作。