AW: [f2py] Intel Fortran 9.0, .NET 2003, Win XP Problems
Mike Mueller
m.mueller at ibgw-leipzig.de
Wed Jan 25 18:17:52 EET 2006
> The best way I have found to solve this is to modify the .py
files
> relevant to the MS compiler to use the intel compiler.
Mike,
Thanks a lot for your answer. But I do NOT have the Intel C++ Compiler.
So the solution does not work. Maybe I can adapted it to the MS Compiler
in such a way it works?
Thanks.
Mike
> This seems to work
> well since all the environment variables are the same and Intel's C++
> compiler is made to be a drop-in replacement for MS's. Below are the
> relevant portions of msvccompiler.py:
>
> -------------------------------------------------
>
> class MSVCCompiler (CCompiler) :
> """Concrete class that implements an interface to Microsoft
Visual
> C++,
> as defined by the CCompiler abstract class."""
>
> compiler_type = 'msvc'
>
> # Just set this so CCompiler's constructor doesn't barf. We
> currently
> # don't use the 'set_executables()' bureaucracy provided by
> CCompiler,
> # as it really isn't necessary for this sort of single-compiler
> class.
> # Would be nice to have a consistent interface with
UnixCCompiler,
> # though, so it's worth thinking about.
> executables = {}
>
> # Private class data (need to distinguish C from C++ source for
> compiler)
> _c_extensions = ['.c']
> _cpp_extensions = ['.cc', '.cpp', '.cxx']
> _rc_extensions = ['.rc']
> _mc_extensions = ['.mc']
>
> # Needed for the filename generation methods provided by the
> # base class, CCompiler.
> src_extensions = (_c_extensions + _cpp_extensions +
> _rc_extensions + _mc_extensions)
> res_extension = '.res'
> obj_extension = '.obj'
> static_lib_extension = '.lib'
> shared_lib_extension = '.dll'
> static_lib_format = shared_lib_format = '%s%s'
> exe_extension = '.exe'
>
> def __init__ (self, verbose=0, dry_run=0, force=0):
> CCompiler.__init__ (self, verbose, dry_run, force)
> self.__version = get_build_version()
> if self.__version >= 7:
> self.__root = r"Software\Microsoft\VisualStudio"
> self.__macros = MacroExpander(self.__version)
> else:
> self.__root = r"Software\Microsoft\Devstudio"
> self.initialized = False
>
> def initialize(self):
> self.__paths = self.get_msvc_paths("path")
>
> if len (self.__paths) == 0:
> raise DistutilsPlatformError, \
> ("Python was built with version %s of Visual
Studio, "
> "and extensions need to be built with the same "
> "version of the compiler, but it isn't installed."
%
> self.__version)
>
> self.cc = self.find_exe("icl.exe") # Intel
> self.linker = self.find_exe("xilink.exe") # Intel
> self.lib = self.find_exe("lib.exe")
> self.rc = self.find_exe("rc.exe") # resource compiler
> self.mc = self.find_exe("mc.exe") # message compiler
> self.set_path_env_var('lib')
> self.set_path_env_var('include')
>
> # extend the MSVC path with the current path
> try:
> for p in string.split(os.environ['path'], ';'):
> self.__paths.append(p)
> except KeyError:
> pass
> os.environ['path'] = string.join(self.__paths, ';')
>
> self.preprocess_options = None
> self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3',
'/Gd',
> '/DNDEBUG']
> self.compile_options_debug = ['/nologo', '/Od', '/MDd',
'/W3',
> '/Gd', '/Z7', '/D_DEBUG']
>
> self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO',
> '/LIBPATH:\Program Files\Intel\Compiler\C++\9.0\IA32\Lib',
> '/LIBPATH:\Program Files\Intel\Compiler\Fortran\9.0\IA32\Lib']
> if self.__version >= 7:
> self.ldflags_shared_debug = [
> '/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
> ]
> else:
> self.ldflags_shared_debug = [
> '/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None',
> '/DEBUG'
> ]
> self.ldflags_static = [ '/nologo']
>
> self.initialized = True
>
> ------------------------------------------------------------
>
> Note the use of "icl.exe" for the C++ compiler (Intel),
"xlink.exe"
> (Intel's linker, which is much better), and the fortran lib and
include
> paths. Finally, modify the intelfcompiler.py file to adjust the
relevant
> intel visual fortran compiler class (do not import ar_exe from
> MSVCCompiler().lib):
>
> -------------------------------------------------------------
>
> class IntelVisualFCompiler(FCompiler):
>
> compiler_type = 'intelv'
> version_pattern = r'Intel\(R\) Fortran Compiler for 32-bit
> applications, '\
> 'Version (?P<version>[^\s*]*)'
>
> ar_exe = 'lib.exe'
> fc_exe = 'ifort'
> if sys.platform=='win32':
> from distutils.msvccompiler import MSVCCompiler
> ar_exe = 'lib.exe' # MSVCCompiler().lib
>
> executables = {
> 'version_cmd' : [fc_exe, "-FI -V -c %(fname)s.f -o
%(fname)s.o"
> \
> % {'fname':dummy_fortran_file()}],
> 'compiler_f77' : [fc_exe,"-FI","-w90","-w95"],
> 'compiler_fix' : [fc_exe,"-FI","-4L72","-w"],
> 'compiler_f90' : [fc_exe],
> 'linker_so' : [fc_exe,"-shared"],
> 'archiver' : [ar_exe, "/verbose", "/OUT:"],
> 'ranlib' : None
> }
>
> compile_switch = '/c '
> object_switch = '/Fo' #No space after /Fo!
> library_switch = '/OUT:' #No space after /OUT:!
> module_dir_switch = '/module:' #No space after /module:
> module_include_switch = '/I'
>
> def get_flags(self):
> opt = ['/nologo','/MD','/nbs','/Qlowercase','/us','/fpp']
> return opt
>
> def get_flags_free(self):
> return ["-FR"]
>
> def get_flags_debug(self):
> return ['/4Yb','/d2']
>
> def get_flags_opt(self):
> return ['/O3','/Qip','/Qipo','/Qipo_obj']
>
> def get_flags_arch(self):
> opt = []
> if cpu.is_PentiumPro() or cpu.is_PentiumII():
> opt.extend(['/G6','/Qaxi'])
> elif cpu.is_PentiumIII():
> opt.extend(['/G6','/QaxK'])
> elif cpu.is_Pentium():
> opt.append('/G5')
> elif cpu.is_PentiumIV():
> opt.extend(['/G7','/QaxW'])
> if cpu.has_mmx():
> opt.append('/QaxM')
> return opt
>
> -------------------------------------------------------
>
> My F2PY now runs fine from the command line with the proper
> environment
> variables set (ifortvars.bat and iclvars.bat). Hope this helps....
More information about the f2py-users
mailing list