0

i'm writing an mpi code that needs to write distributed data to single file. when i check subarray function , subarray function works well. But if using file set view function to collect data, file include data proper data and NaN or some trash data like below.

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.6953355807081653E-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

how can i fix that?

     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
chan lee
  • 1
  • 1
  • If you write `MPI_DOUBLE_PRECISION` you must initialize the first `num_bytes` of `but` and this is not what you are doing. – Gilles Gouaillardet Oct 30 '19 at 12:33
  • 1
    `istatus` should be an integer array of size `MPI_STATUS_SIZE`, not a scalar. – rtoijala Oct 30 '19 at 12:37
  • Gilles Gouallardet you means i must initilize buf array doing like buf=0.d ?? i did but any difference is shown. – chan lee Oct 30 '19 at 12:49
  • You might want to declare an allocate buffer and only allocate the exact subsize on each rank. – Gilles Gouaillardet Oct 30 '19 at 13:25
  • Thank you for answer me. i try to allocate each rank but but still same result occur.if i apply file set view or file write all to my code in 3d distribution array, is any special treatment needed? – chan lee Oct 30 '19 at 14:30
  • after fixing your code that does not compile, i can run it without any issues. are you sure you are running with 4 MPI tasks? did you remove `file` before invoking `mpirun`? how do you test the result ? `od -tf8 file` does not show any suspicious numbers. which MPI library (vendor & version) are you running ? – Gilles Gouaillardet Oct 31 '19 at 00:22
  • i resolve it. i had a mistake making output file.Thank you so much!!!. – chan lee Oct 31 '19 at 00:45

0 Answers0