PyORBIT-Collaboration / PyORBIT3

Python3 compatible version of PyORBIT
MIT License
3 stars 12 forks source link

MPI issue with 2D space charge nodes #31

Open austin-hoover opened 4 days ago

austin-hoover commented 4 days ago

The following script throws the error: Attempting to use an MPI routine (internal_Allreduce) before initializing or after finalizing MPICH. It works fine on installation without MPI. Here is the script:

import random

from orbit.core.bunch import Bunch
from orbit.core.spacecharge import SpaceChargeCalc2p5D
from orbit.space_charge.sc2p5d import SC2p5D_AccNode
from orbit.space_charge.sc2p5d import setSC2p5DAccNodes
from orbit.teapot import teapot

# Create lattice
lattice = teapot.TEAPOT_Lattice()

node = teapot.DriftTEAPOT("DRIFT01")
node.setLength(1.0)
lattice.addNode(node)

node = teapot.QuadTEAPOT("QH01")
node.setLength(0.25)
node.setParam("kq", +0.10)
lattice.addNode(node)

node = teapot.DriftTEAPOT("DRIFT02")
node.setLength(1.0)
lattice.addNode(node)

node = teapot.QuadTEAPOT("QV02")
node.setLength(0.25)
node.setParam("kq", -0.10)
lattice.addNode(node)

lattice.initialize()

# Add space charge nodes
sc_path_length_min = 1.00e-06
sc_calc = SpaceChargeCalc2p5D(64, 64, 64)
sc_nodes = setSC2p5DAccNodes(lattice, sc_path_length_min, sc_calc)

# Create bunch
bunch = Bunch()
bunch.mass(0.938)
bunch.getSyncParticle().kinEnergy(1.300)

size = 10_000
for i in range(size):
    x = random.uniform(-0.010, 0.010)
    y = random.uniform(-0.010, 0.010)
    z = random.uniform(-50.0, 50.0)
    xp = random.uniform(-0.010, 0.010)
    yp = random.uniform(-0.010, 0.010)
    de = random.uniform(-0.001, 0.001)
    bunch.addParticle(x, xp, y, yp, z, de)

intensity = 1.00e+14
bunch.macroSize(1.00e+14 / size)

# Track bunch
for i in range(100):
    lattice.trackBunch(bunch)
    print(i)
austin-hoover commented 4 days ago

I get the error with or without using mpirun.

austin-hoover commented 3 days ago

I don't get this error when I revert PyORBIT to previous state https://github.com/PyORBIT-Collaboration/PyORBIT3/commit/88ac765dd5049b42650b17aef6be8d9e423cc6c1. The tracking loop runs, but at the end it gives the segfault message described in https://github.com/PyORBIT-Collaboration/PyORBIT3/issues/26.