0

The problem below is Write a 4 * 4 buff array using mpiio. I use 4 cores, so the subarray should be 2 * 2. The problem is that, when I set buff is integer(2,2), and set all the MPI_DOUBLE_PRECISION to MPI_INTEGER, the code works well. However, MPI_DOUBLE_PRECISION gives wrong results. It is strang becasue I don't think there are mistakes when I set the buff array.

Integer results::
0000000           1           1           1           1
0000016           1           1           1           1
0000032           1           1           1           1
0000048           1           1           1           1
0000064


Double Precision results::
0000000           0  1072693248           0  1072693248
0000016           0  1072693248           0  1072693248
0000032           0  1072693248           0  1072693248
0000048           0  1072693248           0  1072693248
0000064           0  1072693248           0  1072693248
0000080           0  1072693248           0  1072693248
0000096           0  1072693248           0  1072693248
0000112           0  1072693248           0  1072693248
0000128

This is the code:


    program test
    use mpi
    implicit none
    integer::rank,nproc,ierr,buffsize,status(MPI_STATUS_SIZE),intsize,i,j,filetype,cart_comm,count
    integer::fh
    integer(kind=mpi_offset_kind):: offset=0
    double precision,dimension(2,2)::buff
    character:: filename*50
    integer::sizes(2)
    integer::gsize(2)
    integer::start(2)
    integer::subsize(2)
    integer::coords(2)
    integer:: nprocs_cart(2)=(/2,2/)
    logical::periods(2)
    character:: name*50,para*100,zone*100

    gsize=(/4,4/)
    subsize=(/2,2/)
    offset=0
    buff=1.d0
    count=1

    call MPI_init(ierr)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
    call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
    CALL MPI_Dims_create(nproc, 2, nprocs_cart, ierr)
    CALL MPI_Cart_create(MPI_COMM_WORLD, 2, nprocs_cart, periods, .TRUE., &
    cart_comm, ierr)
    CALL MPI_Comm_rank(cart_comm, rank, ierr)
    CALL MPI_Cart_coords(cart_comm, rank, 2, coords, ierr)


    start=coords*2

    call MPI_TYPE_CREATE_SUBARRAY(2,gsize,subsize,start,MPI_ORDER_FORTRAN,&
    MPI_DOUBLE_PRECISION,filetype,ierr)
    call MPI_TYPE_COMMIT(filetype,ierr)

    If( rank == 0 ) Then
        Call mpi_file_delete( 'out.dat', MPI_INFO_NULL, ierr )
     End If

     Call mpi_barrier( mpi_comm_world, ierr )
    
    call MPI_File_open(MPI_COMM_WORLD,'out.dat',&
            MPI_MODE_WRONLY + MPI_MODE_CREATE, MPI_INFO_NULL, fh,ierr)
    
    
        call MPI_File_set_view(fh,offset,MPI_DOUBLE_PRECISION,filetype,&
        "native",MPI_INFO_NULL,ierr)
      
        CALL MPI_FILE_WRITE_all(fh, buff,4, MPI_DOUBLE_PRECISION, MPI_STATUS_ignore, ierr)
    
    
    call MPI_File_close(fh,ierr)
    call MPI_FINALIZE(ierr)
    end program test
  • 2
    You really, really, really, really should say how you compiled and ran the program, and how you generated the above output - it's only because I answered the previous question that I can see what you have done wrong here. The issue is that integers and "double precision" are represented in different ways in binary files. Try `od -v -Ad -t f8 out.dat` and `man od`. Do you think the program is wrong now? – Ian Bush Jul 15 '21 at 16:30
  • You are perfect!!!! Thank you, you solve all the problems now! – Mac cchiatooo Jul 15 '21 at 16:36

0 Answers0