mpi传递fortran对象问题
本帖最后由 wangmianzhi 于 2011-10-30 23:13 编辑问题:
* fortran要求必须是non-sequencial的type才能扩展成对象
* mpi要求必须是sequencial的type才能通过计算偏移包装成mpi扩展类型
这就造成要想传递对象,必须:
1. 把对象的数据拷给一个不带procedure的sequencial type
2. 计算偏移,制作自定义mpi类型
3. 发送,用同样的sequencial type接收
4. 拷到新的对象里
这个过程太恶心了。有没有体面一些的方法?
多谢
问题已解决。
mpi可以直接传递对象的数据
相关解释在这里:
http://www.mpi-forum.org/docs/mpi21-report/node337.htm#Node341
附上一个例子:module mp
type::typeA
integer::v1(3)
double precision::v2(2)
contains
procedure::show
end type
contains
subroutine show(this)
class(typeA)::this
write(*,*),this%v1,this%v2
end subroutine
end module
program test
use mp
use mpi
integer mpiErr,iP,mpiStat(MPI_status_size),mpiLen(2),mpiType(2)
integer(MPI_address_kind)::mpiDisp(2),mpiBase
type(typeA)::aa
call MPI_init(mpiErr)
call MPI_comm_rank(MPI_comm_world,iP,mpiErr)
mpiLen=
mpiType=
call MPI_get_address(aa%v1,mpiDisp(1),mpiErr)
call MPI_get_address(aa%v2,mpiDisp(2),mpiErr)
mpiBase=mpiDisp(1)
mpiDisp(:)=mpiDisp(:)-mpiBase
call MPI_type_create_struct(2,mpiLen,mpiDisp,mpiType,MPItypeA,mpiErr)
call MPI_type_commit(MPItypeA,mpiErr)
if(iP==0)then
aa%v1=
aa%v2=
call MPI_send(aa,1,MPItypeA,1,1,MPI_comm_world,mpiErr)
else
call MPI_recv(aa,1,MPItypeA,0,1,MPI_comm_world,mpiStat,mpiErr)
call aa%show
write(*,*),iP
end if
call MPI_finalize(mpiErr)
end program
页:
[1]