#NEWLINE# def optimize( self , optimizer = None , start = None , **kwargs ) : #NEWLINE# #INDENT# self . _IN_OPTIMIZATION_ = True #NEWLINE# if ( self . mpi_comm == None ) : #NEWLINE# #INDENT# super ( SSMRD , self ) . optimize ( optimizer , optimizer , ** kwargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . mpi_comm . rank == 0 ) : #NEWLINE# #INDENT# super ( SSMRD , self ) . optimize ( optimizer , start , ** kwargs ) #NEWLINE# self . mpi_comm . Bcast ( np . int32 ( ( - 1 ) ) , root = 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . mpi_comm . rank > 0 ) : #NEWLINE# #INDENT# x = self . optimizer_array . copy ( ) #NEWLINE# flag = np . empty ( 1 , dtype = np . int32 ) #NEWLINE# while True : #NEWLINE# #INDENT# self . mpi_comm . Bcast ( flag , root = 0 ) #NEWLINE# if ( flag == 1 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . optimizer_array = x #NEWLINE# self . _fail_count = 0 #NEWLINE# #UNINDENT# except ( LinAlgError , ZeroDivisionError , ValueError ) : #NEWLINE# #INDENT# if ( self . _fail_count >= self . _allowed_failures ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# self . _fail_count += 1 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( flag == ( - 1 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _IN_OPTIMIZATION_ = False #NEWLINE# raise Exception ( 'Unrecognizable flag for synchronization!' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . _IN_OPTIMIZATION_ = False