Пример #1
0
    def start(self, mpi_port = None):
        if mpi_port is None:
            parent = self.intercomm
            self.communicators.append(parent)
        else:
            parent = MPI.COMM_WORLD.Connect(mpi_port, MPI.INFO_NULL, 0)
            self.communicators.append(parent)
        self.activeid = 0
        self.lastid += 1
        
        rank = parent.Get_rank()
        
        self.must_run = True
        while self.must_run:
            if self.id_to_activate >= 0 and self.id_to_activate != self.activeid:
                print "activating:", self.id_to_activate
                self.activeid = self.id_to_activate
                self.id_to_activate = -1
                parent = self.communicators[self.activeid]
                rank = parent.Get_rank()
            message = ClientSideMPIMessage(polling_interval = self.polling_interval)
            message.receive(parent)

            result_message = ClientSideMPIMessage(message.call_id, message.function_id, message.call_count)
            
            if message.function_id == 0:
                self.must_run = False
            else:
                if message.function_id in self.mapping_from_tag_to_legacy_function:
                    try:
                        self.handle_message(message, result_message)
                    except Exception as ex:
                        print "EX:", ex
                        traceback.print_exc()
                        result_message.set_error(str(ex))
                        #for type, attribute in self.dtype_to_message_attribute.iteritems():
                        #    setattr(result_message, attribute, [])
                            
                        for type, attribute in self.dtype_to_message_attribute.iteritems():
                            array = getattr(result_message, attribute)
                            packed = pack_array(array, result_message.call_count, type)
                            setattr(result_message, attribute, packed)
                        
                else:
                    result_message.set_error("unknown function id " + str(message.function_id))
            
            if rank == 0:
                result_message.send(parent)

        if self.must_disconnect:
            for x in self.communicators:
                x.Disconnect()
Пример #2
0
    def start(self, mpi_port = None):
        if mpi_port is None:
            parent = self.intercomm
            self.communicators.append(parent)
        else:
            parent = MPI.COMM_WORLD.Connect(mpi_port, MPI.INFO_NULL, 0)
            self.communicators.append(parent)
        self.activeid = 0
        self.lastid += 1
        
        rank = parent.Get_rank()
        
        self.must_run = True
        while self.must_run:
            if self.id_to_activate >= 0 and self.id_to_activate != self.activeid:
                print "activating:", self.id_to_activate
                self.activeid = self.id_to_activate
                self.id_to_activate = -1
                parent = self.communicators[self.activeid]
                rank = parent.Get_rank()
            message = ClientSideMPIMessage(polling_interval = self.polling_interval)
            message.receive(parent)

            result_message = ClientSideMPIMessage(message.call_id, message.function_id, message.call_count)
            
            if message.function_id == 0:
                self.must_run = False
            else:
                if message.function_id in self.mapping_from_tag_to_legacy_function:
                    try:
                        self.handle_message(message, result_message)
                    except Exception as ex:
                        print "EX:", ex
                        traceback.print_exc()
                        result_message.set_error(str(ex))
                        #for type, attribute in self.dtype_to_message_attribute.iteritems():
                        #    setattr(result_message, attribute, [])
                            
                        for type, attribute in self.dtype_to_message_attribute.iteritems():
                            array = getattr(result_message, attribute)
                            packed = pack_array(array, result_message.call_count, type)
                            setattr(result_message, attribute, packed)
                        
                else:
                    result_message.set_error("unknown function id " + str(message.function_id))
            
            if rank == 0:
                result_message.send(parent)

        if self.must_disconnect:
            for x in self.communicators:
                x.Disconnect()