-
Notifications
You must be signed in to change notification settings - Fork 146
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
Failed to compile using EGS_GUI #1162
Comments
Could you share your input file? There is likely a typo or mistake in your source definition. Note that this output looks like it comes from trying to run the application, not from compilation. |
I execute my file with egs_gui. Here is my input file:
Before executing that file, the file was compiled succesfully. Because I look problem concerning with random generator, also I share two random generator files listed below:
#ifndef EGS_RANDOM_GENERATOR_
#define EGS_RANDOM_GENERATOR_
#include "egs_libconfig.h"
#include "egs_math.h"
#include "egs_functions.h"
class EGS_Input;
/*! \brief Base random number generator class. All random number generators
* should be derived from this class.
*
* \ingroup egspp_main
*
* A random number generator (RNG) is a central part of every Monte Carlo
* simulation. In order to have the possibility of using different
* RNGs, the egspp class library defines a RNG as an abstract class.
* However, for the sake of efficiency, the main method for drawing
* random numbers getUniform() is implemented as an inline function, which
* returns the next number in an array of random numbers, possibly after
* calling the pure virtual method fillArray() to fill the array with
* random numbers. Appart from getUniform(), which returns a random number
* uniformely distributed between zero (inclusive) and one (exclusive),
* EGS_RandomGenerator implements some frequently needed algorithms such
* as picking a random azimuthal angle ( getAzimuth() ) angle and picking
* a Gaussian distributed number ( getGaussian() ).
*
* \todo Should not EGS_RandomGenerator be derived from EGS_Object,
* so that dynamically loading RNG DSOs is automatically implemented?
*/
class EGS_EXPORT EGS_RandomGenerator {
public:
/*! \brief Construct a RNG that has an array of \a n points to
* hold random numbers.
*
* Memory gets allocated and #rarray points to it. The pointer
* #ip is set to point beyond the array (so that at the next call
* of getUniform() #rarray gets filled via a call to fillArray() ).
*/
EGS_RandomGenerator(int n=128);
/*! \brief Copy constructor.
*
* Being able to save the state of a RNG is useful in advanced applications
* such as correlated sampling.
*/
EGS_RandomGenerator(const EGS_RandomGenerator &r) : np(0) {
copyBaseState(r);
};
/*! \brief Destructor.
*
* Deallocates the memory pointed to by #rarray.
*/
virtual ~EGS_RandomGenerator() {
delete [] rarray;
};
/*! \brief Returns a random number uniformly distributed between
* zero (inclusive) and 1 (exclusive).
*
* Uses the virtual method fillArray() to fill the array #rarray,
* if the pointer #ip points beyond the last element of #rarray.
*/
inline EGS_Float getUniform() {
if (ip >= np) {
fillArray(np,rarray);
ip = 0;
}
return rarray[ip++];
};
/*! \brief Returns the number of random numbers generated so far.
*
* This is useful for simulation diagnostics purposes.
* \sa numbersUsed()
*/
EGS_I64 numbersGenerated() const {
return count;
};
/*! \brief Returns the number of random numbers used so far.
*
* This is normally different than numbersGenerated() as some of the
* numbers in the array #rarray may not have been used yet.
*/
EGS_I64 numbersUsed() const {
return ip<np ? count - np + ip : count;
};
/*! \brief Sets \a cphi and \a sphi to the cosine and sine of a random
* angle uniformely distributed between 0 and \f$2 \pi \f$.
*
* The default implementation uses a box method as this is faster on
* AMD and Intel CPUs. If the preprocessor macro FAST_SINCOS is defined,
* then an azimuthal angle \f$\phi\f$ is drawn uniformly between
* 0 and \f$2 \pi \f$ and \a cphi and \a sphi are calculated using the
* cosine and sine functions.
*/
inline void getAzimuth(EGS_Float &cphi, EGS_Float &sphi) {
#ifndef FAST_SINCOS
register EGS_Float xphi,xphi2,yphi,yphi2,rhophi;
do {
xphi = 2*getUniform() - 1;
xphi2 = xphi*xphi;
yphi = getUniform();
yphi2 = yphi*yphi;
rhophi = xphi2 + yphi2;
}
while (rhophi > 1);
cphi = (xphi2 - yphi2)/rhophi;
sphi = 2*xphi*yphi/rhophi;
#else
EGS_Float phi = 2*M_PI*getUniform();
cphi = cos(phi);
sphi = sin(phi);
#endif
};
/*! \brief Returns a Gaussian distributed random number with mean zero
* and standard deviation 1.
*/
inline EGS_Float getGaussian() {
if (have_x) {
have_x = false;
return the_x;
}
EGS_Float r = sqrt(-2*log(1-getUniform()));
EGS_Float cphi, sphi;
getAzimuth(cphi,sphi);
have_x = true;
the_x = r*sphi;
return r*cphi;
};
/*! \brief Create a RNG object from the information pointed to by
* \a inp and return a pointer to it.
*
* The input \a inp must either be itself, or it mist have a property
* with key <code>rng definition</code>, otherwise the return value
* of this function will be \c null. The \a sequence parameter is
* usefull to automatically adjust the initial random number seeds
* in parallel runs.
*
* Note: it is planned to extend this function to be able to create
* RNG objects by dinamically loading RNG dynamic shared objects,
* but this functionality is not there yet. For now, the only RNG
* type available is a ranmar RNG.
*/
static EGS_RandomGenerator *createRNG(EGS_Input *inp, int sequence=0);
/*! \brief Returns a pointer to the default egspp RNG.
*
* The default egspp RNG is ranmar. The RNG is initialized with
* by increasing the second ranmar default initial seed by
* \a sequence.
*/
static EGS_RandomGenerator *defaultRNG(int sequence=0);
/*! \brief Fill the array of \a n elements pointed to by \a array with
* random numbers.
*
* This pure virtual function must be implemented by derived RNG classes
* to fill the array \a array with \a n random numbers uniformly
* distributed between 0 (inclusive) and 1 (exclusive). The reason for
* having the interval defined to exclude unity is the fact that
* traditionally RNGs used with the EGS system have had this property
* and therefore in many algorithms this behaviour is assumed
* (\em e.g. log(1-r) is used without checking if 1-r is 0).
*/
virtual void fillArray(int n, EGS_Float *array) = 0;
//@{
//! \name state_functions
/*! \brief Functions for storing, seting and reseting the state of a RNG
* object.
*
* These functions are useful for being able to perform restarted
* calculations and to combine the result of parallel runs.
* They are used by the default implementations of the
* outputData(), readData(), etc. of the EGS_Application class.
* The base RNG class implementation stores/reads #count, #np, #ip and
* #rarray to the output or input stream \a data.
* Derived RNG classes should should store/read additional data needed
* to set their state to be the same as at the time of executing one
* of these functions by reimplementing the pure virtual functions
* storePrivateState() and setPrivateState().
*/
bool storeState(ostream &data);
bool setState(istream &data);
bool addState(istream &data);
void resetCounter() {
count = 0;
};
//@}
/*! \brief Get a copy of the RNG */
virtual EGS_RandomGenerator *getCopy() = 0;
/*! \brief Set the state of the RNG from another RNG */
virtual void setState(EGS_RandomGenerator *r) = 0;
/*! \brief Save the RNG state */
virtual void saveState() = 0;
/*! \brief Reset the state to a previously saved state */
virtual void resetState() = 0;
/*! \brief The memory needed to store the rng state */
virtual int rngSize() const = 0;
/*! \brief Describe this RNG
*
* Derived RNG classes should reimplement this method to output
* some information about the RNG being used in ther simulation.
* This is handy for EGSnrc C++ applications.
*/
virtual void describeRNG() const {};
protected:
EGS_I64 count; //!< random number generated so far
int np; //!< size of the array rarray
int ip; //!< pointer to the next rarray element in the sequence
EGS_Float *rarray;//!< array with random numbers of size np.
/*! \brief Store the state of the RNG to the output stream \a data.
*
* Derived RNG classes must implement this function to store as much data
* as needed to the output stream \a data so that a RNG
* object can be set to exactly the same using these data by
* invoking setPrivateState().
*
* \sa storeState(), setState().
*/
virtual bool storePrivateState(ostream &data) = 0;
/*! \brief Set the state of the RNG object from the data in the input
* stream \a data.
*
* This method must be implemented in derived RNG classes. It should read
* the same data as stored by storePrivateState() in the same order from
* the input stream \a data.
*/
virtual bool setPrivateState(istream &data) = 0;
void copyBaseState(const EGS_RandomGenerator &r);
void allocate(int n);
/*! \brief The memory needed to store the base state */
int baseSize() const {
return 2*sizeof(EGS_I32) + sizeof(EGS_I64) + sizeof(bool) +
sizeof(EGS_Float) + np*sizeof(EGS_Float);
};
private:
bool have_x; //!< used for sampling Gaussian random numbers
EGS_Float the_x; //!< used for sampling Gaussian random numbers
};
#endif
2. Random generator file in cpp file
#include "egs_rndm.h"
#include "egs_input.h"
#include "egs_functions.h"
#include <iostream>
#include <string>
using namespace std;
void EGS_RandomGenerator::allocate(int n) {
if (n < 1) {
egsFatal("Attempt to construct a RNG with n < 1\n");
}
rarray = new EGS_Float[n];
np = n;
ip = np;
}
void EGS_RandomGenerator::copyBaseState(const EGS_RandomGenerator &r) {
if (np > 0 && np != r.np) {
delete [] rarray;
np = 0;
}
if (np <= 0) {
allocate(r.np);
}
ip = r.ip;
have_x = r.have_x;
the_x = r.the_x;
count = r.count;
for (int j=ip; j<np; j++) {
rarray[j] = r.rarray[j];
}
}
EGS_RandomGenerator::EGS_RandomGenerator(int n) : count(0), np(0) {
allocate(n);
have_x = false;
for (int j=0; j<np; j++) {
rarray[j] = 0;
}
}
bool EGS_RandomGenerator::storeState(ostream &data) {
if (!egsStoreI64(data,count)) {
return false;
}
data << " " << np << " " << ip << endl;
for (int j=0; j<np; j++) {
data << rarray[j] << " ";
}
data << endl;
if (!data.good()) {
return false;
}
return storePrivateState(data);
}
bool EGS_RandomGenerator::setState(istream &data) {
if (!egsGetI64(data,count)) {
return false;
}
int np1;
data >> np1 >> ip;
if (!data.good() || data.fail() || data.eof()) {
return false;
}
if (np1 < 1) {
return false;
}
if (np1 != np && np > 0) {
delete [] rarray;
rarray = new EGS_Float [np1];
}
np = np1;
for (int j=0; j<np; j++) {
data >> rarray[j];
}
if (!data.good()) {
return false;
}
return setPrivateState(data);
}
bool EGS_RandomGenerator::addState(istream &data) {
EGS_I64 count_save = count;
if (!setState(data)) {
return false;
}
count += count_save;
return true;
}
/*! \brief A ranmar RNG class.
*
* This RNG class implements the Zaman \& Marsaglia ranmar generator.
* ranmar has been the default EGS4 and EGSnrc RNG for many years.
*/
class EGS_LOCAL EGS_Ranmar : public EGS_RandomGenerator {
public:
/*! \brief Construct a ranmar RNG using \a ixx and \a jxx as the
* initial seeds.
*/
EGS_Ranmar(int ixx=1802, int jxx=9373, int n=128) :
EGS_RandomGenerator(n), high_res(false), copy(0) {
setState(ixx,jxx);
};
EGS_Ranmar(const EGS_Ranmar &r) : EGS_RandomGenerator(r),
ix(r.ix), jx(r.jx), c(r.c), iseed1(r.iseed1), iseed2(r.iseed2),
high_res(r.high_res) {
for (int j=0; j<97; j++) {
u[j] = r.u[j];
}
};
~EGS_Ranmar() {
if (copy) {
delete copy;
}
};
/*! \brief Fill the array pointed to by \a array with random numbers
*/
void fillArray(int n, EGS_Float *array);
/*! \brief Output information about this RNG using egsInformation() */
void describeRNG() const;
EGS_RandomGenerator *getCopy();
void setState(EGS_RandomGenerator *r);
void saveState();
void resetState();
int rngSize() const {
return baseSize() + 102*sizeof(int);
};
void setHighResolution(bool hr) {
high_res = hr;
};
protected:
/*! Stores the pointers ix and jx, the carry c, the initial seeds that
* were used to initialize the generator and the 97 element array u.
*/
bool storePrivateState(ostream &data);
/*! Reads the same data stored by storePrivateState() */
bool setPrivateState(istream &data);
void set(const EGS_Ranmar &r) {
copyBaseState(r);
ix = r.ix;
jx = r.jx;
c = r.c;
iseed1 = r.iseed1;
iseed2 = r.iseed2;
for (int j=0; j<97; j++) {
u[j] = r.u[j];
}
};
private:
void setState(int ixx, int jxx);
int ix, jx, c;
int u[97];
static int cd, cm;
static EGS_Float twom24;
int iseed1, iseed2;
bool high_res;
EGS_Ranmar *copy;
};
void EGS_Ranmar::saveState() {
if (copy) {
copy->set(*this);
}
else {
copy = new EGS_Ranmar(*this);
}
copy->copy = 0;
}
void EGS_Ranmar::resetState() {
if (copy) {
EGS_Ranmar *tmp = copy;
set(*copy);
copy = tmp;
}
}
EGS_RandomGenerator *EGS_Ranmar::getCopy() {
EGS_Ranmar *c = new EGS_Ranmar(*this);
c->np = 0;
c->copy = 0;
c->copyBaseState(*this);
return c;
}
void EGS_Ranmar::setState(EGS_RandomGenerator *r) {
copyBaseState(*r);
EGS_Ranmar *r1 = dynamic_cast<EGS_Ranmar *>(r);
if (!r1) {
egsFatal("EGS_Ranmar::setState: attampt to set my state by a non EGS_Ranmar RNG!\n");
}
ix = r1->ix;
jx = r1->jx;
c = r1->c;
iseed1 = r1->iseed1;
iseed2 = r1->iseed2;
for (int j=0; j<97; j++) {
u[j] = r1->u[j];
}
}
bool EGS_Ranmar::storePrivateState(ostream &data) {
data << ix << " " << jx << " " << c << " "
<< iseed1 << " " << iseed2 << " " << high_res << endl;
for (int j=0; j<97; j++) {
data << u[j] << " ";
}
data << endl;
return data.good();
}
bool EGS_Ranmar::setPrivateState(istream &data) {
data >> ix >> jx >> c >> iseed1 >> iseed2 >> high_res;
for (int j=0; j<97; j++) {
data >> u[j];
}
return data.good();
}
EGS_Float EGS_Ranmar::twom24 = 1./16777216.;
int EGS_Ranmar::cd = 7654321;
int EGS_Ranmar::cm = 16777213;
void EGS_Ranmar::describeRNG() const {
egsInformation("Random number generator:\n"
"============================================\n");
egsInformation(" type = ranmar\n");
egsInformation(" high resolution = ");
if (high_res) {
egsInformation("yes\n");
}
else {
egsInformation("no\n");
}
egsInformation(" initial seeds = %d %d\n",iseed1,iseed2);
egsInformation(" numbers used so far = %lld\n",count);
}
void EGS_Ranmar::setState(int ixx, int jxx) {
if (ixx <= 0 || ixx >= 31328) {
ixx = 1802;
}
if (jxx <= 0 || jxx >= 30081) {
jxx = 9373;
}
iseed1 = ixx;
iseed2 = jxx;
int i = (ixx/177)%177 + 2;
int j = ixx%177 + 2;
int k = (jxx/169)%178 + 1;
int l = jxx%169;
for (int ii=0; ii<97; ii++) {
int s = 0;
int t = 8388608;
for (int jj=0; jj<24; jj++) {
int m = (((i*j)%179)*k)%179;
i = j;
j = k;
k = m;
l = (53*l+1)%169;
if ((l*m)%64 >= 32) {
s += t;
}
t /= 2;
}
u[ii] = s;
}
c = 362436;
ix = 96;
jx = 32;
}
void EGS_Ranmar::fillArray(int n, EGS_Float *array) {
for (int ii=0; ii<n; ii++) {
register int r = u[ix] - u[jx--];
#ifdef MSVC
if (r > 16777219) {
egsWarning("r = %d\n",r);
}
#endif
if (r < 0) {
r += 16777216;
}
u[ix--] = r;
if (ix < 0) {
ix = 96;
}
if (jx < 0) {
jx = 96;
}
c -= cd;
if (c < 0) {
c+=cm;
}
r -= c;
if (r < 0) {
r+=16777216;
}
#ifdef MSVC
if (r > 16777219) {
egsWarning("r = %d\n",r);
}
#endif
array[ii] = twom24*r;
}
if (high_res) {
for (int ii=0; ii<n; ii++) {
register int r = u[ix] - u[jx--];
#ifdef MSVC
if (r > 16777219) {
egsWarning("r = %d\n",r);
}
#endif
if (r < 0) {
r += 16777216;
}
u[ix--] = r;
if (ix < 0) {
ix = 96;
}
if (jx < 0) {
jx = 96;
}
c -= cd;
if (c < 0) {
c+=cm;
}
r -= c;
if (r < 0) {
r+=16777216;
}
#ifdef MSVC
if (r > 16777219) {
egsWarning("r = %d\n",r);
}
#endif
array[ii] += twom24*twom24*r;
}
}
count += n;
}
EGS_RandomGenerator *EGS_RandomGenerator::createRNG(EGS_Input *input,
int sequence) {
if (!input) {
egsWarning("EGS_RandomGenerator::createRNG: null input?\n");
return 0;
}
EGS_Input *i;
bool delete_it = false;
if (input->isA("rng definition")) {
i = input;
}
else {
i = input->takeInputItem("rng definition");
if (!i) {
egsWarning("EGS_RandomGenerator::createRNG: no 'RNG definition'"
" input\n");
return 0;
}
delete_it = true;
}
string type;
int err = i->getInput("type",type);
if (err) {
egsWarning("EGS_RandomGenerator::createRNG: no RNG type specified\n"
" Assuming ranmar.\n");
type = "ranmar";
}
EGS_RandomGenerator *result;
if (i->compare(type,"ranmar")) {
vector<int> seeds;
err = i->getInput("initial seeds",seeds);
EGS_Ranmar *res;
if (!err && seeds.size() == 2) {
res = new EGS_Ranmar(seeds[0],seeds[1] + sequence);
}
else {
res = new EGS_Ranmar(1802,9373+sequence);
}
vector<string> hr_options;
hr_options.push_back("no");
hr_options.push_back("yes");
bool hr = i->getInput("high resolution",hr_options,0);
res->setHighResolution(hr);
result = res;
}
else {
egsWarning("EGS_RandomGenerator::createRNG: unknown RNG type %s\n",
type.c_str());
result = 0;
}
if (delete_it) {
delete i;
}
return result;
}
EGS_RandomGenerator *EGS_RandomGenerator::defaultRNG(int sequence) {
sequence += 97;
int ixx = 33;
int iaux = sequence/30081;
int jxx = sequence - iaux*30081;
if (iaux > 0) {
ixx += iaux;
if (iaux > 31328) egsFatal("EGS_RandomGenerator::defaultRNG: "
"sequence %d is outside of allowed range\n",sequence);
}
return new EGS_Ranmar(ixx,jxx);
} Just information, I do not change anything in code or file after I download from github. Thank You very much. |
I tested your input file and it works fine for me. I'm guessing there's a problem with your installation. Do example files work? E.g. does
Run successfully? Please post your installation log, found in HEN_HOUSE/log. |
Right @rtownson . I found many errors in installation log. I post my installation log here.
Please explain to me what my problems are and what i do to repair that problem. Please help me. |
Every I execute, I get some error messages, such as:
|
The egs++ library looks like it failed to compile because your system ran out of memory ( |
My laptop have 4,00 GB (3,82 GB usable) RAM. Is it enough to execute EGSnrc? How much RAM should laptop have to execute EGSnrc? Thank You before. |
This is very little RAM, since your operating system will use nearly all of this. Like I said, you can try closing everything possible to free up more memory and see if that helps. Generally, I would recommend at least 8GB, but I have used 6GB for some basic simulations on linux. |
Thank You very much for your very useful information. |
Problem 01.docx |
The mingw links recently seems to have started failing, I'll have to update our installation instructions. It's OK, all you need to do is go to the same page, and download a zip file instead. Find the section "MinGW-W64 GCC-7.3.0". Download: x86_64-posix-seh https://7-zip.org/download.html After extracting the mingw folder, just place it where you want it to be "installed". That's it, you don't need to actually run an installer. Now, you just need to add the mingw32 bin folder to your PATH, which is described in the EGSnrc installation instructions. From there you should be OK! |
Sir, when I install EGSnrc, I get log massage: GNU Fortran (GCC) 12.3.0 Using xml test file D:\EGSnrc Program\HEN_HOUSE\pieces\tests_win.xml ===> Checking for availability of system dependent functions Can the compiler produce object files? .................... yes ************ Tests concluded ! ******* ===> Creating C Utilities for EGSnrc... Building the utilities object file ... Could egs_c_utils.c be compiled? .......................... no Failed to compile egs_c_utils.c. This may be due to a variety of reasons
**** Failed to compile load_beamlib.c!!! **** Failed compiling read_write_pardose.c! Testing egs_c_utils skipped due to previous errors... Testing load_beamlib skipped due to previous errors... ===> Creating configuration file ... ===> Creating machine.macros ... *** System file D:\EGSnrc Program\HEN_HOUSE\lib\win6432\machine.macros successfully created *** ===> Creating machine.f ... ===> Creating machine.mortran ... *** System file D:\EGSnrc Program\HEN_HOUSE\lib\win6432\machine.mortran successfully created *** ===> Creating dosxyznrc_win6432.spec ... Failed creating dosxyz_win6432.spec ===> Appending VCU library to dosxyznrc_win6432.spec ... Failed finding load_vculib You will not be able to use ===> Compiling Mortran3 ... D:\EGSnrc:1: warning: NUL character seen; rest of line ignored Compilation failed! ===> Compiling Pegs4 ... D:\EGSnrc:1: warning: NUL character seen; rest of line ignored Compilation failed!
***** EGSnrc installation FAILED, see log file for details *****
Sat September 28 2024 21:05:55 It seems there is a problem in C program. I install embarcadero dev C++. Please give a solution. Thank You! |
The |
There's a checkbox in the installer to set the environment variables automatically, if you used that then I'm not sure why EGS_HOME is missing. But you can fix it yourself, just add EGS_HOME. Add a new user variable called EGS_HOME, and set the path to where-ever your egs_home is. I assume something like |
It's not one of the windows pictured, but when you first open |
Hi @ftessier ,
After I compile egs_chamber user code, I got a message from compilation log, writing:
I confused with that message.
Would you like to explain me what my false? Please give me solution!
Thank You very much!
The text was updated successfully, but these errors were encountered: