2015-03-26 20:04:05 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2015-03-27 10:44:39 +01:00
|
|
|
__author__ = "Applencourt PEP8"
|
2015-03-26 20:04:05 +01:00
|
|
|
__date__ = "jeudi 26 mars 2015, 12:49:35 (UTC+0100)"
|
|
|
|
|
|
|
|
"""
|
|
|
|
Creates the provider of a variable that has to be
|
|
|
|
fetched from the EZFIO file.
|
|
|
|
"""
|
|
|
|
|
2015-04-01 12:02:02 +02:00
|
|
|
import sys
|
2015-03-26 20:04:05 +01:00
|
|
|
|
2015-05-11 14:40:55 +02:00
|
|
|
|
2015-03-26 20:04:05 +01:00
|
|
|
class EZFIO_Provider(object):
|
|
|
|
|
2015-03-26 20:26:20 +01:00
|
|
|
data = """
|
2015-05-11 14:40:55 +02:00
|
|
|
BEGIN_PROVIDER [ %(type)s, %(name)s %(size)s ]
|
2015-03-26 20:04:05 +01:00
|
|
|
implicit none
|
|
|
|
BEGIN_DOC
|
2015-03-26 20:26:20 +01:00
|
|
|
! %(doc)s
|
2015-03-26 20:04:05 +01:00
|
|
|
END_DOC
|
|
|
|
|
|
|
|
logical :: has
|
|
|
|
PROVIDE ezfio_filename
|
2017-11-28 00:54:22 +01:00
|
|
|
if (mpi_master) then
|
|
|
|
%(test_null_size)s
|
|
|
|
call ezfio_has_%(ezfio_dir)s_%(ezfio_name)s(has)
|
|
|
|
if (has) then
|
|
|
|
call ezfio_get_%(ezfio_dir)s_%(ezfio_name)s(%(name)s)
|
|
|
|
else
|
|
|
|
print *, '%(ezfio_dir)s/%(ezfio_name)s not found in EZFIO file'
|
|
|
|
stop 1
|
|
|
|
endif
|
2015-03-26 20:04:05 +01:00
|
|
|
endif
|
2017-11-28 00:54:22 +01:00
|
|
|
IRP_IF MPI
|
|
|
|
include 'mpif.h'
|
|
|
|
integer :: ierr
|
|
|
|
call MPI_BCAST( %(name)s, %(size_mpi)s, %(type_mpi)s, 0, MPI_COMM_WORLD, ierr)
|
|
|
|
if (ierr /= MPI_SUCCESS) then
|
|
|
|
stop 'Unable to read %(name)s with MPI'
|
|
|
|
endif
|
|
|
|
IRP_ENDIF
|
2015-03-26 20:26:20 +01:00
|
|
|
%(write)s
|
2015-03-26 20:04:05 +01:00
|
|
|
END_PROVIDER
|
2015-03-26 20:26:20 +01:00
|
|
|
""".strip()
|
2015-03-26 20:04:05 +01:00
|
|
|
|
|
|
|
write_correspondance = {"integer": "write_int",
|
|
|
|
"logical": "write_bool",
|
|
|
|
"double precision": "write_double"}
|
|
|
|
|
2017-11-28 00:54:22 +01:00
|
|
|
mpi_correspondance = {"integer": "MPI_INTEGER",
|
|
|
|
"integer*8": "MPI_INTEGER8",
|
|
|
|
"character*(32)": "MPI_CHARACTER",
|
|
|
|
"logical": "MPI_LOGICAL",
|
|
|
|
"double precision": "MPI_DOUBLE_PRECISION"}
|
|
|
|
|
2015-03-26 20:04:05 +01:00
|
|
|
def __init__(self):
|
2015-03-26 20:26:20 +01:00
|
|
|
self.values = "type doc name ezfio_dir ezfio_name write output".split()
|
2015-03-26 20:04:05 +01:00
|
|
|
for v in self.values:
|
2015-03-26 20:26:20 +01:00
|
|
|
exec "self.{0} = None".format(v)
|
2015-03-26 20:04:05 +01:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
self.set_write()
|
2016-05-10 18:38:54 +02:00
|
|
|
self.set_test_null_size()
|
2015-03-26 20:04:05 +01:00
|
|
|
for v in self.values:
|
2015-03-26 20:26:20 +01:00
|
|
|
if not v:
|
2015-04-20 09:22:28 +02:00
|
|
|
msg = "Error : %s is not set in EZFIO.cfg" % (v)
|
2015-03-26 20:04:05 +01:00
|
|
|
print >>sys.stderr, msg
|
|
|
|
sys.exit(1)
|
2015-05-11 14:40:55 +02:00
|
|
|
if "size" not in self.__dict__:
|
|
|
|
self.__dict__["size"] = ""
|
|
|
|
|
2015-03-26 20:04:05 +01:00
|
|
|
return self.data % self.__dict__
|
|
|
|
|
2016-05-10 18:38:54 +02:00
|
|
|
def set_test_null_size(self):
|
|
|
|
if "size" not in self.__dict__:
|
|
|
|
self.__dict__["size"] = ""
|
|
|
|
if self.size != "":
|
|
|
|
self.test_null_size = "if (size(%s) == 0) return\n" % ( self.name )
|
|
|
|
else:
|
|
|
|
self.test_null_size = ""
|
|
|
|
|
2015-03-26 20:04:05 +01:00
|
|
|
def set_write(self):
|
2017-11-28 14:20:17 +01:00
|
|
|
output = self.output
|
|
|
|
name = self.name
|
|
|
|
l_write = ["",
|
|
|
|
" call write_time(%(output)s)",
|
|
|
|
" if (mpi_master) then",
|
|
|
|
" write(%(output)s, *) 'Read %(name)s'",
|
|
|
|
" endif",
|
|
|
|
""]
|
|
|
|
|
|
|
|
self.write = "\n".join(l_write) % locals()
|
2017-11-28 00:54:22 +01:00
|
|
|
self.type_mpi = self.mpi_correspondance[self.type]
|
2016-05-04 16:14:59 +02:00
|
|
|
if "size" in self.__dict__:
|
|
|
|
return
|
2016-05-10 18:38:54 +02:00
|
|
|
else:
|
2017-11-28 14:20:17 +01:00
|
|
|
if self.type in self.write_correspondance:
|
2016-05-10 18:38:54 +02:00
|
|
|
write = self.write_correspondance[self.type]
|
|
|
|
|
|
|
|
l_write = ["",
|
|
|
|
" call write_time(%(output)s)",
|
|
|
|
" call %(write)s(%(output)s, %(name)s, &",
|
|
|
|
" '%(name)s')",
|
|
|
|
""]
|
|
|
|
|
2015-03-26 20:04:05 +01:00
|
|
|
def set_type(self, t):
|
|
|
|
self.type = t.lower()
|
|
|
|
|
|
|
|
def set_doc(self, t):
|
2015-03-26 20:26:20 +01:00
|
|
|
self.doc = t.strip().replace('\n', '\n! ')
|
2015-03-26 20:04:05 +01:00
|
|
|
|
|
|
|
def set_name(self, t):
|
|
|
|
self.name = t
|
|
|
|
|
|
|
|
def set_ezfio_dir(self, t):
|
|
|
|
self.ezfio_dir = t.lower()
|
|
|
|
|
|
|
|
def set_ezfio_name(self, t):
|
|
|
|
self.ezfio_name = t.lower()
|
|
|
|
|
|
|
|
def set_output(self, t):
|
|
|
|
self.output = t
|
|
|
|
|
2015-05-11 14:40:55 +02:00
|
|
|
def set_size(self, t):
|
2017-11-28 00:54:22 +01:00
|
|
|
self.size_mpi = t.replace(',',')*(').replace('0:','1+')
|
|
|
|
if (self.type == "character*(32)"):
|
|
|
|
self.size_mpi += "*32"
|
2015-05-11 14:40:55 +02:00
|
|
|
if t != "1":
|
|
|
|
self.size = ", " + t
|
|
|
|
else:
|
|
|
|
self.size = ""
|
2015-03-26 20:04:05 +01:00
|
|
|
|
|
|
|
def test_module():
|
|
|
|
T = EZFIO_Provider()
|
|
|
|
T.set_type("double precision")
|
|
|
|
T.set_name("thresh_SCF")
|
|
|
|
T.set_doc("Threshold on the convergence of the Hartree Fock energy")
|
|
|
|
T.set_ezfio_dir("Hartree_Fock")
|
|
|
|
T.set_ezfio_name("thresh_SCF")
|
|
|
|
T.set_output("output_Hartree_Fock")
|
|
|
|
print T
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_module()
|