Beispiel #1
0
    def goodRNGSize(self):
        """ Demande a l'exécutable le nombre de thread prévu dans les RNG existants dans le dossier du projet
        et le compare au nombre de thread des préférences
        """
        if not os.path.exists((u"%s/RNG_state_0000.bin"%self.dir).encode(self.fsCoding)):
            log(3,"RNG binary file cannot be found")
            return False
        if os.path.exists((u"%s/RNG_state_0000_cores.txt"%self.dir).encode(self.fsCoding)):
            os.remove((u"%s/RNG_state_0000_cores.txt"%self.dir).encode(self.fsCoding))
        QApplication.setOverrideCursor( Qt.WaitCursor )
        nbThreadExpected = self.parent.preferences_win.getMaxThreadNumber()

        executablePath = self.parent.preferences_win.getExecutablePath()
        cmd_args_list = [executablePath,"-z", (u"%s/RNG_state_0000.bin"%self.dir).encode(self.fsCoding) ]
        cmd_args_list_quoted = list(cmd_args_list)
        for i in range(len(cmd_args_list_quoted)):
            if ";" in cmd_args_list_quoted[i] or " " in cmd_args_list_quoted[i] or ":" in cmd_args_list_quoted[i]:
                cmd_args_list_quoted[i] = '"'+cmd_args_list_quoted[i]+'"'
        log(3,"Command launched for RNGs check of project '%s' : %s"%(self.name," ".join(cmd_args_list_quoted)))
        addLine("%s/command.txt"%self.dir,"Command launched for RNGs check of project '%s' : %s\n\n"%(self.name," ".join(cmd_args_list_quoted)))
        outfile = u"%s/rng_check.out"%(self.dir)
        f = open(outfile.encode(self.fsCoding),"w")
        p = subprocess.Popen(cmd_args_list, stdout=f, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
        time.sleep(1)
        while (p.poll() == None):
            time.sleep(1)
        f.close()
        if not os.path.exists((u"%s/RNG_state_0000_cores.txt"%self.dir).encode(self.fsCoding)):
            log(3,"RNG info file cannot be found")
            QApplication.restoreOverrideCursor()
            return False
        ff = open((u"%s/RNG_state_0000_cores.txt"%self.dir).encode(self.fsCoding),'rU')
        try:
            first_line = ff.readlines()[0].strip()
            nbRNGThread = int(first_line)
        except Exception as e:
            log(3,"Malformed RNG info file")
            QApplication.restoreOverrideCursor()
            ff.close()
            return False
        ff.close()

        log(3,"RNGs check of project '%s' terminated with returncode : %s"%(self.name,p.poll()))
        if (nbThreadExpected <= nbRNGThread):
            log(3,"GOOD RNG check of project '%s'. No need to generate RNGs again (%s needed, %s found)."%(self.name,nbThreadExpected,nbRNGThread))
        else:
            log(3,"BAD RNG check of project '%s'. They should (and will be) be generated again (%s needed, %s found)."%(self.name,nbThreadExpected,nbRNGThread))

        QApplication.restoreOverrideCursor()
        return (nbThreadExpected <= nbRNGThread)
Beispiel #2
0
    def initializeRNG(self,nbNodes=1,dest=None):
        """ à lancer une fois que le dossier du projet a été créé
        """
        QApplication.setOverrideCursor( Qt.WaitCursor )
        if os.path.exists((u"%s/RNG_state_0000.bin"%self.dir).encode(self.fsCoding)):
            # si on est en mode "cluster" (DEPRECATED)
            if dest != None:
                shutil.copy((u"%s/RNG_state_0000.bin"%self.dir).encode(self.fsCoding),(u"%s/RNG_save"%self.dir).encode(self.fsCoding))

            else:
                os.remove((u"%s/RNG_state_0000.bin"%self.dir).encode(self.fsCoding))
        executablePath = self.parent.preferences_win.getExecutablePath()
        if executablePath == '':
            raise Exception("Impossible to initialize the RNGs")
        nbMaxThread = self.parent.preferences_win.getMaxThreadNumber()
        # en mode cluster les options sont différentes
        if nbNodes > 1 and dest != None:
            cmd_args_list = [executablePath,"-p", dest.encode(self.fsCoding), "-n", "c:%s"%nbNodes]
        else:
            cmd_args_list = [executablePath,"-p", (u"%s/"%self.dir).encode(self.fsCoding), "-n", "t:%s"%nbMaxThread]
        cmd_args_list_quoted = list(cmd_args_list)
        for i in range(len(cmd_args_list_quoted)):
            if ";" in cmd_args_list_quoted[i] or " " in cmd_args_list_quoted[i] or ":" in cmd_args_list_quoted[i]:
                cmd_args_list_quoted[i] = '"'+cmd_args_list_quoted[i]+'"'
        log(3,"Command launched for initialization of RNGs of project '%s' : %s"%(self.name," ".join(cmd_args_list_quoted)))
        addLine("%s/command.txt"%self.dir,"Command launched for initialization of RNGs of project '%s' : %s\n\n"%(self.name," ".join(cmd_args_list_quoted)))
        outfile = u"%s/init_rng.out"%(self.dir)
        f = open(outfile.encode(self.fsCoding),"w")
        p = subprocess.Popen(cmd_args_list, stdout=f, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
        #p = subprocess.Popen(cmd_args_list, stdout=f, stderr=subprocess.STDOUT)
        time.sleep(1)
        while (p.poll() == None):
            time.sleep(1)
        f.close()
        if dest != None:
            log(3,"Generation of RNGs of project '%s' for cluster terminated with returncode : %s"%(self.name,p.poll()))
        else:
            log(3,"Initialization of RNGs of project '%s' terminated with returncode : %s"%(self.name,p.poll()))
        QApplication.restoreOverrideCursor()