Home > Archive > Fortran > April 2005 > Problem when writing unformatted data to file using Intel Fortran
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Problem when writing unformatted data to file using Intel Fortran
|
|
| Matthias Möller 2005-04-27, 8:58 am |
| Hi,
I need to write large data to file without formatting them. The
following program demonstrates what happens if compiled with:
Intel(R) Fortran Compiler for 32-bit applications, Version 8.1 Build
20041019Z Package ID: l_fc_pu_8.1.021
Copyright (C) 1985-2004 Intel Corporation. All rights reserved.
program unform
implicit none
integer, dimension(:,:), pointer :: kdata
integer :: n1,n2
n1=10; n2=264448
allocate(kdata(n1,n2)); kdata=1
open(unit=77,file="test.bin",form="UNFORMATTED")
write(unit=77) n1
write(unit=77) n2
write(unit=77) kdata
close(77)
deallocate(kdata)
open(unit=77,file="test.bin",form="unformatted")
read(unit=77) n1
read(unit=77) n2
allocate(kdata(n1,n2))
read(unit=77) kdata
close(unit=77)
end program unform
In line "write(unit=77) kdata" I get a segmentation fault. If I change
the pointer attribute of kdata into allocatable everything works fine.
However, I need the pointer attribute in my real code. In addition if I
let kdata be "allocatable" but modify its output according to
write(unit=77) kdata(:,:)
the same segmantation fault occurs.
Many thanks in advance,
Matthias Moeller
| |
| glen herrmannsfeldt 2005-04-28, 4:01 am |
| Matthias Möller wrote:
> I need to write large data to file without formatting them. The
following program demonstrates what happens if compiled with:
(snip)
> n1=10; n2=264448
> allocate(kdata(n1,n2)); kdata=1
> open(unit=77,file="test.bin",form="UNFORMATTED")
> write(unit=77) n1
> write(unit=77) n2
> write(unit=77) kdata
> close(77)
Remember that each UNFORMATTED write writes one record to the
file. It might require enough buffer space for the largest
record written, which is huge in your case.
I don't know that there is any magical record size, but
I might suggest keeping it below about 64K bytes, or
16K elements assuming four byte data. For your case, I would
probably try:
open(unit=77,file="test.bin",form="UNFORMATTED")
write(unit=77) n1,n2
do 1 i=1,n2
1 write(unit=77) (kdata(j,i),j=1,n1)
close(77)
Without knowing the possible values for n1, it is hard to say.
This might make the record length a little small, but if n1 can
get to the 100's or 1000's it is probably about right.
If n1 is always 10 then you could write multiple columns
(or is it rows, I forget) to each record.
As data is in memory with the leftmost subscript varying fastest,
you should write it out that way, as shown above.
-- glen
| |
| Matthias Möller 2005-04-28, 8:58 am |
| Thanks for your help. I wonder where to get version 8.1.027. The latest
version which can be downloaded from Intel is 8.1.024
Matthias Moeller
> Your program is running out of stack due to a stack temporary created by the
> compiler. I haven't tried your case, but we did make some changes in this
> area since the compiler you're using. 8.1.027 is current. The alternative is
> to raise your stacksize limit.
>
>
> Steve Lionel
> Software Products Division
> Intel Corporation
> Nashua, NH
>
> User communities for Intel Software Development Products
> http://softwareforums.intel.com/
> Intel Fortran Support
> http://developer.intel.com/software/products/support/
|
|
|
|
|