Segfault in frequency_map when lattice has CHARGE element

Moderators: michael_borland, soliday

Post Reply
nkuklev
Posts: 8
Joined: 13 Aug 2019, 09:08
Location: University of Chicago

Segfault in frequency_map when lattice has CHARGE element

Post by nkuklev » 05 Feb 2020, 20:11

Hi all,

I found an interesting crash - when lattice has CHARGE element, &frequency_map results in segfault.

After (painfully) building elegant with debug symbols, I think the problem stems from the way do_tracking() is called from computeTunesFromTracking() with increasing pass offset, which for all but first call misses charge initialization and crashes at subsequent NULL pointer access. See below for detail.

I have not studied how to properly fix the issue, but in case anyone else gets stuck, the workaround is simple:

Code: Select all

&transmute_elements
	name = *, type = CHARGE, new_type = MARK
&end
-Nikita



Backtrace:

Code: Select all

...
Starting DRIFT_142#1 at s=3.986823e+01 m, pass 0, 1 particles, memory 15249 kB
Tracking fiducial particle completed.

Program received signal SIGSEGV, Segmentation fault.
0x00000000004d163c in do_tracking (beam=0x0, coord=0xba0bd0, nOriginal=1, effort=0x0, beamline=0xa95080, P_central=0x7ffffffe6450, accepted=0x0, sums_vs_z=0x0, n_z_points=0x0, traj_vs_z=0x0, 
    run=0x9eb100 <run_conditions>, step=0, flags=65578, n_passes=1, passOffset=1, sasefel=0x0, sliceAnalysis=0x0, finalCharge=0x0, lostParticles=0x0, startElem=0x0) at ../do_tracking.c:1241
warning: Source file is more recent than executable.
1241                  if (charge->chargePerParticle)
Missing separate debuginfos, use: debuginfo-install atlas-3.10.1-12.el7.x86_64 blas-3.4.2-8.el7.x86_64 glibc-2.17-260.el7.x86_64 gsl-1.15-13.el7.x86_64 lapack-3.4.2-8.el7.x86_64 libgcc-4.8.5-28.el7.x86_64 libgfortran-4.8.5-28.el7.x86_64 libquadmath-4.8.5-28.el7.x86_64 libstdc++-4.8.5-28.el7.x86_64 zlib-1.2.7-17.el7.x86_64
(gdb) bt
#0  0x00000000004d163c in do_tracking (beam=0x0, coord=0xba0bd0, nOriginal=1, effort=0x0, beamline=0xa95080, P_central=0x7ffffffe6450, accepted=0x0, sums_vs_z=0x0, n_z_points=0x0, traj_vs_z=0x0, 
    run=0x9eb100 <run_conditions>, step=0, flags=65578, n_passes=1, passOffset=1, sasefel=0x0, sliceAnalysis=0x0, finalCharge=0x0, lostParticles=0x0, startElem=0x0) at ../do_tracking.c:1241
#1  0x00000000005bc486 in computeTunesFromTracking (tune=0x7ffffffe6610, amp=0x7ffffffe6590, M=0x0, beamline=0xa95080, run=0x9eb100 <run_conditions>, startingCoord=0x7ffffffe65d0, 
    xAmplitude=9.9999999999999995e-07, yAmplitude=9.9999999999999995e-07, deltaOffset=0, turns=256, turnOffset=0, endingCoord=0x7ffffffe65a0, tuneLowerLimit=0x0, tuneUpperLimit=0x0, allowLosses=1, 
    nPeriods=1, flags=3) at ../twiss.cc:3820
#2  0x0000000000601472 in doFrequencyMap (run=0x9eb100 <run_conditions>, control=0x9eb000 <run_control>, referenceCoord=0xa60f70, errcon=0x7ffffffecc00, beamline=0xa95080) at ../frequencyMap.c:245
#3  0x00000000004e4882 in main (argc=2, argv=0x7fffffffd0b8) at ../elegant.c:1586
(gdb) l
1236                      if (nOriginal)
1237                        charge->macroParticleCharge = charge->charge/(nOriginal);
1238                    }
1239    #endif
1240                  }
1241                  if (charge->chargePerParticle)
1242                    charge->macroParticleCharge = charge->chargePerParticle;
1243                  if (charge->macroParticleCharge<0) 
1244                    bombElegantVA("Error: CHARGE element should specify the quantity of charge (in Coulombs) without the sign. Specified value is %g\n", charge->charge);
1245                  break;
(gdb) print charge
$1 = (CHARGE *) 0x0
(gdb) print i_pass
$2 = 1
(gdb)  

michael_borland
Posts: 1927
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Segfault in frequency_map when lattice has CHARGE element

Post by michael_borland » 17 Feb 2020, 13:41

Nikita,

I'm not able to reproduce this problem. Can you upload some files that demonstrate it?

Thanks--Michael

nkuklev
Posts: 8
Joined: 13 Aug 2019, 09:08
Location: University of Chicago

Re: Segfault in frequency_map when lattice has CHARGE element

Post by nkuklev » 18 Feb 2020, 03:02

Michael,

Please see attached. I have also realized the better fix is to add RECIRC after CHARGE, which is what default examples have. See the RC element at the end of the lattice file.

Nikita
Attachments
lattice2.lte
(24.43 KiB) Downloaded 181 times
frequencyMap.ele
(717 Bytes) Downloaded 191 times

Post Reply