Cambridge-Cranfield HPCF > Information for Users > Programming and Compilation > IO |
The rest of this discussion is divided into the following sections:
Finally, there is a section on data transfer.
The point that implicit do loops are far more efficient than explicit ones is well known and applies to almost all architectures. On babbage
PARAMETER(ISIZE=64) DOUBLE PRECISION A(ISIZE*128*1024) WRITE(10)(A(I),I=1,ISIZE*128*1024)produces a 64Mb file which can be read at over 6Mb/s, whereas writing it with
DO I=1,ISIZE*128*1024 WRITE(10)A(I) ENDDOproduces a 128Mb file which reads at under 0.5 Mb/s (useful data transfer rate).
In C the programmer has rather more control over how I/O is performed, and the defaults are less reasonable than for FORTRAN. In particular, with fread it is possible to set the buffer size via a call to setvbuf. This can dramatically improve the I/O performance on babbage:
buffer size | Throughput (Mb/s) |
---|---|
8K | 2.2 |
16K | 3.5 |
32K | 4.8 |
64K | 6.8 |
128K | 8.8 |
512K | 10.4 |
For small quantities of data, the simplest solution is to write out the data in a formatted fashion, and read it in on the other machine in the same way. Do remember not to truncate the precision of the data too hard when writing it out!
For larger quantities of data (tens of Mb), it may be necessary to consider something more efficient. In order for machine A to read data from machine B, the two machines must agree on three points:
The HPCF machines are all big-endian. This is perhaps now the dominant byte ordering, but two important chip lines are little-endian, DEC's Alpha line (Alphas and Cray T3D), and Intel's 80x86 line (all PC's including Pentiums). DEC provides a library call for endian reversal (cvt_ftof in libm), Intel provides an instruction (486+)...
The matter of headers and trailers is one which can be ignored in C - what you write is what you get. In FORTRAN, however the file is opened, the HPCF machines put some sort of header and trailer on the file. The header even includes a time stamp, so files with identical data can fail a comparison using UNIX utilities. Nick recommends forging headers, I (MJR) recommend calling C from FORTRAN to do the I/O. Either way, you may wish to contact us (support@hpcf.cam.ac.uk) for further advice if you need to transfer large amounts of floating point data from the HPCF to other systems.