Skip to content

Commit 6777176

Browse files
OpenMP optimisations
1 parent 88c189e commit 6777176

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

models/ecolab_model.cc

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,14 @@ unsigned SpatialModel::migrate()
690690
}
691691

692692
c.density+=delta[c.idx()];
693+
#ifdef _OPENMP
694+
#pragma omp atomic
695+
#endif
693696
totalMigration+=sum(abs(delta[c.idx()]));
694697
#if !defined(NDEBUG)
698+
#ifdef _OPENMP
695699
#pragma omp critical
700+
#endif
696701
ssum+=delta[c.idx()];
697702
#endif
698703
});
@@ -712,25 +717,6 @@ unsigned SpatialModel::migrate()
712717
MPI_Reduce(ssum.data(),s.data(),s.size(),MPI_INT,MPI_SUM,0,MPI_COMM_WORLD);
713718
ssum=s;
714719
#endif
715-
if (sum(ssum==0)!=int(ssum.size()))
716-
{
717-
for (size_t i=0; i<ssum.size(); ++i)
718-
if (ssum[i])
719-
{
720-
cout<<"species "<<i<<":"<<endl;
721-
for (size_t idx=0; idx<size(); ++idx)
722-
if (delta[idx][i])
723-
{
724-
auto& c=*(*this)[idx]->as<EcolabCell>();
725-
cout<<" delta "<<c.id<<"="<<delta[idx][i]<<" n="<<c.density[i]<<endl;
726-
for (auto& n: c)
727-
{
728-
auto& nbr=*n->as<EcolabCell>();
729-
cout<<" nbr:"<<nbr.id<<"="<<nbr.density[i]<<endl;
730-
}
731-
}
732-
}
733-
}
734720
if (myid()==0) assert(sum(ssum==0)==int(ssum.size()));
735721
#endif
736722
return totalMigration;

models/spatial_ecolab.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
array_urand.seed(10+myid())
1414

1515
# initial number of species
16-
nsp=30
16+
nsp=100
1717

1818
ecolab.repro_min(-0.1)
1919
ecolab.repro_max(0.1)
@@ -28,8 +28,8 @@ def randomList(num, min, max):
2828

2929
ecolab.species(range(nsp))
3030

31-
numX=1
32-
numY=2
31+
numX=16
32+
numY=16
3333
ecolab.setGrid(numX,numY)
3434
ecolab.partitionObjects()
3535

@@ -60,7 +60,7 @@ def randomList(num, min, max):
6060
def stepImpl():
6161
#ecolab.setDensitiesDevice()
6262
ecolab.generate(100)
63-
ecolab.mutate()
63+
#ecolab.mutate()
6464

6565
epochTs=ecolab.tstep()%epoch
6666
if (epochTs==0):
@@ -82,17 +82,18 @@ def stepImpl():
8282
print(ecolab.nsp()())
8383

8484
from timeit import timeit
85-
print(timeit('stepImpl()', globals=globals(), number=10))
85+
#print(timeit('stepImpl()', globals=globals(), number=10))
8686

8787
def step():
88-
global extinctions
88+
global extinctions, migrations
8989
extinctions=0
9090
migrations=0
91-
for i in range(epoch//10000):
91+
for i in range(epoch//epoch):
9292
stepImpl()
9393
if myid()==0:
9494
nsp=len(ecolab.species)
9595
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
96+
print(f't={ecolab.tstep()} nsp:{nsp} extinctions:{extinctions} migrations:{migrations}')
9697
plot('No. species',ecolab.tstep(),nsp,200*(ecolab.tstep()%epoch<0.5*epoch))
9798
#plot('No. species',ecolab.tstep(),nsp)
9899
plot('No. species by cell',ecolab.tstep(),ecolab.nsp()())

0 commit comments

Comments
 (0)