Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel phsp source partition #1126

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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: 2 additions & 2 deletions HEN_HOUSE/egs++/egs_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ int EGS_Application::initSimulation() {
return 0;
}

void EGS_Application::setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) {
void EGS_Application::setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk) {
if (source) {
source->setSimulationChunk(nstart,nrun);
source->setSimulationChunk(nstart,nrun,npar,nchunk);
}
}

Expand Down
3 changes: 2 additions & 1 deletion HEN_HOUSE/egs++/egs_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,12 @@ class EGS_EXPORT EGS_Application {

Tells the application that the next chunk of particles to be
simulated starts at \a nstart and will consist of \a nrun particles.
It also provides the source with the parallel run parameters, \a npar and \a nchunk.
This is necessary for parallel runs using phase space files. The default
implementation simply calls the EGS_BaseSource::setSimulationChunk()
method.
*/
virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun);
virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk);

/*! \brief Runs an EGSnrc simulation.

Expand Down
2 changes: 1 addition & 1 deletion HEN_HOUSE/egs++/egs_base_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class EGS_EXPORT EGS_BaseSource : public EGS_Object {
It may also be re-implemented, if one wanted to use some sort of
a systematic sampling of the phase space.
*/
virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) { };
virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk) { };

/*! \brief Get the charge of the source.
*
Expand Down
2 changes: 1 addition & 1 deletion HEN_HOUSE/egs++/egs_run_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ EGS_I64 EGS_JCFControl::getNextChunk() {
nrun = nleft;
}
if (nrun > 0) {
app->setSimulationChunk(ntot,nrun);
app->setSimulationChunk(ntot,nrun,npar,nchunk);
}
nleft -= nrun;
ntot += nrun;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ class EGS_DYNAMIC_SOURCE_EXPORT EGS_DynamicSource :
return (valid && source != 0);
};

void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) {
source->setSimulationChunk(nstart, nrun);
void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk) {
source->setSimulationChunk(nstart, nrun, npar, nchunk);
};

protected:
Expand Down
36 changes: 25 additions & 11 deletions HEN_HOUSE/egs++/sources/egs_phsp_source/egs_phsp_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,29 @@ union __egs_data32 {
};
#endif

void EGS_PhspSource::setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) {
if (nstart < 0 || nrun < 1 || nstart + nrun > Nparticle) {
egsWarning("EGS_PhspSource::setSimulationChunk(): illegal attempt "
"to set the simulation chunk between %lld and %lld ignored\n",
nstart+1,nstart+nrun);
return;
}
Nfirst = nstart+1;
Nlast = nstart + nrun;
Npos = nstart;
void EGS_PhspSource::setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk) {
//determine the simulation chunk and use this to calculate first/last particles
//in the phase space chunk
EGS_I64 particlesPerChunk = Nparticle/(npar*nchunk);
int ichunk = nstart/nrun;
if (ichunk > npar*nchunk-1)
{
//remainder of histories, reuse the last chunk of the phsp
//there may be a more clever strategy
egsWarning("EGS_PhspSource: Remainder of histories will reuse the last chunk of the phase space source.\n");
ichunk = npar*nchunk-1;
}
Nfirst = ichunk*particlesPerChunk+1;
if (ichunk == npar*nchunk-1)
{
//last chunk of the phsp file, just go to the end of the file
Nlast = Nparticle;
}
else
{
Nlast = Nfirst-1+particlesPerChunk;
}
Npos = Nfirst-1; //we increment Npos before attempting to read a particle
istream::off_type pos = Nfirst*recl;
the_file.seekg(pos,ios::beg);
egsInformation("EGS_PhspSource: using phsp portion between %lld and %lld\n",
Expand All @@ -359,7 +372,8 @@ void EGS_PhspSource::readParticle() {
"of the chunk (%lld) but this "
"implies that uncertainty estimates will be inaccurate\n",
Nlast,Nfirst);
the_file.seekg(recl,ios::beg);
istream::off_type pos = Nfirst*recl;
the_file.seekg(pos,ios::beg);
Nrestart++;
Npos = Nfirst;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class EGS_PHSP_SOURCE_EXPORT EGS_PhspSource : public EGS_BaseSource {
EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
int &q, int &latch, EGS_Float &E, EGS_Float &wt,
EGS_Vector &x, EGS_Vector &u);
void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun);
void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk);
EGS_Float getEmax() const {
return Emax;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ class EGS_SOURCE_COLLECTION_EXPORT EGS_SourceCollection :
return (nsource > 0);
};

void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) {
void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk) {
for (int j=0; j<nsource; j++) {
sources[j]->setSimulationChunk(nstart, nrun);
sources[j]->setSimulationChunk(nstart, nrun, npar, nchunk);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ class EGS_TRANSFORMED_SOURCE_EXPORT EGS_TransformedSource :
return (source != 0);
};

void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) {
source->setSimulationChunk(nstart, nrun);
void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk) {
source->setSimulationChunk(nstart, nrun, npar, nchunk);
};

protected:
Expand Down
33 changes: 23 additions & 10 deletions HEN_HOUSE/egs++/sources/iaea_phsp_source/iaea_phsp_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,29 @@ union __egs_data32 {
};
#endif

void IAEA_PhspSource::setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) {
if (nstart < 0 || nrun < 1 || nstart + nrun > Nparticle) {
egsWarning("IAEA_PhspSource::setSimulationChunk(): illegal attempt "
"to set the simulation chunk between %lld and %lld ignored\n",
nstart+1,nstart+nrun);
return;
}
Nfirst = nstart+1;
Nlast = nstart + nrun;
Npos = nstart;
void IAEA_PhspSource::setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk) {
//determine the simulation chunk and use this to calculate first/last particles
//in the phase space chunk
EGS_I64 particlesPerChunk = Nparticle/(npar*nchunk);
int ichunk = nstart/nrun;
if (ichunk > npar*nchunk-1)
{
//remainder of histories, reuse the last chunk of the phsp
//there may be a more clever strategy
egsInformation("IAEA_PhspSource: Remainder of histories will reuse the last chunk of the phase space source.\n");
ichunk = npar*nchunk-1;
}
Nfirst = ichunk*particlesPerChunk+1;
if (ichunk == npar*nchunk-1)
{
//last chunk of the phsp file, just go to the end of the file
Nlast = Nparticle;
}
else
{
Nlast = Nfirst-1+particlesPerChunk;
}
Npos = Nfirst-1;
iaea_set_record(&iaea_fileid,&Nfirst,&iaea_iostat);
if (iaea_iostat<0) {
egsWarning("IAEA_PhspSource::setSimulationChunk(): error setting phase space chunk\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class IAEA_PHSP_SOURCE_EXPORT IAEA_PhspSource : public EGS_BaseSource {
EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
int &q, int &latch, EGS_Float &E, EGS_Float &wt,
EGS_Vector &x, EGS_Vector &u);
void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun);
void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun, int npar, int nchunk);
EGS_Float getEmax() const {
return Emax;
};
Expand Down