Threads vs execution time #8
2 changed files with 30 additions and 18 deletions
|
@ -5,10 +5,11 @@ from datetime import datetime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# Timestamp that will be put in the file name
|
# Timestamp that will be put in the file name
|
||||||
timestamp = datetime.now().strftime("%H%M%S%f")
|
|
||||||
|
|
||||||
# Get the environment variable for threads
|
# Get the environment variable for threads
|
||||||
threads = os.getenv('OMP_NUM_THREADS')
|
for threads in range(1,12):
|
||||||
|
for _ in range(3):
|
||||||
|
timestamp = datetime.now().strftime("%H%M%S%f")
|
||||||
|
|
||||||
# A relatively large matrix to work on
|
# A relatively large matrix to work on
|
||||||
n = 5_000
|
n = 5_000
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
# IO: This loads the timings for you
|
# IO: This loads the timings for you
|
||||||
threads, timings = [], []
|
threads, timings = [], []
|
||||||
|
@ -11,13 +12,23 @@ for file in os.listdir('timings'):
|
||||||
timings.append(float(t))
|
timings.append(float(t))
|
||||||
threads = np.array(threads)
|
threads = np.array(threads)
|
||||||
timings = np.array(timings)
|
timings = np.array(timings)
|
||||||
|
dat = {'timings': timings, 'threads': threads}
|
||||||
|
|
||||||
print('This is the data I loaded: threads =', threads, ', timings =',timings)
|
data = pd.DataFrame(dat)
|
||||||
|
|
||||||
|
averages = data.groupby('threads').aggregate(['mean','std'])
|
||||||
|
averages.to_csv('data.csv')
|
||||||
fig, axs = plt.subplots()
|
fig, axs = plt.subplots()
|
||||||
|
|
||||||
# CREATE YOUR PLOT HERE
|
# CREATE YOUR PLOT HERE
|
||||||
# Remember to label your axis
|
# Remember to label your axis
|
||||||
# Feel free to make it pretty
|
# Feel free to make it pretty
|
||||||
|
means = averages['timings']['mean']
|
||||||
|
stds = averages['timings']['std']
|
||||||
|
|
||||||
|
axs.plot(averages.index, means)
|
||||||
|
axs.fill_between(averages.index, means-stds, means+stds, alpha=0.3)
|
||||||
|
axs.set_xlabel('Num threads')
|
||||||
|
axs.set_ylabel('Time (s)')
|
||||||
|
plt.show()
|
||||||
plt.savefig('threads_v_timings.png', dpi=300)
|
plt.savefig('threads_v_timings.png', dpi=300)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue