mirror of
https://gitlab.com/scemama/irpf90.git
synced 2025-01-05 02:48:38 +01:00
Merge branch 'master' of github.com:scemama/irpf90
This commit is contained in:
commit
3eef718b68
14
src/Makefile
14
src/Makefile
@ -1,7 +1,21 @@
|
|||||||
PYTHON=python
|
PYTHON=python
|
||||||
PYVERSION=$(shell $(PYTHON) -c "import sys; print(sys.version[:3])")
|
PYVERSION=$(shell $(PYTHON) -c "import sys; print(sys.version[:3])")
|
||||||
|
HAS_CYTHON=$(shell bash -c "which cython &> /dev/null && echo 1 || echo 0")
|
||||||
|
ifneq ($(HAS_CYTHON),0)
|
||||||
|
|
||||||
|
../bin/irpf90: irpf90.so
|
||||||
|
rm ../bin/irpf90 ; cd ../bin ; ln -s ../src/irpf90_python.exe irpf90
|
||||||
|
|
||||||
|
irpf90.so : $(wildcard *.py) irpf90.c
|
||||||
|
./cython_setup.py build_ext --inplace
|
||||||
|
|
||||||
|
irpf90.c: irpf90.py
|
||||||
|
cython --embed irpf90.py
|
||||||
|
|
||||||
|
else
|
||||||
../bin/irpf90: irpf90_python.exe
|
../bin/irpf90: irpf90_python.exe
|
||||||
rm ../bin/irpf90 ; cd ../bin ; ln -s ../src/irpf90_python.exe irpf90
|
rm ../bin/irpf90 ; cd ../bin ; ln -s ../src/irpf90_python.exe irpf90
|
||||||
|
endif
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.c *.so *.pyc *.pyo 2>/dev/null
|
rm -f *.c *.so *.pyc *.pyo 2>/dev/null
|
||||||
|
@ -42,7 +42,7 @@ def dress(f, in_root=False):
|
|||||||
""" Transfoms the filename into $PWD/IRPF90_temp/f
|
""" Transfoms the filename into $PWD/IRPF90_temp/f
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
In root=True resurn $PWD/f
|
In root=True resurn $PWD/f
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
@ -110,7 +110,7 @@ def create_build_link(t, l_irp_m, l_usr_m, l_ext_m, ninja=True):
|
|||||||
# (Module, List[str], List[str]) -> str
|
# (Module, List[str], List[str]) -> str
|
||||||
""" Create the build command who will link the .o file into the target executable
|
""" Create the build command who will link the .o file into the target executable
|
||||||
|
|
||||||
To link we need the .o file corresponding to the target, and the ar lib.
|
To link we need the .o file corresponding to the target, and the ar lib.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
irp_id = irpf90_t.irp_id
|
irp_id = irpf90_t.irp_id
|
||||||
@ -154,8 +154,8 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
|
|||||||
|
|
||||||
- The module can produce a .MOD file
|
- The module can produce a .MOD file
|
||||||
- The module can Need another .MOD file.
|
- The module can Need another .MOD file.
|
||||||
This .MOD file can be produced by:
|
This .MOD file can be produced by:
|
||||||
1) a file generated by IRP_F90 preprocessor.
|
1) a file generated by IRP_F90 preprocessor.
|
||||||
2) a file defined by the user but a .irp.f90 file.
|
2) a file defined by the user but a .irp.f90 file.
|
||||||
3) a file not handle at all by IRPF90.
|
3) a file not handle at all by IRPF90.
|
||||||
|
|
||||||
@ -215,12 +215,12 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
|
|||||||
list_of_includes = ' '
|
list_of_includes = ' '
|
||||||
|
|
||||||
l_build = [
|
l_build = [
|
||||||
"build {target_o}: compile_fortran_{irp_id} {target_F90} | {list_of_includes} {list_of_modules} {list_of_modules_irp}",
|
"build {target_o}: compile_fortran_{irp_id} {target_F90} | ../Makefile {list_of_includes} {list_of_modules} {list_of_modules_irp}",
|
||||||
" short_in = {short_target_F90}", " short_out = {short_target}", ""
|
" short_in = {short_target_F90}", " short_out = {short_target}", ""
|
||||||
]
|
]
|
||||||
|
|
||||||
l_build_make = [
|
l_build_make = [
|
||||||
"{target_o}: {target_F90} | {list_of_includes} {list_of_modules} {list_of_modules_irp}",
|
"{target_o}: {target_F90} | ../Makefile {list_of_includes} {list_of_modules} {list_of_modules_irp}",
|
||||||
'\t@printf "F: {short_target_F90} -> {short_target}\\n"', "\t@$(FC) $(FCFLAGS) -c $^ -o $@",
|
'\t@printf "F: {short_target_F90} -> {short_target}\\n"', "\t@$(FC) $(FCFLAGS) -c $^ -o $@",
|
||||||
""
|
""
|
||||||
]
|
]
|
||||||
@ -297,10 +297,10 @@ def create_make_all_clean(l_main):
|
|||||||
#
|
#
|
||||||
'''Create the ALL and CLEAN target of Makefile
|
'''Create the ALL and CLEAN target of Makefile
|
||||||
|
|
||||||
Note: Portability doesn't mater. -delete is maybe not posix
|
Note: Portability doesn't mater. -delete is maybe not posix
|
||||||
but -exec rm {} + is far more ugly!
|
but -exec rm {} + is far more ugly!
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
l_executable = ' '.join(dress(t.filename, in_root=True) for t in l_main)
|
l_executable = ' '.join(dress(t.filename, in_root=True) for t in l_main)
|
||||||
|
|
||||||
@ -371,8 +371,8 @@ def run(d_module, ninja):
|
|||||||
"""Wrote the ninja file needed to compile the program
|
"""Wrote the ninja file needed to compile the program
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
- FC,AR,CC,CXX,LIB, FCFLAGS, CFLAGS, CXXFLAGS are compiler enviroment read
|
- FC,AR,CC,CXX,LIB, FCFLAGS, CFLAGS, CXXFLAGS are compiler enviroment read
|
||||||
- SRC,OBJ: Are the not irp.f file defined by the user
|
- SRC,OBJ: Are the not irp.f file defined by the user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Add required flags
|
# Add required flags
|
||||||
|
@ -42,12 +42,12 @@ class Entity(object):
|
|||||||
# (list[str], str, int, Irpy_comm_world)
|
# (list[str], str, int, Irpy_comm_world)
|
||||||
'''Instantiate the object.
|
'''Instantiate the object.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text: List of lines between BEGIN_PROVIDER and END_PROVIDER included
|
text: List of lines between BEGIN_PROVIDER and END_PROVIDER included
|
||||||
int: An unique int id (usefull when profilling)
|
int: An unique int id (usefull when profilling)
|
||||||
name: The name of the provider defined after the chosen BEGIN_PROVIDER statement
|
name: The name of the provider defined after the chosen BEGIN_PROVIDER statement
|
||||||
comm_world: A object to communicate we the external world.
|
comm_world: A object to communicate we the external world.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
assert type(text) == list
|
assert type(text) == list
|
||||||
assert len(text) > 0
|
assert len(text) > 0
|
||||||
@ -69,8 +69,8 @@ class Entity(object):
|
|||||||
# () -> Dict[str,Entity]
|
# () -> Dict[str,Entity]
|
||||||
'''Create an alias to the global dictionary of Entity.
|
'''Create an alias to the global dictionary of Entity.
|
||||||
|
|
||||||
Note: Be aware of the possiblity of Cyclic Dependency.
|
Note: Be aware of the possiblity of Cyclic Dependency.
|
||||||
'''
|
'''
|
||||||
return self.comm_world.d_entity
|
return self.comm_world.d_entity
|
||||||
|
|
||||||
@irpy.lazy_property
|
@irpy.lazy_property
|
||||||
@ -78,9 +78,9 @@ class Entity(object):
|
|||||||
# () -> Tuple[str, Parsed_text]
|
# () -> Tuple[str, Parsed_text]
|
||||||
'''Create an alias to the global tuple for parsed text
|
'''Create an alias to the global tuple for parsed text
|
||||||
|
|
||||||
Note: self.comm_world.t_filename_parsed_text need d_entity.
|
Note: self.comm_world.t_filename_parsed_text need d_entity.
|
||||||
Be aware of the possibility of Cyclic Dependency
|
Be aware of the possibility of Cyclic Dependency
|
||||||
'''
|
'''
|
||||||
return self.comm_world.t_filename_parsed_text
|
return self.comm_world.t_filename_parsed_text
|
||||||
|
|
||||||
@irpy.lazy_property
|
@irpy.lazy_property
|
||||||
@ -105,8 +105,8 @@ class Entity(object):
|
|||||||
BEGIN_PROVIDER [pi, double precision] &
|
BEGIN_PROVIDER [pi, double precision] &
|
||||||
BEGIN_PROVIDER [e, double preision]
|
BEGIN_PROVIDER [e, double preision]
|
||||||
|
|
||||||
return True for 'pi' and False for 'e'
|
return True for 'pi' and False for 'e'
|
||||||
'''
|
'''
|
||||||
return self.name == self.same_as
|
return self.name == self.same_as
|
||||||
|
|
||||||
@irpy.lazy_property
|
@irpy.lazy_property
|
||||||
@ -114,12 +114,12 @@ class Entity(object):
|
|||||||
# () -> Line
|
# () -> Line
|
||||||
'''Find the declaration statement associated with the name of the provider
|
'''Find the declaration statement associated with the name of the provider
|
||||||
|
|
||||||
Exemple:
|
Exemple:
|
||||||
BEGIN_PROVIDER [pi, double precision] &
|
BEGIN_PROVIDER [pi, double precision] &
|
||||||
BEGIN_PROVIDER [e, double preision]
|
BEGIN_PROVIDER [e, double preision]
|
||||||
|
|
||||||
if self.name == e, will return BEGIN_PROVIDER [e, double preision]
|
if self.name == e, will return BEGIN_PROVIDER [e, double preision]
|
||||||
'''
|
'''
|
||||||
|
|
||||||
d = self.d_type_lines
|
d = self.d_type_lines
|
||||||
return next(line for _, line in d[Begin_provider] + d[Cont_provider]
|
return next(line for _, line in d[Begin_provider] + d[Cont_provider]
|
||||||
@ -247,16 +247,16 @@ class Entity(object):
|
|||||||
# () -> List[str]
|
# () -> List[str]
|
||||||
'''Extract the dimension of the needed array in a form of list of variable name
|
'''Extract the dimension of the needed array in a form of list of variable name
|
||||||
|
|
||||||
Exemple:
|
Exemple:
|
||||||
BEGIN_PROVIDER [real, ao_num ]
|
BEGIN_PROVIDER [real, ao_num ]
|
||||||
-> []
|
-> []
|
||||||
|
|
||||||
BEGIN_PROVIDER [ real, ao_oneD_p, (ao_num) ]
|
BEGIN_PROVIDER [ real, ao_oneD_p, (ao_num) ]
|
||||||
-> ['ao_num']
|
-> ['ao_num']
|
||||||
|
|
||||||
BEGIN_PROVIDER [ real, ao_oneD_prim_p, (ao_num,ao_prim_num_max) ]
|
BEGIN_PROVIDER [ real, ao_oneD_prim_p, (ao_num,ao_prim_num_max) ]
|
||||||
-> ['ao_num', 'ao_prim_num_max']
|
-> ['ao_num', 'ao_prim_num_max']
|
||||||
'''
|
'''
|
||||||
|
|
||||||
line = self.prototype.text.split('!')[0]
|
line = self.prototype.text.split('!')[0]
|
||||||
buffer = line.replace(']', '').split(',', 2)
|
buffer = line.replace(']', '').split(',', 2)
|
||||||
|
@ -169,9 +169,6 @@ def main():
|
|||||||
if not command_line.do_run:
|
if not command_line.do_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
import irp_stack
|
|
||||||
irp_stack.create()
|
|
||||||
|
|
||||||
comm_world.create_buildfile(command_line.do_ninja)
|
comm_world.create_buildfile(command_line.do_ninja)
|
||||||
comm_world.write_modules()
|
comm_world.write_modules()
|
||||||
|
|
||||||
|
@ -216,15 +216,15 @@ def move_to_top_list(text, it):
|
|||||||
|
|
||||||
Note:
|
Note:
|
||||||
- The permutation neeed to be done following `it` order
|
- The permutation neeed to be done following `it` order
|
||||||
- We can have `nested` subroutine / Function. (Because of interface)
|
- We can have `nested` subroutine / Function. (Because of interface)
|
||||||
- This function is called way to much. Is need to be efficient
|
- This function is called way to much. Is need to be efficient
|
||||||
- This function is Impure
|
- This function is Unpure
|
||||||
- One pass over `text`
|
- One pass over `text`
|
||||||
|
|
||||||
|
|
||||||
NB:
|
NB:
|
||||||
- I am not really proud of the Sentinel value for the deleted,
|
- I am not really proud of the Sentinel value for the deleted,
|
||||||
but I waste already so much time on more cleaver but not working solution...
|
but I waste already so much time on more cleaver but not working solution...
|
||||||
'''
|
'''
|
||||||
|
|
||||||
assert set(it).issubset([NoDep, Declaration, Implicit, Use, Cont_provider])
|
assert set(it).issubset([NoDep, Declaration, Implicit, Use, Cont_provider])
|
||||||
@ -284,7 +284,7 @@ def move_interface(parsed_text, s_type=(Use, Implicit, Declaration, Subroutine,
|
|||||||
'''Move everything containt into 'interface' below the first instance of s_type who preced it
|
'''Move everything containt into 'interface' below the first instance of s_type who preced it
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
= This function is impure
|
= This function is unpur
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Get the born of the interface
|
# Get the born of the interface
|
||||||
@ -311,7 +311,7 @@ def build_sub_needs(parsed_text, d_subroutine):
|
|||||||
'''Set the needs, and provides arguements of Routine present in parsed_text
|
'''Set the needs, and provides arguements of Routine present in parsed_text
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
This function is impure
|
This function is unpure
|
||||||
'''
|
'''
|
||||||
|
|
||||||
l_buffer = []
|
l_buffer = []
|
||||||
|
@ -204,8 +204,8 @@ def save_and_execute(irpdir, scriptname, code, interpreter):
|
|||||||
''' Save the script in irpdir/scriptname and Execute it
|
''' Save the script in irpdir/scriptname and Execute it
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
The script are executed in the orginal directory of the .irp.f (aka '..')
|
The script are executed in the orginal directory of the .irp.f (aka '..')
|
||||||
and this directory is added to PYTHONPATH.
|
and this directory is added to PYTHONPATH.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
irpdir_scriptname = os.path.abspath(os.path.join(irpdir, scriptname))
|
irpdir_scriptname = os.path.abspath(os.path.join(irpdir, scriptname))
|
||||||
@ -418,7 +418,7 @@ def remove_comments(text, form):
|
|||||||
'''Remove all comments
|
'''Remove all comments
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
This function is impure
|
This function is unpur
|
||||||
'''
|
'''
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
@ -800,8 +800,8 @@ def process_old_style_do(text):
|
|||||||
######################################################################
|
######################################################################
|
||||||
def change_single_line_ifs(text):
|
def change_single_line_ifs(text):
|
||||||
# List[Line] -> List[Line]
|
# List[Line] -> List[Line]
|
||||||
'''Changes: `if (test) result`
|
'''Changes: `if (test) result`
|
||||||
into
|
into
|
||||||
`if (test) then
|
`if (test) then
|
||||||
result
|
result
|
||||||
endif`'''
|
endif`'''
|
||||||
|
34
src/util.py
34
src/util.py
@ -75,11 +75,11 @@ def parmap(f, it, parallel=False):
|
|||||||
The parallel flag is set to togle the // execusion
|
The parallel flag is set to togle the // execusion
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
- We try to use the Mulprocesses map is possible else we use our own
|
- We try to use the Mulprocesses map is possible else we use our own
|
||||||
- The order of the sequence if concerved
|
- The order of the sequence if concerved
|
||||||
- Will use all the processesor possible
|
- Will use all the processesor possible
|
||||||
- We return a List
|
- We return a List
|
||||||
- The traceback is loose if an error occur but a Exception is raise.
|
- The traceback is loose if an error occur but a Exception is raise.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if not parallel:
|
if not parallel:
|
||||||
@ -95,12 +95,12 @@ def parmap(f, it, parallel=False):
|
|||||||
# https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled
|
# https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled
|
||||||
#from cPickle import PicklingError
|
#from cPickle import PicklingError
|
||||||
#try:
|
#try:
|
||||||
# p = multiprocessing.Pool(nproc)
|
# p = multiprocessing.Pool(nproc)
|
||||||
# l_res = p.map(f, it,nproc)
|
# l_res = p.map(f, it,nproc)
|
||||||
#except PicklingError:
|
#except PicklingError:
|
||||||
# pass
|
# pass
|
||||||
#else:
|
#else:
|
||||||
# return l_res
|
# return l_res
|
||||||
|
|
||||||
# ~!~!~!
|
# ~!~!~!
|
||||||
# Parallelisation By Us
|
# Parallelisation By Us
|
||||||
@ -129,10 +129,10 @@ def parmap(f, it, parallel=False):
|
|||||||
'''Read a task from q_in, excute it, and store it in q_out
|
'''Read a task from q_in, excute it, and store it in q_out
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
- We use 'F' and not 'f'.
|
- We use 'F' and not 'f'.
|
||||||
- The for loop will break when stop_contition occur
|
- The for loop will break when stop_contition occur
|
||||||
- We get, and put an idx to allow the possibility of ordering afterward
|
- We get, and put an idx to allow the possibility of ordering afterward
|
||||||
- We store any exeception, to raise her afterward
|
- We store any exeception, to raise her afterward
|
||||||
'''
|
'''
|
||||||
for i, x in iter(q_in.get, stop_condition):
|
for i, x in iter(q_in.get, stop_condition):
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ def cached_file(filename, text):
|
|||||||
'''Check if file locatte at filename containt the same data as text
|
'''Check if file locatte at filename containt the same data as text
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if data is the same, false otherwise
|
True if data is the same, false otherwise
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def digest(data):
|
def digest(data):
|
||||||
@ -213,7 +213,7 @@ def lazy_write_file(filename, text, conservative=False, touch=False):
|
|||||||
'''Write data lazily in filename location.
|
'''Write data lazily in filename location.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
If convervative is set, we don't overwrite.
|
If convervative is set, we don't overwrite.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if not os.path.exists(filename) or not cached_file(filename, text) and not conservative:
|
if not os.path.exists(filename) or not cached_file(filename, text) and not conservative:
|
||||||
@ -286,7 +286,7 @@ def flatten(l_2d):
|
|||||||
'''Construct a copy of the 2d list collapsed into one dimension.
|
'''Construct a copy of the 2d list collapsed into one dimension.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
- We collapse in a C-style fashion (row_major).
|
- We collapse in a C-style fashion (row_major).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
return [item for l_1d in l_2d for item in l_1d]
|
return [item for l_1d in l_2d for item in l_1d]
|
||||||
@ -322,8 +322,8 @@ def build_dim(l_dim, colons=False):
|
|||||||
'''Contruct a valid fortran90 array dimension code from a list dimension
|
'''Contruct a valid fortran90 array dimension code from a list dimension
|
||||||
|
|
||||||
Exemple:
|
Exemple:
|
||||||
[4,8] -> (4,8) if not colons
|
[4,8] -> (4,8) if not colons
|
||||||
[4,8] -> (:,:) if colons
|
[4,8] -> (:,:) if colons
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if not l_dim:
|
if not l_dim:
|
||||||
|
Loading…
Reference in New Issue
Block a user