1 #ifndef SMOMPI_BeamRunner_HPP
2 #define SMOMPI_BeamRunner_HPP
8 #include "SMOMPI_LandauLifschitzBeam.h"
11 #include "SM_LandauLifschitzLoader.h"
12 #include "SM_MonteCarloLoader.h"
15 #include "SM_CycleLoader.h"
18 #include "SM_StochasticOutputLoader.h"
22 #include "MPI_WorldToWorldMessage.h"
23 #include "MPI_Chrono.h"
26 template<
class BEAM,
class STOCHASTIC_OUTPUT> requires ( ! functions_type::isBaseOf<SM_StochasticJs,STOCHASTIC_OUTPUT>)
27 tBoolean SMOMPI_BeamRunner::RunBeam(
const tBoolean& isTemplatedRun,
29 STOCHASTIC_OUTPUT& stochasticOutput) {
32 return beam.runWithSCStochasticFunctions(stochasticOutput);
34 return beam.run(stochasticOutput);
40 template<
class STOCHASTIC_OUTPUT>
42 STOCHASTIC_OUTPUT& stochasticOutput,
46 tBoolean succeeds=
true;
54 const tMPICoreId& coreId=mpiEnv.
getCoreId();
61 int nDigits=(int)(log(coresNumber)/log(10.)+1);
62 tString corePrefix=
"_g"+functions_numeric::toString(coreId,nDigits)+
"p"+functions_numeric::toString(coresNumber,nDigits);
66 std::valarray<tMemSize> memorySizePerCore;
67 tString memorySizeSymbol=
"Mo";
68 tReal memorySizeUnit=1024*1024;
83 tString outputPath,outputPrefix;
94 memorySizePerCore.resize(coresNumber);
108 log<<
"number of cores:"<<coresNumber<<
"\n";
110 log<<
"size of int :"<<
sizeof(tInteger)<<
"\n";
111 log<<
"size of real :"<<
sizeof(tReal)<<
"\n";
122 if (uBeam.get()==
null) {
123 std::cout<<
"impossible to create the beam from options values \n";
136 if (succeeds==
false) {
137 std::cout<<
"impossible to load the beam from options values \n";
143 uBeam->getStochasticFunctions().randomSeed(coresNumber,coreId);
149 stochasticOutput.setIndex(coreId,-1,coresNumber);
152 stochasticOutput.adimensionize(uBeam->getSystem().getMaterial());
155 tBoolean isTemplatedRun=
false;
159 tBoolean isSSaved=
true;
166 tULLInt loaderDuration=chrono.
stop();
180 uBeam->getSystem().getNetwork().saveToFile(
CORE_IO::GetAbsolutePath(outputPath+
"/"+outputPrefix+corePrefix+
".net"));
183 tULLInt discretizationDuration=chrono.
stop();
187 memSize=uBeam->getMemorySize();
188 memSize+=stochasticOutput.getMemorySize();
196 log<<
"\n\n beam:"<<uBeam->toString()<<
"\n";
198 log<<
"templated run : "<<isTemplatedRun<<
"\n";
200 log<<
"\n\n stochastic Output:"<<stochasticOutput.toString()<<
"\n";
202 log<<
"Memory size for all cores after discretization: "<<(((tReal)memSize)/memorySizeUnit)<<
"\n";
207 log<<
"discretization duration :"<<discretizationDuration<<
" s="<<chrono.
ConvertDurationToString(discretizationDuration)<<
" \n";
211 for (
const auto& mem:memorySizePerCore) {
212 log<<
"\t memory for core "<<c<<
":"<<(((tReal) mem)/memorySizeUnit)<<
" "<<memorySizeSymbol<<
"\n";
223 if (llBeam!=
null) succeeds=RunBeam(isTemplatedRun,*llBeam,stochasticOutput);
224 else if (mcBeam!=
null) succeeds=RunBeam(isTemplatedRun,*mcBeam,stochasticOutput);
227 tULLInt runningDuration=chrono.
stop();
235 memSize=uBeam->getMemorySize();
236 memSize+=stochasticOutput.getMemorySize();
246 for (
const auto& mem:memorySizePerCore) {
247 log<<
"\t memory for core "<<c<<
":"<<(((tReal)mem)/memorySizeUnit)<<
" "<<memorySizeSymbol<<
"\n";
250 log<<
"Memory size for all cores after running beam: "<<(((tReal)memSize)/memorySizeUnit)<<
"\n";
253 tULLInt totalDuration=loaderDuration+discretizationDuration+runningDuration;
261 std::stringstream comment;
262 comment<<
"Direction of magnetic moments at end of last simulation for "<<coreId<<
"/"<<coresNumber<<
" nParticles:"<<uBeam->getSystem().getNetwork().getParticlesNumber()<<
" nHaloParticles:"<<uBeam->getSystem().getNetwork().getHaloParticlesNumber()<<
" ";
265 uBeam->getSystem().getMagneticMomentDirections().saveToFile(comment.str(),
CORE_IO::GetAbsolutePath(outputPath+
"/"+outputPrefix+corePrefix+
"-St.txt"),12);
279 template<
class BEAM_CYCLE,
class STOCHASTIC_OUTPUT>
282 STOCHASTIC_OUTPUT& stochasticOutput,
293 const tMPICoreId& coreId=mpiEnv.
getCoreId();
298 tBoolean succeeds=
true;
301 int nDigits=(int)(log(coresNumber)/log(10.)+1);
302 tString corePrefix=
"_g"+functions_numeric::toString(coreId,nDigits)+
"p"+functions_numeric::toString(coresNumber,nDigits);
305 std::valarray<tULLInt> memorySizePerCore;
306 tString memorySizeSymbol=
"Mo";
307 tULLInt memorySizeUnit=1024*1024;
330 tString outputPath,outputPrefix;
339 tBoolean isTemplatedRun=
false;
343 tBoolean isSSaved=
true;
351 memorySizePerCore.resize(coresNumber);
365 log<<
"number of cores:"<<coresNumber<<
"\n";
367 log<<
"size of int :"<<
sizeof(tInteger)<<
"\n";
368 log<<
"size of real :"<<
sizeof(tReal)<<
"\n";
374 if (uBeam.get()==
null) {
375 std::cout<<
"impossible to create the beam from options values \n";
380 if (uBeam.get()==
null) {
381 std::cout<<
"impossible to create the beam from options values \n";
393 if (succeeds==
false) {
394 std::cout<<
"impossible to load the beam from options values \n";
401 if (uBeam->hasStochasticFunctions()) {
402 uBeam->getStochasticFunctions().randomSeed(coresNumber,coreId);
414 stochasticOutput.setIndex(coreId,-1,coresNumber);
417 tString soPrefix=stochasticOutput.getPrefix();
420 stochasticOutput.adimensionize(uBeam->getSystem().getMaterial());
423 duration=chrono.
stop();
433 memSize=uBeam->getMemorySize();
437 duration=chrono.
stop();
444 log<<
"\n\n beam:"<<uBeam->toString()<<
"\n";
445 log<<
"templated run : "<<isTemplatedRun<<
"\n";
448 log<<
"\n\n cycle manager:"<<cycleManager.
toString()<<
"\n";
451 log<<
"\n\n stochastic Output:"<<stochasticOutput.toString()<<
"\n";
461 for (
const auto& mem:memorySizePerCore) {
462 log<<
"\t memory for core "<<c<<
":"<<((tReal)(mem/memorySizeUnit))<<
" "<<memorySizeSymbol<<
"\n";
465 log<<
"Memory size for all cores after discretization: "<<((tReal)(memSize/memorySizeUnit))<<
"\n";
472 if (!cycleManager.
open(*uBeam.get(),stochasticOutput,coreId,iCycleStep)) {
473 std::cout<<
"impossible to init cycle step \n";
485 if (uBeam->hasStochasticFunctions()) {
488 std::cout<<
"set the seed for the step of cycle "<<iCycleStep<<
" to "<<cycleManager.
getSeedPerCycleStep()<<
"\n";
498 stochasticOutput.setPrefix(soPrefix+
"-"+std::to_string(iCycleStep)+
"c");
500 stochasticOutput.setPrefix(
"");
504 if (llBeam!=
null) succeeds=RunBeam(isTemplatedRun,*llBeam,stochasticOutput);
505 else if (mcBeam!=
null) succeeds=RunBeam(isTemplatedRun,*mcBeam,stochasticOutput);
509 duration=chrono.
stop();
517 log<<
" duration for beam run at cycle "<<iCycleStep<<
":"<<duration<<
" s="<<chrono.
ConvertDurationToString(duration)<<
"\n";
521 std::stringstream comment;
522 comment<<
"Direction of magnetic moments at end of last simulation for "<<coreId<<
"/"<<coresNumber<<
" nParticles:"<<uBeam->getSystem().getNetwork().getParticlesNumber()<<
" nHaloParticles:"<<uBeam->getSystem().getNetwork().getHaloParticlesNumber()<<
" ";
525 uBeam->getSystem().getMagneticMomentDirections().saveToFile(comment.str(),
CORE_IO::GetAbsolutePath(outputPath+
"/"+outputPrefix+corePrefix+
"-St.txt"),12);
531 cycleManager.
nextCycleStep(iCycleStep,*uBeam.get(),coreId,stochasticOutput);
540 cycleManager.
close(iCycleStep,*uBeam.get());
542 duration=totalChrono.
stop();
546 memSize=uBeam->getMemorySize();
557 for (
const auto& mem:memorySizePerCore) {
558 log<<
"\t memory for core "<<c<<
":"<<((tReal)(mem/memorySizeUnit))<<
" "<<memorySizeSymbol<<
"\n";
561 log<<
"Memory size for all cores after running cycle: "<<((tReal)(memSize/memorySizeUnit))<<
"\n";
565 stochasticOutput.setPrefix(soPrefix);
static tString GetDate()
return the current date as a string
Definition: CORE_Chrono.h:194
tString getMessage() const
return the message of the exception
Definition: CORE_Exception.h:80
static tString GetAbsolutePath(const tString &path)
get the absolute path of the path
Definition: CORE_IO.h:365
static tBoolean Exists(const tString &f)
return true if the file or the path exists
Definition: CORE_IO.h:91
static tBoolean CreatePath(const tString &path)
create a path
Definition: CORE_IO.h:99
This class is an list of options.
Definition: CORE_OptionsList.h:36
tBoolean saveToFile(const tString &fileName) const
save the options to the file by theme
Definition: CORE_OptionsList.cpp:328
tBoolean getOptionValue(const tString &optName, tString &optValue) const
get the option value
Definition: CORE_OptionsList.h:334
this class describes the output stream by default write on standart output
Definition: CORE_Out.h:28
This class is a Run class for core package.
Definition: CORE_Run.h:44
static void ReadOutputOptions(const CORE_OptionsList &options, tString &outputPath, tString &outputPrefix)
read the output path &prefix from options
Definition: CORE_Run.cpp:354
static CORE_ClassFactory & GetClassFactory()
return the class factory
Definition: CORE_Run.h:227
static const tString & GetSoftName()
get soft name
Definition: CORE_Run.h:115
static CORE_Out & Out()
return the output stream
Definition: CORE_Run.h:184
static const tString & GetVersion()
get the version
Definition: CORE_Run.h:129
This class is a time class to manage time within an environment.
Definition: MPI_Chrono.h:20
void start()
start the chrono
Definition: MPI_Chrono.h:114
tULLInt stop() const
stop the chrono
Definition: MPI_Chrono.h:121
static tString ConvertDurationToString(tULLInt duration)
convert the duration the duration to string
Definition: MPI_Chrono.h:151
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
const tMPICoreId & getCoreId() const
get the id of the current process of this environment
Definition: MPI_Environment.h:200
const tMPICoreId & getCoresNumber() const
get the number of cores of this environment of common environment
Definition: MPI_Environment.h:180
tBoolean synchronize() const
wait that all the cores has finished her job
Definition: MPI_Environment.h:280
static MPI_Environment & GetEnvironment()
get the environment
Definition: MPI_Run.h:114
static tBoolean Gather(const MPI_Environment &env, const tMPICoreId &dstCore, const T &srcData, std::valarray< T > &dstData)
blocking gathering a data from all cores of enviroments to the dest core
Definition: MPI_WorldToWorldMessage.h:306
static tBoolean AllReduce(const MPI_Environment &env, T &data, const tMPIOperation &op)
compute a data from data of others cores and to data of core 0 and copy the values to all cores
Definition: MPI_WorldToWorldMessage.h:703
static tBoolean Run(const CORE_Run &runner, STOCHASTIC_OUTPUT &stochasticOutput, const CORE_OptionsList &options)
compute the stochastic output from options
Definition: SMOMPI_BeamRunner.hpp:41
This class describes an OpenMP/MPI implementation simulation of a beam of trajectoris for a Laudau-Li...
Definition: SMOMPI_LandauLifschitzBeam.h:20
This class is an interface of Beam Cycle class for Stoch Microm package.
Definition: SM_BeamCycle.h:20
tBoolean close(const tIndex &iCycle, const SM_Beam &beam)
return true if the cycle is close without error
Definition: SM_BeamCycle.h:186
void nextCycleStep(const tIndex &iCycleStep, SM_Beam &beam, const SM_StochasticOutputComponent &output)
next step of the cycle of beam run
Definition: SM_BeamCycle.h:162
const tULLInt & getSeedPerCycleStep() const
get the seed
Definition: SM_BeamCycle.h:124
virtual tString toString() const override
return the string representation of the class
Definition: SM_BeamCycle.h:193
tBoolean open(SM_Beam &beam, SM_StochasticOutputComponent &stochasticOutput, const tInteger &outputId, tIndex &iCycleStep)
init the cycle of beam run
Definition: SM_BeamCycle.h:150
tBoolean isCycleFinished(const tIndex &iCycle, const SM_Beam &beam)
return true if the cycle is finished
Definition: SM_BeamCycle.h:178
const tBoolean & isStochasticOutputSavedAtEachStep() const
get if the output is saved at each step
Definition: SM_BeamCycle.h:97
const tBoolean & isSeedUpdatedPerCycleStep() const
return true if the seed is generated at each cycle step
Definition: SM_BeamCycle.h:111
This class defines a general stochastic beam of trajectories of system.
Definition: SM_Beam.h:61
static tBoolean LoadCycleFromOptions(SM_BeamCycle< T > &cycle, const CORE_OptionsList &options)
load the cycle from options
Definition: SM_CycleLoader.h:94
this class describes the exceptions raised for SM package
Definition: SM_Exception.h:14
SM_LandauLifschitzSystem & getLLSystem()
get the landau lifschitz system
Definition: SM_LandauLifschitzBeam.h:82
static tBoolean LoadLandauLifschitzBeamFromOptions(SM_LandauLifschitzBeam &beam, const CORE_OptionsList &options)
load the beam from options
Definition: SM_LandauLifschitzLoader.cpp:8
const tReal & getTime() const
get the time
Definition: SM_LandauLifschitzSystem.h:214
This class is a simulation of a Monte Carlo for spins system.
Definition: SM_MonteCarloBeam.h:17
static tBoolean LoadMonteCarloBeamFromOptions(SM_MonteCarloBeam &beam, const CORE_OptionsList &options)
load the beam from options
Definition: SM_MonteCarloLoader.cpp:5
static tBoolean LoadStochasticOutputFromOptions(SM_StochasticTrajectory &stochasticOutput, const CORE_OptionsList &options)
load the stochastic output from options
Definition: SM_StochasticOutputLoader.cpp:31