24小时热门版块排行榜    

查看: 910  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 328求调剂,英语六级551,有科研经历 +3 生物工程调剂 2026-03-16 4/200 2026-03-16 20:13 by Wangjingyue
[考研] 0703化学调剂 +6 妮妮ninicgb 2026-03-15 9/450 2026-03-16 16:40 by houyaoxu
[考研] 0703一志愿211 285分求调剂 +5 ly3471z 2026-03-13 5/250 2026-03-16 16:16 by 哦哦123
[考研] 290求调剂 +5 孔志浩 2026-03-12 10/500 2026-03-16 09:01 by 余晖&
[考研] 085601材料工程315分求调剂 +3 yang_0104 2026-03-15 3/150 2026-03-15 10:58 by peike
[考研] 328求调剂 +3 5201314Lsy! 2026-03-13 6/300 2026-03-14 15:31 by hyswxzs
[考研] 267一志愿南京工业大学0817化工求调剂 +5 SUICHILD 2026-03-12 5/250 2026-03-14 14:53 by jean5056
[考研] 材料与化工(0856)304求B区调剂 +7 邱gl 2026-03-10 11/550 2026-03-14 12:18 by 邱gl
[考研] 308 085701 四六级已过求调剂 +7 温乔乔乔乔 2026-03-12 14/700 2026-03-14 10:49 by JourneyLucky
[考研] 0805,333求调剂 +3 112253525 2026-03-10 3/150 2026-03-13 23:42 by JourneyLucky
[考研] 336求调剂 +6 Iuruoh 2026-03-11 6/300 2026-03-13 22:06 by JourneyLucky
[考研] 材料工程调剂 +4 咪咪空空 2026-03-11 4/200 2026-03-13 19:57 by JourneyLucky
[考研] 工科材料085601 279求调剂 +8 困于星晨 2026-03-12 10/500 2026-03-13 15:42 by ms629
[考研] 277求调剂 +4 anchor17 2026-03-12 4/200 2026-03-13 11:15 by 白夜悠长
[考研] 289求调剂 +3 李政莹 2026-03-12 3/150 2026-03-13 11:02 by 求调剂zz
[考研] 材料专硕274一志愿陕西师范大学求调剂 +4 薛云鹏 2026-03-13 4/200 2026-03-13 10:40 by 学员8dgXkO
[考研] 283求调剂,材料、化工皆可 +8 苏打水7777 2026-03-11 10/500 2026-03-13 09:06 by Linda Hu
[考研] 279求调剂 +3 莫xiao 2026-03-10 4/200 2026-03-11 08:06 by 斩魂滴兔子!
[考研] 化工0817调剂 +8 灿若星晨 2026-03-10 8/400 2026-03-10 22:44 by 星空星月
[考博] 26申博求助 +3 跳跃饼干 2026-03-10 4/200 2026-03-10 21:15 by Tntcnn
信息提示
请填处理意见