Re: Writing output files to memory



justabeginner wrote:
> Hi, is it possible for me to get Fortran to write its output files to
> memory instead of to a file on the hard drive?

Well yes, certainly. After all, your data lives in memory. And you can
use e.g. internal writes to massage that data in whatever ways you can
when you do file i/o as well.

> If so, what is the
> command I should use so I can look it up?

While it's certainly possible in principle, I have a nagging suspicion
that what you want to do (or rather, what you think you want to do)
involves relying on non-specified, non-standard and non-portable
behavior that it's not worth doing except for some _very_ special
circumstances.

> I am using SuSE 9.2 with the
> Intel Fortran compiler. Some people told me I need to write to
> /dev/null, but they weren't sure how to proceed beyond that.

Well, either those people didn't have a clue what they were talking
about, or then they misunderstood your question, or perhaps they were
mean and tried to mislead you. Whatever you write to /dev/null goes
straight to byte heaven.

> If I do get Fortran to write to memory, I will then require a 3rd
> party program (I have no access to this program's source code) to
> locate the output file in memory so that it can read/write to it. How
> do I know what memory address Fortran has written to?

To answer your second question first, I think some compilers have some
non-standard extension %LOC() for getting the address of a variable.

As for you first question, keep in mind that most contemporary
operating systems use something called virtual memory, where the
address you get via %LOC() (or from a C pointer) is not an absolute
address, but rather a process-specific virtual address. The operating
system kernel, in concert with a piece of hardware called the memory
management unit (MMU) takes care of translating these virtual
addresses into physical addresses as seen by the hardware.

Even if you via some black magic (such as a kernel module you have
written) aquire the physical address where your Fortran data resides,
that won't help you since if you try to access it somehow from the 3rd
party program, the kernel will detect that the 3rd party program is
overstepping its bounds and kill it.

The situation isn't all that bleak however; interprocess communication
is a common enough problem that most operating systems do have some
kind of support for it. I won't go into detail here, for unix see
e.g. chapter 7 of "the art of unix programming" available online at
http://www.faqs.org/docs/artu/

However, if you don't require any two-way communication the easiest
solution is probably a ramdisk, e.g. a piece of (virtual) memory that
looks like a disk. This is simple to set up in Linux (see
documentation about "tmpfs" filesystems), and your Fortran program
won't see any difference between a ramdisk and a normal disk.

Of course, in a virtual memory operating system the contents of the
ramdisk might very well be written to swap (to make room in the memory
for something the OS considers more important), and conversely a
short-lived file on a normal filesystem might never touch the disk,
living its entire life in buffer memory. So, back at square one. Go
figure. ;-)

> The next step for me will be to send these output files from Fortran
> over a distributed computing network. I suppose it is unavoidable that
> I will need to write the files to the hard disks then?

Well no, you can use a ramdisk like I explained above. OTOH, disk
bandwidth is something like two orders of magnitude higher than
between (DSL connected?) nodes in a distributed computing network, so
why worry? Writing results to disk now and then might be a good idea
anyway to avoid data loss in case of power failure etc..

--
Janne Blomqvist
.