Skip to content

Commit 16bea69

Browse files
authored
Merge pull request #23 from xsuite/investigate_omp
v0.1.0
2 parents 49111e4 + dc46b10 commit 16bea69

31 files changed

+4202
-504
lines changed

examples/apertures/000_rect_aperture_standalone.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
sigma = np.zeros(n_part),
2727
delta = np.zeros(n_part))
2828

29-
part_dict = xt.pyparticles_to_xtrack_dict(pyst_part)
30-
particles = xt.Particles(_context=context, **part_dict)
29+
particles = xt.Particles(_context=context, **pyst_part.to_dict())
3130

3231
aper_pyst = xline.elements.LimitRect(min_x=x_aper_min,
3332
max_x=x_aper_max,

examples/apertures/001_rect_aperture_withinline.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import xobjects as xo
44
import xtrack as xt
55

6-
import xline
6+
import xline as xl
7+
import xpart as xp
78

89
context = xo.ContextCpu()
910
context = xo.ContextCupy()
@@ -17,7 +18,7 @@
1718
part_gen_range = 0.35
1819
n_part=10000
1920

20-
pyst_part = xline.Particles(
21+
xparticles = xp.Particles(
2122
p0c=6500e9,
2223
x=np.random.uniform(-part_gen_range, part_gen_range, n_part),
2324
px = np.zeros(n_part),
@@ -26,27 +27,26 @@
2627
sigma = np.zeros(n_part),
2728
delta = np.zeros(n_part))
2829

29-
part_dict = xt.pyparticles_to_xtrack_dict(pyst_part)
30-
particles = xt.Particles(_context=context, **part_dict)
30+
particles = xt.Particles(_context=context, **xparticles.to_dict())
3131

32-
aper_pyst = xline.elements.LimitRect(min_x=x_aper_min,
32+
aper_xline = xl.elements.LimitRect(min_x=x_aper_min,
3333
max_x=x_aper_max,
3434
min_y=y_aper_min,
3535
max_y=y_aper_max)
3636

3737
aper = xt.LimitRect(_context=context,
38-
**aper_pyst.to_dict())
38+
**aper_xline.to_dict())
3939

40-
aper_pyst.track(pyst_part)
40+
aper_xline.track(xparticles)
4141

4242
# Build a small test line
43-
pyst_line = xline.Line(elements=[
44-
xline.elements.Drift(length=5.),
45-
aper_pyst,
46-
xline.elements.Drift(length=5.)],
43+
line = xl.Line(elements=[
44+
xl.elements.Drift(length=5.),
45+
aper_xline,
46+
xl.elements.Drift(length=5.)],
4747
element_names=['drift0', 'aper', 'drift1'])
4848

49-
tracker = xt.Tracker(_context=context, sequence=pyst_line)
49+
tracker = xt.Tracker(_context=context, sequence=line)
5050

5151
tracker.track(particles)
5252

@@ -58,7 +58,7 @@
5858

5959
id_alive = part_id[part_state>0]
6060

61-
assert np.allclose(np.sort(pyst_part.particle_id), np.sort(id_alive))
61+
assert np.allclose(np.sort(xparticles.particle_id), np.sort(id_alive))
6262
assert np.allclose(part_s[part_state>0], 10.)
6363
assert np.allclose(part_s[part_state<1], 5.)
6464

examples/full_ring/005_one_turn_check.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@
111111
problem_found = False
112112
for ii, (eexl, nn) in enumerate(zip(sequence.elements, sequence.element_names)):
113113
vars_before = {vv :getattr(xl_part, vv) for vv in vars_to_check}
114-
pp_dict = xt.pyparticles_to_xtrack_dict(xl_part)
115-
particles.set_particle(ip_check, **pp_dict)
114+
particles.set_particle(ip_check, **xl_part.to_dict())
116115

117116
tracker.track(particles, ele_start=ii, num_elements=1)
118117

examples/full_ring/006_timing.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
# Choose a context #
4141
####################
4242

43-
n_part = 200
44-
context = xo.ContextCpu()
43+
n_part = 8000
44+
context = xo.ContextCpu(omp_num_threads=8)
45+
#context = xo.ContextCpu(omp_num_threads=0)
4546

4647
#n_part = 20000
4748
#context = xo.ContextCupy()
@@ -75,6 +76,21 @@
7576

7677
print('Import sequence')
7778
sequence = xl.Line.from_dict(input_data['line'])
79+
80+
81+
#fodo = [xl.Drift(length=1.), xl.Multipole(knl=[0, 1.]),
82+
# xl.Drift(length=1.), xl.Multipole(knl=[0, -1.])]
83+
#
84+
#elelist = 4000*fodo
85+
#elenames = [f'e{ii}' for ii in range(len(elelist))]
86+
#
87+
#sequence = xl.Line(elements=elelist, element_names=elenames)
88+
89+
90+
91+
92+
93+
7894
if short_test:
7995
sequence = make_short_line(sequence)
8096

@@ -84,7 +100,8 @@
84100

85101
print('Build tracker')
86102
tracker = xt.Tracker(_context=context,
87-
sequence=sequence)
103+
sequence=sequence,
104+
save_source_as='source.c')
88105

89106
######################
90107
# Get some particles #

0 commit comments

Comments
 (0)