Skip to content

Commit

Permalink
Refactor JuliaPetra to support v0.7/1.0
Browse files Browse the repository at this point in the history
Note that backwards compatibility with 0.6 wasn't kept
  • Loading branch information
neil-lindquist committed Aug 21, 2018
1 parent 61398f9 commit 5e7b72a
Show file tree
Hide file tree
Showing 41 changed files with 667 additions and 624 deletions.
23 changes: 23 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = "JuliaPetra"
uuid = "8bcd7168-9f1b-11e8-152f-8b64b7efc5e0"
authors = ["Neil Lindquist <[email protected]>"]
version = "0.1.0"

[deps]
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
julia = "1222c4b2-2114-5bfd-aeef-88e4692bbb3e"
TypeStability = "73ec333a-e3df-5994-9c7a-5ef2077ce03e"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[compat]
MPI = "≥ 0.7.0"
TypeStability = "≥ 0.1.2"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"


[targets]
test = ["Test"]
2 changes: 0 additions & 2 deletions REQUIRE

This file was deleted.

24 changes: 12 additions & 12 deletions src/BasicDirectory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export BasicDirectory
Creates a BasicDirectory, which implements the methods of Directory with
basic implmentations
"""
type BasicDirectory{GID <: Integer, PID <:Integer, LID <: Integer} <: Directory{GID, PID, LID}
mutable struct BasicDirectory{GID <: Integer, PID <:Integer, LID <: Integer} <: Directory{GID, PID, LID}
map::BlockMap{GID, PID, LID}

directoryMap::Nullable{BlockMap}
directoryMap::Union{BlockMap, Nothing}

procList::Vector{PID}
procListLists::Vector{Vector{PID}}
Expand All @@ -21,7 +21,7 @@ type BasicDirectory{GID <: Integer, PID <:Integer, LID <: Integer} <: Directory{
function BasicDirectory{GID, PID, LID}(map::BlockMap{GID, PID, LID}) where {GID, PID, LID}

if !(distributedGlobal(map))
new(map, Nullable{BlockMap}(), [], [], numProc(getComm(map))!=1, [], [])
new(map, nothing, [], [], numProc(getComm(map))!=1, [], [])
elseif linearMap(map)
commObj = getComm(map)

Expand All @@ -30,10 +30,10 @@ type BasicDirectory{GID <: Integer, PID <:Integer, LID <: Integer} <: Directory{

entryOnMultipleProcs = length(Set(allMinGIDs)) != length(allMinGIDs)

new(map, Nullable{BlockMap}(), [], [], entryOnMultipleProcs, [], allMinGIDs)
new(map, nothing, [], [], entryOnMultipleProcs, [], allMinGIDs)
else
generateContent(
new(map, Nullable{BlockMap}(), [], [], false, [], []),
new(map, nothing, [], [], false, [], []),
map)
end
end
Expand All @@ -49,13 +49,13 @@ function generateContent(dir::BasicDirectory{GID, PID, LID}, map::BlockMap{GID,
dirNumGlobalElements = maxAllGID - minAllGID + 1

directoryMap = BlockMap(dirNumGlobalElements, minAllGID, commObj)
dir.directoryMap = Nullable(directoryMap)
dir.directoryMap = directoryMap

dirNumMyElements = numMyElements(dir.directoryMap)

if dirNumMyElements > 0
dir.procList = Array{PID}(dirNumMyElements)
dir.localIndexList = Array{LID}(dirNumMyElements)
dir.procList = Vector{PID}(undef, dirNumMyElements)
dir.localIndexList = Vector{LID}(undef, dirNumMyElements)

fill!(dir.procList, -1)
fill!(dir.localIndexList, -1)
Expand Down Expand Up @@ -91,8 +91,8 @@ function generateContent(dir::BasicDirectory{GID, PID, LID}, map::BlockMap{GID,
if dir.procList[currLID] != proc
if dir.procListLists == []
numProcLists = numMyElements(directoryMap)
procListLists = Array{Array{PID}}(numProcLists)
fill!(procListLists, [])
procListLists = Vector{Vector{PID}}(undef, numProcLists)
fill!(procListLists, PID[])
end

l = procListLists[currLID]
Expand Down Expand Up @@ -122,8 +122,8 @@ end
function getDirectoryEntries(directory::BasicDirectory{GID, PID, LID}, map::BlockMap{GID, PID, LID}, globalEntries::AbstractVector{GID},
high_rank_sharing_procs::Bool)::Tuple{Vector{PID}, Vector{LID}} where GID <: Integer where PID <: Integer where LID <: Integer
numEntries = length(globalEntries)
procs = Vector{PID}(numEntries)
localEntries = Vector{LID}(numEntries)
procs = Vector{PID}(undef, numEntries)
localEntries = Vector{LID}(undef, numEntries)

if !distributedGlobal(map)
myPIDVal = myPid(getComm(map))
Expand Down
58 changes: 29 additions & 29 deletions src/BlockMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ function BlockMap(numGlobalElements::GID, comm::Comm{GID, PID, LID}) where GID <
throw(InvalidArgumentError("NumGlobalElements = $(numGlobalElements). Should be >= 0"))
end

const data = BlockMapData(numGlobalElements, comm)
const map = BlockMap{GID, PID, LID}(data)
data = BlockMapData(numGlobalElements, comm)
map = BlockMap{GID, PID, LID}(data)

const numProcVal = numProc(comm)
numProcVal = numProc(comm)
data.linearMap = true

const myPIDVal = myPid(comm) - 1
myPIDVal = myPid(comm) - 1

data.numMyElements = floor(typeof(data.numGlobalElements),
data.numGlobalElements/numProcVal)
Expand Down Expand Up @@ -89,8 +89,8 @@ function BlockMap(numGlobalElements::GID, numMyElements::LID, comm::Comm{GID, PI
throw(InvalidArgumentError("NumMyElements = $(numMyElements). Should be >= 0"))
end

const data = BlockMapData(numGlobalElements, comm)
const map = BlockMap{GID, PID, LID}(data)
data = BlockMapData(numGlobalElements, comm)
map = BlockMap{GID, PID, LID}(data)

data.numMyElements = numMyElements
data.linearMap = true
Expand Down Expand Up @@ -141,8 +141,8 @@ function BlockMap(numGlobalElements::Integer, myGlobalElements::UnitRange{GID},

numMyElements = LID(length(myGlobalElements))

const data = BlockMapData(GID(0), comm)
const map = BlockMap{GID, PID, LID}(data)
data = BlockMapData(GID(0), comm)
map = BlockMap{GID, PID, LID}(data)

data.numMyElements = numMyElements

Expand All @@ -160,8 +160,8 @@ function BlockMap(numGlobalElements::Integer, myGlobalElements::UnitRange{GID},
data.maxAllGID = data.maxMyGID
else
tmp_send = [
-((data.numMyElements > 0)?
data.minMyGID:Inf)
-((data.numMyElements > 0) ?
data.minMyGID : Inf)
, data.maxMyGID]

tmp_recv = maxAll(data.comm, tmp_send)
Expand Down Expand Up @@ -206,14 +206,14 @@ function BlockMap(numGlobalElements::Integer, myGlobalElements::AbstractArray{GI
) where GID <: Integer where PID <: Integer where LID <: Integer
numMyElements = LID(length(myGlobalElements))

const data = BlockMapData(GID(0), comm)
const map = BlockMap{GID, PID, LID}(data)
data = BlockMapData(GID(0), comm)
map = BlockMap{GID, PID, LID}(data)

data.numMyElements = numMyElements

linear = 1
if numMyElements > 0
data.myGlobalElements = Array{GID, 1}(numMyElements)
data.myGlobalElements = Array{GID, 1}(undef, numMyElements)

data.myGlobalElements[1] = myGlobalElements[1]
data.minMyGID = myGlobalElements[1]
Expand Down Expand Up @@ -242,8 +242,8 @@ function BlockMap(numGlobalElements::Integer, myGlobalElements::AbstractArray{GI
data.maxAllGID = data.maxMyGID
else
tmp_send = [
-((data.numMyElements > 0)?
data.minMyGID:Inf)
-((data.numMyElements > 0) ?
data.minMyGID : Inf)
, data.maxMyGID]

tmp_recv = maxAll(data.comm, tmp_send)
Expand Down Expand Up @@ -309,14 +309,14 @@ function BlockMap(numGlobalElements::GID, numMyElements::LID,
throw(InvalidArgumentError("Minimum global element index = $(data.minAllGID). Should be >= 1"))
end

const data = BlockMapData(numGlobalElements, comm)
const map = BlockMap{GID, PID, LID}(data)
data = BlockMapData(numGlobalElements, comm)
map = BlockMap{GID, PID, LID}(data)

data.numMyElements = numMyElements

linear = 1
if numMyElements > 0
data.myGlobalElements = Array{GID}(numMyElements)
data.myGlobalElements = Vector{GID}(undef, numMyElements)

data.myGlobalElements[1] = myGlobalElements[1]
data.minMyGID = myGlobalElements[1]
Expand Down Expand Up @@ -397,7 +397,7 @@ function GlobalToLocalSetup(map::BlockMap)

val = myGlobalElements[1]
i = 1
for i = 1:numMyElements-1
while i < numMyElements
if val+1 != myGlobalElements[i+1]
break
end
Expand Down Expand Up @@ -489,7 +489,7 @@ function getLocalMap(map::BlockMap{GID, PID, LID})::BlockMap{GID, PID, LID} wher
oldData = map.data
data = BlockMapData(oldData.numGlobalElements, LocalComm(oldData.comm))

data.directory = Nullable{Directory}()
data.directory = nothing
data.lid = copy(oldData.lid)
#maps shouldn't be modified anyways, may as well share array
#data.myGlobalElements = copy(oldData.myGlobalElements)
Expand Down Expand Up @@ -524,17 +524,17 @@ The returned value is a tuple containing
"""
function remoteIDList(map::BlockMap{GID, PID, LID}, gidList::AbstractArray{<:Integer}
)::Tuple{AbstractArray{PID}, AbstractArray{LID}} where GID <: Integer where PID <: Integer where LID <: Integer
remoteIDList(map, Array{GID}(gidList))
remoteIDList(map, Vector{GID}(gidList))
end

