diff --git a/include/Makefile b/include/Makefile index 37ee2fd..95a6b71 100644 --- a/include/Makefile +++ b/include/Makefile @@ -21,6 +21,7 @@ TIMER= # use TkPhotoSurface for CairoItem, overriding platform specific optimisation TKPHOTOSURFACE= NOGUI= +DPCPP= # enables ecolab for the MXE environment MXE= @@ -103,9 +104,15 @@ CPP=$(CPLUSPLUS) -E # disable inclusion of mpi++.h in the MPICH case (don't know what the problem is here) FLAGS+=-UHAVE_MPI_CPP else -CC=gcc +# Engage Intel OneAPI compiler +ifdef DPCPP +CPLUSPLUS=icpx +SYCL+=-fsycl +else CPLUSPLUS=g++ -LINK=$(CPLUSPLUS) +endif +CC=gcc +LINK=$(CPLUSPLUS) $(SYCL) CPP=g++ -E endif @@ -622,7 +629,7 @@ DCXX=distcc endif .cc.o: - $(DCXX) -c $(FLAGS) $(CXXFLAGS) $(OPT) -o $@ $< + $(DCXX) -c $(FLAGS) $(SYCL) $(CXXFLAGS) $(OPT) -o $@ $< .c.o: $(CC) -c $(FLAGS) $(OPT) -o $@ $< diff --git a/include/arrays.h b/include/arrays.h index 520e9ed..a4e30be 100644 --- a/include/arrays.h +++ b/include/arrays.h @@ -1566,7 +1566,7 @@ namespace ecolab array_data* oldData=dt; bool freeMem = ref()-- == 0; dt=alloc(size()); - memcpy(data(),oldData->dt,size()*sizeof(T)); + memcpy(dt->dt,oldData->dt,size()*sizeof(T)); if (freeMem) free(oldData); } } @@ -2033,7 +2033,7 @@ namespace ecolab { array r(x.size()); vdCosh(static_cast(x.size()),x.data(),r.data()); - return r; + r; } inline array sinh(const array& x) diff --git a/include/cairo_base.h b/include/cairo_base.h index 0af0f5e..8b5ef92 100644 --- a/include/cairo_base.h +++ b/include/cairo_base.h @@ -10,6 +10,8 @@ #define CAIRO_BASE_H #if defined(CAIRO) #include "classdesc.h" +#undef None +#undef Success #include "arrays.h" #include diff --git a/include/ecolab.h b/include/ecolab.h index 2dca02b..570ee86 100644 --- a/include/ecolab.h +++ b/include/ecolab.h @@ -13,6 +13,7 @@ #define ECOLAB_H #include #include "pythonBuffer.h" +#include "graphcode.h" // mpi.h must appear before any standard library stuff #ifdef MPI_SUPPORT @@ -52,6 +53,11 @@ typedef classdesc::string eco_string; #include #include "eco_strstream.h" +#include "random.h" + +#ifdef SYCL_LANGUAGE_VERSION +#include +#endif namespace ecolab { @@ -72,9 +78,37 @@ namespace ecolab using classdesc::xdr_pack; using classdesc::isa_t; using classdesc::is_array; -} -#include "random.h" + template struct Model + { + /// checkpoint the model to \a fileName + void checkpoint(const char* fileName); + /// restart the model from checkpoint saved in \a fileName + void restart(const char* fileName); + }; + +#ifdef SYCL_LANGUAGE_VERSION + sycl::queue& syclQ(); +#endif + + template struct EcolabGraph: public graphcode::Graph + { + /// apply a functional to all local cells of this processor in parallel + /// @param f + template + void forAll(F f) { +#ifdef SYCL_LANGUAGE_VERSION + syclQ().submit([&](sycl::handler& h) { + h.parallel_for(this->size(), [=,this](auto i) { + f(*(*this)[i]->template as()); + }); + }); +#else + for (auto& i: *this) f(*i->template as()); +#endif + } + }; +} #ifdef MPI_SUPPORT #include @@ -88,4 +122,5 @@ namespace ecolab } #endif +#include "ecolab.cd" #endif /* ECOLAB_H */ diff --git a/include/ecolab_epilogue.h b/include/ecolab_epilogue.h index 9c06f02..2e0906c 100644 --- a/include/ecolab_epilogue.h +++ b/include/ecolab_epilogue.h @@ -11,7 +11,28 @@ Put this after including all .cd files */ -#include "classdesc_epilogue.h" #ifdef GRAPHCODE_H #include "graphcode.cd" #endif +#include "classdesc_epilogue.h" + +#ifdef ECOLAB_H +#include "pack_base.h" + +namespace ecolab +{ + template + void Model::checkpoint(const char* fileName) + { + pack_t b(fileName,"w"); + b<(*this); + } + + template + void Model::restart(const char* fileName) + { + pack_t b(fileName,"r"); + b>>static_cast(*this); + } +} +#endif diff --git a/models/ecolab_model.cc b/models/ecolab_model.cc index af4e945..95bd75d 100644 --- a/models/ecolab_model.cc +++ b/models/ecolab_model.cc @@ -26,6 +26,7 @@ using array_ns::pcoord; #include "ecolab_epilogue.h" + using namespace classdesc; // TODO - move this into main library @@ -51,7 +52,6 @@ namespace r[i]=ROUND(x[i]); return r; } - } @@ -462,7 +462,7 @@ void SpatialModel::setGrid(size_t nx, size_t ny) void SpatialModel::generate(unsigned niter) { if (tstep==0) makeConsistent(); - for (auto& i: *this) i->as()->generate(niter,*this); + forAll([=,this](EcolabCell& c) {c.generate(niter,*this);}); tstep+=niter; } diff --git a/models/ecolab_model.h b/models/ecolab_model.h index 1b5d546..5741dc3 100644 --- a/models/ecolab_model.h +++ b/models/ecolab_model.h @@ -8,7 +8,7 @@ #include #include -#include +#include using classdesc::Object; #include @@ -67,7 +67,7 @@ struct EcolabPoint unsigned nsp() const; ///< number of living species in this cell }; -struct PanmicticModel: public ModelData, public EcolabPoint +struct PanmicticModel: public ModelData, public EcolabPoint, public ecolab::Model { ConnectionPlot connectionPlot; void updateConnectionPlot() {connectionPlot.update(density,interaction);} @@ -81,9 +81,10 @@ struct PanmicticModel: public ModelData, public EcolabPoint struct EcolabCell: public EcolabPoint, public graphcode::Object {}; -class SpatialModel: public ModelData, public graphcode::Graph +class SpatialModel: public ModelData, public EcolabGraph, public ecolab::Model { size_t numX=1, numY=1; + CLASSDESC_ACCESS(SpatialModel); public: size_t makeId(size_t x, size_t y) const {return x%numX + numX*(y%numY);} void setGrid(size_t nx, size_t ny); diff --git a/src/ecolab.cc b/src/ecolab.cc index 25d9d23..bef4a3b 100644 --- a/src/ecolab.cc +++ b/src/ecolab.cc @@ -8,19 +8,39 @@ #include "tcl++.h" #define TK 1 +#undef None #include "cairoSurfaceImage.h" +#undef None #include "plot.h" #include "pythonBuffer.h" #include "ecolab.h" #ifdef MPI_SUPPORT #include "graphcode.h" #endif +#include "classdesc.h" #include "ecolab_epilogue.h" using namespace ecolab; using namespace std; #include +#ifdef SYCL_LANGUAGE_VERSION +using namespace sycl; +queue& ecolab::syclQ() { + static queue q{default_selector_v}; + return q; +} +void* operator new(size_t s) { + cout<