24小时热门版块排行榜    

CyRhmU.jpeg
查看: 827  |  回复: 6

xianweiwang

铁虫 (小有名气)

[求助] 这段并行程序有问题,不知道错在什么地方请大家看看!

MODULE GLOBAL
implicit none
type INDATA_TYPE
real a
real b
integer n
end type INDATA_TYPE
END MODULE GLOBAL

program Get_data3
use global
include 'mpif.h'
type(INDATA_TYPE) indata
integer my_rank
integer mesg_mpi_t
integer ierr
  call MPI_INIT (ierr)
  call MPI_COMM_RANK (MPI_COMM_WORLD,my_rank,ierr)
  call MPI_COMM_SIZE (MPI_COMM_WORLD,numproc,ierr)
print*, my_rank
print*, numproc
  call MPI_Barrier(MPI_COMM_WORLD,ierr)

if(my_rank.eq.0)then
  print *, 'Enter a, b, and n'
  read *, indata%a, indata%b, indata%n
endif

  call Build_derived_type(indata, mesg_mpi_t)
  call MPI_BCAST(indata, 1, mesg_mpi_t, 0,MPI_COMM_WORLD,ierr )
       print*, indata%a, indata%b, indata%n
  call MPI_Barrier(MPI_COMM_WORLD,ierr)
  call MPI_FINALIZE(ierr)
end
subroutine Build_derived_type(indata, mesg_mpi_t)
use GLOBAL
IMPLICIT NONE
INCLUDE 'mpif.h'
type(INDATA_TYPE) indata
integer mesg_mpi_t
integer ierr
integer block_lengths(3)
integer displacements(3)
integer address(4)
integer typelist(3)
typelist(1) = MPI_REAL
typelist(2) = MPI_REAL
typelist(3) = MPI_INTEGER
block_lengths(1) = 1
block_lengths(2) = 1
block_lengths(3) = 1
call MPI_address(indata, address(1), ierr)
call MPI_address(indata%a, address(2), ierr)
call MPI_address(indata%b, address(3), ierr)
call MPI_address(indata%n, address(4), ierr)
displacements(1) = address(2) - address(1)
displacements(2) = address(3) - address(1)
displacements(3) = address(4) - address(1)
call MPI_TYPE_STRUCT(3, block_lengths, displacements, typelist, mesg_mpi_t, ierr)
call MPI_TYPE_COMMIT(mesg_mpi_t, ierr)
return
end
运行结果是
mpirun -np 8 ./a.out
0
1
Enter a, b, and n
0
1
Enter a, b, and n
0
1
Enter a, b, and n
0
1
Enter a, b, and n
0
1
Enter a, b, and n
0
1
Enter a, b, and n
0
1
Enter a, b, and n
0
1
Enter a, b, and n
forrtl: severe (24): end-of-file during read, unit -4, file stdin
Image PC Routine Line Source
a.out 00000000004B8891 Unknown Unknown Unknown
这样看是进程的编号不对,不知道为什么这样!
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖


感谢参与,应助指数 +1
jjdg(金币+1): 感谢参与 2012-01-14 00:07:27
你的输入不对吧,程序要三个数,你只输入两个?
2楼2012-01-13 13:41:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xianweiwang

铁虫 (小有名气)

print*, my_rank
print*, numproc
实际上 我连输入也没赶上,这两个数是进程号,和总的进程数,这就是我郁闷的地方!
3楼2012-01-13 15:05:21
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xianweiwang

铁虫 (小有名气)

也就是说我的这个程序是八个进程 同时获取了进程号和进程数,每个进程获取一个进程号,八个并行程序并行执行!
4楼2012-01-13 15:08:30
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cean

金虫 (职业作家)

屌绳一条

【答案】应助回帖


感谢参与,应助指数 +1
jjdg(金币+1): 感谢参与 2012-01-16 10:11:43
  read *, indata%a, indata%b, indata%n

不明白。是说a的类型是indata么?那样a本身就需要3个数了。
To do great work, you have to have a pure mind.
5楼2012-01-16 04:31:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xianweiwang

铁虫 (小有名气)

引用回帖:
: Originally posted by cean at 2012-01-16 04:31:45:
  read *, indata%a, indata%b, indata%n

不明白。是说a的类型是indata么?那样a本身就需要3个数了。

这个是f90里面的扩展类型,indata%a表示数据indata里面的a元素!
6楼2012-01-16 12:48:43
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cean

金虫 (职业作家)

屌绳一条

【答案】应助回帖


jjdg(金币+1): 感谢参与 2012-01-17 10:08:46
你试一下先读数,后赋值给indata.
To do great work, you have to have a pure mind.
7楼2012-01-16 13:27:58
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 xianweiwang 的主题更新
信息提示
请填处理意见