Commit ea19273c authored by gsell's avatar gsell
Browse files

Merge branch '441-cleanup-keep-rngxdiv-only' into 'master'

Resolve "cleanup: keep RNGXDiv only"

Closes #441

See merge request !253
parents 6fc0d433 7d6029ad
......@@ -41,7 +41,6 @@ set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
add_definitions (-DIPPL_USE_XDIV_RNG)
add_definitions (-DNOCTAssert)
add_compile_options (-Wall)
......
......@@ -38,12 +38,8 @@ template<class T, unsigned D> class Vektor;
template<class T, unsigned D> class Tenzor;
template<class T, unsigned D> class AntiSymTenzor;
template<class T, unsigned D> class SymTenzor;
class RNGBitReverse;
template <class T> class RNGLattice;
class RNGSimple;
class RNGRand;
class RNGXDiv;
class RNGXCI;
// definition of global sign function
......@@ -94,13 +90,9 @@ _SCALAR_RNG_RETURNS_(GEN,float) \
_SCALAR_RNG_RETURNS_(GEN,double) \
_SCALAR_RNG_RETURNS_(GEN,std::complex<double>)
_PETE_RNG_RETURNS_(RNGBitReverse)
_PETE_RNG_RETURNS_(RNGLattice<float>)
_PETE_RNG_RETURNS_(RNGLattice<double>)
_PETE_RNG_RETURNS_(RNGSimple)
_PETE_RNG_RETURNS_(RNGRand)
_PETE_RNG_RETURNS_(RNGXDiv)
_PETE_RNG_RETURNS_(RNGXCI)
// Life is way easier with this feature.
......
......@@ -13,8 +13,6 @@ set (_SRCS
IpplTimings.cpp
PAssert.cpp
ParticleDebugFunctions.cpp
RNGSimple.cpp
RNGXCI.cpp
RNGXDiv.cpp
RandomNumberGen.cpp
StaticIpplInfo.cpp
......@@ -57,9 +55,6 @@ set (_HDRS
RNGAssignDefs.h
RNGBitReverse.h
RNGLattice.h
RNGRand.h
RNGSimple.h
RNGXCI.h
RNGXDiv.h
RandomNumberGen.h
RefBlock.h
......
......@@ -3,9 +3,6 @@
*
* The IPPL Framework
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
***************************************************************************/
#ifndef RNG_LATTICE_H
......@@ -155,9 +152,3 @@ public:
#endif // RNG_LATTICE_H
/***************************************************************************
* $RCSfile: RNGLattice.h,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: RNGLattice.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
***************************************************************************/
#ifndef RNG_RAND_H
#define RNG_RAND_H
/***********************************************************************
*
* class RNGRand
* class RNGRandSequence : public SequenceGen<RNGRand>
*
* Simple wrapper around C rand() function, to generate random numbers
* in the range [0...1]. The first class may be
* used standalone, or as a template parameter to SequenceGen. The
* second class is derived from SequenceGen, and makes it easier to
* use this RNG in expressions.
* Use RNGRand as a scalar or container element, and use
* RNGRandSequence when you need a sequence of numbers to fill a container.
*
***********************************************************************/
#include "Utility/SequenceGen.h"
#include <cstdlib>
class RNGRand {
public:
// return type
typedef double Return_t;
public:
// default constructor
RNGRand(int advance = 0) : CurrentSeed(1U) { AdvanceSeed(advance); }
// copy constructor
RNGRand(const RNGRand& rng) : CurrentSeed(rng.CurrentSeed) {}
// destructor
~RNGRand(void) {}
// advance indicates number of times to advance random number source
// there's no standard way to do this with rand(), so make one up!
// just require one-to-one correspondence of old and new seeds
inline void AdvanceSeed(int advance = 0) {
for (int iadv=0; iadv<advance; iadv++) {
// first reseed with current seed
srand(CurrentSeed);
// use first random number as seed step
int seedstep = rand();
CurrentSeed = (CurrentSeed + seedstep) % RAND_MAX;
}
// finally, reseed with new seed value
srand(CurrentSeed);
}
// set seed to user-specified value (any shifting is done by srand)
inline void SetSeed(unsigned int seed) {
CurrentSeed = seed;
srand(CurrentSeed);
}
// get seed value
inline unsigned int GetSeed(void) const { return CurrentSeed; }
// return the next pseudo-random number (from 0 ... 1)
inline Return_t GetRandom(void) const {
return ( (Return_t(rand())) / (Return_t(RAND_MAX)+1) );
}
// pseudonym for GetRandom()
inline Return_t operator()(void) const { return GetRandom(); }
// conversion to Return_t, same as GetRandom()
inline operator Return_t() const { return GetRandom(); }
// return the period of the RNG
static Return_t GetRandMax(void) { return Return_t(RAND_MAX)+1; }
private:
unsigned int CurrentSeed;
};
RNG_BASIC_MATH(RNGRand)
// A version of SequenceGen with extra constructors to make using this
// class easier. This is the version that people should use to fill
// containers with a random number sequence in an expression. This
// class is PETE-aware via its inheritance from SequenceGen.
class RNGRandSequence : public SequenceGen<RNGRand> {
public:
// default constructor
RNGRandSequence(int advance = 0)
: SequenceGen<RNGRand>(RNGRand(advance)) {}
// copy constructor
RNGRandSequence(const RNGRandSequence& rngseq)
: SequenceGen<RNGRand>(rngseq.getGenerator()) {}
// destructor
~RNGRandSequence(void) {}
// wrappers around RNG generator functions
inline void AdvanceSeed(int adv = 0) { getGenerator().AdvanceSeed(adv); }
inline void SetSeed(unsigned int seed) { getGenerator().SetSeed(seed); }
inline unsigned int GetSeed(void) const { return getGenerator().GetSeed(); }
inline Return_t GetRandom(void) { return getGenerator().GetRandom(); }
inline Return_t operator()(void) { return getGenerator().GetRandom(); }
static Return_t GetRandMax(void) { return RNGRand::GetRandMax(); }
};
#endif // RNG_RAND_H
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
* This program was prepared by PSI.
* All rights in the program are reserved by PSI.
* Neither PSI nor the author(s)
* makes any warranty, express or implied, or assumes any liability or
* responsibility for the use of this software
*
* Visit www.amas.web.psi for more details
*
***************************************************************************/
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
***************************************************************************/
// include files
#include "Utility/RNGSimple.h"
// initialize static variables for RNGSimple
const long RNGSimple::RandModulus = 714025;
const long RNGSimple::RandMultipplier = 1366;
const long RNGSimple::RandShift = 150889;
/***************************************************************************
* $RCSfile: RNGSimple.cpp,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: RNGSimple.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
***************************************************************************/
#ifndef RNG_SIMPLE_H
#define RNG_SIMPLE_H
/***********************************************************************
*
* class RNGSimple
* class RNGSimpleSequence : public SequenceGen<RNGSimple>
*
* Simple class that implements random number generator a la
* Numerical Recipes, in the range [0...1]. The first class may be
* used standalone, or as a template parameter to SequenceGen. The
* second class is derived from SequenceGen, and makes it easier to
* use this RNG in expressions.
* Use RNGSimple as a scalar or container element, and use
* RNGSimpleSequence when you need a sequence of numbers to fill a container.
*
***********************************************************************/
#include "Utility/SequenceGen.h"
class RNGSimple {
public:
typedef double Return_t;
public:
// default constructor
RNGSimple(int advance = 0)
: CurrentSeed(RandShift + 1), CurrentRand(0) { AdvanceSeed(advance); }
// copy constructor
RNGSimple(const RNGSimple& rng)
: CurrentSeed(rng.CurrentSeed), CurrentRand(rng.CurrentRand) { }
// destructor
~RNGSimple(void) {}
// advance indicates number of times to advance random number source
inline void AdvanceSeed(int advance = 0) {
for (int iadv=0; iadv<advance; iadv++)
CurrentSeed = (CurrentSeed + RandShift) % RandModulus;
CurrentRand = CurrentSeed;
}
// set seed to user-specified value, plus shift to ensure it is large
inline void SetSeed(unsigned long seed) {
CurrentSeed = (seed + RandShift) % RandModulus;
CurrentRand = CurrentSeed;
}
// get seed value
inline unsigned long GetSeed(void) const { return CurrentSeed; }
// return the next pseudo-random number (from 0 ... 1)
inline Return_t GetRandom(void) const {
CurrentRand = (CurrentRand * RandMultipplier + RandShift) % RandModulus;
return ( Return_t(CurrentRand) / Return_t(RandModulus) );
}
// pseudonym for GetRandom()
inline Return_t operator()(void) const { return GetRandom(); }
// conversion to Return_t, same as GetRandom()
inline operator Return_t() const { return GetRandom(); }
// return the period of the RNG
static Return_t GetRandMax(void) { return Return_t(RandModulus); }
private:
long CurrentSeed;
mutable long CurrentRand;
static const long RandModulus;
static const long RandMultipplier;
static const long RandShift;
};
RNG_BASIC_MATH(RNGSimple)
// A version of SequenceGen with extra constructors to make using this
// class easier. This is the version that people should use to fill
// containers with a random number sequence in an expression. This
// class is PETE-aware via its inheritance from SequenceGen.
class RNGSimpleSequence : public SequenceGen<RNGSimple> {
public:
// default constructor
RNGSimpleSequence(int advance = 0)
: SequenceGen<RNGSimple>(RNGSimple(advance)) {}
// copy constructor
RNGSimpleSequence(const RNGSimpleSequence& rngseq)
: SequenceGen<RNGSimple>(rngseq.getGenerator()) {}
// destructor
~RNGSimpleSequence(void) {}
// wrappers around RNG generator functions
inline void AdvanceSeed(int adv = 0) { getGenerator().AdvanceSeed(adv); }
inline void SetSeed(unsigned long seed) { getGenerator().SetSeed(seed); }
inline unsigned long GetSeed(void) const { return getGenerator().GetSeed(); }
inline Return_t GetRandom(void) { return getGenerator().GetRandom(); }
inline Return_t operator()(void) { return getGenerator().GetRandom(); }
static Return_t GetRandMax(void) { return RNGSimple::GetRandMax(); }
};
#endif // RNG_SIMPLE_H
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
* This program was prepared by PSI.
* All rights in the program are reserved by PSI.
* Neither PSI nor the author(s)
* makes any warranty, express or implied, or assumes any liability or
* responsibility for the use of this software
*
* Visit www.amas.web.psi for more details
*
***************************************************************************/
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
***************************************************************************/
// include files
#include "Utility/RNGXCI.h"
// initialize static variables for RNGXCI
const RNlong RNGXCI::RN_MULT = 19073486328125LL; // 5^19
const RNlong RNGXCI::RN_MOD = 281474976710656LL; // 2^48
const RNlong RNGXCI::RN_PERIOD = RNGXCI::RN_MOD/4; // period
// normalize to (0,1)
const double RNGXCI::RN_NORM = 1./281474976710656.;
// 48-bit mask
const RNlong RNGXCI::RN_MASK = RNGXCI::RN_MOD - 1L;
/***************************************************************************
* $RCSfile: RNGXCI.cpp,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: RNGXCI.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
***************************************************************************/
#ifndef RNG_XCI_H
#define RNG_XCI_H
/***********************************************************************
*
* class RNGXCI
* class RNGXCISequence : public SequenceGen<RNGXCI>
*
* RNGXCI is a simple class that implements random number generator from LANL
* XCI group (Forrest Brown), in the range (0...1). The first class is used
* as a scalar, as an element of a Field or ParticleAttrib, or as a template
* parameter to SequenceGen. The second class is derived from SequenceGen,
* and makes it easier to use this RNG in an expression as a sequence of
* numbers that will fill a Field or ParticleAttrib container.
* Use RNGXCI as a scalar or container element, and use
* RNGXCISequence when you need a sequence of numbers to fill a container.
*
***********************************************************************/
#include "Utility/SequenceGen.h"
// define type that we ensure is 8 bytes long
#define LONG_IS_8_BYTES (((1L<<16)<<16)<<16)
typedef long long RNlong;
class RNGXCI {
public:
// return type
typedef double Return_t;
public:
// default constructor
RNGXCI(RNlong advance = 0L)
: Seed(1L) { AdvanceSeed(advance); }
// copy constructor
RNGXCI(const RNGXCI& rng)
: Seed(rng.Seed) {}
// destructor
~RNGXCI(void) {}
// advance seed for random number generator n times
inline void AdvanceSeed(RNlong n = 0L) {
// skip ahead n RNs: Seed*RN_MULT^n mod RN_MOD
while( n<0 ) n += RN_PERIOD; // add period till >0
n &= RN_MASK; // mod RN_MOD
RNlong gen=1L, g=RN_MULT; // get gen=RN_MULT^n, in
for( ; n; n>>=1 ) { // log2(n) ops, not n ops !
if( n&1 ) gen = gen*g & RN_MASK;
g = g*g & RN_MASK;
}
Seed = gen*Seed & RN_MASK;
return;
}
// set seed to user-specified value
inline void SetSeed(RNlong s) {
Seed = (s|1) & RN_MASK; // must be odd to get full period
}
// get seed value
inline RNlong GetSeed(void) const { return Seed; }
// return the next pseudo-random number (from 0 ... 1)
inline Return_t GetRandom(void) const {
Return_t r = Seed*RN_NORM;
Seed = Seed*RN_MULT & RN_MASK;
return r;
}
// pseudonym for GetRandom()
inline Return_t operator()(void) const { return GetRandom(); }
// conversion to Return_t, same as GetRandom()
inline operator Return_t() const { return GetRandom(); }
// return the period of the RNG
static Return_t GetRandMax(void) { return Return_t(RN_MASK); }
private:
mutable RNlong Seed;
// constants for RN gen: Seed = Seed*RN_MULT mod RN_MOD
static const RNlong RN_MULT; // 5^19
static const RNlong RN_MOD; // 2^48
static const RNlong RN_PERIOD; // period
static const double RN_NORM; // normalize to (0,1)
static const RNlong RN_MASK; // 48-bit mask
};
RNG_BASIC_MATH(RNGXCI)
// A version of SequenceGen with extra constructors to make using this
// class easier. This is the version that people should use to fill
// containers with a random number sequence in an expression. This
// class is PETE-aware via its inheritance from SequenceGen.
class RNGXCISequence : public SequenceGen<RNGXCI> {
public:
// default constructor
RNGXCISequence(int advance = 0)
: SequenceGen<RNGXCI>(RNGXCI(advance)) {}
// copy constructor
RNGXCISequence(const RNGXCISequence& rngseq)
: SequenceGen<RNGXCI>(rngseq.getGenerator()) {}
// destructor
~RNGXCISequence(void) {}
// wrappers around RNG generator functions
inline void AdvanceSeed(RNlong adv = 0L) {
getGenerator().AdvanceSeed(adv);
}
inline void SetSeed(RNlong seed) { getGenerator().SetSeed(seed); }
inline RNlong GetSeed(void) const { return getGenerator().GetSeed(); }
inline Return_t GetRandom(void) { return getGenerator().GetRandom(); }
inline Return_t operator()(void) { return getGenerator().GetRandom(); }
static Return_t GetRandMax(void) { return RNGXCI::GetRandMax(); }
};
#endif // RNG_XCI_H
/***************************************************************************
* $RCSfile: RNGXCI.h,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: RNGXCI.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
......@@ -25,8 +25,6 @@
#include "Utility/SequenceGen.h"
#define CTYPE double
class RNGXDiv {
public:
......
......@@ -2,9 +2,6 @@
/***************************************************************************
*
* The IPPL Framework
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
***************************************************************************/
......@@ -25,25 +22,9 @@
*
***********************************************************************/
// include files
#include "Utility/RNGRand.h"
#include "Utility/RNGSimple.h"
#include "Utility/RNGXDiv.h"
#include "Utility/RNGXCI.h"
// typedef for the default RNG ... selected by #define
#if defined(IPPL_USE_XDIV_RNG)
typedef RNGXDivSequence RandomNumberGen;
#elif defined(IPPL_USE_RAND_RNG)
typedef RNGRandSequence RandomNumberGen;
#elif defined(IPPL_USE_SIMPLE_RNG)
typedef RNGSimpleSequence RandomNumberGen;
#elif defined(IPPL_USE_XCI_RNG)
typedef RNGXCISequence RandomNumberGen;
#else
typedef RNGSimpleSequence RandomNumberGen;
#endif
// a default RandomNumberGen object for use in the Framework. When
// running in parallel, the Ippl object will advance this by the
......@@ -52,11 +33,4 @@ typedef RNGSimpleSequence RandomNumberGen;
// own RNG sequence object and use that.
extern RandomNumberGen IpplRandom;
#endif // RANDOM_NUMBER_GEN_H
/***************************************************************************
* $RCSfile: RandomNumberGen.h,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: RandomNumberGen.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
......@@ -4,7 +4,6 @@ project (MSLANG)
set (MSLANG_VERSION_MAJOR 0)
set (MSLANG_VERSION_MINOR 1)
add_definitions (-DIPPL_USE_XDIV_RNG)
add_definitions (-DNOCTAssert)
include_directories (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment