24小时热门版块排行榜    

查看: 924  |  回复: 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

铁虫 (小有名气)

也就是说我的这个程序是八个进程 同时获取了进程号和进程数,每个进程获取一个进程号,八个并行程序并行执行!
4楼2012-01-13 15:08:30
已阅   回复此楼   关注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

铁虫 (小有名气)

print*, my_rank
print*, numproc
实际上 我连输入也没赶上,这两个数是进程号,和总的进程数,这就是我郁闷的地方!
3楼2012-01-13 15:05:21
已阅   回复此楼   关注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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 328求调剂,英语六级551,有科研经历 +5 生物工程调剂 2026-03-17 9/450 2026-03-21 23:32 by zhujy1982
[考研] 生物学调剂 +3 Surekei 2026-03-21 3/150 2026-03-21 18:31 by 学员8dgXkO
[考研] 0703化学297求调剂 +3 Daisy☆ 2026-03-20 3/150 2026-03-21 17:45 by ColorlessPI
[考研] 317求调剂 +9 申子申申 2026-03-19 15/750 2026-03-21 17:31 by 学员8dgXkO
[考研] 299求调剂 +6 △小透明* 2026-03-17 6/300 2026-03-21 02:42 by JourneyLucky
[考研] 083200学硕321分一志愿暨南大学求调剂 +3 innocenceF 2026-03-17 3/150 2026-03-21 02:35 by JourneyLucky
[考研] 一志愿华南师大 070300(化学)304分求调剂 +3 0703武芊慧雪304 2026-03-18 3/150 2026-03-21 00:48 by JourneyLucky
[考研] 南京大学化学376求调剂 +3 hisfailed 2026-03-19 6/300 2026-03-20 23:43 by hisfailed
[考研] 考研调剂求学校推荐 +3 伯乐29 2026-03-18 5/250 2026-03-20 22:59 by JourneyLucky
[考研] 287求调剂 +7 晨昏线与星海 2026-03-19 8/400 2026-03-20 22:19 by JourneyLucky
[考研] 生物学调剂招人!!! +3 山海天岚 2026-03-17 4/200 2026-03-19 21:34 by 怎么释怀
[考研] 288求调剂,一志愿华南理工大学071005 +5 ioodiiij 2026-03-17 5/250 2026-03-19 18:22 by zcl123
[考研] 286求调剂 +6 lemonzzn 2026-03-16 10/500 2026-03-19 14:31 by lemonzzn
[考研] 一志愿985,本科211,0817化学工程与技术319求调剂 +10 Liwangman 2026-03-15 10/500 2026-03-19 10:25 by 无际的草原
[考研] 【同济软件】软件(085405)考研求调剂 +3 2026eternal 2026-03-18 3/150 2026-03-18 19:09 by 搏击518
[考研] 085601专硕,总分342求调剂,地区不限 +5 share_joy 2026-03-16 5/250 2026-03-18 14:48 by haxia
[考研] 材料,纺织,生物(0856、0710),化学招生啦 +3 Eember. 2026-03-17 9/450 2026-03-18 10:28 by Eember.
[考研] 一志愿南京大学,080500材料科学与工程,调剂 +4 Jy? 2026-03-16 4/200 2026-03-17 11:02 by gaoqiong
[考研] 318求调剂 +3 Yanyali 2026-03-15 3/150 2026-03-16 16:41 by houyaoxu
[考研] 0856专硕279求调剂 +5 加油加油!? 2026-03-15 5/250 2026-03-15 11:58 by 2020015
信息提示
请填处理意见