def test_random_seeding(self): """Random seed should be set every function call""" # On Windows process ids are not guaranteed to be sequential(1,2,3,4...) # thus they cannot be used for reproducibility index1 = [2, 3, 4, 5, 6, 7, 8, 9, 10] index2 = [2, 2, 2, 2, 2, 2, 2, 2, 2] result1 = parallel.map(get_ranint, index1, max_workers=1, use_mpi=False) result2 = parallel.map(get_ranint, index2, max_workers=1, use_mpi=False) self.assertEqual(result1[0], result2[0]) self.assertNotEqual(result1, result2)
def main(): # Each worker will evaluate 20 prime numbers. This is just to slow the # script down! PRIMES = ( [ 112272535095293, 112582705942171, 112272535095293, 115280095190773, 115797848077099, 117450548693743, 993960000099397, ] * PBS_NCPUS * 20 ) print(f"MPI World size: {parallel.size}\n") start = time.time() result = parallel.map(is_prime, PRIMES, use_mpi=True, max_workers=PBS_NCPUS) if result != [True] * len(PRIMES): print(" failed\n") else: print(f"{time.time() - start:.2f} seconds\n")
def test_create_processes(self): """Procressor pool should create multiple distingue processes""" max_worker_count = multiprocessing.cpu_count() - 1 index = [index for index in range(max_worker_count)] result = parallel.map(get_process_value, index, max_workers=None, use_mpi=False) result_processes = [v[0] for v in result] result_values = [v[1] for v in result] self.assertEqual(sorted(list(result_values)), index) self.assertEqual(len(set(result_processes)), max_worker_count)
print(f"Rank: {r}") if n % 2 == 0: return False sqrt_n = int(math.floor(math.sqrt(n))) for i in range(3, sqrt_n + 1, 2): if n % i == 0: return False return True PRIMES = [ 112272535095293, 112582705942171, 112272535095293, 115280095190773, 115797848077099, 117450548693743, 993960000099397, ] * 4 # multiplying just to increase the amount of data to calculate print(f"World size: {parallel.size}\n") start = time.time() result = parallel.map(is_prime, PRIMES, max_workers=4) print(f"{time.time() - start:.2f} seconds\n")