24小时热门版块排行榜    

查看: 909  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[硕博家园] 深圳大学硕士招生(2026秋,传感器方向,仅录取第一志愿) +4 xujiaoszu 2026-03-11 8/400 2026-03-16 09:45 by xujiaoszu
[考研] 材料专硕306英一数二 +3 z1z2z3879 2026-03-16 3/150 2026-03-16 09:19 by Demonsssss
[考研] 290求调剂 +5 孔志浩 2026-03-12 10/500 2026-03-16 09:01 by 余晖&
[考研] 东南大学364求调剂 +4 JasonYuiui 2026-03-15 4/200 2026-03-16 08:36 by Linda Hu
[考研] 0703化学调剂 ,六级已过,有科研经历 +4 曦熙兮 2026-03-15 4/200 2026-03-15 18:01 by JourneyLucky
[考研] 304求调剂 +5 小熊joy 2026-03-14 5/250 2026-03-14 21:07 by peike
[考研] 330求调剂 +3 ?酱给调剂跪了 2026-03-13 3/150 2026-03-14 10:13 by JourneyLucky
[考研] 0703求调剂 +7 jtyq001 2026-03-10 7/350 2026-03-14 01:06 by JourneyLucky
[考研] 321求调剂 +3 CUcat 2026-03-10 3/150 2026-03-14 00:25 by JourneyLucky
[考研] 26考研调剂 +3 ying123. 2026-03-10 3/150 2026-03-14 00:18 by JourneyLucky
[考研] 2026考研调剂+本科延边大学+山东大学+生物化学与分子生物学+有项目经验 +3 ccdsscjy 2026-03-10 3/150 2026-03-14 00:12 by JourneyLucky
[考研] 26调剂/材料科学与工程/总分295/求收留 +9 2026调剂侠 2026-03-12 9/450 2026-03-13 20:46 by 18595523086
[考研] 材料工程调剂 +4 咪咪空空 2026-03-11 4/200 2026-03-13 19:57 by JourneyLucky
[考研] 310求调剂 +3 【上上签】 2026-03-11 3/150 2026-03-13 16:16 by JourneyLucky
[考研] 302求调剂 +6 负心者当诛 2026-03-11 6/300 2026-03-13 16:11 by JourneyLucky
[考研] 26考研求调剂 +5 丶宏Sir 2026-03-13 5/250 2026-03-13 13:05 by JourneyLucky
[考研] 0856化工原理 +6 z2839474511 2026-03-10 6/300 2026-03-13 10:41 by houyaoxu
[考研] 材料专硕274一志愿陕西师范大学求调剂 +4 薛云鹏 2026-03-13 4/200 2026-03-13 10:40 by 学员8dgXkO
[考研] 调剂 +5 呵唔哦豁 2026-03-10 5/250 2026-03-10 22:00 by 28375m
[考博] 26申博求助 +3 跳跃饼干 2026-03-10 4/200 2026-03-10 21:15 by Tntcnn
信息提示
请填处理意见