Generally you know the type and number of the things written in your binary file (e.g. all integers, 10 int
3 float
, etc). You can read as numbers of bytes but MPI binary files are usually read/written as a whole number of types, in your case 9 integers (so number of digits are not important). You open the file and read with something like,
call MPI_FILE_OPEN(MPI_COMM_WORLD, filename, &
MPI_MODE_RDONLY , MPI_INFO_NULL, fh, ierr)
bufsize = 3*3
allocate(buf(bufsize))
call MPI_FILE_READ_ALL(fh, buf, bufsize, MPI_integer, &
MPI_STATUS_IGNORE, ierr)
For variable matrix sizes, you can use things like MPI_File_get_size
to get the size and work out how many elements to read. For mixed data, you can have the first (or last) part of the binary file as a header, which you read first and use to decode the rest of your file. You would still need to know the format of the header and this can be problematic as you break backwards compatibility when you change the code/header format. This is part of the reason for data formats like HDF5 https://support.hdfgroup.org/HDF5/