jameskermode / f90wrap

F90 to Python interface generator with derived type support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type "complex" not in kind map

jpolk opened this issue · comments

commented

Hi @jameskermode,

I'm trying to wrap a large, complex code that uses Intel's MKL PARDISO routines. These solvers use a number of complex types defined like this:
COMPLEX(KIND=8), INTENT(IN) :: A(*)

They appear to be producing this error:
f90wrap: RuntimeError('Unknown type "complex" - add to kind map and try again')

Can you provide some guidance on how to get it to wrap?

Thanks--Jay

You need to provide a kind_map file that gives the mapping from Fortran kinds to C types, and pass it to f90wrap with the -k command line argument. Here's an example which includes complex types:

https://github.com/jameskermode/f90wrap/blob/master/examples/elemental/kind_map#L9

commented

Thanks for the quick response! That example looks like it has all the kinds I need, so I'll try it.

commented

Hi @jameskermode, this fixed the issue with complex declarations (i just had to add an entry for complex(kind=4)), but now I'm having issues with character declarations. They were in the form (for instance):

CHARACTER*30

and PARDISO has a few

CHARACTER(*)

I tried adding this to the kind map to deal with the strings:

'character' : {'' : 'char',
'1' : 'char',
'*30' : 'char[30]'}

but am still getting this message:

Unknown combination of type "character" and kind "*" - add to kind map and try again

Is there another format I should use in either the declaration or the kind map? I tried changing the declarations to CHARACTER (LEN=30), but that did not work either. Thanks--Jay

In this case you need to use the string lengths Command line argument.

commented

Can you point me to an example STRING_LENGTHS dictionary? It's not clear to me what the "string length names" are.
Thanks--J

Sure, here's an example:

https://github.com/libAtoms/QUIP/blob/public/quippy/Makefile#L94

Keys are the string length identifiers, but for your case I think what matters is the default entry, set either with the * entry in the string lengths map or with the -S command line argument and used for character(len=*) and character(*).

commented

OK, thanks! That seems to have gotten me past that set of problems. My largest string length is 100 characters, so I set both the default entry in the string lengths map to 100 (and left all others the same as the quippy example) and set the -S command line entry to 100 (which is presumably redundant, but at least consistent). It has successfully created f90wrap_ files for my three global variable and data structure modules, but is having problems with the MKL PARDISO module. I'm getting this error when it hits the pardiso module.

INFO:root:F90WrapperGenerator visiting module mkl_pardiso_private
INFO:root:F90WrapperGenerator visiting type mkl_pardiso_handle
INFO:root:F90WrapperGenerator visiting routine mkl_pardiso_handle_initialise call_name mkl_pardiso_handle_initialise mod_name 'mkl_pardiso_private'
INFO:root:F90WrapperGenerator visiting routine mkl_pardiso_handle_finalise call_name mkl_pardiso_handle_finalise mod_name 'mkl_pardiso_private'
INFO:root:F90WrapperGenerator visiting type mkl_pardiso_handle_x*_array
INFO:root:F90WrapperGenerator visiting routine mkl_pardiso_handle_x*_array_initialise call_name mkl_pardiso_handle_x*_array_initialise mod_name 'mkl_pardiso_private'
INFO:root:F90WrapperGenerator visiting routine mkl_pardiso_handle_x*_array_finalise call_name mkl_pardiso_handle_x*_array_finalise mod_name 'mkl_pardiso_private'
Traceback (most recent call last):
File "/Users/jpolk/miniconda2/envs/python37/bin/f90wrap", line 385, in main
max_length=f90_max_line_length).visit(f90_tree)
File "/Users/jpolk/miniconda2/envs/python37/lib/python3.7/site-packages/f90wrap/fortran.py", line 473, in visit
result = visitor(node)
File "/Users/jpolk/miniconda2/envs/python37/lib/python3.7/site-packages/f90wrap/f90wrapgen.py", line 104, in visit_Root
self.generic_visit(node)
File "/Users/jpolk/miniconda2/envs/python37/lib/python3.7/site-packages/f90wrap/fortran.py", line 481, in generic_visit
self.visit(item)
File "/Users/jpolk/miniconda2/envs/python37/lib/python3.7/site-packages/f90wrap/fortran.py", line 473, in visit
result = visitor(node)
File "/Users/jpolk/miniconda2/envs/python37/lib/python3.7/site-packages/f90wrap/f90wrapgen.py", line 130, in visit_Module
self._write_sc_array_wrapper(node, el, dims[0], self.sizeof_fortran_t)
File "/Users/jpolk/miniconda2/envs/python37/lib/python3.7/site-packages/f90wrap/f90wrapgen.py", line 431, in write_sc_array_wrapper
self.write_uses_lines(t, {t.name: ['%s
%s => %s' % (t.name, el.name, el.name)]})
File "/Users/jpolk/miniconda2/envs/python37/lib/python3.7/site-packages/f90wrap/f90wrapgen.py", line 170, in write_uses_lines
if symbol not in all_uses[mod]:
TypeError: argument of type 'NoneType' is not iterable
f90wrap: TypeError("argument of type 'NoneType' is not iterable")
for help use --help
make: *** [Hall2Def2py.so] Error 2

I'm attaching the module file (it's a .f90 file, but I attached it as a .docx file).
mkl_pardiso.docx
Do you see what might be causing the problem? Thanks again for being so helpful. I'm trying to wrap my code so I can interface it with a front end we have for the DAKOTA package to do uncertainty quantification on our predictions of lifetime for a plasma thruster we are developing as the propulsion system for NASA's Lunar Gateway, a space station in lunar orbit that will host astronauts for the return to the moon's surface in the late 2020s. I really appreciate your help!

Can you try the fix in pull request #126?

commented

It looks like pull request #126 fixed the problems I was having with f90wrap--thanks for doing that! I'm still having issues but they are with the f2py statement in my makefile not finding my intel compiler, so I'll keep beating on that. Thanks for all your help!