diff --git a/exercises/exerciseC/plot.py b/exercises/exerciseC/plot.py index ec73761..2c8cc64 100755 --- a/exercises/exerciseC/plot.py +++ b/exercises/exerciseC/plot.py @@ -3,11 +3,11 @@ import numpy as np import matplotlib.pyplot as plt import matplotlib.patheffects as PathEffects -N_processes = 5 -N_threads = 5 +N_processes = 16 +N_threads = 16 # Load measured timings -times = np.empty((N_processes, N_threads)) +times = np.ones((N_processes, N_threads)) for fname in os.listdir('timings'): values = open(f'timings/{fname}').read().split() n_processes = int(values[0]) @@ -25,6 +25,7 @@ fig_time.colorbar(im, ax=axs_time, label='Measured computation time (s)') """ Plot speedup """ workers = np.arange(N_processes + 1)[:, None] * np.arange(N_threads + 1) speedup = times[0, 0] / times +speedup[times == 0] = np.nan fig_speedup, axs_speedup = plt.subplots() im = axs_speedup.imshow(speedup.T, origin='lower') @@ -36,13 +37,13 @@ for axs, data in zip([axs_time, axs_speedup], [times, speedup]): axs.set_xlabel('# processes') axs.set_ylabel('# threads') axs.set_xticks(np.arange(N_processes)) - axs.set_xticklabels(np.arange(N_processes)+1) + axs.set_xticklabels(np.arange(N_processes)+1, fontsize=6) axs.set_yticks(np.arange(N_threads)) - axs.set_yticklabels(np.arange(N_threads)+1) + axs.set_yticklabels(np.arange(N_threads)+1, fontsize=6) for i in range(N_processes): for j in range(N_threads): - txt = axs.text(i, j, f'{data[i, j]:.2f}', fontsize=10, color='w', + txt = axs.text(i, j, f'{data[i, j]:.2f}', fontsize=4, color='w', ha='center', va='center', fontweight='bold') txt.set_path_effects([PathEffects.withStroke(linewidth=0.5, foreground='k')]) axs.spines[['right', 'top']].set_visible(False) diff --git a/exercises/exerciseC/process_images.py b/exercises/exerciseC/process_images.py index 99743e7..c942ea2 100755 --- a/exercises/exerciseC/process_images.py +++ b/exercises/exerciseC/process_images.py @@ -6,9 +6,12 @@ import time def process_image(input_tuple): fname, A = input_tuple + if len(A.shape) > 2: + A = A.mean(axis=-1) # Take average color + A = A[::5, ::5] # Downsample n_threads = os.getenv('OMP_NUM_THREADS', '(unset)') print(f"Worker {fname=} OMP_NUM_THREADS={n_threads}", flush=True) - + # Decompose image U, S, Vh = np.linalg.svd(A) @@ -57,10 +60,10 @@ if __name__ == '__main__': new_images = p.map(process_image, image_arrays) elapsed_time = time.time() - start_time - # I/O save the processed images - for im, fname in zip(new_images, fnames): - im = Image.fromarray(im) - im.save(fname.replace('images', 'processed_images')) + # # I/O save the processed images + # for im, fname in zip(new_images, fnames): + # im = Image.fromarray(im) + # im.save(fname.replace('images', 'processed_images')) print(f'{n_processes} processes and {n_threads} threads and {len(fnames)} jobs: {elapsed_time}\n', flush=True) diff --git a/exercises/exerciseC/run_with_all_configurations.sh b/exercises/exerciseC/run_with_all_configurations.sh index 30a1414..f65b754 100755 --- a/exercises/exerciseC/run_with_all_configurations.sh +++ b/exercises/exerciseC/run_with_all_configurations.sh @@ -1,8 +1,8 @@ # This is bash # It runs the python script multiple times with different arguments -for i in {1..5} # Number of processes +for i in {1..16} # Number of processes do - for j in {1..5} # Number of threads + for j in {1..16} # Number of threads do python process_images.py $i $j images/* done