there is a diffult decision to be taken when working with big arrays
in fortran and how to store them. Which of the two is better? The
problem arises when this is becoming really big (ie. 2**14 x 512).
1. To store the whole array in memory during a loop and then write it
to a file.
example
-------------
real :: array1(3,4096)
do i = 1, 4096
do j = 1, 3
array(i,j) = .....
end do
end do
write(10,*) array1
2. To store the information in a scalar and add it at the end of the
file at each iteration.
example
-------------
real :: tmp
do i = 1, 4096
do j = 1, 3
tmp = .....
write(10,*) tmp
end do
end do
PS. Of course in both cases the appropriate format is used.
Here's the deal:
If you run your application on a cluster, my gut says that you should
store it in memory. On one hand, the cluster should be able to handle
the matrix (i.e. it should have enough memory). On the other hand, if
you write down the value upon its calculation, imagine all processors
trying to access the same file at once... It will be a message passing
nightmare and it will cause a lot of overhead, thus making your
program slower (a processor will start stalling as it waits for the
others to write their values in).
On a desktop computer however it should work the other way around.
Memory allocation can be a problem and some compilers even complain
when given an enormous array. Having a WRITE(file_number,*) command
inside a loop should not really influence its speed. You can make it
even faster by not using a FORMAT statement. Use simply
WRITE(file_number). This will write down the values in machine code
(don't ask me any details in that direction). Make sure to open the
file either as a direct acess file or simply as a unformatted file:
open(1,file='vangelis.txt',form='UNFORMATTED') After you are done with
the calculations, you can rewind the file and read the values again in
order to translate them in actual numbers!
I hope this helps
Vangelis