Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move MPI structs into extension #136

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <claire.harris@bioss.ac.uk>", "Richard Reeve <Richard.Reeve@glasgow.ac.uk>"]
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 @@
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 @@
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 @@
relab
end

function gather_diversity(eco::MPIEcosystem, divmeasure::F,
q) where {F <: Function}
function EcoSISTEM.gather_diversity(eco::MPIEcosystem, divmeasure::F,

Check warning on line 179 in src/MPIEcosystem.jl

View check run for this annotation

Codecov / codecov/patch

src/MPIEcosystem.jl#L179

Added line #L179 was not covered by tests
q) where {F <: Function}
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
totalsize = MPI.Comm_size(comm)
Expand Down
Loading
Loading