微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MPI (MPICH2) 和 Fortran 的布尔运算问题

如何解决MPI (MPICH2) 和 Fortran 的布尔运算问题

在使用 MPI(MPI_LAND 操作)对 Fortran 中的逻辑值执行归约时,MPICH2 返回 logical 类型的无效值,这将 .true. 返回给 value.not.value

例如,这是下面示例程序中 MPI_ALLREDUCE logicalmy_value = rank>=0 的结果:

on cpu 0,the local boolean value is 00000000000000000000000000000001
on cpu 0,the logical and of all values is T; its negation is T
on cpu 0,logical AND bits = 11111111111111111111111111111111 negation bits = 11111111111111111111111111111110  

MPI 似乎对逻辑变量执行了按位 AND 而不是运算。 MPI 错误还是我只是在这里做错了什么?顺便说一句 - 请注意:

  • 使用旧式 mpif.h 以实现可移植性
  • MPICH2 v1.4.1 + gfortran 10.2.0
program test_mpi_land
   implicit none
   
   include 'mpif.h'
   
   ! Local variables
   integer :: ierror,ncpu,cpuid
   logical :: my_bool,all_ok
   integer,parameter :: master_node = 0
   
   ! Init MPI; get basic info
   CALL MPI_Init(ierror)
   CALL MPI_Comm_size(MPI_COMM_WORLD,ierror)
   CALL MPI_Comm_rank(MPI_COMM_WORLD,cpuid,ierror)
 
   ! Each MPI process sends .true. to reduction
   my_bool = cpuid>=master_node
   CALL MPI_AllReduce(my_bool,all_ok,1,MPI_LOGICAL,MPI_LAND,MPI_COMM_WORLD,ierror)
 
   if (cpuid==master_node) then 
     print '(A,I0,A,B32.32)','on cpu ',',the local boolean value is ',my_bool
     print '(A,2(A,L0))',the logical and of all values is ','; its negation is ',.not.all_ok
     print '(A,B32.32))',logical AND bits = ',' negation bits = ',.not.all_ok
   endif    
 
   CALL MPI_Finalize(ierror)   
   
end program test_mpi_land

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。