Skip to content

[WIP] Add Branson Monte Carlo Kernel - #683

Draft
michaelmckinsey1 wants to merge 23 commits into
developfrom
branson-kernel-photon-transport
Draft

[WIP] Add Branson Monte Carlo Kernel#683
michaelmckinsey1 wants to merge 23 commits into
developfrom
branson-kernel-photon-transport

Conversation

@michaelmckinsey1

@michaelmckinsey1 michaelmckinsey1 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

An intern (@RanivG) will be implementing https://github.com/lanl/branson/blob/3f538e31a51b144b6621d4665f465d8d44ee85b8/src/event_based_transport.h#L323 as a kernel in RAJAPerf.

  • Add Apps_MC_HISTORY_PARTICLE_TRANSPORT kernel
  • Add reference implementation to header file (see other kernels for examples)
  • CPU-only implementation
  • RAJA implementation
  • CUDA implementation
  • HIP implementation
  • Rename to MC_HISTORY_PARTICLE_TRANSPORT

@michaelmckinsey1 michaelmckinsey1 self-assigned this May 20, 2026
@MrBurmark

Copy link
Copy Markdown
Member

Is there a better name for this kernel?

@michaelmckinsey1

Copy link
Copy Markdown
Contributor Author

Is there a better name for this kernel?

I am open to suggestions, but it can be renamed easily.

@rhornung67

Copy link
Copy Markdown
Member

I'm fine with the name. @MrBurmark do you have a specific concern about the name?

@MrBurmark

Copy link
Copy Markdown
Member

The name is just very generic. Is the kernel any specific part of the Monty Carlo algorithm?

@rhornung67

Copy link
Copy Markdown
Member

The name is just very generic. Is the kernel any specific part of the Monty Carlo algorithm?

That's a good point. A brief scan of the code at the link @michaelmckinsey1 provided above to the Branson code, perhaps something like MC_EVENT_PHOTON_TRANSPORT, if that's not too long.

@rhornung67

Copy link
Copy Markdown
Member

@michaelmckinsey1 please add a reference implementation to the kernel header file.

