update
This commit is contained in:
		| @@ -40,10 +40,12 @@ program main | |||||||
|     implicit none |     implicit none | ||||||
|  |  | ||||||
|     integer, allocatable :: index1(:) |     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, allocatable :: A(:,:) | ||||||
|     double precision time_used |     double precision time_used | ||||||
|  |  | ||||||
|  |     test_times = 20 | ||||||
|  |  | ||||||
|     ! 定义不同阶段的参数 |     ! 定义不同阶段的参数 | ||||||
|     do stage = 1, 3 |     do stage = 1, 3 | ||||||
|         select case(stage) |         select case(stage) | ||||||
| @@ -55,9 +57,9 @@ program main | |||||||
|             start = 2000 |             start = 2000 | ||||||
|             end_val = 10000 |             end_val = 10000 | ||||||
|             step = 1000 |             step = 1000 | ||||||
|         case(3)  ! 第三阶段:20000-50000,步长10000 |         case(3)  ! 第三阶段:20000-30000,步长10000 | ||||||
|             start = 20000 |             start = 20000 | ||||||
|             end_val = 50000 |             end_val = 30000 | ||||||
|             step = 10000 |             step = 10000 | ||||||
|         end select |         end select | ||||||
|  |  | ||||||
| @@ -65,21 +67,25 @@ program main | |||||||
|         do while (n <= end_val) |         do while (n <= end_val) | ||||||
|  |  | ||||||
|             allocate(index1(n), stat=ierr) |             allocate(index1(n), stat=ierr) | ||||||
|             call generate_random_matrix(n, A) |  | ||||||
|              |              | ||||||
|             call system_clock(count_start, count_rate) |             call system_clock(count_start, count_rate) | ||||||
|  |             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 不再是原来的矩阵了,而是求逆后的矩阵。 |                 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) |             call system_clock(count_end) | ||||||
|  |  | ||||||
|             ! 打印计算时间 |             ! 打印计算时间 | ||||||
|             if (count_rate > 0) then |             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, ' 秒' |                 write(*, '(a, I6, a, f12.6, a)') 'n = ', n, ' 的计算时间: ', time_used, ' 秒' | ||||||
|             else |             else | ||||||
|                 write(*,*) "无法获取计算时间" |                 write(*,*) "无法获取计算时间" | ||||||
|             endif |             endif | ||||||
|  |  | ||||||
|             deallocate(A, stat=ierr) |  | ||||||
|             deallocate(index1, stat=ierr) |             deallocate(index1, stat=ierr) | ||||||
|  |  | ||||||
|             n = n + step |             n = n + step | ||||||
|   | |||||||
| @@ -8,11 +8,13 @@ import time | |||||||
|  |  | ||||||
| n_array = np.concatenate((np.arange(100, 1000, 100), | n_array = np.concatenate((np.arange(100, 1000, 100), | ||||||
|                           np.arange(1000, 10000, 1000), |                           np.arange(1000, 10000, 1000), | ||||||
|                           np.arange(10000, 60000, 10000))) |                           np.arange(10000, 40000, 10000))) | ||||||
|  |  | ||||||
| for n in n_array: | for n in n_array: | ||||||
|     A = np.random.rand(n, n) |     test_times = 20 | ||||||
|     start_time = time.time() |     start_time = time.time() | ||||||
|  |     for _ in range(test_times): | ||||||
|  |         A = np.random.rand(n, n) | ||||||
|         inv_A = np.linalg.inv(A) |         inv_A = np.linalg.inv(A) | ||||||
|     inv_time = time.time() - start_time |     inv_time = (time.time() - start_time)/test_times | ||||||
|     print(f"n = {n} 的计算时间: {inv_time:.6f} 秒") |     print(f"n = {n} 的计算时间: {inv_time:.6f} 秒") | ||||||
| @@ -0,0 +1,4 @@ | |||||||
|  | #!/bin/sh | ||||||
|  | #PBS -N fortran | ||||||
|  | #PBS -l nodes=1:ppn=24 | ||||||
|  | ./a.exe | ||||||
| @@ -0,0 +1,4 @@ | |||||||
|  | #!/bin/sh | ||||||
|  | #PBS -N python | ||||||
|  | #PBS -l nodes=1:ppn=24 | ||||||
|  | python a.py | ||||||
		Reference in New Issue
	
	Block a user