#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import os from cobjects import CBuffer import sixtracklib as st from sixtracklib.stcommon import st_NODE_UNDEFINED_INDEX import sixtracklib_test as testlib from sixtracklib_test.generic_obj import GenericObj if __name__ == '__main__': if not st.supports('cuda'): raise SystemExit("cuda support required for this test") try: num_nodes = st.CudaController.NUM_AVAILABLE_NODES() except RuntimeError as e: num_nodes = 0 if num_nodes <= 0: print("No CUDA nodes available -> skip test") sys.exit(0) ctrl = st.CudaController() assert ctrl.num_nodes > 0 assert ctrl.has_selected_node assert ctrl.selected_node_index != st_NODE_UNDEFINED_INDEX.value print("ctrl arch_id : {0}".format(ctrl.arch_id)) if ctrl.arch_str is not None:
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import numpy as np import sixtracklib as pyst elements = pyst.Elements() elements.Drift(length=1.2) elements.Multipole(knl=[0, 0.001]) particles = pyst.Particles.from_ref(num_particles=10, p0c=1e9) particles.px += np.linspace(0, 1e-2, 10) job = pyst.TrackJob(elements, particles) status = job.track_until(1) print(particles.x) print(particles.px) if pyst.supports('opencl'): jobcl = pyst.TrackJob(elements, particles, device="opencl:0.0") status = jobcl.track_until(2) jobcl.collect() print(particles.x) print(particles.px)
from sixtracklib import stcommon as st pycuda_spec = util.find_spec('pycuda') numpy_spec = util.find_spec('numpy') if pycuda_spec is not None: import pycuda import pycuda.gpuarray import pycuda.driver import pycuda.autoinit if numpy_spec is not None: import numpy as np if __name__ == '__main__': if not pyst.supports('cuda'): raise SystemExit("Example requires cuda support in sixtracklib") if pycuda_spec is None: raise SystemExit("Example requires pycuda installation") if numpy_spec is None: raise SystemExit("Example requires numpy installation") num_particles = 42 partset = pyst.ParticlesSet() particles = partset.Particles(num_particles=num_particles) cmp_partset = pyst.ParticlesSet() cmp_particles = cmp_partset.Particles(num_particles=num_particles)