This commit is contained in:
guanjihuan 2025-04-03 23:46:51 +08:00
parent 8d726fe9e6
commit 02a3f2b279
4 changed files with 28 additions and 12 deletions

View File

@ -40,10 +40,12 @@ program main
implicit none
integer, allocatable :: index1(:)
integer n, i, j, info, ierr, stage, start, end_val, step, count_start, count_end, count_rate
integer n, i, j, info, ierr, stage, start, end_val, step, count_start, count_end, count_rate, test_0, test_times
double precision, allocatable :: A(:,:)
double precision time_used
test_times = 20
!
do stage = 1, 3
select case(stage)
@ -55,9 +57,9 @@ program main
start = 2000
end_val = 10000
step = 1000
case(3) ! 20000-5000010000
case(3) ! 20000-3000010000
start = 20000
end_val = 50000
end_val = 30000
step = 10000
end select
@ -65,21 +67,25 @@ program main
do while (n <= end_val)
allocate(index1(n), stat=ierr)
call generate_random_matrix(n, A)
call system_clock(count_start, count_rate)
call getrf(A, index1, info); call getri(A, index1, info) ! 使 getrf getri A
test_0 = 1
do while (test_0 <= test_times)
call generate_random_matrix(n, A)
call getrf(A, index1, info); call getri(A, index1, info) ! 使 getrf getri A
deallocate(A, stat=ierr)
test_0 = test_0 + 1
end do
call system_clock(count_end)
!
if (count_rate > 0) then
time_used = real(count_end - count_start) / real(count_rate)
time_used = real(count_end - count_start) / real(count_rate) / test_times
write(*, '(a, I6, a, f12.6, a)') 'n = ', n, ' 的计算时间: ', time_used, ' 秒'
else
write(*,*) "无法获取计算时间"
endif
deallocate(A, stat=ierr)
deallocate(index1, stat=ierr)
n = n + step

View File

@ -8,11 +8,13 @@ import time
n_array = np.concatenate((np.arange(100, 1000, 100),
np.arange(1000, 10000, 1000),
np.arange(10000, 60000, 10000)))
np.arange(10000, 40000, 10000)))
for n in n_array:
A = np.random.rand(n, n)
test_times = 20
start_time = time.time()
inv_A = np.linalg.inv(A)
inv_time = time.time() - start_time
for _ in range(test_times):
A = np.random.rand(n, n)
inv_A = np.linalg.inv(A)
inv_time = (time.time() - start_time)/test_times
print(f"n = {n} 的计算时间: {inv_time:.6f}")

View File

@ -0,0 +1,4 @@
#!/bin/sh
#PBS -N fortran
#PBS -l nodes=1:ppn=24
./a.exe

View File

@ -0,0 +1,4 @@
#!/bin/sh
#PBS -N python
#PBS -l nodes=1:ppn=24
python a.py