update
This commit is contained in:
parent
65d9777440
commit
eb11e84063
@ -1,7 +1,7 @@
|
||||
import guan # https://py.guanjihuan.com | install: pip install --upgrade guan
|
||||
import numpy as np
|
||||
|
||||
cpu_num_array = np.arange(1, 11)
|
||||
cpu_num_array = np.arange(1, 17)
|
||||
|
||||
sh_filename = 'task'
|
||||
task_name = 'test'
|
||||
|
@ -12,42 +12,42 @@ B = np.random.rand(n, n)
|
||||
|
||||
# 矩阵行列式
|
||||
start_time = time.time()
|
||||
for _ in range(10):
|
||||
for _ in range(20):
|
||||
det_A = np.linalg.det(A)
|
||||
det_time = (time.time() - start_time)/10
|
||||
det_time = (time.time() - start_time)/20
|
||||
print(f"矩阵行列式时间: {det_time:.3f} 秒")
|
||||
|
||||
# 矩阵乘法
|
||||
start_time = time.time()
|
||||
for _ in range(10):
|
||||
for _ in range(20):
|
||||
C = np.dot(A, B)
|
||||
multiply_time = (time.time() - start_time)/10
|
||||
multiply_time = (time.time() - start_time)/20
|
||||
print(f"矩阵乘法时间: {multiply_time:.3f} 秒")
|
||||
|
||||
# 矩阵求逆
|
||||
start_time = time.time()
|
||||
for _ in range(10):
|
||||
for _ in range(20):
|
||||
inv_A = np.linalg.inv(A)
|
||||
inv_time = (time.time() - start_time)/10
|
||||
inv_time = (time.time() - start_time)/20
|
||||
print(f"矩阵求逆时间: {inv_time:.3f} 秒")
|
||||
|
||||
# 矩阵的秩
|
||||
start_time = time.time()
|
||||
for _ in range(10):
|
||||
for _ in range(20):
|
||||
rank_A = np.linalg.matrix_rank(A)
|
||||
rank_time = (time.time() - start_time)/10
|
||||
rank_time = (time.time() - start_time)/20
|
||||
print(f"矩阵的秩时间: {rank_time:.3f} 秒")
|
||||
|
||||
# 矩阵的特征值
|
||||
start_time = time.time()
|
||||
for _ in range(10):
|
||||
for _ in range(20):
|
||||
eigenvalues_A = np.linalg.eigvals(A)
|
||||
eigen_time = (time.time() - start_time)/10
|
||||
eigen_time = (time.time() - start_time)/20
|
||||
print(f"矩阵特征值时间: {eigen_time:.3f} 秒")
|
||||
|
||||
# 矩阵的特征值和特征向量
|
||||
start_time = time.time()
|
||||
for _ in range(10):
|
||||
for _ in range(20):
|
||||
eigenvalues_A, eigenvector_A = np.linalg.eig(A)
|
||||
eigen_time = (time.time() - start_time)/10
|
||||
eigen_time = (time.time() - start_time)/20
|
||||
print(f"矩阵特征值和特征向量时间: {eigen_time:.3f} 秒")
|
@ -0,0 +1,32 @@
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.ticker import MultipleLocator
|
||||
import numpy as np
|
||||
|
||||
cpu_num_array = np.arange(1, 17)
|
||||
|
||||
time_array_1 = [3.999, 1.679, 1.257, 0.985, 0.699, 0.562, 0.534, 0.525, 0.510, 0.424, 0.409, 0.380, 0.372, 0.339, 0.334, 0.293]
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_title('np.dot()')
|
||||
ax.set_xlabel('Number of CPU cores')
|
||||
ax.set_ylabel('Time (s)')
|
||||
ax.xaxis.set_major_locator(MultipleLocator(1))
|
||||
plt.plot(cpu_num_array, time_array_1, '-o', )
|
||||
plt.show()
|
||||
|
||||
time_array_2 = [6.059, 2.723, 2.190, 1.577, 1.169, 0.939, 1.231, 0.958, 1.070, 0.793, 1.208, 0.760, 0.709, 0.677, 0.671, 0.906]
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_title('np.linalg.inv()')
|
||||
ax.set_xlabel('Number of CPU cores')
|
||||
ax.set_ylabel('Time (s)')
|
||||
ax.xaxis.set_major_locator(MultipleLocator(1))
|
||||
plt.plot(cpu_num_array, time_array_2, '-o', )
|
||||
plt.show()
|
||||
|
||||
time_array_3 = [95.896, 49.107, 41.703, 38.915, 32.468, 25.804, 40.716, 31.072, 40.045, 26.397, 38.557, 28.684, 28.267, 26.840, 27.381, 34.494]
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_title('np.linalg.eig()')
|
||||
ax.set_xlabel('Number of CPU cores')
|
||||
ax.set_ylabel('Time (s)')
|
||||
ax.xaxis.set_major_locator(MultipleLocator(1))
|
||||
plt.plot(cpu_num_array, time_array_3, '-o', )
|
||||
plt.show()
|
@ -1,7 +1,7 @@
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
cpu_num_array = np.arange(1, 11)
|
||||
cpu_num_array = np.arange(1, 17)
|
||||
|
||||
for cpu_num in cpu_num_array:
|
||||
os.system(f'qsub task_{cpu_num}.sh')
|
Loading…
x
Reference in New Issue
Block a user