Exemplo n.º 1
0
 def __init__(self, S, BuildMasterOnly=True):
     """
     Construction : with named arguments only.
     Possible constructors from source S : 
        - Parameters(d) : d is a dict to be copied (no deepcopy, just updated).
        - Parameters(f) : f is a string containing the path of a file
          The type of the file is determined from the extension: 
             - .py, .txt : the file is executed in the Parameters
             - .xml : to be written
     MPI : if BuildMasterOnly is true, the contruction is only made on the master, 
           the result is then bcasted to all the nodes.
           Otherwise, it is done on all nodes (not recommended to read files).
     """
     if MPI.IS_MASTER_NODE() or not BuildMasterOnly:
         if type(S) == type(''):
             # detect the type of the file
             try:
                 extension = S.split('.')[-1].lower()
             except IndexError:
                 raise ValueError, "I am lost : I can not determine the extension of the file !"
             if extension in ['py', 'txt']: execfile(S, {}, self)
             else: raise ValueError, "Extension of the file not recognized"
         else:  # S is therefore a dict
             try:
                 self.update(S)
             except:
                 print "Error in Parameter constructor. Is the source an iterable ?"
                 raise
     # end of master only
     if BuildMasterOnly: MPI.bcast(self)  # bcast it on the nodes
Exemplo n.º 2
0
 def __init__(self, S, BuildMasterOnly =True) :
     """
     Construction : with named arguments only.
     Possible constructors from source S : 
        - Parameters(d) : d is a dict to be copied (no deepcopy, just updated).
        - Parameters(f) : f is a string containing the path of a file
          The type of the file is determined from the extension: 
             - .py, .txt : the file is executed in the Parameters
             - .xml : to be written
     MPI : if BuildMasterOnly is true, the contruction is only made on the master, 
           the result is then bcasted to all the nodes.
           Otherwise, it is done on all nodes (not recommended to read files).
     """
     if MPI.IS_MASTER_NODE() or not BuildMasterOnly : 
         if type(S) == type(''):
            # detect the type of the file
            try : 
               extension = S.split('.')[-1].lower()
            except IndexError: 
               raise ValueError, "I am lost : I can not determine the extension of the file !"
            if extension in ['py','txt'] : execfile(S,{},self)
            else : raise ValueError, "Extension of the file not recognized"
         else : # S is therefore a dict 
             try : 
               self.update(S)
             except : 
               print "Error in Parameter constructor. Is the source an iterable ?"
               raise
     # end of master only
     if BuildMasterOnly : MPI.bcast(self) # bcast it on the nodes
Exemplo n.º 3
0
 def __should_continue(self,N_Iter_SelfCons_Max) :
   """ stop test"""
   should_continue = True
   if MPI.IS_MASTER_NODE():
     if (self.Iteration_Number > N_Iter_SelfCons_Max):
       should_continue = False
   should_continue = MPI.bcast(should_continue)
   return should_continue
Exemplo n.º 4
0
    def read_input_from_HDF(self, SubGrp, thingstoread, optionalthings=[]):
        """
        Reads data from the HDF file
        """

        retval = True
        # init variables on all nodes:
        for it in thingstoread:
            exec "self.%s = 0" % it
        for it in optionalthings:
            exec "self.%s = 0" % it

        if MPI.IS_MASTER_NODE():
            ar = HDF_Archive(self.HDFfile, "a")
            if SubGrp in ar:
                # first read the necessary things:
                for it in thingstoread:
                    if it in ar[SubGrp]:
                        exec "self.%s = ar['%s']['%s']" % (it, SubGrp, it)
                    else:
                        MPI.report("Loading %s failed!" % it)
                        retval = False

                if (retval) and (len(optionalthings) > 0):
                    # if necessary things worked, now read optional things:
                    retval = {}
                    for it in optionalthings:
                        if it in ar[SubGrp]:
                            exec "self.%s = ar['%s']['%s']" % (it, SubGrp, it)
                            retval["%s" % it] = True
                        else:
                            retval["%s" % it] = False
            else:
                MPI.report("Loading failed: No %s subgroup in HDF5!" % SubGrp)
                retval = False

            del ar

        # now do the broadcasting:
        for it in thingstoread:
            exec "self.%s = MPI.bcast(self.%s)" % (it, it)
        for it in optionalthings:
            exec "self.%s = MPI.bcast(self.%s)" % (it, it)

        retval = MPI.bcast(retval)

        return retval