Skip to content

Instantly share code, notes, and snippets.

@Kojirion
Created October 8, 2014 01:03
Show Gist options
  • Save Kojirion/a4f5b4f1e7350f88e9f0 to your computer and use it in GitHub Desktop.
Save Kojirion/a4f5b4f1e7350f88e9f0 to your computer and use it in GitHub Desktop.
Testing a cholesky factorisation C program through a python script
import subprocess
import pickle
SetupTime = []
FactorisationTime = []
TotalTime = []
ApproximateSolution = []
TrueSolution = 0.199268 # hardcoded
AbsoluteError = []
m_list = [m for m in range(4, 62, 2)] # m >= 4, m even
for m in m_list:
raw_output = subprocess.check_output('./laplace_cholesky_double', input=bytes(str(m), 'ascii'))
processed_output = raw_output.decode().split('\n')
SetupTime.append(processed_output[1].split()[-1])
FactorisationTime.append(processed_output[2].split()[-1])
TotalTime.append(processed_output[3].split()[-1])
ApproximateSolution.append(processed_output[4].split()[-1])
AbsoluteError.append(processed_output[6].split()[-1])
file = open("cholesky_data", "wb")
pickle.dump(m_list, file)
pickle.dump(SetupTime, file)
pickle.dump(FactorisationTime, file)
pickle.dump(TotalTime, file)
pickle.dump(ApproximateSolution, file)
pickle.dump(AbsoluteError, file)
file.close()
import pickle
from matplotlib import pyplot
from matplotlib.legend_handler import HandlerLine2D
file = open("cholesky_data", "rb")
m_list = pickle.load(file)
SetupTime = pickle.load(file)
FactorisationTime = pickle.load(file)
TotalTime = pickle.load(file)
ApproximateSolution = pickle.load(file)
TrueSolution = 0.199268 # hardcoded
AbsoluteError = pickle.load(file)
file.close()
file = open("cholesky_banded_data", "rb")
bm_list = pickle.load(file)
bSetupTime = pickle.load(file)
bFactorisationTime = pickle.load(file)
bTotalTime = pickle.load(file)
bApproximateSolution = pickle.load(file)
bTrueSolution = 0.199268 # hardcoded
bAbsoluteError = pickle.load(file)
file.close()
O_n3 = [pow(i, 2) for i in m_list]
true_solution = [TrueSolution for i in bm_list]
pyplot.plot(m_list, FactorisationTime)
pyplot.plot(bm_list, bFactorisationTime)
pyplot.ylabel('Factorisation time')
# line1, = pyplot.plot(m_list, ApproximateSolution, label='Non-banded Approximate solution')
# pyplot.plot(bm_list, bApproximateSolution, label='Banded Approximate solution')
# pyplot.plot(bm_list, true_solution, label='True solution')
# pyplot.legend(handler_map={line1: HandlerLine2D(numpoints=4)})
pyplot.xlabel('m')
pyplot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment