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 (将#修改为@)