Пример #1
0
class Environment():
    def __init__(self):
        self.shell = Shell()

    def get_os(self):
        """
            Add a new architecture to this function.
        """
        # k: if k_accountj exists
        test_k = self.shell.execute("k_accountj", [], [], "")[0]
        if type(test_k) is bytes:
            test_k = test_k.decode('utf-8')
        if test_k != '':
            return "k"

        test_os = self.shell.execute("uname", [], [], "")[0].lower().rstrip()
        if type(test_os) is bytes:
            test_os = test_os.decode('utf-8')
        if test_os == 'darwin':
            return "osx"
        if test_os == 'linux':
            # centos + ubuntu
            test_linux = self.shell.execute("lsb_release", [], ['-a'], "")[0]
            if type(test_linux) is bytes:
                test_linux = test_linux.decode('utf-8')
            exp = re.compile("Distributor ID:\t(?P<os>\w+)\n")
            index = test_linux.find("Distributor")
            if index == -1:
                return "unkown"
            m = exp.match(test_linux[index:])
            return m.group("os").lower()

        return "unknown"

    def get_env(self):
        os = self.get_os()
        if os == "k":
            return "k"
        elif os != "unknown":
            return "cluster"
        else:
            return "unknown"
Пример #2
0
class Summarizer:
    """
    "
    """
    def __init__(self):
        self.shell = Shell()

    def summary(self, job_id, job_cnt):
        core_time = self.obtain_time("job{0}.sh.o{1}".format(job_cnt, job_id))

        # self.clean_up(job_type, job_id)
        self.clean_up(job_cnt, job_id)
        return core_time

    def obtain_time(self, filename):
        f_check = Path("{0}{1}".format(dir_path, filename))
        while not f_check.exists():
            time.sleep(5)
        f = open("{0}{1}".format(dir_path, filename))
        lines = f.readlines()
        f.close()
        for line in lines:
            m = time_exp.match(line)
            if m:
                calc_time = int(m.group("decimal")) +\
                    int(m.group("float")) * 10**(-len(m.group("float")))
                print(calc_time)
                return calc_time

    def clean_up(self, job_cnt, job_id):
        self.shell.execute(
            "cp", ["job{0}.sh.o{1} ../../tmp/".format(job_cnt, job_id)], [],
            dir_path)
        self.shell.execute(
            "cp", ["job{0}.sh.e{1} ../../tmp/".format(job_cnt, job_id)], [],
            dir_path)
        self.shell.execute("rm", [
            "job{0}.sh.o{1}".format(job_cnt, job_id),
            "job{0}.sh.e{1}".format(job_cnt, job_id),
        ], ["-f"], dir_path)
Пример #3
0
class DeployCommand():
    def __init__(self, neuron_path):
        self.env = Environment()
        self.shell = Shell()
        self.neuron_path = neuron_path
        job_name = 'job_{0}'.format(self.env.get_env())
        self.build_generator = BuildGenerator()
        self.job_generator = JobGenerator(job_name)

    def build(self, env, bench, params, use_tmp, build_neuron, neuron_use_tmp):
        self.build_generator.gen(params, use_tmp, neuron_use_tmp, env)
        commands = []
        tmp_str = ".tmp" if use_tmp else ""
        if env == "cluster":
            if build_neuron:
                commands.append({
                    "command":
                    "make",
                    "args": ["clean"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "../../genie/simulator/tmp/build_config.sh",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": ["install"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
            commands.append({
                "command":
                "./make_special.sh",
                "args": ["x86_64", bench, tmp_str],
                "options": [],
                "work_dir":
                "{0}/specials{1}".format(self.neuron_path, tmp_str)
            })
        if env == "k":
            if build_neuron:
                commands.append({
                    "command":
                    "../config/do_config_k1.sh",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": ["install"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "../../genie/simulator/tmp/build_config.sh",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "export",
                    "args": ["LANG=C"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "export",
                    "args": ["LC_ALL=C"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": ["install"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "cp",
                    "args": ["./x86_64/bin/*", "./sparc64/bin/"],
                    "options": [],
                    "work_dir":
                    "{0}/exec{1}".format(self.neuron_path, tmp_str)
                })
            commands.append({
                "command":
                "./make_special.sh",
                "args": [],
                "options": ["sparc64", bench, tmp_str],
                "work_dir":
                "{0}/specials{1}".format(self.neuron_path, tmp_str)
            })
        self.shell.run_cmds(commands)

    def run(self, env, params, cnt, use_tmp):
        self.job_generator.gen(params, cnt, use_tmp)
        if env == "cluster":
            res = self.shell.execute(
                "qsub", ["../../genie/simulator/tmp/job{0}.sh".format(cnt)],
                [], "{0}/hoc".format(self.neuron_path))[0]
            if type(res) is bytes:
                res = res.decode('utf-8')
            m = id_cluster_exp.match(res)
            return m.group("id")
        elif env == "k":
            res = self.shell.execute(
                "pjsub", ["../../genie/simulator/tmp/job{0}.sh".format(cnt)],
                [], "{0}/hoc".format(self.neuron_path))[0]
            if type(res) is bytes:
                res = res.decode('utf-8')
            m = id_k_exp.match(res)
            return m.group("id")