找回密码
 注册
Simdroid-非首页
查看: 63|回复: 1

[3. Fortran] mpi传递fortran对象问题

[复制链接]
发表于 2011-10-30 23:12:14 | 显示全部楼层 |阅读模式 来自 美国
本帖最后由 wangmianzhi 于 2011-10-30 23:13 编辑

问题:
* fortran要求必须是non-sequencial的type才能扩展成对象
* mpi要求必须是sequencial的type才能通过计算偏移包装成mpi扩展类型

这就造成要想传递对象,必须:
1. 把对象的数据拷给一个不带procedure的sequencial type
2. 计算偏移,制作自定义mpi类型
3. 发送,用同样的sequencial type接收
4. 拷到新的对象里
这个过程太恶心了。有没有体面一些的方法?
多谢


 楼主| 发表于 2011-10-31 09:22:58 | 显示全部楼层 来自 美国
Simdroid开发平台
问题已解决。
mpi可以直接传递对象的数据
相关解释在这里:
http://www.mpi-forum.org/docs/mpi21-report/node337.htm#Node341

附上一个例子:
  1. module mp
  2.   type::typeA
  3.     integer::v1(3)
  4.     double precision::v2(2)
  5.   contains
  6.     procedure::show
  7.   end type
  8. contains
  9.   subroutine show(this)
  10.     class(typeA)::this
  11.     write(*,*),this%v1,this%v2
  12.   end subroutine
  13. end module

  14. program test
  15.   use mp
  16.   use mpi
  17.   
  18.   integer mpiErr,iP,mpiStat(MPI_status_size),mpiLen(2),mpiType(2)
  19.   integer(MPI_address_kind)::mpiDisp(2),mpiBase
  20.   type(typeA)::aa
  21.   
  22.   call MPI_init(mpiErr)
  23.   call MPI_comm_rank(MPI_comm_world,iP,mpiErr)
  24.   
  25.   mpiLen=[3,2]
  26.   mpiType=[MPI_integer,MPI_double_precision]
  27.   call MPI_get_address(aa%v1,mpiDisp(1),mpiErr)
  28.   call MPI_get_address(aa%v2,mpiDisp(2),mpiErr)
  29.   mpiBase=mpiDisp(1)
  30.   mpiDisp(:)=mpiDisp(:)-mpiBase
  31.   call MPI_type_create_struct(2,mpiLen,mpiDisp,mpiType,MPItypeA,mpiErr)
  32.   call MPI_type_commit(MPItypeA,mpiErr)
  33.   
  34.   if(iP==0)then
  35.     aa%v1=[1,2,3]
  36.     aa%v2=[1,2]
  37.     call MPI_send(aa,1,MPItypeA,1,1,MPI_comm_world,mpiErr)
  38.   else
  39.     call MPI_recv(aa,1,MPItypeA,0,1,MPI_comm_world,mpiStat,mpiErr)
  40.     call aa%show
  41.     write(*,*),iP
  42.   end if
  43.   
  44.   call MPI_finalize(mpiErr)
  45. end program
复制代码
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-6-12 13:38 , Processed in 0.052651 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表