def __init__(self, level_n): self.work = True self.n = config.N self.cell_size = config.CELL_SIZE self.matrix = get_matrix(level_n) self.top = self.left = 50 self.image = pygame.image.load(f"image/{level_n}.JPG")
import time from functions import get_matrix def matrixMult(a, b, res): time_start = time.time() for i in range(len(a)): for j in range(len(b[0])): for k in range(len(b)): res[i][j] += a[i][k] * b[k][j] print("Finished in %s seconds" % (time.time() - time_start)) sizes = [1, 2, 4, 8, 16, 32, 64, 128, 256, 384] print("SERIAL") for size in sizes: first_matrix = get_matrix(size, 36.6) second_matrix = get_matrix(size, 1.23) res = get_matrix(size, 0) matrixMult(first_matrix, second_matrix, res)
import time from mpi4py import MPI from functions import line_and_second_matrix_multiplication from functions import get_matrix comm = MPI.COMM_WORLD my_rank = comm.Get_rank() num_of_processes = comm.Get_size() first_matrix = get_matrix(num_of_processes, 36.6) second_matrix = get_matrix(num_of_processes, 1.23) if my_rank == 0: time_start = time.time() if my_rank != 0: line = [my_rank, line_and_second_matrix_multiplication( first_matrix[my_rank], second_matrix)] req = comm.isend(line, dest=0) req.wait() else: result_matrix = [[] for i in range(0, num_of_processes)] result_matrix[0] = line_and_second_matrix_multiplication( first_matrix[0], second_matrix) for procid in range(1, num_of_processes): req = comm.irecv(source=procid) line = req.wait() result_matrix[line[0]] = line[1] # print(result_matrix) if my_rank == 0:
def level_render(level_n, id_n, screen, fps, clock): board = Level(str(level_n)) matrix = get_matrix(str(level_n)) player = Player(start_cords_generstion(board.matrix)) enemyes = get_enemy(str(level_n)) finish = enemyes.pop(0) enemyes = [Enemy(enemy) for enemy in enemyes] background = pygame.image.load("image/background.jpg") shadow = pygame.image.load("image/shadow.png") pause = False running = True while running: screen.blit(background, (0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.KEYDOWN: if event.unicode == " ": for enemy in enemyes: if player.attak(screen, enemy.cords): enemy.life = False if event.key == 27: pause = True keys = list(pygame.key.get_pressed()) if 1 in keys: player.move(keys.index(1), matrix) screen.blit(board.image, (50, 50)) #board.render(screen) player.render(screen) for enemy in enemyes: if enemy.life: enemy.render(screen) enemy.move(screen) if enemy.atack(screen, player.cords): enemy.do_attack(screen) player.heart -= 1 if player.isfinish(screen, finish): screen.blit(shadow, (0, 0)) result = win_render(screen, fps, clock, level_n, 3 * player.heart // 8) player.score += 100 * player.heart // 8 if result - level_n == 1: update(level_n, player.score, id_n, 3 * player.heart // 8) running = False if pause: screen.blit(shadow, (0, 0)) menu_render(screen, fps, clock) pause = False if player.heart < 1: result = lose_render(screen, fps, clock, level_n) running = False pygame.display.flip() clock.tick(fps) return result