Program does not write the output completely

Hi all,
I have successfully moved hydrodynamic code from Compaq Visual Fortran to PG Fortran in Unix. Everything works correctly except some outputs are not completly written. In other words, some data is missing at the end of each file.

Any suggestion from experts as why this happens. I need to fix this problem as soon as possible. Thanks for your help.

Regards,
Venkat

Hi Venkat,

Some questions for you.

How does your program exit?
What kind of Fortran writes are you doing for the files? i.e. Formatted/Unformatted? Sequential/Direct?
What OPEN Specifiers are you using for the file?

  • Mat

Hi Mat,
Thanks for getting back to me.
Here is one of my open statements.
open (NFlog, file = file_name(1:len_trim(file_name)), status = ‘unknown’)
It is a formatted file. Some files are direct and some are sequential.

I have shown below top section of the output

Minimum droplet size = 11
Maximum droplet size = 133

PartID SrcID Size(um) Mass (tons) Rls Time(secs)

1 1 0 0.201900E+01 0.173000E+03
2 1 0 0.201900E+01 0.346000E+03
3 1 0 0.201900E+01 0.518000E+03
4 1 0 0.201900E+01 0.691000E+03
5 1 0 0.201900E+01 0.864000E+03
6 1 0 0.201900E+01 0.103700E+04
7 1 0 0.201900E+01 0.121000E+04
8 1 0 0.201900E+01 0.138200E+04
9 1 0 0.201900E+01 0.155500E+04
10 1 0 0.201900E+01 0.172800E+04

And in the end,

10957 2 93 0.664546E+01 0.103308E+07
10958 2 106 0.664546E+01 0.103317E+07
10959 2 120 0.664546E+01 0.103326E+07
10960 2 133 0.664546E+0

It did not write completely.

Hope this helps.

Thanks
Venkat

Hi Venkat,

My best guess is that I/O buffers aren’t getting flushed to disk before your program exits. Are you closing your files before exiting? Is the program abnormally exiting or hitting a stop statement before close can be called?

One thing to try is to disable buffering by calling “setvbuf3f(NFlog,2,0)”. It will slow down your program but ensure I/O gets to the disk.

  • Mat

From the PGI Fortran Reference Guide:

setvbuf3f
Change I/O buffering behavior.

interface
function setvbuf3f(lu, typ, size)
integer setvbuf3f, lu, typ, size
end function
end interface


Description
Fortran I/O supports 3 types of buffering., described in detail in the
description of “setvbuf,” on page 310

Logical units 5 (stdin) and 6 (stdout) are line buffered. Logical unit 0 (stderr) is unbuffered. Disk files are fully buffered. These defaults generally give the expected behavior. You can use setvbuf3f to change a unit’s buffering type and size of the buffer.

Note. The underlying stdio implementation may silently restrict your choice of buffer size. This function must be called after the unit is opened and before any I/O is done on the unit. The typ parameter can have the following values, 0 specifies full buffering, 1 specifies line buffering, and 2 specifies unbuffered. The size parameter specifies the size of the buffer.

This function returns zero on success and non-zero on failure. An example of a program in which this function might be useful is a long-running program that periodically writes a small amount of data to a log file. If the log file is line buffered, you could check the log file for progress. If the log file is fully buffered (the default), the data may not be written to disk until the program terminates.

Thanks Mat,
When I used your suggestion, couple of files wrote correctly.
But some files still does not show any data until the program is completed.
I will check some more and get back to you.

Regards,
Venkat