0

我正在编写一个需要将分布式数据写入单个文件的 mpi 代码。当我检查子数组函数时,子数组函数运行良好。但是如果使用文件集视图功能来收集数据,文件包括数据正确数据和 NaN 或一些垃圾数据,如下所示。

0.0000000000000000E+00    0.0000000000000000E+00    0.0000000000000000E+00
0.0000000000000000E+00    0.1000000000000000E+01    0.1000000000000000E+01
0.1000000000000000E+01    0.1000000000000000E+01    0.2000000000000000E+01
0.2000000000000000E+01    0.0000000000000000E+00    0.0000000000000000E+00
0.0000000000000000E+00    0.0000000000000000E+00    0.1000000000000000E+01
0.1000000000000000E+01    0.1000000000000000E+01    0.1000000000000000E+01
0.2000000000000000E+01    0.2000000000000000E+01    0.3000000000000000E+01
0.3000000000000000E+01    0.3000000000000000E+01    0.3000000000000000E+01
0.3000000000000000E+01    0.0000000000000000E+00   0.2073889954983216E-316

0.2317786220294740E-309 NaN 0.2317786709764340E-309 0.2317786698253895E-309 0.0000000000000000E+00 0.0000000000000000E+00 0.2317786820155404E-309 0.6953355807072957E-309 0.2317786698253895E-309 0.2317786820155404E-309 0.2317786698250041E-309 0.2317786836681109E-309 0.2073889954983216E-316 0.6953355807081653 E-309 0.2317786674551244E-309 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.2317788916456275E-309 0.0000000000000000E+00 0.0000000000000000E+00 0.6953355807081653E-309 0.2073889954983216E-316

我该如何解决?

     program test
  use mpi
  implicit none
  integer ierr,istatus,myrank,NPROCS,SUBARRAY,NUM,fh
  INTEGER START(0:2),GSIZE(0:2),SUBSIZE(0:2),i,j,k
  real*8,dimensional(:,:,:),pointer:: buf
  real*8 f(0:9)  
      call mpi_init(ierr)
  call mpi_comm_size(MPI_COMM_WORLD,NPROCS,IERR)
  CALL MPI_COMM_RANK(MPI_COMM_WORLD,MYRANK,IERR)

  GSIZE(0)=2
  GSIZE(1)=5
  GSIZE(2)=5

  IF(MYRANK.EQ.0)THEN
  allocate(buf(0:1,0:1,0:1))
  START(0)=0
  START(1)=0
  START(2)=0
  SUBSIZE(0)=2
  SUBSIZE(1)=2
  SUBSIZE(2)=2
  NUM=2*2*2
  buf=real(myrank)
  ELSEIF(MYRANK.EQ.1)THEN.
  allocate(buf(0:1,0:1,0:1))

  START(0)=0
  START(1)=2
  START(2)=0
  SUBSIZE(0)=2
  SUBSIZE(1)=2
  SUBSIZE(2)=2
  NUM=2*2*2
  buf=real(myrank)
  ELSEIF(MYRANK.EQ.2)THEN
  allocate(buf(0:1,1,0:1))

  START(0)=0
  START(1)=4
  START(2)=0      
  SUBSIZE(0)=2
  SUBSIZE(1)=1
  SUBSIZE(2)=2
  NUM=2*1*2
  buf=real(myrank)
  ELSEIF(MYRANK.EQ.3)THEN
  allocate(buf(0:1,0:4,0:1))

  START(0)=0
  START(1)=0
  START(2)=2      
  SUBSIZE(0)=2
  SUBSIZE(1)=5
  SUBSIZE(2)=2
      NUM=2*5*2  
  buf=real(myrank)
  ELSEIF(MYRANK.EQ.4)THEN
  allocate(buf(0:1,0:4,1))

  START(0)=0
  START(1)=0
  START(2)=4      
  SUBSIZE(0)=2
  SUBSIZE(1)=5
  SUBSIZE(2)=1
  NUM=2*5*1
  BUF=REAL(MYRANK)  

  ENDIF

  CALL MPI_TYPE_CREATE_SUBARRAY(3,GSIZE,SUBSIZE,START,
 &     MPI_ORDER_fortran,MPI_DOUBLE_PRECISION,SUBARRAY,IERR)
  CALL MPI_TYPE_COMMIT(SUBARRAY,IERR)

      call mpi_file_open(mpi_comm_world,'file',
 &    mpi_mode_wronly+mpi_mode_create,mpi_info_null,fh,ierr)

      call mpi_file_set_view(fh,0_mpi_offset_kind,
 &     mpi_double_precision,subarray,'native',mpi_info_null,ierr)
      call mpi_file_write_all(fh,buf,num,mpi_double_precision,
 &     istatus,ierr)

      call mpi_file_close(fh,ierr)



    CALL MPI_FINALIZE(IERR)

    END
4

0 回答 0