Hi developers of SIESTA

I should state that this bug has no effect on result of computation.
Nor should this bug concern you if you have never experienced a problem
with SIESTA, running MD calculations. (except that your execution actually
has a large set of open files)

I do not know how you would prefer bug-reports, so I will do my best in the
following.

I have experienced this problem using both Intel and gfortran compilers and
with NetCDF 4.1.2 and 4.1.3.
Checked in versions 3.0 and 3.1. I have not checked trunk-367.
I do not expect it to have anything to do with compiler nor what version of
libraries that is used, but for clarity you have my setup.

I have toyed with SIESTA for the last couple of months and when running it
on my own computer I always came short when doing MD-calculations.

The reason is simple. The files DM.nc and DMHS.nc gets opened/overwritten
anew on each MD-step. As I had not increased my maximum number of open
files count to a very large number, I quickly fell short.
A run of ulimit -n shows that I only had 1024 files allowed to be open at
the same time. Which meant that after ~500 steps I would flood my system
with open files.
This I verified in the folder /proc/{pid}/fd where each iteration led to a
new set of file-ids for the before mentioned files.

This is a bug as you should never open a file twice with a new
file-descriptor.
The bugfix is luckily as simple as checking if the NetCDF id is defined
before setting it up.

The corresponding fix is in these files:
iodmhs_netcdf.F90
iodm_netcdf.F90

A fix is to check for the ncid being defined on before hand.
So in steps: make ncid a saved variable. Initializing it to -1.
On setup of new file check if ncid > -1.
If it is, close the old file and continue as normal.
It should be noted that NetCDF only does file-ids of numbers above 0, so >
0 should also do! However, I find this approach clearer...

>>> Bugfix code changes

! In module header:
integer, save :: ncid = -1

! Inserted at top right before create, in subroutines setup_...:
if ( ncid >= 0 ) call check( nf90_close(ncid))
call check( nf90_create(fname,NF90_CLOBBER,ncid))

>>> Bugfix end of code changes

I have also attached diffs.

This will correctly close a file before creating a new/overwriting it.

By checking the folder: /proc/{pid}/fd one can see that the file-descriptor
use is actually kept constant when employing the above code-fix.

Kind regards Nick Papior Andersen

Attachment: iodmhs_netcdf.diff
Description: Binary data

Attachment: iodm_netcdf.diff
Description: Binary data

Responder a