%load_ext autoreload
%autoreload 2
import sys
import os
import pandas as pd
import random as rd
import matplotlib.pyplot as pl
from timeit import default_timer as timer
import tsp_pythran
from tsp_pythran import TSP, run_tests, Compiler
.so
files¶c = Compiler()
c.run(force=False)
#c.remove()
I ran this notebook on 3 machines
def which_machine():
stdout = !uname -a
name = stdout[0]
if 'Central' in name: return 'iMac'
elif 'Satellite' in name: return 'MBPro'
else: return 'LinuxVM'
def how_many_cores():
if which_machine() in ['iMac', 'MBPro']:
stdout = !sysctl hw.physicalcpu
nb_core = int(stdout[0].split(' ')[-1])
else:
stdout = !lscpu | grep -E '^Thread|^CPU\('
nb_cpu = int(stdout[0].split(' ')[-1])
nb_thread_per_core = int(stdout[1].split(' ')[-1])
nb_core = int(nb_cpu/nb_thread_per_core)
return nb_core
def is_concurrent_pythran_module():
if hasattr(tsp_pythran.tsp_compute_single_threaded, '__pythran__'):
return 'pythran'
return 'python'
def is_omp_pythran_module():
if hasattr(tsp_pythran.tsp_compute_multi_threaded_omp, '__pythran__'):
return 'pythran'
return 'python'
machine = which_machine()
nb_core = how_many_cores()
lang_concurrent = is_concurrent_pythran_module()
lang_omp = is_omp_pythran_module()
print(f'Machine: {machine} with {nb_core} cores')
print(f'Module concurrent:\t{lang_concurrent}')
print(f'Module omp:\t\t{lang_omp}')
nb_city = 100
nb_step = int(1e6)
beta_mult = 1.02
accept_nb_step = 100
p1 = 0.2
p2 = 0.8
nb_run = 1
tsp_1 = TSP(nb_city, nb_run, nb_step, beta_mult, accept_nb_step, p1, p2)
tsp_1.show_params()
nb_run = nb_core
tsp_N = TSP(nb_city, nb_run, nb_step, beta_mult, accept_nb_step, p1, p2)
tsp_N.show_params()
seed = 54321
tsp_1.generate_cities(seed=seed)
tsp_N.generate_cities(seed=seed)
tsp_N.show_cities()
tsp_1.search_concurrent(f'perf-{lang_concurrent}-{machine}-1-concurrent-nosig',
max_workers=nb_core, check_signature=False, dated=False)
tsp_1.save_results()
tsp_1.show_results(nb_best=3, save=True)
tsp_N.search_concurrent(f'perf-{lang_concurrent}-{machine}-{nb_core}-concurrent-nosig',
max_workers=nb_core, check_signature=False, dated=False)
tsp_N.save_results()
tsp_N.show_results(nb_best=3, save=True)
if lang_omp == 'pythran':
tsp_N.search_omp(f'perf-{lang_omp}-{machine}-{nb_core}-omp-nosig',
check_signature=False, dated=False)
tsp_N.save_results()
tsp_N.show_results(nb_best=3, save=True)