Skip to content

Commit

Permalink
Merge pull request #45 from JuliaParallel/an/one
Browse files Browse the repository at this point in the history
Updates for Julia 1.0
  • Loading branch information
andreasnoack authored Oct 31, 2018
2 parents fc534b9 + 45b96a3 commit 0bd7be0
Show file tree
Hide file tree
Showing 39 changed files with 515 additions and 499 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ os:
- linux

julia:
- 0.6
- nightly
- 0.7
- 1.0
# - nightly

matrix:
allow_failures:
Expand Down Expand Up @@ -56,8 +57,9 @@ install:
- export CPU_CORES=2
- sh ./mpi.sh $MPI > /dev/null
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("Elemental")'
- while sleep 30; do tail ./deps/build.log -f ; done &
- julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("Elemental")'
- echo `ccache -s`

script:
- julia --check-bounds=yes -e 'Pkg.test("Elemental")'
- julia --check-bounds=yes -e 'using Pkg; Pkg.test("Elemental")'
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ The install script will build against any MPI installation that can be detected

### Simple example without MPI
```jl
julia> using Elemental
julia> using LinearAlgebra, Elemental

julia> A = Elemental.Matrix(Float64)
0x0 Elemental.Matrix{Float64}

julia> Elemental.gaussian!(A, 100, 80);

julia> U, s, V = Elemental.svd(A);
julia> U, s, V = svd(A);

julia> convert(Matrix{Float64}, s)[1:10]
10-element Array{Float64,1}:
Expand All @@ -46,7 +46,7 @@ julia> man = MPIManager(np = 4);

julia> addprocs(man);

julia> using Elemental
julia> using LinearAlgebra, Elemental

julia> @mpi_do man A = Elemental.DistMatrix(Float64);

Expand Down
5 changes: 2 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
julia 0.6
Compat 0.31.0
DistributedArrays 0.4.0
julia 0.7
DistributedArrays 0.5
17 changes: 9 additions & 8 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Libdl, LibGit2, LinearAlgebra

# Use this version of Elemental
Elsha = "79987d38b04838acf6b6195be1967177521ee908"

using Compat

if is_windows()
if Sys.iswindows()
error("Elemental only works on Unix Platforms")
end

Expand All @@ -26,12 +26,12 @@ cd(srcdir) do
LibGit2.checkout!(LibGit2.GitRepo("."), "$Elsha")
end

BLAS.check()
blas = BLAS.vendor()
mathlib = Libdl.dlpath(BLAS.libblas)
blas64 = LinAlg.USE_BLAS64 ? "ON" : "OFF"
LinearAlgebra.BLAS.check()
blas = LinearAlgebra.BLAS.vendor()
mathlib = Libdl.dlpath(LinearAlgebra.BLAS.libblas)
blas64 = LinearAlgebra.USE_BLAS64 ? "ON" : "OFF"
blas_suffix = blas === :openblas64 ? "_64_" : "_"
build_procs = (haskey(ENV, "CI") && ENV["CI"] == "true") ? 2 : Sys.CPU_CORES
build_procs = (haskey(ENV, "CI") && ENV["CI"] == "true") ? 2 : Sys.CPU_THREADS

builddir = joinpath(depdir, "builds")
if isdir(builddir)
Expand All @@ -54,3 +54,4 @@ cd(builddir) do
run(`make -j $build_procs`)
run(`make install`)
end
GC.gc() # work-around for https://github.com/JuliaLang/julia/issues/28306
26 changes: 13 additions & 13 deletions extras/elpp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ finalize() = icxx"El::Finalize();"
### ElementalMatrix ###
# Many of the definitions in Elemental are very similar which makes it easy to define methods for a common abstract type. However, we should be careful when calling into the library with e.g. @cxx or icxx because all leaf types might not implement the actual method.

@compat abstract type ElementalMatrix{T} <: AbstractMatrix{T} end
abstract type ElementalMatrix{T} <: AbstractMatrix{T} end

_getindex(A::ElementalMatrix, i::ElInt, j::ElInt) = icxx"$(A.buf).Get($i, $j);"
getindex(A::ElementalMatrix, i::Integer, j::Integer) = _getindex(A, ElInt(i - 1), ElInt(j - 1))
Expand Down Expand Up @@ -63,16 +63,16 @@ end
svdvals(A::ElementalMatrix) = svdvals!(copy(A))

### AbstractDistMatrix ###
@compat abstract type AbstractDistMatrix{T} <: ElementalMatrix{T} end
abstract type AbstractDistMatrix{T} <: ElementalMatrix{T} end

_resize!(A::AbstractDistMatrix, i::ElInt, j::ElInt) = icxx"$(A.buf).Resize($i, $j);"
resize!(A::AbstractDistMatrix, i::Integer, j::Integer) = _resize!(A, ElInt(i), ElInt(j))

_reserve(A::AbstractDistMatrix, n::ElInt) = icxx"$(A.buf).Reserve($n);"
reserve(A::AbstractDistMatrix, n::Integer) = _reserve(A, ElInt(n))

_queueUpdate{T}(A::AbstractDistMatrix{T}, i::ElInt, j::ElInt, x::T) = icxx"$(A.buf).QueueUpdate($i, $j, $x);"
queueUpdate{T}(A::AbstractDistMatrix{T}, i::Integer, j::Integer, x) = _queueUpdate(A, ElInt(i - 1), ElInt(j - 1), T(x))
_queueUpdate(A::AbstractDistMatrix{T}, i::ElInt, j::ElInt, x::T) where {T} = icxx"$(A.buf).QueueUpdate($i, $j, $x);"
queueUpdate(A::AbstractDistMatrix{T}, i::Integer, j::Integer, x) where {T} = _queueUpdate(A, ElInt(i - 1), ElInt(j - 1), T(x))

processQueues!(A::AbstractDistMatrix) = icxx"$(A.buf).ProcessQueues();"

Expand All @@ -81,7 +81,7 @@ zeros!(A::AbstractDistMatrix, m::Integer = size(A,1), n::Integer = size(A,2)) =

### Matrix ###

immutable Matrix{T} <: ElementalMatrix{T}
struct Matrix{T} <: ElementalMatrix{T}
# buf::Cxx.CppValue{Cxx.CxxQualType{Cxx.CppTemplate{Cxx.CppBaseType{symbol("El::Matrix")},Tuple{T}},(false,false,false)},56}
buf::Any
end
Expand All @@ -91,7 +91,7 @@ convert(::Type{Matrix{Float64}}, m::ElInt = 0, n::ElInt = 0) = Matrix{Float64}(i

_randn!(A::Matrix, i::ElInt, j::ElInt) = icxx"Gaussian($(A.buf), $i, $j);"

function svdvals!{T}(A::Matrix{T})
function LinearAlgebra.svdvals!(A::Matrix{T}) where {T}
s = Matrix{T}(min(size(A)...),1)
@cxx El::SVD(A.buf, s.buf)
return s
Expand All @@ -101,7 +101,7 @@ end

# DistMatrix

immutable DistMatrix{T,U,V} <: AbstractDistMatrix{T}
struct DistMatrix{T,U,V} <: AbstractDistMatrix{T}
# buf::Cxx.CppValue{Cxx.CxxQualType{Cxx.CppTemplate{Cxx.CppBaseType{symbol("El::DistMatrix")},Tuple{T,U,V,U}},(false,false,false)},144}
buf::Any
end
Expand All @@ -115,18 +115,18 @@ convert(::Type{Cxx.CppEnum{symbol("El::DistWrapNS::DistWrap")}}, x::Int) = Cxx.C

convert(::Type{DistMatrix{Float32,MC,MR}}, m::ElInt = 0, n::ElInt = 0) = DistMatrix{Float32,MC,MR}(icxx"El::DistMatrix<float,El::MC,El::MR>($m,$n);")
convert(::Type{DistMatrix{Float64,MC,MR}}, m::ElInt = 0, n::ElInt = 0) = DistMatrix{Float64,MC,MR}(icxx"El::DistMatrix<double,El::MC,El::MR>($m,$n);")
convert{T}(::Type{DistMatrix{T}}, m::ElInt = 0, n::ElInt = 0) = DistMatrix{T,MC,MR}(m, n)
convert(::Type{DistMatrix{T}}, m::ElInt = 0, n::ElInt = 0) where {T} = DistMatrix{T,MC,MR}(m, n)

_randn!(A::DistMatrix, i::ElInt, j::ElInt) = icxx"Gaussian($(A.buf), $i, $j);"

function svdvals!{T}(A::DistMatrix{T})
function LinearAlgebra.svdvals!(A::DistMatrix{T}) where {T}
s = DistMatrix{T}(min(size(A)...),1)
@cxx El::SVD(A.buf, s.buf)
return s
end

# DistSparseMatrix
immutable DistSparseMatrix{T} <: AbstractDistMatrix{T}
struct DistSparseMatrix{T} <: AbstractDistMatrix{T}
buf::Any
end

Expand All @@ -136,16 +136,16 @@ convert(::Type{DistSparseMatrix{Float64}}, m::ElInt = 0, n::ElInt = 0) = DistSpa
processLocalQueues!(A::DistSparseMatrix) = icxx"$(A.buf).ProcessLocalQueues();"

# DistMultiVec
immutable DistMultiVec{T} <: AbstractDistMatrix{T}
struct DistMultiVec{T} <: AbstractDistMatrix{T}
buf::Any
end

convert(::Type{DistMultiVec{ElInt}}, m::ElInt = 0, n::ElInt = 0) = DistMultiVec{ElInt}(icxx"El::DistMultiVec<El::Int>($m,$n);")
convert(::Type{DistMultiVec{Float32}}, m::ElInt = 0, n::ElInt = 0) = DistMultiVec{Float32}(icxx"El::DistMultiVec<float>($m,$n);")
convert(::Type{DistMultiVec{Float64}}, m::ElInt = 0, n::ElInt = 0) = DistMultiVec{Float64}(icxx"El::DistMultiVec<double>($m,$n);")

_setindex!{T}(A::DistMultiVec{T}, x::T, i::ElInt, j::ElInt) = icxx"$(A.buf).Set($i, $j, $x);"
setindex!{T}(A::DistMultiVec{T}, x, i::Integer, j::Integer) = _setindex!(A, T(x), ElInt(i - 1), ElInt(j - 1))
_setindex!(A::DistMultiVec{T}, x::T, i::ElInt, j::ElInt) where {T} = icxx"$(A.buf).Set($i, $j, $x);"
setindex!(A::DistMultiVec{T}, x, i::Integer, j::Integer) where {T} = _setindex!(A, T(x), ElInt(i - 1), ElInt(j - 1))


### SOCP ###
Expand Down
12 changes: 6 additions & 6 deletions src/Elemental.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module Elemental

using Compat
import Compat.String
using Distributed
using DistributedArrays
using LinearAlgebra

import Base: *, \, Ac_mul_B
import Base: convert, copy, copy!, countnz, dot, eltype, fill!, getindex, hcat, inv, length,
logdet, pointer, print, setindex!, showarray, similar, size
import Base.LinAlg: A_mul_B!, Ac_mul_B!, axpy!, norm, scale!, svd, svdvals, svdvals!
import Base: *, \
import Base: convert, copy, copy!, eltype, fill!, getindex, hcat, inv, length, pointer, print, setindex!, similar, size

const libEl = abspath(joinpath(dirname(@__FILE__), "..", "deps", "usr", "lib", "libEl"))

Expand All @@ -33,9 +31,11 @@ function Finalize()
end

function __init__()
# ccall(:jl_, Cvoid, (Any,), "starting up!")
Init()
DefaultGrid[] = Grid()
atexit() do
# ccall(:jl_, Cvoid, (Any,), "closing down!")
Initialized() && Finalize()
end
end
Expand Down
24 changes: 12 additions & 12 deletions src/blas_like/level1.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
for (elty, relty, ext) in ((:Float32, :Float32, :s),
(:Float64, :Float64, :d),
(:Complex64, :Float32, :c),
(:Complex128, :Float64, :z))
(:ComplexF32, :Float32, :c),
(:ComplexF64, :Float64, :z))
for (mat, sym) in ((:Matrix, "_"),
(:DistMatrix, "Dist_"),
(:DistMultiVec, "DistMultiVec_"))
@eval begin
function axpy!::$elty, x::$mat{$elty}, y::$mat{$elty})
function LinearAlgebra.axpy!::$elty, x::$mat{$elty}, y::$mat{$elty})
ElError(ccall(($(string("ElAxpy", sym, ext)), libEl), Cuint,
($elty, Ptr{Void}, Ptr{Void}),
($elty, Ptr{Cvoid}, Ptr{Cvoid}),
α, x.obj, y.obj))
return y
end

# Which is opposite Julia's copy! so we call it _copy! to avoid confusion
function _copy!(src::$mat{$elty}, dest::$mat{$elty})
ElError(ccall(($(string("ElCopy", sym, ext)), libEl), Cuint,
(Ptr{Void}, Ptr{Void}),
(Ptr{Cvoid}, Ptr{Cvoid}),
src.obj, dest.obj))
dest
end

function dot(x::$mat{$elty}, y::$mat{$elty})
function LinearAlgebra.dot(x::$mat{$elty}, y::$mat{$elty})
rval = Ref{$elty}(0)
ElError(ccall(($(string("ElDot", sym, ext)), libEl), Cuint,
(Ptr{Void}, Ptr{Void}, Ref{$elty}),
(Ptr{Cvoid}, Ptr{Cvoid}, Ref{$elty}),
x.obj, y.obj, rval))
return rval[]
end

function fill!(x::$mat{$elty}, val::Number)
ElError(ccall(($(string("ElFill", sym, ext)), libEl), Cuint,
(Ptr{Void}, $elty),
(Ptr{Cvoid}, $elty),
x.obj, $elty(val)))
return x
end
Expand All @@ -40,7 +40,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s),
# C := [A, B]
function hcat!(A::$mat{$elty}, B::$mat{$elty}, C::$mat{$elty})
ElError(ccall(($(string("ElHCat", sym, ext)), libEl), Cuint,
(Ptr{Void}, Ptr{Void}, Ptr{Void}),
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
A.obj, B.obj, C.obj))
return C
end
Expand All @@ -49,14 +49,14 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s),
function nrm2(x::$mat{$elty})
rval = Ref{$relty}(0)
ElError(ccall(($(string("ElNrm2", sym, ext)), libEl), Cuint,
(Ptr{Void}, Ref{$relty}),
(Ptr{Cvoid}, Ref{$relty}),
x.obj, rval))
return rval[]
end

function scale!(x::$mat{$elty}, val::Number)
ElError(ccall(($(string("ElScale", sym, ext)), libEl), Cuint,
(Ptr{Void}, $elty),
(Ptr{Cvoid}, $elty),
x.obj, $elty(val)))
return x
end
Expand All @@ -65,7 +65,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s),
# C := [A; B]
function vcat!(A::$mat{$elty}, B::$mat{$elty}, C::$mat{$elty})
ElError(ccall(($(string("ElVCat", sym, ext)), libEl), Cuint,
(Ptr{Void}, Ptr{Void}, Ptr{Void}),
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
A.obj, B.obj, C.obj))
return C
end
Expand Down
37 changes: 22 additions & 15 deletions src/blas_like/level2.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
for (elty, relty, ext) in ((:Float32, :Float32, :s),
(:Float64, :Float64, :d),
(:Complex64, :Float32, :c),
(:Complex128, :Float64, :z))
for (elty, ext) in ((:Float32, :s),
(:Float64, :d),
(:ComplexF32, :c),
(:ComplexF64, :z))

# Distributed sparse gemv
for (trans, elenum) in (("", :NORMAL), ("t", :TRANSPOSE), ("c", :ADJOINT))

f = Symbol("A", trans, "_mul_B!")

@eval begin
function ($f)(α::$elty, A::DistSparseMatrix{$elty}, x::DistMultiVec{$elty}, β::$elty, y::DistMultiVec{$elty})
ElError(ccall(($(string("ElMultiplyDist_", ext)), libEl), Cuint,
(Cint, $elty, Ptr{Void}, Ptr{Void}, $elty, Ptr{Void}),
$elenum, α, A.obj, x.obj, β, y.obj))
return y
end
@eval begin
function LinearAlgebra.mul!(y::DistMultiVec{$elty}, A::DistSparseMatrix{$elty}, x::DistMultiVec{$elty}, α::$elty, β::$elty)
ElError(ccall(($(string("ElMultiplyDist_", ext)), libEl), Cuint,
(Cint, $elty, Ptr{Cvoid}, Ptr{Cvoid}, $elty, Ptr{Cvoid}),
NORMAL, α, A.obj, x.obj, β, y.obj))
return y
end
function LinearAlgebra.mul!(y::DistMultiVec{$elty}, adjA::Adjoint{<:Any,DistSparseMatrix{$elty}}, x::DistMultiVec{$elty}, α::$elty, β::$elty)
ElError(ccall(($(string("ElMultiplyDist_", ext)), libEl), Cuint,
(Cint, $elty, Ptr{Cvoid}, Ptr{Cvoid}, $elty, Ptr{Cvoid}),
ADJOINT, α, parent(adjA).obj, x.obj, β, y.obj))
return y
end
function LinearAlgebra.mul!(y::DistMultiVec{$elty}, trA::Transpose{<:Any,DistSparseMatrix{$elty}}, x::DistMultiVec{$elty}, α::$elty, β::$elty)
ElError(ccall(($(string("ElMultiplyDist_", ext)), libEl), Cuint,
(Cint, $elty, Ptr{Cvoid}, Ptr{Cvoid}, $elty, Ptr{Cvoid}),
TRANSPOSE, α, parent(trA).obj, x.obj, β, y.obj))
return y
end
end
end
8 changes: 4 additions & 4 deletions src/blas_like/level3.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
for (elty, relty, ext) in ((:Float32, :Float32, :s),
(:Float64, :Float64, :d),
(:Complex64, :Float32, :c),
(:Complex128, :Float64, :z))
(:ComplexF32, :Float32, :c),
(:ComplexF64, :Float64, :z))

for (mat, sym) in ((:Matrix, "_"),
(:DistMatrix, "Dist_"))
Expand All @@ -10,15 +10,15 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s),

function gemm(orientationOfA::Orientation, orientationOfB::Orientation, α::$elty, A::$mat{$elty}, B::$mat{$elty}, β::$elty, C::$mat{$elty})
ElError(ccall(($(string("ElGemm", sym, ext)), libEl), Cuint,
(Orientation, Orientation, $elty, Ptr{Void}, Ptr{Void}, $elty, Ptr{Void}),
(Orientation, Orientation, $elty, Ptr{Cvoid}, Ptr{Cvoid}, $elty, Ptr{Cvoid}),
orientationOfA, orientationOfB, α, A.obj, B.obj, β, C.obj))
return C
end

function trsm(side::LeftOrRight, uplo::UpperOrLower, orientation::Orientation, diag::UnitOrNonUnit, α::$elty, A::$mat{$elty}, B::$mat{$elty})
ElError(ccall(($(string("ElTrsm", sym, ext)), libEl), Cuint,
(LeftOrRight, UpperOrLower, Orientation, UnitOrNonUnit,
$elty, Ptr{Void}, Ptr{Void}),
$elty, Ptr{Cvoid}, Ptr{Cvoid}),
side, uplo, orientation, diag,
α, A.obj, B.obj))
return B
Expand Down
Loading

0 comments on commit 0bd7be0

Please sign in to comment.