Changeset d5e0592 in sasmodels


Ignore:
Timestamp:
May 23, 2016 7:18:10 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
4d8e0bb
Parents:
4bfbca2 (diff), 7e16db7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of github.com:sasview/sasmodels

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    r558d3b3 ra7a5ff3  
    785785    model_info = dict( 
    786786        id=kernel_id,  # string used to load the kernel 
    787         filename=abspath(kernel_module.__file__), 
     787        filename=abspath(kernel_module.__file__.rstrip("cd")), 
    788788        name=name, 
    789789        title=kernel_module.title, 
  • sasmodels/kerneldll.py

    r5efe850 r7e16db7  
    4949import os 
    5050from os.path import join as joinpath, split as splitpath, splitext 
     51import subprocess 
    5152import tempfile 
    5253import ctypes as ct 
     
    6364    # Windows compiler; check if TinyCC is available 
    6465    try: 
    65         from tinycc import TCC 
     66        import tinycc 
    6667    except ImportError: 
    67         TCC = None 
     68        tinycc = None 
    6869    # call vcvarsall.bat before compiling to set path, headers, libs, etc. 
    6970    if "VCINSTALLDIR" in os.environ: 
     
    7576        # TODO: maybe don't use randomized name for the c file 
    7677        # TODO: maybe ask distutils to find MSVC 
    77         CC = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG /Tp%(source)s " 
    78         LN = "/link /DLL /INCREMENTAL:NO /MANIFEST /OUT:%(output)s" 
     78        CC = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG".split() 
    7979        if "SAS_OPENMP" in os.environ: 
    80             COMPILE = " ".join((CC, "/openmp", LN)) 
    81         else: 
    82             COMPILE = " ".join((CC, LN)) 
    83     elif TCC: 
     80            CC.append("/openmp") 
     81        LN = "/link /DLL /INCREMENTAL:NO /MANIFEST".split() 
     82        def compile_command(source, output): 
     83            return CC + ["/Tp%s"%source] + LN + ["/OUT:%s"%output] 
     84    elif tinycc: 
    8485        # TinyCC compiler. 
    85         COMPILE = TCC + " -shared -rdynamic -Wall %(source)s -o %(output)s" 
     86        CC = [tinycc.find_tcc_path()] + "-shared -rdynamic -Wall".split() 
     87        def compile_command(source, output): 
     88            return CC + ["%s"%source, "-o", "%s"%output] 
    8689    else: 
    8790        # MinGW compiler. 
    88         COMPILE = "gcc -shared -std=c99 -O2 -Wall %(source)s -o %(output)s -lm" 
     91        CC = "gcc -shared -std=c99 -O2 -Wall".split() 
    8992        if "SAS_OPENMP" in os.environ: 
    90             COMPILE += " -fopenmp" 
     93            CC.append("-fopenmp") 
     94        def compile_command(source, output): 
     95            return CC + ["%s"%source, "-o", "%s"%output, "-lm"] 
    9196else: 
    9297    # Generic unix compile 
    9398    # On mac users will need the X code command line tools installed 
    94     COMPILE = "cc -shared -fPIC -std=c99 -O2 -Wall %(source)s -o %(output)s -lm" 
    95  
     99    #COMPILE = "gcc-mp-4.7 -shared -fPIC -std=c99 -fopenmp -O2 -Wall %s -o %s -lm -lgomp" 
     100    CC = "gcc -shared -fPIC -std=c99 -O2 -Wall".split() 
    96101    # add openmp support if not running on a mac 
    97     if sys.platform != 'darwin': 
    98         #COMPILE = "gcc-mp-4.7 -shared -fPIC -std=c99 -fopenmp -O2 -Wall %s -o %s -lm -lgomp" 
    99         COMPILE += " -fopenmp" 
     102    if sys.platform != "darwin": 
     103        CC.append("-fopenmp") 
     104    def compile_command(source, output): 
     105        return CC + ["%s"%source, "-o", "%s"%output, "-lm"] 
    100106 
    101107# Windows-specific solution 
     
    111117ALLOW_SINGLE_PRECISION_DLLS = True 
    112118 
     119def compile(source, output): 
     120    command = compile_command(source=source, output=output) 
     121    command_str = " ".join('"%s"'%p if ' ' in p else p for p in command) 
     122    logging.info(command_str) 
     123    try: 
     124        subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT) 
     125    except subprocess.CalledProcessError as exc: 
     126        raise RuntimeError("compile failed.\n%s\n%s"%(command_str, exc.output)) 
     127    if not os.path.exists(output): 
     128        raise RuntimeError("compile failed.  File is in %r"%source) 
    113129 
    114130def dll_path(model_info, dtype="double"): 
     
    180196        need_recompile = dll_time < newest_source 
    181197    if need_recompile: 
    182         fid, filename = tempfile.mkstemp(suffix=".c", prefix=tempfile_prefix) 
    183198        source = generate.convert_type(source, dtype) 
    184         os.fdopen(fid, "w").write(source) 
    185         command = COMPILE%{"source":filename, "output":dll} 
    186         logging.info(command) 
    187         status = os.system(command) 
    188         if status != 0 or not os.path.exists(dll): 
    189             raise RuntimeError("compile failed.  File is in %r"%filename) 
    190         else: 
    191             ## comment the following to keep the generated c file 
    192             os.unlink(filename) 
    193             #print("saving compiled file in %r"%filename) 
     199        fd, filename = tempfile.mkstemp(suffix=".c", prefix=tempfile_prefix) 
     200        with os.fdopen(fd, "w") as file: 
     201            file.write(source) 
     202        compile(source=filename, output=dll) 
     203        # comment the following to keep the generated c file 
     204        # Note: if there is a syntax error then compile raises an error 
     205        # and the source file will not be deleted. 
     206        os.unlink(filename) 
     207        #print("saving compiled file in %r"%filename) 
    194208    return dll 
    195209 
  • sasmodels/custom/__init__.py

    rcd0a808 r4bfbca2  
    2525    def load_module_from_path(fullname, path): 
    2626        module = imp.load_source(fullname, path) 
    27         os.unlink(path+"c")  # remove the automatic pyc file 
     27        #os.unlink(path+"c")  # remove the automatic pyc file 
    2828        return module 
    2929 
Note: See TracChangeset for help on using the changeset viewer.