Exemple #1
0
def build_worker(codestring,
                 path_to_results,
                 specification_class,
                 write_header=True,
                 extra_args=[],
                 needs_mpi=False):
    path = os.path.abspath(path_to_results)
    codefile = os.path.join(path, "code.o")
    headerfile = os.path.join(path, "worker_code.h")
    interfacefile = os.path.join(path, "interface.o")
    exefile = os.path.join(path, "c_worker")

    c_compile(codefile, codestring)

    uc = create_c.GenerateACHeaderStringFromASpecificationClass()
    uc.specification_class = specification_class
    uc.needs_mpi = needs_mpi
    header = uc.result

    if write_header:
        with open(headerfile, "w") as f:
            f.write(header)
        extra_args = extra_args + ["-I", path]

    uc = create_c.GenerateACSourcecodeStringFromASpecificationClass()
    uc.specification_class = specification_class
    uc.needs_mpi = needs_mpi
    code = uc.result

    cxx_compile(interfacefile,
                code if write_header else header + "\n\n" + code,
                extra_args=extra_args)
    c_build(exefile, [interfacefile, codefile], extra_args=extra_args)

    return exefile
    def build_worker(self):
        
        path = os.path.abspath(self.get_path_to_results())
        codefile = os.path.join(path,"code.o")
        headerfile = os.path.join(path,"worker_code.h")
        interfacefile = os.path.join(path,"interface.o")
        self.exefile = os.path.join(path,"c_worker")
        
        self.c_compile(codefile, codestring)
        
        uc = create_c.GenerateACHeaderStringFromASpecificationClass()
        uc.specification_class = ForTestingInterface
        uc.needs_mpi = False
        header =  uc.result

        with open(headerfile, "w") as f:
            f.write(header)
        
        uc = create_c.GenerateACSourcecodeStringFromASpecificationClass()
        uc.specification_class = ForTestingInterface
        uc.needs_mpi = False
        code =  uc.result
        
        
        
        #print string
        
        self.cxx_compile(interfacefile, code)
        self.c_build(self.exefile, [interfacefile, codefile] )
Exemple #3
0
    def build_worker(self):

        path = os.path.abspath(get_path_to_results())
        codefile = os.path.join(path, "code.o")
        interfacefile = os.path.join(path, "interface.o")
        self.exefile = os.path.join(path, "c_worker")

        self.c_compile(codefile, codestring)

        uc = create_c.GenerateACHeaderStringFromASpecificationClass()
        uc.specification_class = TestCode
        uc.make_extern_c = False
        header = uc.result

        uc = create_c.GenerateACSourcecodeStringFromASpecificationClass()
        uc.specification_class = TestCode
        uc.needs_mpi = False
        code = uc.result

        string = '\n\n'.join([header, code])

        #print string

        self.cxx_compile(interfacefile, string)
        self.c_build(self.exefile, [interfacefile, codefile])
    def build_worker(self):
        path = os.path.abspath(self.get_path_to_results())
        codefile = os.path.join(path, "code.o")
        interfacefile = os.path.join(path, "interface.o")
        self.exefile = os.path.join(path, "c_worker")

        self.cxx_compile(codefile, codestring)

        uc = create_c.GenerateACHeaderStringFromASpecificationClass()
        uc.specification_class = self.get_interface_class()
        uc.make_extern_c = True
        uc.needs_mpi = True
        uc.ignore_functions_from_specification_classes = [
            stopping_conditions.StoppingConditionInterface
        ]
        header = uc.result

        uc = create_c.GenerateACSourcecodeStringFromASpecificationClass()
        uc.needs_mpi = True

        uc.specification_class = self.get_interface_class()
        code = uc.result

        string = '\n\n'.join([header, code])

        #print string

        self.cxx_compile(interfacefile, string)
        self.c_build(self.exefile, [interfacefile, codefile])
    def build_worker(self):
        
        path = os.path.abspath(self.get_path_to_results())
        codefile = os.path.join(path,"code.o")
        interfacefile = os.path.join(path,"interface.o")
        headerfile = os.path.join(path,"worker_code.h")
        self.sofile = os.path.join(path,"interface.so")
        self.interfacec_o_file = os.path.join(path,"interfacec.o")
        self.exefile = os.path.join(path,"c_worker")
        
        compile_tools.fortran_compile(codefile, test_fortran_implementation.codestring,
                                      extra_args=["-fPIC"])
        
        
        uc = create_c.GenerateACHeaderStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.needs_mpi = False
        header =  uc.result
        
        
        with open(headerfile, "w") as f:
            f.write(header)
        
        
        root, ext = os.path.splitext(interfacefile)
        sourcename = root + '.pyx'
        cname = root + '.c'
        
        uc = create_cython.GenerateACythonSourcecodeStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.function_name_prefix = "ci_"
        uc.needs_mpi = True
        code =  uc.result
        
        with open(sourcename, "w") as f:
            f.write(code)


        uc = create_cython.GenerateACythonStartScriptStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.needs_mpi = True
        script =  uc.result
        
        with open(self.exefile, "w") as f:
            f.write(script)

        os.chmod(self.exefile, 0777)

        import mpi4py
        process, stdout, stderr = compile_tools.open_subprocess([config.compilers.cython, 
        '-I',
        mpi4py.get_include(),
         sourcename, '-o', cname])

        if process.returncode == 0:
            compile_tools.wait_for_file(cname)
        
        if process.returncode != 0 or not os.path.exists(cname):
            print "Could not cythonize {0}, error = {1}".format(sourcename, stderr)
            raise Exception("Could not cythonize {0}, error = {1}".format(sourcename, stderr))
        
        with open(cname, "r") as f:
            string = f.read()


        
        
        uc = create_cython.GenerateAFortranInterfaceSourcecodeStringFromASpecificationClass()
        uc.specification_class = test_fortran_implementation.ForTestingInterface
        uc.function_name_prefix = "ci_"
        uc.needs_mpi = False
        code =  uc.result

        compile_tools.fortran_compile(self.interfacec_o_file, code,
                                      extra_args=["-fPIC"])

        compile_tools.c_pythondev_compile(interfacefile, string)
        compile_tools.fortran_pythondev_buildso(self.sofile,  [interfacefile, codefile, self.interfacec_o_file] )
    def build_worker(self):

        path = os.path.abspath(self.get_path_to_results())
        codefile = os.path.join(path, "code.o")
        interfacefile = os.path.join(path, "interface.o")
        headerfile = os.path.join(path, "worker_code.h")
        self.sofile = os.path.join(path, "interface.so")
        self.exefile = os.path.join(path, "c_worker")

        self.c_compile(codefile, test_c_implementation.codestring)

        uc = create_c.GenerateACHeaderStringFromASpecificationClass()
        uc.specification_class = test_c_implementation.ForTestingInterface
        uc.needs_mpi = False
        header = uc.result

        with open(headerfile, "w") as f:
            f.write(header)

        root, ext = os.path.splitext(interfacefile)
        sourcename = root + '.pyx'
        cname = root + '.c'

        uc = create_cython.GenerateACythonSourcecodeStringFromASpecificationClass(
        )
        uc.specification_class = test_c_implementation.ForTestingInterface
        uc.needs_mpi = True
        code = uc.result

        with open(sourcename, "w") as f:
            f.write(code)

        uc = create_cython.GenerateACythonStartScriptStringFromASpecificationClass(
        )
        uc.specification_class = test_c_implementation.ForTestingInterface
        uc.needs_mpi = True
        script = uc.result

        with open(self.exefile, "w") as f:
            f.write(script)

        os.chmod(self.exefile, 0777)

        process = subprocess.Popen(
            # [config.compilers.cython, '--embed', sourcename, '-o', cname],
            [config.compilers.cython, sourcename, '-o', cname],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()

        if process.returncode == 0:
            self.wait_for_file(cname)

        if process.returncode != 0 or not os.path.exists(cname):
            print "Could not cythonize {0}, error = {1}".format(
                sourcename, stderr)
            raise Exception("Could not cythonize {0}, error = {1}".format(
                sourcename, stderr))

        with open(cname, "r") as f:
            string = f.read()

        self.c_pythondev_compile(interfacefile, string)
        # self.c_pythondev_build(self.exefile, [interfacefile, codefile] )
        self.c_pythondev_buildso(self.sofile, [interfacefile, codefile])
Exemple #7
0
def make_cplusplus_header():
    result = create_c.GenerateACHeaderStringFromASpecificationClass()
    result.make_extern_c = False
    return result