-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
\Appendix | ||
\begin{center} | ||
Тест производительности функции для расчета эффекта пространственного заряда в разных режимах работы REDPIC | ||
\end{center} | ||
|
||
\begin{lstlisting}[language=python, caption={Тест производительности функции для расчета эффекта пространственного заряда в разных режимах работы REDPIC}, label={lst:appendix_test_performance_redpic}] | ||
import numpy as np | ||
from numba import njit, prange | ||
import matplotlib.pyplot as plt | ||
import time | ||
|
||
def sum_field_particles( | ||
x: np.array, y: np.array, z: np.array, z_start: float, z_stop: float, Fx: np.array, Fy: np.array, Fz: np.array | ||
) -> None: | ||
for i in range(int(len(x))): # pylint: disable=E1133 | ||
if z_start <= z[i] <= z_stop: | ||
for j in range(int(len(x))): | ||
if z_start <= z[j] <= z_stop and i != j: | ||
Fx[i] += (x[i] - x[j]) / ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2 + (z[j] - z[i]) ** 2) ** (3 / 2) | ||
Fy[i] += (y[i] - y[j]) / ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2 + (z[j] - z[i]) ** 2) ** (3 / 2) | ||
Fz[i] += (z[i] - z[j]) / ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2 + (z[j] - z[i]) ** 2) ** (3 / 2) | ||
|
||
|
||
def sum_field_particles_parallel_cpu( | ||
x: np.array, y: np.array, z: np.array, z_start: float, z_stop: float, Fx: np.array, Fy: np.array, Fz: np.array | ||
) -> None: | ||
for i in prange(int(len(x))): # pylint: disable=E1133 | ||
if z_start <= z[i] <= z_stop: | ||
for j in range(int(len(x))): | ||
if z_start <= z[j] <= z_stop and i != j: | ||
Fx[i] += (x[i] - x[j]) / ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2 + (z[j] - z[i]) ** 2) ** (3 / 2) | ||
Fy[i] += (y[i] - y[j]) / ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2 + (z[j] - z[i]) ** 2) ** (3 / 2) | ||
Fz[i] += (z[i] - z[j]) / ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2 + (z[j] - z[i]) ** 2) ** (3 / 2) | ||
|
||
|
||
jit_sum_field_particles = njit(sum_field_particles) | ||
cpu_parallel_jit_sum_field_particles = njit(parallel=True)(sum_field_particles_parallel_cpu) | ||
|
||
def measure_time(func, *args): | ||
start_time = time.time() | ||
func(*args) | ||
return time.time() - start_time | ||
|
||
particle_counts = [2**i for i in range(13)] | ||
times_no_jit = [] | ||
times_jit = [] | ||
times_cpu_parallel_jit = [] | ||
|
||
for N in particle_counts: | ||
x, y, z = np.random.rand(N), np.random.rand(N), np.random.rand(N) | ||
Fx, Fy, Fz = np.zeros(N), np.zeros(N), np.zeros(N) | ||
z_start, z_stop = 0.0, 1.0 | ||
|
||
times_no_jit.append(measure_time(sum_field_particles, x, y, z, z_start, z_stop, Fx, Fy, Fz)) | ||
times_jit.append(measure_time(jit_sum_field_particles, x, y, z, z_start, z_stop, Fx, Fy, Fz)) | ||
times_cpu_parallel_jit.append(measure_time(cpu_parallel_jit_sum_field_particles, x, y, z, z_start, z_stop, Fx, Fy, Fz)) | ||
|
||
plt.figure(figsize=(10, 6)) | ||
plt.plot(particle_counts, times_no_jit, label='without JIT', marker='o') | ||
plt.plot(particle_counts, times_jit, label='with JIT', marker='s') | ||
plt.plot(particle_counts, times_cpu_parallel_jit, label='with parallel CPU', marker='^') | ||
plt.xlabel('Particles, $N$') | ||
plt.ylabel('Time, $t$ [s]') | ||
plt.legend() | ||
plt.grid(True) | ||
plt.show() | ||
\end{lstlisting} |