Skip to content

Commit 691f272

Browse files
Migration wasn't enabled. Debugging in progress.
1 parent 41bbccf commit 691f272

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

models/ecolab_model.cc

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void SpatialModel::generate(unsigned niter)
633633
tstep+=niter;
634634
}
635635

636-
void SpatialModel::migrate()
636+
unsigned SpatialModel::migrate()
637637
{
638638
/* each cell gets a distinct random salt value */
639639
hostForAll([=,this](EcolabCell& c) {c.salt=c.rand();});
@@ -665,36 +665,47 @@ void SpatialModel::migrate()
665665
});
666666

667667
array<int> ssum(species.size(),0);
668+
size_t totalMigration=0;
668669
hostForAll([&,this](EcolabCell& c) {
669-
// adjust delta so that density remains +ve
670-
array<int> adjust=delta[c.idx()]+c.density;
671-
adjust*=-(adjust<0);
672-
if (sum(adjust)>0)
673-
{
674-
// distribute adjust among neighbours
675-
array<int> totalDiff(c.density.size(),0);
676-
for (auto& n: c)
677-
{
678-
auto& nbr=*n->as<EcolabCell>();
679-
totalDiff+=nbr.density-c.density;
680-
}
681-
// adjust adjust to be divisible by totalDiff
682-
adjust-=adjust%totalDiff;
683-
for (auto& n: c)
684-
{
685-
auto& nbr=*n->as<EcolabCell>();
686-
delta[nbr.idx()]+=((nbr.density-c.density)/totalDiff)*adjust;
687-
}
688-
delta[c.idx()]-=adjust;
689-
}
690-
c.density+=delta[c.idx()];
670+
// // adjust delta so that density remains +ve
671+
// array<int> adjust=delta[c.idx()]+c.density;
672+
// adjust*=-(adjust<0);
673+
// if (sum(adjust)>0)
674+
// {
675+
// // distribute adjust among neighbours
676+
// array<int> totalDiff(c.density.size(),0);
677+
// for (auto& n: c)
678+
// {
679+
// auto& nbr=*n->as<EcolabCell>();
680+
// totalDiff+=nbr.density-c.density;
681+
// }
682+
// // adjust adjust to be divisible by totalDiff
683+
// adjust-=adjust%totalDiff;
684+
// for (auto& n: c)
685+
// {
686+
// auto& nbr=*n->as<EcolabCell>();
687+
// delta[nbr.idx()]+=((nbr.density-c.density)/totalDiff)*adjust;
688+
// }
689+
// delta[c.idx()]-=adjust;
690+
// }
691+
692+
//c.density+=delta[c.idx()];
693+
cout<<delta[c.idx()]<<endl;
694+
totalMigration+=sum(abs(delta[c.idx()]));
691695
#if !defined(NDEBUG)
692696
#pragma omp critical
693697
ssum+=delta[c.idx()];
694698
#endif
695699
});
696700
last_mig_tstep=tstep;
697701

702+
#ifdef MPI_SUPPORT
703+
if (myid()==0)
704+
MPI_Reduce(MPI_IN_PLACE, &totalMigration,1,MPI_UNSIGNED,MPI_SUM,0,MPI_COMM_WORLD);
705+
else
706+
MPI_Reduce(&totalMigration,nullptr,1,MPI_UNSIGNED,MPI_SUM,0,MPI_COMM_WORLD);
707+
#endif
708+
698709
/* assertion testing that population numbers are conserved */
699710
#if !defined(NDEBUG) && !defined(SYCL_LANGUAGE_VERSION)
700711
#ifdef MPI_SUPPORT
@@ -723,6 +734,7 @@ void SpatialModel::migrate()
723734
}
724735
if (myid()==0) assert(sum(ssum==0)==int(ssum.size()));
725736
#endif
737+
return totalMigration;
726738
}
727739

728740
void ModelData::makeConsistent(size_t nsp)

models/ecolab_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ class SpatialModel: public ModelData, public EcolabGraph<EcolabCell>,
131131
/// returns number of extinctions
132132
unsigned condense();
133133
void mutate();
134-
void migrate();
134+
unsigned migrate();
135135
};
136136

models/spatial_ecolab.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def randomList(num, min, max):
4747
ecolab.interaction.val(randomList(len(ecolab.interaction.val), ecolab.odiag_min(), ecolab.odiag_max()))
4848

4949
ecolab.mutation(nsp*[ecolab.mut_max()])
50-
ecolab.migration(nsp*[1e-1])
50+
ecolab.migration(nsp*[1e-20])
5151

5252
from plot import plot
5353
from GUI import gui, statusBar, windows
@@ -56,6 +56,7 @@ def randomList(num, min, max):
5656
mut_factor=1000
5757

5858
extinctions=0
59+
migrations=0
5960
def stepImpl():
6061
#ecolab.setDensitiesDevice()
6162
ecolab.generate(100)
@@ -67,8 +68,8 @@ def stepImpl():
6768
if (epochTs==epoch//2):
6869
ecolab.migration([x/mut_factor for x in ecolab.migration()])
6970

70-
#ecolab.migrate()
71-
global extinctions
71+
global extinctions, migrations
72+
migrations+=ecolab.migrate()
7273
extinctions+=ecolab.condense()
7374
#ecolab.syncThreads()
7475
#print(ecolab.nsp()())
@@ -86,15 +87,18 @@ def stepImpl():
8687
def step():
8788
global extinctions
8889
extinctions=0
90+
migrations=0
8991
for i in range(epoch//10000):
9092
stepImpl()
9193
if myid()==0:
94+
print(migrations)
9295
nsp=len(ecolab.species)
9396
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
9497
plot('No. species',ecolab.tstep(),nsp,200*(ecolab.tstep()%epoch<0.5*epoch))
9598
#plot('No. species',ecolab.tstep(),nsp)
9699
plot('No. species by cell',ecolab.tstep(),ecolab.nsp()())
97100
plot('Extinctions',ecolab.tstep(),extinctions)
101+
plot('Migration',ecolab.tstep(),migrations)
98102
# for i in range(numX):
99103
# for j in range(numY):
100104
# plot(f'Density({i},{j})',ecolab.tstep(),ecolab.cell(i,j).density(), pens=ecolab.species())

0 commit comments

Comments
 (0)