* Re: Forcing 32-bit integers and math
[not found] ` <6vt65k$5hp$1@walter-fddi.cray.com>
@ 1998-10-14 4:00 ` G. Hugh SONG
1998-10-14 4:00 ` Greg Lindahl
1998-10-15 4:00 ` Toon Moene
0 siblings, 2 replies; 13+ messages in thread
From: G. Hugh SONG @ 1998-10-14 4:00 UTC (permalink / raw)
Jeff Drummond wrote:
> In article <YQsT1.507$525.1552696@ptah.visi.com>, epowell@visi.com (Edward J. Powell) writes:
> |>
> |> Okay, I'm attempting to learn Fortran on a Cray (gloat gloat), and I've
> |> run into a bit of a problem with what I'm working on.
> |>
> |> I need 32-bit integers. Cray really wants to do 64-bit stuff.
>
> Yes, we really do. You can get 32-bit integers on CRAY MPP (T3E) systems,
> but not on the CRAY PVP (C90/T90) systems.
>
> |> I define variables as integer*4. This should make them 32-bit.
>
> No. We generally regard integer*n as a request rather than a commandment.
> On CRAY PVP systems it may allow us to use a reduced precision model, but
> the container size will still be 64-bits.
>
It seems that the exact same thing happens with Alpha/Linux g77 fortran.
I was trying to enforce compatibility between Intel/Linux and Alpha/Linux
g77.
Here is what I did:
I created a simple fortran program:
program OUTtest
implicit none
integer UOUt, i, id(5)
parameter(Uout = 11)
integer*2 i2(5)
integer*4 i4(5)
real rd(5)
real*8 r8(5)
do i = 1, 5
i2(i) = i
id(i) = i
i4(i) = i
r8(i) = i
rd(i) =i
end do
open(Uout, file = 'i2.dt', form='unformatted')
write(Uout) i2
close(Uout)
open(Uout, file = 'i4.dt', form='unformatted')
write(Uout) i4
close(Uout)
open(Uout, file = 'id.dt', form='unformatted')
write(Uout) id
close(Uout)
open(Uout, file = 'rd.dt', form='unformatted')
write(Uout) rd
close(Uout)
open(Uout, file = 'r8.dt', form='unformatted')
write(Uout) r8
close(Uout)
stop
end
Then, I created two executables, test.ix for intel and test.ax for alpha.
The file sizes of the output files after running test.ix are
-rw------- 1 ghsong faculty 28 Oct 14 11:47 i4.dt
-rw------- 1 ghsong faculty 28 Oct 14 11:47 id.dt
-rw------- 1 ghsong faculty 48 Oct 14 11:47 r8.dt
-rw------- 1 ghsong faculty 28 Oct 14 12:21 rd.dt
-rw------- 1 ghsong faculty 18 Oct 14 11:47 i2.dt
After running test.ax, they are
-rw------- 1 ghsong faculty 36 Oct 14 11:35 i4.dt
-rw------- 1 ghsong faculty 36 Oct 14 11:35 id.dt
-rw------- 1 ghsong faculty 56 Oct 14 11:35 r8.dt
-rw------- 1 ghsong faculty 36 Oct 14 12:18 rd.dt
-rw------- 1 ghsong faculty 26 Oct 14 11:35 i2.dt
This result implies that the two output "record" files are
significantly different.
Even if they both use IEEE-format, there is extra bits of
information appended on the fortran output files must also
be different.
Reading the files from test.ax into IDL running on Intel/Linux
fails with the message such as "Corrupted input data".
It seems that the only solution to this incompatibility problem
is to let C-code handle all the binary outputs or to use
ascii outputs only, which is unacceptable with huge data files.
Regards,
>
> Hope this helps,
>
> -Jeff jjd@cray.com
--
G. Hugh Song
PS: Please remove "Spamspoiler" when replying
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-14 4:00 ` Forcing 32-bit integers and math G. Hugh SONG
@ 1998-10-14 4:00 ` Greg Lindahl
1998-10-15 4:00 ` Jeff Drummond
1998-10-15 4:00 ` H.W. Stockman
1998-10-15 4:00 ` Toon Moene
1 sibling, 2 replies; 13+ messages in thread
From: Greg Lindahl @ 1998-10-14 4:00 UTC (permalink / raw)
"G. Hugh SONG" <ghsong@\"Spamspoiler\"kjist.ac.kr> writes:
> This result implies that the two output "record" files are
> significantly different.
> Even if they both use IEEE-format, there is extra bits of
> information appended on the fortran output files must also
> be different.
Yes, a Cray writes an 8-byte record length expressed in WORDS, not
BYTES.
Linux/Alpha writes an 8-byte record length in bytes.
Linux/x86 writes a 4-byte record length in bytes.
It is fairly trivial to write a conversion program. There is a
record length at the start and end of each record.
-- g
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-14 4:00 ` Greg Lindahl
1998-10-15 4:00 ` Jeff Drummond
@ 1998-10-15 4:00 ` H.W. Stockman
1998-10-15 4:00 ` Jeff Drummond
1998-10-15 4:00 ` Greg Lindahl
1 sibling, 2 replies; 13+ messages in thread
From: H.W. Stockman @ 1998-10-15 4:00 UTC (permalink / raw)
Greg Lindahl wrote:
[...]
> Linux/Alpha writes an 8-byte record length in bytes.
>
> Linux/x86 writes a 4-byte record length in bytes.
>
> It is fairly trivial to write a conversion program. There is a
> record length at the start and end of each record.
I was under the impression that the exact form of the record
delimiter (for unformatted files) is not specified by F77. In
most FORTRANs I have used, the delimiter is simply an integer
that corresponds to the record length, as implied in the
previous discussion. However, I think other FORTRANs (e.g.
Lahey) have more complicated record delimiters. Thus two FORTRANs
on the same platform may not seemlessly exchange unformatted files--
que no?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-15 4:00 ` H.W. Stockman
1998-10-15 4:00 ` Jeff Drummond
@ 1998-10-15 4:00 ` Greg Lindahl
1998-10-15 4:00 ` James Giles
1 sibling, 1 reply; 13+ messages in thread
From: Greg Lindahl @ 1998-10-15 4:00 UTC (permalink / raw)
"H.W. Stockman" <hwstock@wizard.com> writes:
> I was under the impression that the exact form of the record
> delimiter (for unformatted files) is not specified by F77. In
> most FORTRANs I have used, the delimiter is simply an integer
> that corresponds to the record length, as implied in the
> previous discussion. However, I think other FORTRANs (e.g.
> Lahey) have more complicated record delimiters. Thus two FORTRANs
> on the same platform may not seemlessly exchange unformatted files--
> que no?
Right. On Unix platforms, which is what this fellow is using, there is
a simple convention: a 4-byte delimiter giving the length of the
record in bytes. I've yet to meet an alternate Fortran compiler on a
Unix box which did anything different; the only incompatibility I've
seen springs from the desire to support 64 bits, and between
platforms, Cray's use of a word length instead of a byte length.
-- g
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-15 4:00 ` H.W. Stockman
@ 1998-10-15 4:00 ` Jeff Drummond
1998-10-15 4:00 ` Greg Lindahl
1 sibling, 0 replies; 13+ messages in thread
From: Jeff Drummond @ 1998-10-15 4:00 UTC (permalink / raw)
[ followups set to comp.lang.fortran ]
In article <36255A0B.4C40@wizard.com>, "H.W. Stockman" <hwstock@wizard.com> writes:
|> Greg Lindahl wrote:
|> [...]
|> > Linux/Alpha writes an 8-byte record length in bytes.
|> >
|> > Linux/x86 writes a 4-byte record length in bytes.
|> >
|> > It is fairly trivial to write a conversion program. There is a
|> > record length at the start and end of each record.
|>
|> I was under the impression that the exact form of the record
|> delimiter (for unformatted files) is not specified by F77. In
|> most FORTRANs I have used, the delimiter is simply an integer
|> that corresponds to the record length, as implied in the
|> previous discussion. However, I think other FORTRANs (e.g.
|> Lahey) have more complicated record delimiters. Thus two FORTRANs
|> on the same platform may not seemlessly exchange unformatted files--
|> que no?
That is correct. The Fortran standard specifically leaves the structure
of unformatted files up to the individual implementation. Since the
standard also requires various record positioning capabilities (i.e.,
BACKSPACE and skipping records), that effectively requires that there be
_some_ structure.
-Jeff jjd@sgi.com
--
"Are we going to push it to the edge of the envelope?" --Pinky
"No, Pinky. We may, however, reach the sticky part." --The Brain
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-14 4:00 ` Greg Lindahl
@ 1998-10-15 4:00 ` Jeff Drummond
1998-10-15 4:00 ` H.W. Stockman
1 sibling, 0 replies; 13+ messages in thread
From: Jeff Drummond @ 1998-10-15 4:00 UTC (permalink / raw)
[ followups set to comp.lang.fortran ]
In article <702t4k$met@news3.newsguy.com>, lindahl@pbm.com (Greg Lindahl) writes:
|> "G. Hugh SONG" <ghsong@\"Spamspoiler\"kjist.ac.kr> writes:
|>
|> > This result implies that the two output "record" files are
|> > significantly different.
|> > Even if they both use IEEE-format, there is extra bits of
|> > information appended on the fortran output files must also
|> > be different.
|>
|> Yes, a Cray writes an 8-byte record length expressed in WORDS, not
|> BYTES.
This is incorrect. On CRAY systems we read and write a variety of
unformatted file types. They all express record lengths in bytes
(either 8-bit or 12-bit) or bits.
-Jeff jjd@sgi.com
--
"If an expert says something can be done he is probably correct, but if he
says it is impossible then consider getting another opinion." -R. W. Hamming
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-15 4:00 ` Greg Lindahl
@ 1998-10-15 4:00 ` James Giles
1998-10-15 4:00 ` Greg Lindahl
1998-10-15 4:00 ` Richard Maine
0 siblings, 2 replies; 13+ messages in thread
From: James Giles @ 1998-10-15 4:00 UTC (permalink / raw)
Greg Lindahl wrote in message <703ulq$68a@news3.newsguy.com>...
...
>Right. On Unix platforms, which is what this fellow is using, there is
>a simple convention: a 4-byte delimiter giving the length of the
>record in bytes. I've yet to meet an alternate Fortran compiler on a
>Unix box which did anything different; the only incompatibility I've
>seen springs from the desire to support 64 bits, and between
>platforms, Cray's use of a word length instead of a byte length.
I would be surprised if there were only a 4-byte record length on
UNIX platforms. One main reason to have record marks is to be
able to BACKSPACE the unit. This means that if you're positioned
at the start of record N in the file, you need to know the length of
record N-1 so that you can skip that distance backwards.
All Fortran I/O libraries I've seen (and I've even written one) have
a record mark which contains both the length of the next record
and the length of the preceeding record. On Crays, this was represented
as a 64-bit quantity: the first 32 were the length of the preceeding
record and the second 32 were the length of the following record.
If UNIX platforms typically use only 4 bytes for this, they must be
limiting records to lengths of 64K(16 bit length counts). And since
they use bytes as their unit of length, that's 64K bytes = 16K (32-bit)
words. Is that what they do?
--
J. Giles
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-14 4:00 ` Forcing 32-bit integers and math G. Hugh SONG
1998-10-14 4:00 ` Greg Lindahl
@ 1998-10-15 4:00 ` Toon Moene
1 sibling, 0 replies; 13+ messages in thread
From: Toon Moene @ 1998-10-15 4:00 UTC (permalink / raw)
"G. Hugh SONG" <ghsong@\"Spamspoiler\"kjist.ac.kr> wrote:
> open(Uout, file = 'i2.dt', form='unformatted')
> write(Uout) i2
> close(Uout)
...
> open(Uout, file = 'r8.dt', form='unformatted')
> write(Uout) r8
> close(Uout)
> stop
> end
> Then, I created two executables, test.ix for intel and test.ax for alpha.
> The file sizes of the output files after running test.ix are
> -rw------- 1 ghsong faculty 28 Oct 14 11:47 i4.dt
> -rw------- 1 ghsong faculty 28 Oct 14 11:47 id.dt
> -rw------- 1 ghsong faculty 48 Oct 14 11:47 r8.dt
> -rw------- 1 ghsong faculty 28 Oct 14 12:21 rd.dt
> -rw------- 1 ghsong faculty 18 Oct 14 11:47 i2.dt
> After running test.ax, they are
> -rw------- 1 ghsong faculty 36 Oct 14 11:35 i4.dt
> -rw------- 1 ghsong faculty 36 Oct 14 11:35 id.dt
> -rw------- 1 ghsong faculty 56 Oct 14 11:35 r8.dt
> -rw------- 1 ghsong faculty 36 Oct 14 12:18 rd.dt
> -rw------- 1 ghsong faculty 26 Oct 14 11:35 i2.dt
> This result implies that the two output "record" files are
> significantly different.
Indeed they are - the Alpha unformatted records have two 64-bit record length
specifiers, whereas the Intel ones use 32-bit specifiers.
Note that the Fortran Standard doesn't guarantee you anything about the
possibility of reading unformatted files on one system that were written on
another; therefore the records in them and their sizes do not necessarily
have to agree.
For this sort of exchange, use formatted I/O or a portable "binary" format
like HDF.
Hope this helps,
--
Toon Moene (mailto:toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
g77 Support: mailto:fortran@gnu.org; egcs: mailto:egcs-bugs@cygnus.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-15 4:00 ` James Giles
@ 1998-10-15 4:00 ` Greg Lindahl
1998-10-16 4:00 ` Jeff Drummond
1998-10-15 4:00 ` Richard Maine
1 sibling, 1 reply; 13+ messages in thread
From: Greg Lindahl @ 1998-10-15 4:00 UTC (permalink / raw)
"James Giles" <jamesgiles@worldnet.att.net> writes:
> All Fortran I/O libraries I've seen (and I've even written one) have
> a record mark which contains both the length of the next record
> and the length of the preceeding record.
Conceptual difference: I call that 2 record marks. At the start of the
file there is only 1 record mark.
> On Crays, this was represented
> as a 64-bit quantity: the first 32 were the length of the preceeding
> record and the second 32 were the length of the following record.
I just looked on a Cray and it seems to have changed formats between
f77 and f90. The new format is considerably different.
-- g
unicos% od o
0000000000000 000000 000000 000000 000001 000000 000000 000000 000020
[ r1 length ? ] [ record 1 data ]
0000000000020 100000 000000 000000 000001 000000 000000 000000 000021
[ combo of r1 and r2 len? ] [ record 2 data ]
0000000000040 100000 000000 000000 000000 160000 000000 000000 000000
[ r2 length? ]
0000000000060 170000 000000 000000 000000 000000 000000 000000 000000
0000000000100 000000 000000 000000 000000 000000 000000 000000 000000
*
0000000010000
A bit satantic for my taste, with the reverse lengths reversed?
unicos% cat test.f
program test
open (unit=21, file = 'o', form='unformatted', status='unknown')
write (21) 16
write (21) 17
close (unit=21)
stop
end
32-bit linux% od o
0000000 000004 000000 000020 000000 000004 000000 000004 000000
^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^
little-endian data repeat of length of
length in bytes r1 length record 2
0000020 000021 000000 000004 000000
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
record 2 data repeat of r2 length
64-bit linux% od o
0000000 000004 000000 000000 000000 000020 000000 000004 000000
0000020 000000 000000 000004 000000 000000 000000 000021 000000
0000040 000004 000000 000000 000000
0000050
Note the 32-bit lengths are now 64-bit lengths.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-15 4:00 ` James Giles
1998-10-15 4:00 ` Greg Lindahl
@ 1998-10-15 4:00 ` Richard Maine
1998-10-18 4:00 ` James Giles
1 sibling, 1 reply; 13+ messages in thread
From: Richard Maine @ 1998-10-15 4:00 UTC (permalink / raw)
"James Giles" <jamesgiles@worldnet.att.net> writes:
> I would be surprised if there were only a 4-byte record length on
> UNIX platforms....
>
> If UNIX platforms typically use only 4 bytes for this, they must be
> limiting records to lengths of 64K(16 bit length counts). And since
> they use bytes as their unit of length, that's 64K bytes = 16K (32-bit)
> words. Is that what they do?
No. Definitely not. I've regularly write longer records that that.
As far as I'm aware, both Gren and you are right. The record header
is only 4 bytes. But there is also a 4 byte record trailer. This is
almost synonymous with your record hearder that has 2 4-bytes words.
The difference is just at the beginning and end of the file. I.E. If
H is the header and T the trailer, you should see
H...TH...TH...TH...T
instead of (calling T and H the coressponding 2 parts of your header).
TH...TH...TH...TH...
P.S. I *HAVE* seen a non-unix system (Elxsi) that used only headers with no
trailer or other way to record the size of the preceding record. Backspace
even worked - wanna know how? It kept track of the current record number
and, if you wanted to backspace, it rewound the file and skipped N-2 records.
This made some things "interesting". One nice thing about the Elxsi
headers, though, was that they kept one bit for a record continuation
mark. Thus you could have arbitrarily long records, even with just a
2-byte header. (The header size was user-selectable and the system
remembered which size each file had). This if you had a file with mostly
short records, you could use a 2-byte (or even 1-byte) header to keep
the overhead down without ruling out the possibility of the occasional
long record. The long records just ended up using multiple headers
with the record continuation bit set. Lets see, in the old IBM mainframe
days, I thing we'd have called that a segmented record, but I could
misrecall the terminology.
--
Richard Maine
maine@altair.dfrc.nasa.gov
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-15 4:00 ` Greg Lindahl
@ 1998-10-16 4:00 ` Jeff Drummond
1998-10-16 4:00 ` James Giles
0 siblings, 1 reply; 13+ messages in thread
From: Jeff Drummond @ 1998-10-16 4:00 UTC (permalink / raw)
[ followups trimmed to comp.lang.fortran ]
In article <705o8j$g5f@news1.newsguy.com>, lindahl@pbm.com (Greg Lindahl) writes:
|> "James Giles" <jamesgiles@worldnet.att.net> writes:
|>
|> > All Fortran I/O libraries I've seen (and I've even written one) have
|> > a record mark which contains both the length of the next record
|> > and the length of the preceeding record.
|>
|> Conceptual difference: I call that 2 record marks. At the start of the
|> file there is only 1 record mark.
|>
|> > On Crays, this was represented
|> > as a 64-bit quantity: the first 32 were the length of the preceeding
|> > record and the second 32 were the length of the following record.
That's not the default format. It's what we call f77 format, which is
just our implementation of the usual Unix Fortran format.
|> I just looked on a Cray and it seems to have changed formats between
|> f77 and f90. The new format is considerably different.
As the maintainer of the run-time library, I can assure you that the
default file formats have not changed between cf77 and f90. They haven't
changed appreciably in the 17 years I've been at Cray (now SGI).
|> unicos% od o
|> 0000000000000 000000 000000 000000 000001 000000 000000 000000 000020
|> [ r1 length ? ] [ record 1 data ]
[ r1 length amonst other things ]
|> 0000000000020 100000 000000 000000 000001 000000 000000 000000 000021
|> [ combo of r1 and r2 len? ] [ record 2 data ]
No, the upper bit (in the word starting at byte 20)
indicates that the previous record has been terminated
and that a new record is starting.
|> 0000000000040 100000 000000 000000 000000 160000 000000 000000 000000
|> [ r2 length? ]
No, it indicates that the second record has been
terminated. The word starting at byte 48 is the endfile
indicator.
|> 0000000000060 170000 000000 000000 000000 000000 000000 000000 000000
^^ end of data.
|> 0000000000100 000000 000000 000000 000000 000000 000000 000000 000000
|> *
|> 0000000010000
|>
|> A bit satantic for my taste,
Satanic? You have no idea.
|> with the reverse lengths reversed?
No, what you are interpreting as the reverse lengths is actually
other information in the record control word.
-Jeff jjd@sgi.com
--
The mistakes of the past become the archetypes of the future.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-16 4:00 ` Jeff Drummond
@ 1998-10-16 4:00 ` James Giles
0 siblings, 0 replies; 13+ messages in thread
From: James Giles @ 1998-10-16 4:00 UTC (permalink / raw)
Jeff Drummond wrote in message <707pop$20h$1@walter-fddi.cray.com>...
...
>|> > On Crays, this was represented
>|> > as a 64-bit quantity: the first 32 were the length of the preceeding
>|> > record and the second 32 were the length of the following record.
>
>That's not the default format. It's what we call f77 format, which is
>just our implementation of the usual Unix Fortran format.
It's what CTSS used. I never was really an expert on COS.
--
J. Giles
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Forcing 32-bit integers and math
1998-10-15 4:00 ` Richard Maine
@ 1998-10-18 4:00 ` James Giles
0 siblings, 0 replies; 13+ messages in thread
From: James Giles @ 1998-10-18 4:00 UTC (permalink / raw)
Richard Maine wrote in message ...
...
>P.S. I *HAVE* seen a non-unix system (Elxsi) that used only headers with no
>trailer or other way to record the size of the preceding record. Backspace
>even worked - wanna know how? It kept track of the current record number
>and, if you wanted to backspace, it rewound the file and skipped N-2 records.
Ouch. Well, in order to get to record N, it should have traversed the
file sequentially. Why not keep track of the previous record's length
instead of just the record number? Then a single backspace would
be easy. Multiple backspaces would still require going back to the
start. Actually, you could make a trade-off between memory overhead
in the I/O implementation and the time required for backspacing by
keeping the last N record lengths on a stack (throwing away the oldest
one when you try to push more than N) and figuring what value of
N is sufficient for the "average" number of consecutive backspaces.
It cold be made to work I suppose. Not worth it though: better
to have the backward link.
--
J. Giles
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~1998-10-18 4:00 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <YQsT1.507$525.1552696@ptah.visi.com>
[not found] ` <6vt65k$5hp$1@walter-fddi.cray.com>
1998-10-14 4:00 ` Forcing 32-bit integers and math G. Hugh SONG
1998-10-14 4:00 ` Greg Lindahl
1998-10-15 4:00 ` Jeff Drummond
1998-10-15 4:00 ` H.W. Stockman
1998-10-15 4:00 ` Jeff Drummond
1998-10-15 4:00 ` Greg Lindahl
1998-10-15 4:00 ` James Giles
1998-10-15 4:00 ` Greg Lindahl
1998-10-16 4:00 ` Jeff Drummond
1998-10-16 4:00 ` James Giles
1998-10-15 4:00 ` Richard Maine
1998-10-18 4:00 ` James Giles
1998-10-15 4:00 ` Toon Moene
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox