24小时热门版块排行榜    

查看: 923  |  回复: 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的回帖

xianweiwang

铁虫 (小有名气)

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

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖


感谢参与,应助指数 +1
jjdg(金币+1): 感谢参与 2012-01-14 00:07:27
你的输入不对吧,程序要三个数,你只输入两个?
2楼2012-01-13 13:41:14
已阅   回复此楼   关注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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 326求调剂 +4 mlpqaz03 2026-03-15 4/200 2026-03-21 19:10 by ColorlessPI
[考研] 求调剂 +5 十三加油 2026-03-21 5/250 2026-03-21 18:48 by 学员8dgXkO
[考研] 0703化学297求调剂 +3 Daisy☆ 2026-03-20 3/150 2026-03-21 17:45 by ColorlessPI
[考研] 298求调剂 +4 上岸6666@ 2026-03-20 4/200 2026-03-21 17:14 by 学员8dgXkO
[考研] 材料学学硕080502 337求调剂-一志愿华中科技大学 +4 顺顺顺mr 2026-03-18 5/250 2026-03-21 10:22 by luoyongfeng
[考研] 一志愿天津大学化学工艺专业(081702)315分求调剂 +12 yangfz 2026-03-17 12/600 2026-03-21 03:30 by JourneyLucky
[考研] 化学求调剂 +4 临泽境llllll 2026-03-17 5/250 2026-03-21 02:23 by JourneyLucky
[考研] 一志愿武理材料305分求调剂 +6 想上岸的鲤鱼 2026-03-18 7/350 2026-03-21 01:03 by JourneyLucky
[考研] 一志愿华南师大 070300(化学)304分求调剂 +3 0703武芊慧雪304 2026-03-18 3/150 2026-03-21 00:48 by JourneyLucky
[考研] 材料学求调剂 +4 Stella_Yao 2026-03-20 4/200 2026-03-20 20:28 by ms629
[考研] 材料与化工专硕调剂 +7 heming3743 2026-03-16 7/350 2026-03-20 19:31 by zhukairuo
[考研] 环境工程调剂 +9 大可digkids 2026-03-16 9/450 2026-03-20 17:38 by 醉在风里
[考研] 求调剂 +3 暗涌afhb 2026-03-16 3/150 2026-03-20 00:28 by 河南大学校友
[考研] 081700化工学硕调剂 +3 【1】 2026-03-16 3/150 2026-03-19 23:40 by edmund7
[考研] 286求调剂 +6 lemonzzn 2026-03-16 10/500 2026-03-19 14:31 by lemonzzn
[考研] 本科郑州大学物理学院,一志愿华科070200学硕,346求调剂 +4 我不是一根葱 2026-03-18 4/200 2026-03-19 09:11 by 浮云166
[考研] 293求调剂 +11 zjl的号 2026-03-16 16/800 2026-03-18 08:10 by zhukairuo
[考研] 考研求调剂 +3 橘颂. 2026-03-17 4/200 2026-03-17 21:43 by 有只狸奴
[考研] 326求调剂 +5 上岸的小葡 2026-03-15 6/300 2026-03-17 17:26 by ruiyingmiao
[考研] 材料工程专硕274一志愿211求调剂 +6 薛云鹏 2026-03-15 6/300 2026-03-17 11:05 by 学员h26Tkc
信息提示
请填处理意见