Exemple #1
0
 def __init__(self, S, build_master_only =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 build_master_only 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 build_master_only : 
         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 build_master_only : mpi.bcast(self) # bcast it on the nodes
Exemple #2
0
 def __should_continue(self, n_iter_max) :
   """ stop test"""
   should_continue = True
   if mpi.is_master_node():
     if (self.Iteration_Number > n_iter_max):
       should_continue = False
   should_continue = mpi.bcast(should_continue)
   return should_continue
Exemple #3
0
    def read_input_from_hdf(self, subgrp, things_to_read, optional_things=[]):
        """
        Reads data from the HDF file
        """
        
        retval = True
        # init variables on all nodes:
        for it in things_to_read: exec "self.%s = 0"%it
        for it in optional_things: exec "self.%s = 0"%it
        
        if (mpi.is_master_node()):
            ar=HDFArchive(self.hdf_file,'a')
            if (subgrp in ar):
                # first read the necessary things:
                for it in things_to_read:
                    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(optional_things)>0)):
                    # if necessary things worked, now read optional things:
                    retval = {}
                    for it in optional_things:
                        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 things_to_read: exec "self.%s = mpi.bcast(self.%s)"%(it,it)
        for it in optional_things: exec "self.%s = mpi.bcast(self.%s)"%(it,it)
        

        retval = mpi.bcast(retval)
               
        return retval