0

The below code gives me 4 variables saving 4 different rows with 10 colums, whereas I need to save like 4 columns in 10 rows. I'm using hexdump syntax to extract from the file

program main
use mpi
integer :: wsize,wrank,ierr,i,fh,offset
integer , parameter :: count = 10
integer :: buf1(count),buf2(count),buf3(count),buf4(count)
integer , dimension(10,2) :: buf
call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD,wrank,ierr)
call MPI_Comm_size(MPI_COMM_WORLD,wsize,ierr)

offset = 0;

call MPI_File_open(MPI_COMM_WORLD, "test1.dat", MPI_MODE_RDWR + MPI_MODE_CREATE, MPI_INFO_NULL, fh, ierr)

do i = 1,count
    buf1(i) = 1*i
    buf2(i) = 2*i
    buf3(i) = 3*i
    buf4(i) = 4*i

end do

call MPI_FILE_WRITE_AT(fh, offset, /buf1,buf2,buf3,buf4/), 4*count, MPI_INTEGER, mpi_status_ignore, ierr)

call MPI_File_close(fh,ierr)
call MPI_FINALIZE(ierr)
end program main

using Hexdump command:

hexdump -v -e ' "%10d" ' -e ' "\n"' test1.dat > hextest1.dat`

If you try to open hextest1.dat after conversions it seems to be like what I posted.

1    2      3      4      5      6      7      8      9     10
2    4      6      8     10      12    14     16     18     20
3    6      9     12     15      18    21     24     27     30
4   8      12     16     20      24    28     32     36     40
francescalus
  • 30,576
  • 16
  • 61
  • 96
  • Welcome. Please take the [tour] and read [ask] and [mcve]. Please use tag [tag:fortran] for all Fortran questions to get more attention. Your question is not Fortran 90 specific (Fortran 90 is old and obsolete). – Vladimir F Героям слава Dec 20 '17 at 06:27
  • What is your question? I can't find a question within your post. Any probles? Are the results not correct? – Vladimir F Героям слава Dec 20 '17 at 06:34
  • The file is binary. How do you define rows and columns? The file is just a sequence of values. – Vladimir F Героям слава Dec 20 '17 at 07:20
  • If you use %10d as a format for hexdump you are going to get values in chunks of 10. But I don't really get what you are asking, as Vladimir says the file is binary, internally there is no format. What are you trying to do? – Ian Bush Dec 20 '17 at 09:02
  • here buf1(i), buf2(i), buf3(i) and buf4(i) should be saved in test1.dat file with some delimiter. – Mallikarjun Dec 20 '17 at 12:08
  • If you want it to look lie a text file you are going to have to do the conversion to character yourself and manually add the delimiter - MPI-I/O, unlike Fortran I/O, wont do the conversion for you. – Ian Bush Dec 20 '17 at 15:49

0 Answers0