Skip to content

Commit

Permalink
Merge pull request #136 from EcoJulia/rr/mpi
Browse files Browse the repository at this point in the history
Move MPI structs into extension
  • Loading branch information
richardreeve authored Apr 15, 2024
2 parents 58d833d + 585b842 commit eb9445e
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 148 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Thanks for contributing to EcoSISTEM.jl! Please read the below on how best to ma

2. Name the branch `username/featurename` and have fun!

3. When your feature is ready to merge back into the `dev` branch create a PR against `boydorr/EcoSISTEM.jl` **and assign `boydorr/EcoSISTEM-admins` as reviewers**.
3. When your feature is ready to merge back into the `dev` branch create a PR against `EcoJulia/EcoSISTEM.jl` **and assign `EcoJulia/EcoSISTEM-admins` as reviewers**.

4. Semver will be handled in PRs from `dev` into `master`.
4. Semver will be handled in PRs from `dev` into `main`.

5. Thanks for your time and effort!

Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# NEWS

- v0.2.1
- Move MPI structs into extension
- v0.2.0
- Require Julia v1.9 for extensions
- Create package extensions
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EcoSISTEM"
uuid = "ed2dc23b-ada4-5fdb-a26f-56368a14ad8f"
authors = ["Claire Harris <[email protected]>", "Richard Reeve <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand Down
45 changes: 8 additions & 37 deletions src/EcoSISTEM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,19 @@ export meta_simpson, meta_shannon, meta_speciesrichness, mean_abun,

using Random

"""
MPIGridLandscape{RA <: Base.ReshapedArray, NT <: NamedTuple}
MPIEcosystem abundances housed in the landscape, shared across multiple nodes.
"""
mutable struct MPIGridLandscape{RA <: Base.ReshapedArray, NT <: NamedTuple}
rows_matrix::Matrix{Int64}
cols_vector::Vector{Int64}
reshaped_cols::Vector{RA}
rows_tuple::NT
cols_tuple::NT
rngs::Vector{MersenneTwister}
end

"""
MPIEcosystem{MPIGL <: MPIGridLandscape, Part <: AbstractAbiotic,
SL <: SpeciesList, TR <: AbstractTraitRelationship} <: AbstractEcosystem{Part, SL, TR}
MPIEcosystem houses information on species and their interaction with their environment. It houses all information of a normal `Ecosystem` (see documentation for more details), with additional fields to describe which species are calculated on which machine. This includes: `sppcounts` - a vector of number of species per node, `firstsp` - the identity of the first species held by that particular node.
"""
mutable struct MPIEcosystem{MPIGL <: MPIGridLandscape, Part <: AbstractAbiotic,
SL <: SpeciesList,
TR <: AbstractTraitRelationship} <:
AbstractEcosystem{Part, SL, TR}
abundances::MPIGL
spplist::SL
abenv::Part
ordinariness::Union{Matrix{Float64}, Missing}
relationship::TR
lookup::Vector{Lookup}
sppcounts::Vector{Int32}
firstsp::Int64
sccounts::Vector{Int32}
firstsc::Int64
cache::Cache
end

abstract type MPIGridLandscape end
export MPIGridLandscape

abstract type MPIEcosystem{MPIGL <: MPIGridLandscape, Part <: AbstractAbiotic,
SL <: SpeciesList,
TR <: AbstractTraitRelationship} <:
AbstractEcosystem{Part, SL, TR} end
export MPIEcosystem

function gather_abundance end
function gather_diversity end
export gather_abundance, gather_diversity

function emptyMPIgridlandscape end
function synchronise_from_rows! end
function synchronise_from_cols! end
Expand Down
103 changes: 68 additions & 35 deletions src/MPIEcosystem.jl
Original file line number Diff line number Diff line change
@@ -1,45 +1,76 @@
using EcoSISTEM
import EcoSISTEM
using MPI
using Diversity
using HCubature
using Unitful
using EcoSISTEM.Units
using Missings

import EcoSISTEM: MPIEcosystem, gather_abundance, gather_diversity
using EcoSISTEM: AbstractAbiotic, AbstractTraitRelationship, Lookup, Cache

function MPIEcosystem(abundances::MPIGL,
spplist::SL, abenv::Part,
ordinariness::Union{Matrix{Float64}, Missing},
relationship::TR, lookup::Vector{Lookup},
sppcounts::Vector, firstsp::Int64, sccounts::Vector,
firstsc::Int64,
cache::Cache) where
{MPIGL <: MPIGridLandscape, Part <: AbstractAbiotic,
SL <: SpeciesList, TR <: AbstractTraitRelationship}
tematch(spplist, abenv) || error("Traits do not match habitats")
trmatch(spplist, relationship) ||
error("Traits do not match trait functions")
#_mcmatch(abundances.matrix, spplist, abenv) ||
# error("Dimension mismatch")
return MPIEcosystem{MPIGL, Part, SL, TR}(abundances, spplist, abenv,
ordinariness,
relationship, lookup, sppcounts,
firstsp,
sccounts, firstsc, cache)
"""
MPIEcosystem{MPIGL <: MPIGridLandscape, Part <: AbstractAbiotic,
SL <: SpeciesList, TR <: AbstractTraitRelationship} <:
AbstractEcosystem{Part, SL, TR}
MPIEcosystem houses information on species and their interaction with their
environment. It houses all information of a normal `Ecosystem` (see
documentation for more details), with additional fields to describe which
species are calculated on which machine. This includes: `sppcounts` - a
vector of number of species per node, `firstsp` - the identity of the
first species held by that particular node.
"""
mutable struct MPIEcosystem{MPIGL <: EcoSISTEM.MPIGridLandscape,
Part <: EcoSISTEM.AbstractAbiotic,
SL <: EcoSISTEM.SpeciesList,
TR <: EcoSISTEM.AbstractTraitRelationship} <:
EcoSISTEM.MPIEcosystem{MPIGL, Part, SL, TR}
abundances::MPIGL
spplist::SL
abenv::Part
ordinariness::Union{Matrix{Float64}, Missing}
relationship::TR
lookup::Vector{EcoSISTEM.Lookup}
sppcounts::Vector{Int32}
firstsp::Int64
sccounts::Vector{Int32}
firstsc::Int64
cache::EcoSISTEM.Cache

function MPIEcosystem(abundances::MPIGL,
spplist::SL, abenv::Part,
ordinariness::Union{Matrix{Float64},
Missing},
relationship::TR,
lookup::Vector{EcoSISTEM.Lookup},
sppcounts::Vector,
firstsp::Int64,
sccounts::Vector,
firstsc::Int64,
cache::EcoSISTEM.Cache) where {MPIGL, Part, SL, TR}
EcoSISTEM.tematch(spplist, abenv) || error("Traits do not match habitats")
EcoSISTEM.trmatch(spplist, relationship) ||
error("Traits do not match trait functions")
#_mcmatch(abundances.matrix, spplist, abenv) ||
# error("Dimension mismatch")
return new{MPIGL, Part, SL, TR}(abundances, spplist, abenv,
ordinariness, relationship, lookup,
sppcounts, firstsp, sccounts, firstsc,
cache)
end
end

EcoSISTEM.MPIEcosystem(args...) = MPIEcosystem(args...)

using EcoSISTEM: getkernels, genlookups, numrequirements
"""
MPIEcosystem(spplist::SpeciesList, abenv::GridAbioticEnv,
rel::AbstractTraitRelationship)
Function to create an `MPIEcosystem` given a species list, an abiotic environment and trait relationship.
Function to create an `MPIEcosystem` given a species list, an abiotic
environment and trait relationship.
"""
function MPIEcosystem(popfun::F, spplist::SpeciesList{T, Req},
abenv::GridAbioticEnv,
rel::AbstractTraitRelationship) where
function MPIEcosystem(popfun::F, spplist::EcoSISTEM.SpeciesList{T, Req},
abenv::EcoSISTEM.GridAbioticEnv,
rel) where
{F <: Function, T, Req}
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
Expand All @@ -60,7 +91,7 @@ function MPIEcosystem(popfun::F, spplist::SpeciesList{T, Req},
firstsc = scindices[rank + 1] + 1

# Create matrix landscape of zero abundances
ml = emptyMPIgridlandscape(sppcounts, sccounts)
ml = EcoSISTEM.emptyMPIgridlandscape(sppcounts, sccounts)

# Populate this matrix with species abundances
popfun(ml, spplist, abenv, rel)
Expand All @@ -71,20 +102,22 @@ function MPIEcosystem(popfun::F, spplist::SpeciesList{T, Req},
nm = zeros(Int64, (sppcounts[rank + 1], numsc))
totalE = zeros(Float64, (numsc, numrequirements(Req)))
return MPIEcosystem(ml, spplist, abenv, missing, rel, lookup_tab, sppcounts,
firstsp, sccounts, firstsc, Cache(nm, totalE, false))
firstsp, sccounts, firstsc,
EcoSISTEM.Cache(nm, totalE, false))
end

function MPIEcosystem(spplist::SpeciesList, abenv::GridAbioticEnv,
rel::AbstractTraitRelationship)
return MPIEcosystem(populate!, spplist, abenv, rel)
function MPIEcosystem(spplist::EcoSISTEM.SpeciesList,
abenv::EcoSISTEM.GridAbioticEnv,
rel)
return MPIEcosystem(EcoSISTEM.populate!, spplist, abenv, rel)
end

"""
gather_abundance(eco::MPIEcosystem)
Gather full abundances matrix on root node.
"""
function gather_abundance(eco::MPIEcosystem)
function EcoSISTEM.gather_abundance(eco::MPIEcosystem)
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
true_abuns = zeros(Int64, counttypes(eco), countsubcommunities(eco))
Expand Down Expand Up @@ -143,8 +176,8 @@ function _calcordinariness(eco::MPIEcosystem)
relab
end

function gather_diversity(eco::MPIEcosystem, divmeasure::F,
q) where {F <: Function}
function EcoSISTEM.gather_diversity(eco::MPIEcosystem, divmeasure::F,
q) where {F <: Function}
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
totalsize = MPI.Comm_size(comm)
Expand Down
Loading

2 comments on commit eb9445e

@richardreeve
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104906

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" eb9445e7580c7c6f612ef5ca03c11655dde5a322
git push origin v0.2.1

Please sign in to comment.