fix larger than memory error
This commit is contained in:
parent
895ba73144
commit
eae8e29f47
3 changed files with 17 additions and 13 deletions
|
@ -3,11 +3,11 @@ import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib.patheffects as PathEffects
|
import matplotlib.patheffects as PathEffects
|
||||||
|
|
||||||
N_processes = 5
|
N_processes = 16
|
||||||
N_threads = 5
|
N_threads = 16
|
||||||
|
|
||||||
# Load measured timings
|
# Load measured timings
|
||||||
times = np.empty((N_processes, N_threads))
|
times = np.ones((N_processes, N_threads))
|
||||||
for fname in os.listdir('timings'):
|
for fname in os.listdir('timings'):
|
||||||
values = open(f'timings/{fname}').read().split()
|
values = open(f'timings/{fname}').read().split()
|
||||||
n_processes = int(values[0])
|
n_processes = int(values[0])
|
||||||
|
@ -25,6 +25,7 @@ fig_time.colorbar(im, ax=axs_time, label='Measured computation time (s)')
|
||||||
""" Plot speedup """
|
""" Plot speedup """
|
||||||
workers = np.arange(N_processes + 1)[:, None] * np.arange(N_threads + 1)
|
workers = np.arange(N_processes + 1)[:, None] * np.arange(N_threads + 1)
|
||||||
speedup = times[0, 0] / times
|
speedup = times[0, 0] / times
|
||||||
|
speedup[times == 0] = np.nan
|
||||||
|
|
||||||
fig_speedup, axs_speedup = plt.subplots()
|
fig_speedup, axs_speedup = plt.subplots()
|
||||||
im = axs_speedup.imshow(speedup.T, origin='lower')
|
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_xlabel('# processes')
|
||||||
axs.set_ylabel('# threads')
|
axs.set_ylabel('# threads')
|
||||||
axs.set_xticks(np.arange(N_processes))
|
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_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 i in range(N_processes):
|
||||||
for j in range(N_threads):
|
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')
|
ha='center', va='center', fontweight='bold')
|
||||||
txt.set_path_effects([PathEffects.withStroke(linewidth=0.5, foreground='k')])
|
txt.set_path_effects([PathEffects.withStroke(linewidth=0.5, foreground='k')])
|
||||||
axs.spines[['right', 'top']].set_visible(False)
|
axs.spines[['right', 'top']].set_visible(False)
|
||||||
|
|
|
@ -6,6 +6,9 @@ import time
|
||||||
def process_image(input_tuple):
|
def process_image(input_tuple):
|
||||||
|
|
||||||
fname, A = 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)')
|
n_threads = os.getenv('OMP_NUM_THREADS', '(unset)')
|
||||||
print(f"Worker {fname=} OMP_NUM_THREADS={n_threads}", flush=True)
|
print(f"Worker {fname=} OMP_NUM_THREADS={n_threads}", flush=True)
|
||||||
|
|
||||||
|
@ -57,10 +60,10 @@ if __name__ == '__main__':
|
||||||
new_images = p.map(process_image, image_arrays)
|
new_images = p.map(process_image, image_arrays)
|
||||||
elapsed_time = time.time() - start_time
|
elapsed_time = time.time() - start_time
|
||||||
|
|
||||||
# I/O save the processed images
|
# # I/O save the processed images
|
||||||
for im, fname in zip(new_images, fnames):
|
# for im, fname in zip(new_images, fnames):
|
||||||
im = Image.fromarray(im)
|
# im = Image.fromarray(im)
|
||||||
im.save(fname.replace('images', 'processed_images'))
|
# im.save(fname.replace('images', 'processed_images'))
|
||||||
|
|
||||||
print(f'{n_processes} processes and {n_threads} threads and {len(fnames)} jobs: {elapsed_time}\n',
|
print(f'{n_processes} processes and {n_threads} threads and {len(fnames)} jobs: {elapsed_time}\n',
|
||||||
flush=True)
|
flush=True)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# This is bash
|
# This is bash
|
||||||
# It runs the python script multiple times with different arguments
|
# 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
|
do
|
||||||
for j in {1..5} # Number of threads
|
for j in {1..16} # Number of threads
|
||||||
do
|
do
|
||||||
python process_images.py $i $j images/*
|
python process_images.py $i $j images/*
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue