Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/mccode_antlr/translators/c_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ def jump_line(instance, jump):
#endif
#if RNG_ALG == _RNG_ALG_MT // MT
#define randstate_t uint32_t
#define RANDSTATE_LEN 1
#elif RNG_ALG == _RNG_ALG_KISS // KISS
#define randstate_t uint64_t
#define RANDSTATE_LEN 7
#endif

#ifndef MC_NUSERVAR
Expand All @@ -186,7 +188,7 @@ def jump_line(instance, jump):
double _mctmp_a; /* temp a */
double _mctmp_b; /* temp b */
double _mctmp_c; /* temp c */
randstate_t randstate[7];
randstate_t randstate[RANDSTATE_LEN];
double t, p; /* time, event weight */
long long _uid; /* Unique event ID */
long _index; /* component index where to send this event */
Expand Down
24 changes: 13 additions & 11 deletions src/mccode_antlr/translators/c_raytrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ def cogen_raytrace(source, ok_to_skip):
# following https://github.com/McStasMcXtrace/McCode/commit/72cb740d465e2780b228bd937cf62429a96f64d5
' #pragma acc loop independent',
f' for (int SplitN_{comp.name}=0; SplitN_{comp.name} < SplitS_{comp.name}; SplitN_{comp.name}++) {{',
' randstate_t randbackup = *_particle->randstate;',
' randstate_t randbackup[RANDSTATE_LEN];',
f' for (int Split_{comp.name}_randstate_idx = 0; Split_{comp.name}_randstate_idx < RANDSTATE_LEN; Split_{comp.name}_randstate_idx++) {{',
f' randbackup[Split_{comp.name}_randstate_idx] = _particle->randstate[Split_{comp.name}_randstate_idx];',
' }',
f' *_particle=Split_{comp.name}_particle;',
' *_particle->randstate = randbackup;',
f' for (int Split_{comp.name}_randstate_idx = 0; Split_{comp.name}_randstate_idx < RANDSTATE_LEN; Split_{comp.name}_randstate_idx++) {{',
f' _particle->randstate[Split_{comp.name}_randstate_idx] = randbackup[Split_{comp.name}_randstate_idx];',
' }',
f' p /= SplitS_{comp.name} > 0 ? SplitS_{comp.name} : 1;',
'#endif'
])
Expand Down Expand Up @@ -214,17 +219,16 @@ def cogen_raytrace(source, ok_to_skip):
" for (unsigned long pidx=0 ; pidx < gpu_innerloop ; pidx++) {",
" _class_particle particleN = mcgenstate(); // initial particle",
" _class_particle* _particle = &particleN;",
" particleN._uid = pidx;",
" particleN._uid = cloop*gpu_innerloop + pidx;",
" #ifdef USE_MPI",
" particleN._uid += mpi_node_rank * ncount;",
" particleN._uid += mpi_node_rank * loops*gpu_innerloop;",
" #endif",
"",
" srandom(_hash((pidx+1)*(seed+1)));",
" srandom(_hash(_hash(seed) + cloop*gpu_innerloop + pidx));",
" particle_uservar_init(_particle);",
"",
" raytrace(_particle);",
" } /* inner for */",
" seed = seed+gpu_innerloop;",
" } /* CPU for */",
" /* if on GPU, printf has been globally nullified, re-enable here */",
" #ifdef OPENACC",
Expand Down Expand Up @@ -318,11 +322,11 @@ def cogen_funnel(source, ok_to_skip):
" // generate particle state, set loop index and seed",
" particles[pidx] = mcgenstate();",
" _class_particle* _particle = particles + pidx;",
" _particle->_uid = pidx;",
" _particle->_uid = cloop*gpu_innerloop + pidx;",
" #ifdef USE_MPI",
" _particle->_uid += mpi_node_rank * ncount;",
" _particle->_uid += mpi_node_rank * loops*gpu_innerloop;",
" #endif",
" srandom(_hash((pidx+1)*(seed+1))); // _particle->state usage built into srandom macro",
" srandom(_hash(_hash(seed) + cloop*gpu_innerloop + pidx)); // _particle->state usage built into srandom macro",
" particle_uservar_init(_particle);",
" }",
"",
Expand Down Expand Up @@ -416,8 +420,6 @@ def cogen_funnel(source, ok_to_skip):

lines.extend([
' }',
" // jump to next viable seed",
" seed = seed + gpu_innerloop;",
" } // outer loop / particle batches",
"",
" free(particles);",
Expand Down
Loading