Skip to content

Commit

Permalink
DPCPP=1 build now compiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Oct 17, 2024
1 parent b146219 commit 87abf00
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
41 changes: 21 additions & 20 deletions models/ecolab_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,6 @@ using namespace classdesc;
// TODO - move this into main library
namespace
{
/* Rounding function, randomly round up or down, in the range 0..INT_MAX */
inline int ROUND(double x)
{
double dum;
if (x<0) x=0;
if (x>INT_MAX-1) x=INT_MAX-1;
return std::fabs(std::modf(x,&dum)) > array_urand.rand() ?
(int)x+1 : (int)x;
}

inline int ROUND(float x) {return ROUND(double(x));}

template <class E>
inline array<int> ROUND(const E& x)
{
array<int> r(x.size());
for (size_t i=0; i<x.size(); i++)
r[i]=ROUND(x[i]);
return r;
}
}


Expand All @@ -77,6 +57,27 @@ void PanmicticModel::generate(unsigned niter)
tstep+=niter;
}

/* Rounding function, randomly round up or down, in the range 0..INT_MAX */
int EcolabPoint::ROUND(double x)
{
double dum;
if (x<0) x=0;
if (x>std::numeric_limits<int>::max()-1) x=std::numeric_limits<int>::max()-1;
return std::fabs(std::modf(x,&dum))*(rand.max()-rand.min()) > (rand()-rand.min()) ?
(int)x+1 : (int)x;
}

//inline int ROUND(float x) {return ROUND(double(x));}

template <class E>
inline array<int> EcolabPoint::ROUND(const E& x)
{
array<int> r(x.size());
for (size_t i=0; i<x.size(); i++)
r[i]=ROUND(x[i]);
return r;
}

void EcolabPoint::generate(unsigned niter, const ModelData& model)
{
array<double> n(density);
Expand Down
7 changes: 7 additions & 0 deletions models/ecolab_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <ecolab.h>
using classdesc::Object;

#include <random>
#include <vector>
#include <pack_stl.h>

Expand Down Expand Up @@ -65,13 +66,18 @@ struct EcolabPoint
void condense(const array<bool>& mask, size_t mask_true);
array<int> mutate(const array<double>&);
unsigned nsp() const; ///< number of living species in this cell
/// Rounding function, randomly round up or down, in the range 0..INT_MAX
int ROUND(double x);
template <class E> array<int> ROUND(const E& x);
Exclude<std::mt19937> rand; // random number generator
};

struct PanmicticModel: public ModelData, public EcolabPoint, public ecolab::Model<PanmicticModel>
{
ConnectionPlot connectionPlot;
void updateConnectionPlot() {connectionPlot.update(density,interaction);}
void makeConsistent() {ModelData::makeConsistent(density.size());}
void seed(double x) {rand.seed(x);}
void generate(unsigned niter);
void generate() {generate(1);}
void condense();
Expand All @@ -93,6 +99,7 @@ class SpatialModel: public ModelData, public EcolabGraph<EcolabCell>, public eco
}
array<unsigned> nsp() const;
void makeConsistent();
void seed(double x) {forAll([=](EcolabCell& cell){cell.rand.seed(x);});}
void generate(unsigned niter);
void generate() {generate(1);}
void condense();
Expand Down

0 comments on commit 87abf00

Please sign in to comment.