Repository navigation
MCPL_input: consolidate with MCPL_input_once (MPI slicing + repeat_count) - #2780
Conversation
…unt) MCPL_input now splits the MCPL file between MPI processes the way MCPL_input_once did (each process reads/preloads only its own slice), and keeps repeat_count from MCPL_input: each slice is replayed repeat_count times, with smearing on all passes after the first (or on all passes with always_smear=1) and weights scaled by #events / #rays on that process (= 1/repeat_count without MPI). This also compensates the uneven slices when the event count does not divide by the number of MPI processes. ncount is set to (#events) x repeat_count, independent of the number of MPI processes (before, MCPL_input gave every process the whole file). Other changes: verbose prints the first 10 particles read, an empty file or energy window is an error, repeat_count>1 without smearing is reset to 1 without the 10 s sleep, and the file is closed / memory freed in FINALLY rather than SAVE (which can run mid-simulation on a signal). MCPL_input_once is now "DEFINE COMPONENT MCPL_input_once INHERIT MCPL_input", keeping its name and all its parameters (it gains repeat_count, default 1). McXtrace gets the same implementation adapted to photons (E_smear, keV, k and E-field). This also fixes two bugs in the old McXtrace MCPL_input: k was computed as sqrt(E*E2K) instead of E*E2K when not preloading, and preloaded positions were divided by 100 twice. ESS_butterfly_MCPL_test now uses MCPL_input with repeat_count=repeat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QeSKcxUdgbJSVRpyB1vgdq
- Regenerate misc/MCPL_input.tex (McStas and McXtrace) with mcdoc --tex - Move the MCPL_input_once snippet to obsolete/, regenerated - Add obsolete/MCPL_input_once_static.tex: mcdoc does not list inherited parameters, so point to MCPL_input's - obsolete.tex: list and include MCPL_input_once - misc.tex: describe MPI slicing and repeat_count in the MCPL section Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QeSKcxUdgbJSVRpyB1vgdq
Regenerated with mcdoc --tex after dacc4b8 changed the default from -1 to 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QeSKcxUdgbJSVRpyB1vgdq
|
I like the idea, but could imagine the behavior change
might catch someone out. If you think this is likely to be a problem, maybe there is a straight-forward way to enable the old-behavior by default for Something like and |
|
No, I think we should have just one component. Nothing prevents to run with repeat_count=what_you_want. A suitable heading will of course go in the release notes. |
|
But then again you are right that this effectively is still just one component thanks to Will give it another thought, even though I kind of like the idea that the default behavior is single pass. |
|
@g5t I put my LLM to work on your suggestion, yet the analysis is that
Which means that the body of the MCPL_input_once comp looks like this: What do you think? |
Split the replayed stream of (#particles in file) x repeat_count rays into one contiguous chunk per MPI process, as KDSource does. Each process now seeks once and then reads forward, rewinding to the start of the file when it wraps. Before, every replay pass did an mcpl_seek back to the slice start, which for .mcpl.gz means decompressing up to that point on every pass and every process. Preload loads only the part of the file the process's chunk covers. Weights are p / repeat_count. New parameter replicate_across_processes (default 0). With 1 and MPI, repeat_count is rounded up to a multiple of the number of processes, so that each process runs through the whole file, as MCPL_input did before Oct 2026. MCPL_input_once stays in obsolete/ as an INHERIT of MCPL_input. Its INITIALIZE puts repeat_count=1 and replicate_across_processes=0 in front of the inherited code, so each event is always used exactly once. Behaviour changes: - ncount is always (#particles in file) x repeat_count. Particles that are not neutrons (photons for McXtrace), or are outside [Emin, Emax], are ABSORBed. Before, with preload only the kept events were counted. - An energy window that keeps no events no longer stops the run. The closing "used X of Y" message reports it. The same changes go into McXtrace MCPL_input. Manual snippets are regenerated with mcdoc/mxdoc --tex. misc.tex, obsolete.tex, MCPL_input_once_static.tex and the Test_MCPL_input_once description are updated. Tested on macOS arm64 with OpenMPI: serial and --mpi=2/3, repeat_count 1 and 3, preload 0 and 1, replicate 0 and 1, MCPL_input and MCPL_input_once. Total intensity is preserved and ray counts are as expected. McXtrace round trip: intensity is preserved and the mean energy is about 10 keV. mcstas and mcstas-antlr both generate the MCPL_input_once override. Not tested: GPU/OpenACC, Linux, Windows, manual PDF build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Sounds good to me, since the current state has way too many components for mcpl i/o. But @g5t does have a valid concern, I am just not really sure how to prevent it. One way would be to have a period with a flag defaulting first to the old, then the new behaviour (like what we did for the stat:sum migration). But of course, that is up to @willend . |
|
Change of behaviour with:
merge. |
Free-form text area
Please describe what your PR is adding in terms of features or bugfixes:
MCPL_input: consolidate with MCPL_input_once (MPI slicing + repeat_count)
MCPL_inputandMCPL_input_onceare merged into one implementation inMCPL_input.MCPL_input_oncemoves toobsolete/asDEFINE COMPONENT MCPL_input_once INHERIT MCPL_input, so existing instruments keep working.What
MCPL_inputdoes nowMCPL_input_oncedid it. Each process reads, or preloads, only its own slice, so every event is used once per repetition across the whole run.repeat_count: kept from the oldMCPL_input. Each process replays its slicerepeat_counttimes. Every pass after the first is smeared withv_smear/pos_smear/dir_smear. The newalways_smear=1smears the first pass too.1/repeat_countwithout MPI. This also corrects for uneven slices when the event count doesn't divide by the number of processes.#events × repeat_count, independent of the number of MPI processes.Behaviour changes
MCPL_inputgave every process the whole file, smeared on all but the master, so--mpi=Nmeant N× the rays. Now it's 1×.repeat_count>1with all*_smear=0: still reset to 1, but without the 10 ssleep.verbose: now defaults to 0, and prints the first 10 particles read.MCPL_input_once(now inobsolete/): keeps all its parameters and gainsrepeat_count(default 1). Its parameter order now followsMCPL_input; instruments that set parameters by name are unaffected.McXtrace
MCPL_inputgets the same implementation adapted to photons (E_smear, keV,k, E-field). This fixes two bugs in the old McXtrace version:|k|was computed assqrt(E·E2K)instead ofE·E2K, so energies were wrong.Other changes
ESS_butterfly_MCPL_testusesMCPL_inputwithrepeat_count=repeatinstead of the commented-out alternative.Test_MCPL_input_oncedescription is updated.Manuals
misc/MCPL_input.tex(McStas and McXtrace) regenerated withmcdoc --tex.MCPL_input_oncesnippet moves frommisc/toobsolete/, regenerated. A newobsolete/MCPL_input_once_static.texpoints toMCPL_input's parameters, since mcdoc does not list inherited ones.obsolete.texlists and includesMCPL_input_once.misc.tex: the MCPL section gets a short paragraph on MPI slicing andrepeat_count.misc/MCPL_output.tex(McStas and McXtrace) regenerated: theweight_modedefault is shown as 1, followingdacc4b87c.Testing
Built from source on Linux with OpenMPI, comparing the old and new components on the same input. "Old" means the previous
MCPL_input.repeat_count=1, serial, preload 0 and 1: new, old, new-once and old-once give identical results (m1 I=2.27516e11, N=1000).repeat_count=1with MPI:--mpi=2: identical to the serial run. The oldMCPL_inputemitted 2000 rays.--mpi=3: 999 rays, I=2.27488e11. The oldMCPL_input_oncegave 2.27252e11, losing intensity on the uneven slice.repeat_count=3, serial and MPI 2/3: the total intensity on an all-accepting time monitor is preserved.ESS_BEER_MCPL(repeat_count=50), 10 seeds: new 150.7 ± 0.9, old 150.5 ± 0.5.Source_flat→MCPL_output→MCPL_input): the new component reproduces the source's mean energy of 9.9917 keV serial and with MPI 2/3, preload 0 and 1. The old one without preload put nothing on the energy monitor.--comp MCPL_inputand--comp MCPL_input_once: no wrong values..texfiles are byte-identical tomcdoc --texoutput from the current components.Not tested
_uid, asMCPL_input_oncealready did.mcstas-antlrcode generator. Whole-component INHERIT is already used byDiaphragm.ESS_butterfly_MCPL_test, whose input file is downloaded at build time ([CI/repo]: Use GitHub LFS / cache to make MCPL-input for ESS instrument available #2628). It does generate and compile..texchanges are not compiled.Notes
%Examplereference values look stale.Test_MCPL_inputandTest_MCPL_input_oncereach 94% of reference, andESS_BEER_MCPL110%, with both the old and new components.Declaration of use of AI-tools
^ 🤖 Generated with Claude Code
Development OS / boundary conditions
Please describe what OS you developed and tested your additions on, and if any special dependencies are required:
PR Checklist for contributing to McStas/McXtrace
For a coherent and useful contribution to McStas/McXtrace, please fill in relevant parts of the checklist:
My contribution includes patches to an existing component file
mcdocutility and rendered a reasonable documentation page for the component (please attach as screenshot in comments!)mctestutility to test one or more instruments making use of the component (please attachmcviewtestreport as screenshot in comments)mccode-clangformattool to apply the standard McCode component indentation schememcrun --c-lint"linter" and followed advice to remove most / all warnings that are raisedMy contribution contains something else