function remoteIDList(map::BlockMap{GID, PID, LID}, gidList::AbstractArray{GID}
)::Tuple{AbstractArray{PID}, AbstractArray{LID}} where GID <: Integer where PID <: Integer where LID <: Integer
data = map.data
if isnull(data.directory)
if data.directory == nothing
data.directory = createDirectory(data.comm, map)
end

getDirectoryEntries(get(data.directory), map, gidList)
getDirectoryEntries(data.directory, map, gidList)
end


Expand Down Expand Up @@ -621,7 +621,7 @@ function myGlobalElements(map::BlockMap{GID})::AbstractArray{GID} where GID <: I
data = map.data

if length(data.myGlobalElements) == 0
myGlobalElements = Vector{GID}(data.numMyElements)
myGlobalElements = Vector{GID}(undef, data.numMyElements)
@inbounds for i = GID(1):GID(data.numMyElements)
myGlobalElements[i] = data.minMyGID + i - 1
end
Expand Down Expand Up @@ -661,8 +661,8 @@ sameBlockMapDataAs(this::BlockMap, other::BlockMap) = this.data == other.data
Return true if this and other are identical maps
"""
# behavior by specification
sameAs(this::BlockMap, other::BlockMap) = false
# behavior by specification

function sameAs(this::BlockMap{GID, PID, LID}, other::BlockMap{GID, PID, LID})::Bool where GID <: Integer where PID <: Integer where LID <: Integer
tData = this.data
Expand Down Expand Up @@ -721,7 +721,7 @@ function myGlobalElementIDs(map::BlockMap{GID})::AbstractArray{GID} where GID <:
data = map.data
if length(data.myGlobalElements) == 0
base = 0:data.numMyElements-1
rng = data.minMyGID + base
rng = data.minMyGID .+ base
collect(rng)
else
copy(data.myGlobalElements)
Expand All @@ -743,9 +743,9 @@ function determineIsOneToOne(map::BlockMap)::Bool
if numProc(data.comm) < 2
true
else
if isnull(data.directory)
data.directory = Nullable(createDirectory(data.comm, map))
if data.directory == nothing
data.directory = createDirectory(data.comm, map)
end
gidsAllUniquelyOwned(get(data.directory))
gidsAllUniquelyOwned(data.directory)
end
end
6 changes: 3 additions & 3 deletions src/BlockMapData.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Contains the data for a BlockMap
"""
type BlockMapData{GID <: Integer, PID <:Integer, LID <: Integer}
mutable struct BlockMapData{GID <: Integer, PID <:Integer, LID <: Integer}
comm::Comm{GID, PID, LID}
directory::Nullable{Directory}
directory::Union{Directory, Nothing}
lid::Vector{LID}
myGlobalElements::Vector{GID}
# firstPointInElementList::Array{Integer}
Expand Down Expand Up @@ -39,7 +39,7 @@ end
function BlockMapData(numGlobalElements::GID, comm::Comm{GID, PID, LID}) where GID <: Integer where PID <: Integer where LID <: Integer
BlockMapData(
comm,
Nullable{Directory}(),
nothing,
LID[],
GID[],

Expand Down
Loading

0 comments on commit 5e7b72a

Please sign in to comment.