Comment thread dane7-blackhole-1516011.core Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably don't want this and would be good to double check on the other extra files

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are a bunch of unwanted files committed in this. Please refrain from using git add *.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Comment thread src/apps/TRANSPORT3DMC-Seq.cpp Outdated
transport3dmc_lam_setup(vid, iend);
// Loop counter increment uses macro to quiet C++20 compiler warning
for (RepIndex_type irep = 0; irep < run_reps; RP_REPCOUNTINC(irep)) {
transport3dmc_lam_reset();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the loop body needs to be in a lambda.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the reset is also a loop body.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/apps/TRANSPORT3DMC-Seq.cpp Outdated
case Base_Seq : {

startTimer();
TRANSPORT3DMC_DATA_SETUP(vid, iend);

@MrBurmark MrBurmark Aug 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setup should happen once above the variant switch statement.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/apps/TRANSPORT3DMC-Seq.cpp Outdated
TRANSPORT3DMC_DATA_SETUP(vid, iend);
// Loop counter increment uses macro to quiet C++20 compiler warning
for (RepIndex_type irep = 0; irep < run_reps; RP_REPCOUNTINC(irep)) {
TRANSPORT3DMC_RESET

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If reset involves a loop from begin to end, you probably want to express that loop outside of the reset macro.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No loop, just a deep copy of the reference set to another object actually conducting transport.

Comment thread src/apps/TRANSPORT3DMC.cpp Outdated
Comment on lines +51 to +59
setItsPerRep( getActualProblemSize() );
setKernelsPerRep(1);

setBytesAllocatedPerRep( 0 ); // in, out
setBytesReadPerRep( 0 ); // in
setBytesWrittenPerRep( 0 ); // out
setBytesModifyWrittenPerRep( 0 );
setBytesAtomicModifyWrittenPerRep( 0 );
setFLOPsPerRep( 0 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add a TODO comment as a reminder.

Comment thread src/apps/TRANSPORT3DMC.cpp Outdated

void TRANSPORT3DMC::initMaterials(std::vector<TRANSPORT3DMC::Material> &mats) {
size_t matCt = 12;
mats.resize(matCt);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably want to use something like allocDataForInit to get memory here and allow you to manually set it up. Note that all setup for the data must be completed before the object returned by allocDataForInit goes out of scope, see examples by searching for ForInit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented

Comment thread src/apps/TRANSPORT3DMC.cpp Outdated
{
}

int TRANSPORT3DMC::Cell::GLBL = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using static class variables?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the mesh is an array, the static GLBL helps to identify/assign cells their ID/index into the mesh vector. Can probably be removed once all vectors have been migrated to pointers.

Comment thread src/apps/TRANSPORT3DMC.hpp Outdated
Comment on lines +175 to +178
#define dT 0.001
#define N_ISOTOPE 68
//#define GROUPS 10
#define cutoff 1e-5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defs should be above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though you may be able to make these static constexpr class variables instead.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public:
static int GLBL;
int ID;
std::array<double, 6> planes; //-x, +x, -y, +y, -z, +z

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to use camp::array, its the same as std::array but works on gpus.

SOURCE,
};

struct XS {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to CrossSection for clarity?

Comment thread src/apps/TRANSPORT3DMC.hpp Outdated
Comment on lines +206 to +207
XS operator*(const double c) const;
XS operator+(const XS &sigma) const;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define inline for performance?

Comment thread src/apps/TRANSPORT3DMC.hpp Outdated

struct Material {
int isotopeCt;
std::vector<double> conc;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer allocData and deallocData and related helper functions to get memory.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented.

Comment thread src/common/RunParams.cpp Outdated
Comment on lines +50 to +52
transport3dMC_particles(10000),
transport3dMC_cube_dim(3),
transport3dMC_groups(10),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, we'll have to have to think about what are reasonable defaults later.

Comment thread .gitignore Outdated
/install_*/
/install-*/
/Debug/
*.cmake

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit broad, don't we use cmake?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, checked out the gitignore from develop

Comment on lines +27 to +28
setDefaultProblemSize(1);
setDefaultReps(1000);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, long term I'm going to guess this is going to move toward values like this.

Suggested change
setDefaultProblemSize(1);
setDefaultReps(1000);
setDefaultProblemSize(1000000);
setDefaultReps(10);

setSize(params.getTargetSize(getDefaultProblemSize()),
params.getReps(getDefaultReps()));

setChecksumConsistency(ChecksumConsistency::ConsistentPerVariantTuning);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this stays consistent as we'll have consistent pseudo random numbers.

Comment thread src/apps/TRANSPORT3DMC.cpp Outdated
Comment on lines +370 to +374
TRANSPORT3DMC::Material::Material() {
isotopeCt = 1;
conc = std::vector<double>();
nucIDs = std::vector<int>();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, but c++ has a syntax for initializing class members https://en.cppreference.com/cpp/language/constructor.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up just deleting it and letting the compiler define a default constructor.

@RanivG

RanivG commented Aug 8, 2026

Copy link
Copy Markdown

I was reading through earlier comments, I disagree with the name MC_EVENT_PHOTON_TRANSPORT; the kernel emulates history-based transport of neutrons (or at least that's how I designed it).
Might I propose "HISTORY_TRANSPORT3DMC" ?

@michaelmckinsey1

Copy link
Copy Markdown
Contributor Author

I was reading through earlier comments, I disagree with the name MC_EVENT_PHOTON_TRANSPORT; the kernel emulates history-based transport of neutrons (or at least that's how I designed it). Might I propose "HISTORY_TRANSPORT3DMC" ?

If the difference is history vs event, why not MC_HISTORY_PHOTON_TRANSPORT then?

@RanivG

RanivG commented Aug 10, 2026

Copy link
Copy Markdown

I was reading through earlier comments, I disagree with the name MC_EVENT_PHOTON_TRANSPORT; the kernel emulates history-based transport of neutrons (or at least that's how I designed it). Might I propose "HISTORY_TRANSPORT3DMC" ?

If the difference is history vs event, why not MC_HISTORY_PHOTON_TRANSPORT then?

Well it's not really photons, at least I don't think. Also I was more trying to keep with the 3D kernel's naming scheme (MASS3D, CONVECTION3D, VOL3D, DIFFUSION3D, etc). If this convention isn't desired for this kernel then we can stay with the MC_HISTORY_PARTICLE_TRANSPORT convention

@MrBurmark

Copy link
Copy Markdown
Member

Well it's not really photons, at least I don't think. Also I was more trying to keep with the 3D kernel's naming scheme (MASS3D, CONVECTION3D, VOL3D, DIFFUSION3D, etc). If this convention isn't desired for this kernel then we can stay with the MC_HISTORY_PARTICLE_TRANSPORT convention

I don't think there is much reason to limit yourself to that 3D naming convention as this is a different type of kernel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RanivG Rm this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RanivG Rm this

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants