diff --git a/.travis.yml b/.travis.yml index 71507f4..b312f6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,9 @@ os: - linux julia: - - 0.6 - - nightly + - 0.7 + - 1.0 + # - nightly matrix: allow_failures: @@ -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")' diff --git a/README.md b/README.md index d5c71da..9fe8e09 100644 --- a/README.md +++ b/README.md @@ -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}: @@ -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); diff --git a/REQUIRE b/REQUIRE index e135f43..98c6509 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,2 @@ -julia 0.6 -Compat 0.31.0 -DistributedArrays 0.4.0 +julia 0.7 +DistributedArrays 0.5 diff --git a/deps/build.jl b/deps/build.jl index 0e48f82..d2c3e62 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -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 @@ -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) @@ -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 diff --git a/extras/elpp.jl b/extras/elpp.jl index bd1efe6..9164573 100644 --- a/extras/elpp.jl +++ b/extras/elpp.jl @@ -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)) @@ -63,7 +63,7 @@ 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)) @@ -71,8 +71,8 @@ resize!(A::AbstractDistMatrix, i::Integer, j::Integer) = _resize!(A, ElInt(i), E _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();" @@ -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 @@ -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 @@ -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 @@ -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($m,$n);") convert(::Type{DistMatrix{Float64,MC,MR}}, m::ElInt = 0, n::ElInt = 0) = DistMatrix{Float64,MC,MR}(icxx"El::DistMatrix($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 @@ -136,7 +136,7 @@ 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 @@ -144,8 +144,8 @@ convert(::Type{DistMultiVec{ElInt}}, m::ElInt = 0, n::ElInt = 0) = DistMultiVec{ convert(::Type{DistMultiVec{Float32}}, m::ElInt = 0, n::ElInt = 0) = DistMultiVec{Float32}(icxx"El::DistMultiVec($m,$n);") convert(::Type{DistMultiVec{Float64}}, m::ElInt = 0, n::ElInt = 0) = DistMultiVec{Float64}(icxx"El::DistMultiVec($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 ### diff --git a/src/Elemental.jl b/src/Elemental.jl index ebce364..fcc72fc 100644 --- a/src/Elemental.jl +++ b/src/Elemental.jl @@ -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")) @@ -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 diff --git a/src/blas_like/level1.jl b/src/blas_like/level1.jl index 7301419..97bbff5 100644 --- a/src/blas_like/level1.jl +++ b/src/blas_like/level1.jl @@ -1,14 +1,14 @@ 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 @@ -16,22 +16,22 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), # 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 @@ -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 @@ -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 @@ -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 diff --git a/src/blas_like/level2.jl b/src/blas_like/level2.jl index 074fc64..2defea3 100644 --- a/src/blas_like/level2.jl +++ b/src/blas_like/level2.jl @@ -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 \ No newline at end of file diff --git a/src/blas_like/level3.jl b/src/blas_like/level3.jl index c3f3d28..932f983 100644 --- a/src/blas_like/level3.jl +++ b/src/blas_like/level3.jl @@ -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_")) @@ -10,7 +10,7 @@ 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 @@ -18,7 +18,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), 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 diff --git a/src/core/distmatrix.jl b/src/core/distmatrix.jl index 0731a12..92b3879 100644 --- a/src/core/distmatrix.jl +++ b/src/core/distmatrix.jl @@ -1,29 +1,29 @@ -type DistMatrix{T} <: ElementalMatrix{T} - obj::Ptr{Void} +mutable struct DistMatrix{T} <: ElementalMatrix{T} + obj::Ptr{Cvoid} g::Grid # keep the grid around to avoid that it's freed before the matrix end for (elty, ext) in ((:ElInt, :i), (:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) @eval begin # destructor to be used in finalizer. Don't call explicitly function destroy(A::DistMatrix{$elty}) ElError(ccall(($(string("ElDistMatrixDestroy_", ext)), libEl), Cuint, - (Ptr{Void},), A.obj)) + (Ptr{Cvoid},), A.obj)) return nothing end function DistMatrix(::Type{$elty}, colDist::Dist = MC, rowDist::Dist = MR, grid::Grid = DefaultGrid[]) - obj = Ref{Ptr{Void}}(C_NULL) + obj = Ref{Ptr{Cvoid}}(C_NULL) ElError(ccall(($(string("ElDistMatrixCreateSpecific_", ext)), libEl), Cuint, - (Cint, Cint, Ptr{Void}, Ref{Ptr{Void}}), + (Cint, Cint, Ptr{Cvoid}, Ref{Ptr{Cvoid}}), colDist, rowDist, grid.obj, obj)) A = DistMatrix{$elty}(obj[], grid) - finalizer(A, destroy) + finalizer(destroy, A) return A end @@ -31,15 +31,15 @@ for (elty, ext) in ((:ElInt, :i), # function Grid(A::DistMatrix{$elty}) # g = Grid() # ElError(ccall(($(string("ElDistMatrixGrid_", ext)), libEl), Cuint, - # (Ptr{Void}, Ref{Ptr{Void}}), - # A.obj, Ref{Ptr{Void}}(g.obj))) + # (Ptr{Cvoid}, Ref{Ptr{Cvoid}}), + # A.obj, Ref{Ptr{Cvoid}}(g.obj))) # return g # end function comm(A::DistMatrix{$elty}) cm = Ref{ElComm}() ElError(ccall(($(string("ElDistMatrixDistComm_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElComm}), + (Ptr{Cvoid}, Ref{ElComm}), A.obj, cm)) return cm[] end @@ -47,7 +47,7 @@ for (elty, ext) in ((:ElInt, :i), function get(A::DistMatrix{$elty}, i::Integer, j::Integer) rv = Ref{$elty}(0) ElError(ccall(($(string("ElDistMatrixGet_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, Ref{$elty}), + (Ptr{Cvoid}, ElInt, ElInt, Ref{$elty}), A.obj, i - 1, j - 1, rv)) return rv[] end @@ -55,7 +55,7 @@ for (elty, ext) in ((:ElInt, :i), function getLocal(A::DistMatrix{$elty}, i::Integer, j::Integer) rv = Ref{$elty}(0) ElError(ccall(($(string("ElDistMatrixGetLocal_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, Ref{$elty}), + (Ptr{Cvoid}, ElInt, ElInt, Ref{$elty}), A.obj, i - 1, j - 1, rv)) return rv[] end @@ -63,7 +63,7 @@ for (elty, ext) in ((:ElInt, :i), function globalCol(A::DistMatrix{$elty}, i::Integer) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMatrixGlobalCol_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, Ref{ElInt}), + (Ptr{Cvoid}, ElInt, Ref{ElInt}), A.obj, i - 1, rv)) return rv[] + 1 end @@ -71,7 +71,7 @@ for (elty, ext) in ((:ElInt, :i), function globalRow(A::DistMatrix{$elty}, i::Integer) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMatrixGlobalRow_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, Ref{ElInt}), + (Ptr{Cvoid}, ElInt, Ref{ElInt}), A.obj, i - 1, rv)) return rv[] + 1 end @@ -79,7 +79,7 @@ for (elty, ext) in ((:ElInt, :i), function height(A::DistMatrix{$elty}) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMatrixHeight_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rv)) return rv[] end @@ -87,7 +87,7 @@ for (elty, ext) in ((:ElInt, :i), function localHeight(A::DistMatrix{$elty}) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMatrixLocalHeight_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rv)) return rv[] end @@ -95,41 +95,41 @@ for (elty, ext) in ((:ElInt, :i), function localWidth(A::DistMatrix{$elty}) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMatrixLocalWidth_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rv)) return rv[] end function processPullQueue(A::DistMatrix{$elty}, buf::Array{$elty,2}) ElError(ccall(($(string("ElDistMatrixProcessPullQueue_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{$elty}), + (Ptr{Cvoid}, Ptr{$elty}), A.obj, buf)) return buf end function processQueues(A::DistMatrix{$elty}) ElError(ccall(($(string("ElDistMatrixProcessQueues_", ext)), libEl), Cuint, - (Ptr{Void},), A.obj)) + (Ptr{Cvoid},), A.obj)) return A end function queuePull(A::DistMatrix{$elty}, i::Integer, j::Integer) ElError(ccall(($(string("ElDistMatrixQueuePull_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, i - 1, j - 1)) return nothing end function queueUpdate(A::DistMatrix{$elty}, i::Integer, j::Integer, value::$elty) ElError(ccall(($(string("ElDistMatrixQueueUpdate_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty), + (Ptr{Cvoid}, ElInt, ElInt, $elty), A.obj, i - 1, j - 1, value)) return nothing end function reserve(A::DistMatrix{$elty}, numEntries::Integer) ElError(ccall(($(string("ElDistMatrixReserve_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt), + (Ptr{Cvoid}, ElInt), A.obj, numEntries)) return nothing end @@ -137,14 +137,14 @@ for (elty, ext) in ((:ElInt, :i), function width(A::DistMatrix{$elty}) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMatrixWidth_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rv)) return rv[] end function resize!(A::DistMatrix{$elty}, i::Integer, j::Integer = 1) # to mimic vector behavior ElError(ccall(($(string("ElDistMatrixResize_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, i, j)) return A end @@ -156,13 +156,12 @@ DistMatrix() = DistMatrix(Float64) ######################### ### Julia convenience ### ######################### -countnz(A::DistMatrix) = length(A) # Do I want to provide this function? It's an invitation to be slow getindex(A::DistMatrix, i::Integer, j::Integer) = get(A, i, j) # This might be wrong. Should consider how to extract distributions properties of A -function similar{T}(::DistMatrix, ::Type{T}, sz::Dims) +function similar(::DistMatrix, ::Type{T}, sz::Dims) where {T} A = DistMatrix(T) resize!(A, sz...) return A @@ -181,7 +180,7 @@ function getindex(A::DistMatrix, iInd::Colon, jInd::UnitRange) end # FixMe! Should this one handle vectors of matrices? -function hcat{T}(x::Vector{DistMatrix{T}}) +function hcat(x::Vector{DistMatrix{T}}) where {T} l = length(x) if l == 0 throw(ArgumentError("cannot flatten empty vector")) diff --git a/src/core/distmultivec.jl b/src/core/distmultivec.jl index 1dcc032..a97e2c7 100644 --- a/src/core/distmultivec.jl +++ b/src/core/distmultivec.jl @@ -1,35 +1,35 @@ -type DistMultiVec{T} <: ElementalMatrix{T} - obj::Ptr{Void} +mutable struct DistMultiVec{T} <: ElementalMatrix{T} + obj::Ptr{Cvoid} end for (elty, ext) in ((:ElInt, :i), (:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) @eval begin # destructor to be used in finalizer. Don't call explicitly function destroy(A::DistMultiVec{$elty}) ElError(ccall(($(string("ElDistMultiVecDestroy_", ext)), libEl), Cuint, - (Ptr{Void},), A.obj)) + (Ptr{Cvoid},), A.obj)) return nothing end - function DistMultiVec(::Type{$elty}, cm::ElComm = CommWorld) - obj = Ref{Ptr{Void}}(C_NULL) + function DistMultiVec(::Type{$elty}, cm::ElComm = MPI.CommWorld[]) + obj = Ref{Ptr{Cvoid}}(C_NULL) ElError(ccall(($(string("ElDistMultiVecCreate_", ext)), libEl), Cuint, - (Ref{Ptr{Void}}, ElComm), + (Ref{Ptr{Cvoid}}, ElComm), obj, cm)) A = DistMultiVec{$elty}(obj[]) - finalizer(A, destroy) + finalizer(destroy, A) return A end function comm(A::DistMultiVec{$elty}) cm = Ref{ElComm}() ElError(ccall(($(string("ElDistMultiVecComm_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElComm}), + (Ptr{Cvoid}, Ref{ElComm}), A.obj, cm)) return cm[] end @@ -37,7 +37,7 @@ for (elty, ext) in ((:ElInt, :i), function get(x::DistMultiVec{$elty}, i::Integer = size(x, 1), j::Integer = 1) v = Ref{$elty}() ElError(ccall(($(string("ElDistMultiVecGet_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, Ref{$elty}), + (Ptr{Cvoid}, ElInt, ElInt, Ref{$elty}), x.obj, i - 1, j - 1, v)) return v[] end @@ -45,7 +45,7 @@ for (elty, ext) in ((:ElInt, :i), function getLocal(A::DistMultiVec{$elty}, i::Integer, j::Integer) rv = Ref{$elty}(0) ElError(ccall(($(string("ElDistMultiVecGetLocal_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, Ref{$elty}), + (Ptr{Cvoid}, ElInt, ElInt, Ref{$elty}), A.obj, i - 1, j - 1, rv)) return rv[] end @@ -53,7 +53,7 @@ for (elty, ext) in ((:ElInt, :i), function globalRow(A::DistMultiVec{$elty}, i::Integer) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMultiVecGlobalRow_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, Ref{ElInt}), + (Ptr{Cvoid}, ElInt, Ref{ElInt}), A.obj, i - 1, rv)) return rv[] + 1 end @@ -61,7 +61,7 @@ for (elty, ext) in ((:ElInt, :i), function height(x::DistMultiVec{$elty}) i = Ref{ElInt}() ElError(ccall(($(string("ElDistMultiVecHeight_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), x.obj, i)) return i[] end @@ -69,34 +69,34 @@ for (elty, ext) in ((:ElInt, :i), function localHeight(A::DistMultiVec{$elty}) rv = Ref{ElInt}(0) ElError(ccall(($(string("ElDistMultiVecLocalHeight_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rv)) return rv[] end function processQueues(A::DistMultiVec{$elty}) ElError(ccall(($(string("ElDistMultiVecProcessQueues_", ext)), libEl), Cuint, - (Ptr{Void},), A.obj)) + (Ptr{Cvoid},), A.obj)) return nothing end function queueUpdate(A::DistMultiVec{$elty}, i::Integer, j::Integer, value::$elty) ElError(ccall(($(string("ElDistMultiVecQueueUpdate_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty), + (Ptr{Cvoid}, ElInt, ElInt, $elty), A.obj, i - 1, j - 1, value)) return nothing end function reserve(A::DistMultiVec{$elty}, numEntries::Integer) ElError(ccall(($(string("ElDistMultiVecReserve_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt), + (Ptr{Cvoid}, ElInt), A.obj, numEntries)) return nothing end function resize!(A::DistMultiVec{$elty}, m::Integer, n::Integer = 1) # to mimic vector behavior ElError(ccall(($(string("ElDistMultiVecResize_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, ElInt(m), ElInt(n))) return A end @@ -104,7 +104,7 @@ for (elty, ext) in ((:ElInt, :i), function width(x::DistMultiVec{$elty}) i = Ref{ElInt}() ElError(ccall(($(string("ElDistMultiVecWidth_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), x.obj, i)) return i[] end @@ -117,14 +117,14 @@ end getindex(x::DistMultiVec, i, j) = get(x, i, j) -function similar{T}(::DistMultiVec, ::Type{T}, sz::Dims, cm::ElComm = CommWorld) +function similar(::DistMultiVec, ::Type{T}, sz::Dims, cm::ElComm = MPI.CommWorld[]) where {T} A = DistMultiVec(T, cm) resize!(A, sz...) return A end # FixMe! Should this one handle vectors of matrices? -function hcat{T}(x::Vector{DistMultiVec{T}}) +function hcat(x::Vector{DistMultiVec{T}}) where {T} l = length(x) if l == 0 throw(ArgumentError("cannot flatten empty vector")) diff --git a/src/core/distsparsematrix.jl b/src/core/distsparsematrix.jl index 04b562a..131b210 100644 --- a/src/core/distsparsematrix.jl +++ b/src/core/distsparsematrix.jl @@ -1,35 +1,35 @@ -type DistSparseMatrix{T} <: ElementalMatrix{T} - obj::Ptr{Void} +mutable struct DistSparseMatrix{T} <: ElementalMatrix{T} + obj::Ptr{Cvoid} end for (elty, ext) in ((:ElInt, :i), (:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) @eval begin # destructor to be used in finalizer. Don't call explicitly function destroy(A::DistSparseMatrix{$elty}) ElError(ccall(($(string("ElDistSparseMatrixDestroy_", ext)), libEl), Cuint, - (Ptr{Void},), A.obj)) + (Ptr{Cvoid},), A.obj)) return nothing end - function DistSparseMatrix(::Type{$elty}, comm::ElComm = CommWorld) - obj = Ref{Ptr{Void}}(C_NULL) + function DistSparseMatrix(::Type{$elty}, comm::ElComm = MPI.CommWorld[]) + obj = Ref{Ptr{Cvoid}}(C_NULL) ElError(ccall(($(string("ElDistSparseMatrixCreate_", ext)), libEl), Cuint, - (Ref{Ptr{Void}}, ElComm), + (Ref{Ptr{Cvoid}}, ElComm), obj, comm)) A = DistSparseMatrix{$elty}(obj[]) - finalizer(A, destroy) + finalizer(destroy, A) return A end function comm(A::DistSparseMatrix{$elty}) cm = Ref{ElComm}() ElError(ccall(($(string("ElDistSparseMatrixComm_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElComm}), + (Ptr{Cvoid}, Ref{ElComm}), A.obj, cm)) return cm[] end @@ -37,7 +37,7 @@ for (elty, ext) in ((:ElInt, :i), function globalRow(A::DistSparseMatrix{$elty}, iLoc::Integer) i = Ref{ElInt}(0) ElError(ccall(($(string("ElDistSparseMatrixGlobalRow_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, Ref{ElInt}), + (Ptr{Cvoid}, ElInt, Ref{ElInt}), A.obj, iLoc-1, i)) return i[]+1 end @@ -45,7 +45,7 @@ for (elty, ext) in ((:ElInt, :i), function height(A::DistSparseMatrix{$elty}) i = Ref{ElInt}(0) ElError(ccall(($(string("ElDistSparseMatrixHeight_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, i)) return i[] end @@ -53,7 +53,7 @@ for (elty, ext) in ((:ElInt, :i), function localHeight(A::DistSparseMatrix{$elty}) i = Ref{ElInt}(0) ElError(ccall(($(string("ElDistSparseMatrixLocalHeight_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, i)) return i[] end @@ -61,42 +61,42 @@ for (elty, ext) in ((:ElInt, :i), function numLocalEntries(A::DistSparseMatrix{$elty}) n = Ref{ElInt}(0) ElError(ccall(($(string("ElDistSparseMatrixNumLocalEntries_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, n)) return n[] end function processQueues(A::DistSparseMatrix{$elty}) ElError(ccall(($(string("ElDistSparseMatrixProcessQueues_", ext)), libEl), Cuint, - (Ptr{Void},), + (Ptr{Cvoid},), A.obj)) return nothing end function queueLocalUpdate(A::DistSparseMatrix{$elty}, localRow::Integer, col::Integer, value::$elty) ElError(ccall(($(string("ElDistSparseMatrixQueueLocalUpdate_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty), + (Ptr{Cvoid}, ElInt, ElInt, $elty), A.obj, localRow-1, col-1, value)) return nothing end function queueUpdate(A::DistSparseMatrix{$elty}, row::Integer, col::Integer, value::$elty, passive::Bool = true) ElError(ccall(($(string("ElDistSparseMatrixQueueUpdate_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty, Bool), + (Ptr{Cvoid}, ElInt, ElInt, $elty, Bool), A.obj, row-1, col-1, value, passive)) return nothing end function reserve(A::DistSparseMatrix{$elty}, numLocalEntries::Integer, numRemoteEntries::Integer = 0) ElError(ccall(($(string("ElDistSparseMatrixReserve_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, numLocalEntries, numRemoteEntries)) return nothing end function resize!(A::DistSparseMatrix{$elty}, height::Integer, width::Integer = 1) # to mimic vector behavior ElError(ccall(($(string("ElDistSparseMatrixResize_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, height, width)) return A end @@ -104,7 +104,7 @@ for (elty, ext) in ((:ElInt, :i), function width(A::DistSparseMatrix{$elty}) i = Ref{ElInt}(0) ElError(ccall(($(string("ElDistSparseMatrixWidth_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, i)) return i[] end @@ -112,7 +112,7 @@ for (elty, ext) in ((:ElInt, :i), end # The other constructors don't have a version with dimensions. Should they, or should this one go? -function DistSparseMatrix{T}(::Type{T}, m::Integer, n::Integer, comm::ElComm = CommWorld) +function DistSparseMatrix(::Type{T}, m::Integer, n::Integer, comm::ElComm = MPI.CommWorld[]) where {T} A = DistSparseMatrix(T, comm) resize!(A, m, n) return A @@ -120,8 +120,6 @@ end # Julia convenience -countnz(A::DistSparseMatrix) = MPI.allreduce(Cint(numLocalEntries(A)), +, comm(A)) - -function showarray(io::IO, A::DistSparseMatrix; kwargs...) +function Base.show(io::IO, ::MIME"text/plain", A::DistSparseMatrix) print(io, "$(size(A, 1))x$(size(A, 2)) $(typeof(A))") end diff --git a/src/core/grid.jl b/src/core/grid.jl index b3c1253..6d0040f 100644 --- a/src/core/grid.jl +++ b/src/core/grid.jl @@ -1,20 +1,20 @@ -type Grid - obj::Ptr{Void} +mutable struct Grid + obj::Ptr{Cvoid} end # destructor to be used in finalizer. Don't call explicitly function destroy(G::Grid) ElError(ccall(("ElGridDestroy", libEl), Cuint, - (Ptr{Void},), G.obj)) + (Ptr{Cvoid},), G.obj)) return nothing end # Returns the default Grid. The default grid is finalized when Elemental is finalized # so we shouldn't register a `destroy` as finalizer. function Grid() - obj = Ref{Ptr{Void}}(C_NULL) + obj = Ref{Ptr{Cvoid}}(C_NULL) ElError(ccall(("ElDefaultGrid", libEl), Cuint, - (Ref{Ptr{Void}},), obj)) + (Ref{Ptr{Cvoid}},), obj)) return Grid(obj[]) end diff --git a/src/core/matrix.jl b/src/core/matrix.jl index b16b666..da52534 100644 --- a/src/core/matrix.jl +++ b/src/core/matrix.jl @@ -1,41 +1,41 @@ -type Matrix{T} <: ElementalMatrix{T} - obj::Ptr{Void} +mutable struct Matrix{T} <: ElementalMatrix{T} + obj::Ptr{Cvoid} end for (elty, ext) in ((:ElInt, :i), (:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) @eval begin # destructor to be used in finalizer. Don't call explicitly function destroy(A::Matrix{$elty}) ElError(ccall(($(string("ElMatrixDestroy_", ext)), libEl), Cuint, - (Ptr{Void},), A.obj)) + (Ptr{Cvoid},), A.obj)) return nothing end function Matrix(::Type{$elty}) - obj = Ref{Ptr{Void}}(0) + obj = Ref{Ptr{Cvoid}}(0) ElError(ccall(($(string("ElMatrixCreate_", ext)), libEl), Cuint, - (Ref{Ptr{Void}},), obj)) + (Ref{Ptr{Cvoid}},), obj)) A = Matrix{$elty}(obj[]) - finalizer(A, destroy) + finalizer(destroy, A) return A end function getindex(A::Matrix{$elty}, i::Integer, j::Integer) x = Ref{$elty}(0) ElError(ccall(($(string("ElMatrixGet_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, Ref{$elty}), + (Ptr{Cvoid}, ElInt, ElInt, Ref{$elty}), A.obj, i - 1, j - 1, x)) return x[] end function resize!(A::Matrix{$elty}, i::Integer, j::Integer = 1) # to mimic vector behavior ElError(ccall(($(string("ElMatrixResize_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, i, j)) return A end @@ -43,7 +43,7 @@ for (elty, ext) in ((:ElInt, :i), function height(A::Matrix{$elty}) rs = Ref{ElInt}(0) ElError(ccall(($(string("ElMatrixHeight_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rs)) return rs[] end @@ -51,7 +51,7 @@ for (elty, ext) in ((:ElInt, :i), function width(A::Matrix{$elty}) rs = Ref{ElInt}(0) ElError(ccall(($(string("ElMatrixWidth_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rs)) return rs[] end @@ -59,14 +59,14 @@ for (elty, ext) in ((:ElInt, :i), function lockedBuffer(A::Matrix{$elty}) rp = Ref{Ptr{$elty}}(0) ElError(ccall(($(string("ElMatrixLockedBuffer_", ext)), libEl), Cuint, - (Ptr{Void}, Ref{Ptr{$elty}}), + (Ptr{Cvoid}, Ref{Ptr{$elty}}), A.obj, rp)) return rp[] end function setindex!(A::Matrix{$elty}, x::Number, i::Integer, j::Integer) ElError(ccall(($(string("ElMatrixSet_", ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty), + (Ptr{Cvoid}, ElInt, ElInt, $elty), A.obj, i - 1, j - 1, x)) return A end @@ -79,10 +79,8 @@ Matrix() = Matrix(Float64) pointer(A::Matrix) = lockedBuffer(A) -function similar{T}(::Matrix, ::Type{T}, sz::Dims) +function similar(::Matrix, ::Type{T}, sz::Dims) where {T} A = Matrix(T) resize!(A, sz...) return A end - -countnz(A::Matrix) = length(A) diff --git a/src/core/sparsematrix.jl b/src/core/sparsematrix.jl index 6d75bea..174082c 100644 --- a/src/core/sparsematrix.jl +++ b/src/core/sparsematrix.jl @@ -1,3 +1,3 @@ -type SparseMatrix{T} <: AbstractMatrix{T} - obj::Ptr{Void} +mutable struct SparseMatrix{T} <: AbstractMatrix{T} + obj::Ptr{Cvoid} end \ No newline at end of file diff --git a/src/core/types.jl b/src/core/types.jl index d9fc332..dd3aec9 100644 --- a/src/core/types.jl +++ b/src/core/types.jl @@ -10,7 +10,7 @@ function ElCommType() sameSizeAsInt = Cint[0] ElError(ccall((:ElMPICommSameSizeAsInteger, libEl), Cuint, (Ptr{Cint},), sameSizeAsInt)) - return sameSizeAsInt[1] == 1 ? Cint : Ptr{Void} + return sameSizeAsInt[1] == 1 ? Cint : Ptr{Cvoid} end const ElComm = ElCommType() @@ -18,7 +18,7 @@ function ElGroupType() sameSizeAsInt = Cint[0] ElError(ccall((:ElMPIGroupSameSizeAsInteger, libEl), Cuint, (Ptr{Cint},), sameSizeAsInt)) - return sameSizeAsInt[1] == 1 ? Cint : Ptr{Void} + return sameSizeAsInt[1] == 1 ? Cint : Ptr{Cvoid} end const ElGroup = ElGroupType() @@ -43,14 +43,14 @@ function ElBool(value::Bool) end end -using Base.LinAlg: BlasFloat, BlasReal, BlasComplex +using LinearAlgebra: BlasFloat, BlasReal, BlasComplex -const ElElementType = Union{ElInt,Float32,Float64,Complex64,Complex128} +const ElElementType = Union{ElInt,Float32,Float64,ComplexF32,ComplexF64} const ElFloatType = Union{Float32,Float64} # TODO: Maybe just use BlasReal here -@compat abstract type ElementalMatrix{T} <: AbstractMatrix{T} end -eltype{T}(A::ElementalMatrix{T}) = T +abstract type ElementalMatrix{T} <: AbstractMatrix{T} end +eltype(A::ElementalMatrix{T}) where {T} = T # Error is handled in error.jl as an Exception @@ -61,11 +61,3 @@ eltype{T}(A::ElementalMatrix{T}) = T @enum LeftOrRight LEFT RIGHT @enum UnitOrNonUnit NON_UNIT UNIT @enum Pencil AXBX=1 ABX=2 BAX=3 - -# Get MPIWorldComm -function CommWorldValue() - r = Ref{ElComm}(0) - ccall((:ElMPICommWorld, libEl), Cuint, (Ref{ElComm},), r) - return r[] -end -const CommWorld = CommWorldValue() diff --git a/src/io.jl b/src/io.jl index 579a1ce..cc0cd4e 100644 --- a/src/io.jl +++ b/src/io.jl @@ -2,20 +2,20 @@ for (elty, ext) in ((:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) for mattype in ("", "Dist") mat = Symbol(mattype, "Matrix") @eval begin function print(A::$mat{$elty}, title::String) ElError(ccall(($(string("ElPrint", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{UInt8}), + (Ptr{Cvoid}, Ptr{UInt8}), A.obj, title)) end function write(A::$mat{$elty}, basename::String, format::FileFormat, title::String) ElError(ccall(($(string("ElWrite", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{UInt8}, FileFormat, Ptr{UInt8}), + (Ptr{Cvoid}, Ptr{UInt8}, FileFormat, Ptr{UInt8}), A.obj, basename, format, title)) end end diff --git a/src/julia/darray.jl b/src/julia/darray.jl index 85d9505..6f6262a 100644 --- a/src/julia/darray.jl +++ b/src/julia/darray.jl @@ -1,21 +1,23 @@ # FixMe! Right now the MPI workers are deduced from the DArrays, but if a DArray is distributed on fewer workers that what consistutes the MPI world, then this approach will fail. -type RemoteElementalMatrix +using DistributedArrays: procs + +mutable struct RemoteElementalMatrix refs::Matrix{Any} end -function toback{T<:BlasFloat,S<:StridedMatrix}(A::DArray{T,2,S}) - rs = Array{Any}(size(procs(A))) +function toback(A::DArray{T,2,S}) where {T<:BlasFloat,S<:StridedMatrix} + rs = Array{Any}(undef, size(procs(A))) @sync for p in eachindex(procs(A)) - ind = A.indexes[p] + ind = A.indices[p] @async rs[p] = remotecall(procs(A)[p]) do lA = localpart(A) AlA = Elemental.DistMatrix(T) zeros!(AlA, size(A)...) for j = 1:size(lA,2), i = 1:size(lA, 1) queueUpdate(AlA, - start(ind[1]) + i - 1, - start(ind[2]) + j - 1, lA[i,j]) + first(ind[1]) + i - 1, + first(ind[2]) + j - 1, lA[i,j]) end processQueues(AlA) AlA @@ -25,7 +27,7 @@ function toback{T<:BlasFloat,S<:StridedMatrix}(A::DArray{T,2,S}) end function tofront(r::Base.Matrix) - tt = Array{Any}(length(r)) + tt = Array{Any}(undef, length(r)) for i = 1:length(r) tt[i] = remotecall(r[i].where, r[i]) do t typeof(fetch(t)) @@ -50,15 +52,15 @@ function tofront(r::Base.Matrix) Int[r[i].where for i in eachindex(r)]) @sync for p in eachindex(r) - ind = A.indexes[p] + ind = A.indices[p] rr = r[p] @async remotecall_wait(r[p].where) do rrr = fetch(rr) lA = localpart(A) for j = 1:size(lA, 2), i = 1:size(lA, 1) queuePull(rrr, - start(ind[1]) + i - 1, - start(ind[2]) + j - 1) + first(ind[1]) + i - 1, + first(ind[2]) + j - 1) end processPullQueue(rrr, lA) end @@ -71,11 +73,11 @@ function tofront(r::Base.Matrix) return A end -function (\){T<:BlasFloat,S}(A::DArray{T,2,S}, B::DArray{T,2,S}) +function (\)(A::DArray{T,2,S}, B::DArray{T,2,S}) where {T<:BlasFloat,S} rA = toback(A) rB = toback(B) pidsAB = union(A.pids, B.pids) - rvals = Vector{Any}(length(pidsAB)) + rvals = Vector{Any}(undef, length(pidsAB)) @sync for i = 1:length(pidsAB) @async rvals[i] = remotecall_wait(pidsAB[i], rA[i], rB[i]) do t1,t2 solve!(fetch(t1), fetch(t2)) @@ -84,9 +86,9 @@ function (\){T<:BlasFloat,S}(A::DArray{T,2,S}, B::DArray{T,2,S}) return tofront(reshape(rvals, size(procs(B)))) end -function eigvals{T<:BlasFloat}(A::Hermitian{T,DArray{T,2,Array{T,2}}}) +function LinearAlgebra.eigvals(A::Hermitian{T,DArray{T,2,Array{T,2}}} where {T<:BlasFloat} ) rA = toback(A.data) - rvals = Array{Any}(size(procs(A.data))) + rvals = Array{Any}(undef, size(procs(A.data))) uplo = A.uplo == 'U' ? UPPER : LOWER @sync for i in eachindex(rvals) @async rvals[i] = remotecall_wait(rA[i].where, rA[i]) do t @@ -96,9 +98,9 @@ function eigvals{T<:BlasFloat}(A::Hermitian{T,DArray{T,2,Array{T,2}}}) return tofront(rvals) end -function svdvals{T<:BlasFloat}(A::DArray{T,2}) +function LinearAlgebra.svdvals(A::DArray{<:BlasFloat,2}) rA = toback(A) - rvals = Array{Any}(size(procs(A))) + rvals = Array{Any}(undef, size(procs(A))) @sync for i in eachindex(rvals) @async rvals[i] = remotecall_wait(rA[i].where, rA[i]) do t svdvals(fetch(t)) @@ -107,9 +109,9 @@ function svdvals{T<:BlasFloat}(A::DArray{T,2}) return tofront(rvals) end -function inv!{T<:BlasFloat}(A::DArray{T,2}) +function LinearAlgebra.inv!(A::DArray{<:BlasFloat,2}) rA = toback(A) - rvals = Array{Any}(size(procs(A))) + rvals = Array{Any}(undef, size(procs(A))) @sync for j = 1:size(rvals, 2) for i = 1:size(rvals, 1) @async rvals[i,j] = remotecall_wait(t -> inverse!(fetch(t)), rA[i,j].where, rA[i,j]) @@ -118,11 +120,11 @@ function inv!{T<:BlasFloat}(A::DArray{T,2}) return tofront(rvals) end -inv{T<:BlasFloat}(A::DArray{T,2}) = inv!(copy(A)) +LinearAlgebra.inv(A::DArray{<:BlasFloat,2}) = LinearAlgebra.inv!(copy(A)) -function logdet{T<:BlasFloat}(A::DArray{T,2}) +function LinearAlgebra.logdet(A::DArray{<:BlasFloat,2}) rA = toback(A) - rvals = Array{Any}(size(procs(A))) + rvals = Array{Any}(undef, size(procs(A))) @sync for i in eachindex(rvals) @async rvals[i] = remotecall_wait(rA[i].where, rA[i]) do t d = safeHPDDeterminant(Elemental.LOWER, fetch(t)) @@ -132,12 +134,12 @@ function logdet{T<:BlasFloat}(A::DArray{T,2}) return fetch(rvals[1]) end -function spectralPortrait{T<:BlasReal}(A::DArray{T,2}, - realSize::Integer, - imagSize::Integer, - psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) +function spectralPortrait(A::DArray{T,2}, + realSize::Integer, + imagSize::Integer, + psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) where {T<:BlasReal} rA = toback(A) - rvals = Array{Any}(size(procs(A))) + rvals = Array{Any}(undef, size(procs(A))) @sync for i in eachindex(rvals) @async rvals[i] = remotecall_wait(rA[i].where, rA[i]) do t spectralPortrait(fetch(t), ElInt(realSize), ElInt(imagSize), psCtrl)[1] @@ -146,12 +148,12 @@ function spectralPortrait{T<:BlasReal}(A::DArray{T,2}, return tofront(rvals) end -function spectralPortrait{T<:BlasReal}(A::DArray{Complex{T},2}, - realSize::Integer, - imagSize::Integer, - psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) +function spectralPortrait(A::DArray{Complex{T},2}, + realSize::Integer, + imagSize::Integer, + psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) where {T<:BlasReal} rA = toback(A) - rvals = Array{Any}(size(procs(A))) + rvals = Array{Any}(undef, size(procs(A))) @sync for i in eachindex(rvals) @async rvals[i,j] = remotecall_wait(rA[i].where, rA[i]) do t spectralPortrait(fetch(t), ElInt(realSize), ElInt(imagSize), psCtrl)[1] @@ -160,15 +162,15 @@ function spectralPortrait{T<:BlasReal}(A::DArray{Complex{T},2}, return tofront(rvals) end -function spectralWindow{T<:BlasReal}(A::DArray{T,2}, - center::Complex{T}, - realWidth::T, - imagWidth::T, - realSize::Integer, - imagSize::Integer, - psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) +function spectralWindow(A::DArray{T,2}, + center::Complex{T}, + realWidth::T, + imagWidth::T, + realSize::Integer, + imagSize::Integer, + psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) where {T<:BlasReal} rA = toback(A) - rvals = Array{Any}(size(procs(A))) + rvals = Array{Any}(undef, size(procs(A))) @sync for i in eachindex(rvals) @async rvals[i] = remotecall_wait(rA[i].where, rA[i]) do t spectralWindow(fetch(t), center, realWidth, imagWidth, @@ -178,15 +180,15 @@ function spectralWindow{T<:BlasReal}(A::DArray{T,2}, return tofront(rvals) end -function spectralWindow{T<:BlasReal}(A::DArray{Complex{T},2}, - center::Complex{T}, - realWidth::T, - imagWidth::T, - realSize::Integer, - imagSize::Integer, - psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) +function spectralWindow(A::DArray{Complex{T},2}, + center::Complex{T}, + realWidth::T, + imagWidth::T, + realSize::Integer, + imagSize::Integer, + psCtrl::PseudospecCtrl{T}=PseudospecCtrl(T)) where {T<:BlasReal} rA = toback(A) - rvals = Array{Any}(size(procs(A))) + rvals = Array{Any}(undef, size(procs(A))) @sync for i in eachindex(rvals) @async rvals[i] = remotecall_wait(rA[i,j].where, rA[i]) do t spectralWindow(fetch(t), center, realWidth, imagWidth, @@ -196,9 +198,9 @@ function spectralWindow{T<:BlasReal}(A::DArray{Complex{T},2}, return tofront(rvals) end -function foxLi{T<:BlasComplex}(::Type{T}, n::Integer, ω::Real) +function foxLi(::Type{T}, n::Integer, ω::Real) where {T<:BlasComplex} sz = tuple(DistributedArrays.defaultdist((n,n), workers())...) - rvals = Array{Any}(sz) + rvals = Array{Any}(undef, sz) @sync for j = 1:size(rvals, 2), i = 1:size(rvals, 1) @async rvals[i,j] = remotecall_wait(workers()[sub2ind(sz, i, j)]) do A = Elemental.DistMatrix(T) @@ -207,7 +209,7 @@ function foxLi{T<:BlasComplex}(::Type{T}, n::Integer, ω::Real) end return tofront(rvals) end -foxLi(n::Integer, ω::Real) = foxLi(Complex128, n, ω) +foxLi(n::Integer, ω::Real) = foxLi(ComplexF64, n, ω) # Andreas: Just saw this one. It is almost identical to the one I wrote above, # but I don't think that we can return a Elemental array beacause it has to @@ -216,8 +218,8 @@ foxLi(n::Integer, ω::Real) = foxLi(Complex128, n, ω) for (elty, ext) in ((:ElInt, :i), (:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) @eval begin function convert(::Type{DistSparseMatrix{$elty}}, DA::DistributedArrays.DArray) npr, npc = size(procs(DA)) @@ -233,7 +235,7 @@ for (elty, ext) in ((:ElInt, :i), for id in workers() let A = A, DA = DA @async remotecall_fetch(id) do - rows, cols = DistributedArrays.localindexes(DA) + rows, cols = DistributedArrays.localindices(DA) i,j,v = findnz(DistributedArrays.localpart(DA)) gi, gj, gv = (i.+(first(rows)-1), j.+(first(cols)-1), v) numLocal = length(gi) diff --git a/src/julia/generic.jl b/src/julia/generic.jl index 118c3b7..295a578 100644 --- a/src/julia/generic.jl +++ b/src/julia/generic.jl @@ -1,6 +1,6 @@ # Julia interface when not defined in source files -Base.eltype{T}(x::DistMultiVec{T}) = T +Base.eltype(x::DistMultiVec{T}) where {T} = T function Base.size(A::ElementalMatrix, i::Integer) if i < 1 @@ -16,70 +16,70 @@ end Base.size(A::ElementalMatrix) = (size(A, 1), size(A, 2)) -Base.copy!(A::T, B::T) where {T<:ElementalMatrix} = _copy!(B, A) +Base.copyto!(A::T, B::T) where {T<:ElementalMatrix} = _copy!(B, A) # copy(A::ElementalMatrix) = copy!(similar(A), A) Base.length(A::ElementalMatrix) = prod(size(A)) ## Current mutating Julia multiplication API -Base.A_mul_B!(C::T, A::T, B::T) where {T<:ElementalMatrix} = gemm(NORMAL, NORMAL, one(eltype(T)), A, B, zero(eltype(T)), C) -Base.Ac_mul_B!(C::T, A::T, B::T) where {T<:ElementalMatrix} = gemm(ADJOINT, NORMAL, one(eltype(T)), A, B, zero(eltype(T)), C) -Base.At_mul_B!(C::T, A::T, B::T) where {T<:ElementalMatrix} = gemm(TRANSPOSE, NORMAL, one(eltype(T)), A, B, zero(eltype(T)), C) -Base.A_mul_Bc!(C::T, A::T, B::T) where {T<:ElementalMatrix} = gemm(NORMAL, ADJOINT, one(eltype(T)), A, B, zero(eltype(T)), C) -Base.A_mul_Bt!(C::T, A::T, B::T) where {T<:ElementalMatrix} = gemm(NORMAL, TRANSPOSE, one(eltype(T)), A, B, zero(eltype(T)), C) +LinearAlgebra.mul!(C::T, A::T, B::T) where {T<:ElementalMatrix} = gemm(NORMAL, NORMAL, one(eltype(T)), A, B, zero(eltype(T)), C) +LinearAlgebra.mul!(C::T, adjA::Adjoint{<:Any,T}, B::T) where {T<:ElementalMatrix} = gemm(ADJOINT, NORMAL, one(eltype(T)), parent(adjA), B, zero(eltype(T)), C) +LinearAlgebra.mul!(C::T, trA::Transpose{<:Any,T}, B::T) where {T<:ElementalMatrix} = gemm(TRANSPOSE, NORMAL, one(eltype(T)), parent(trA), B, zero(eltype(T)), C) +LinearAlgebra.mul!(C::T, A::T, adjB::Adjoint{<:Any,T}) where {T<:ElementalMatrix} = gemm(NORMAL, ADJOINT, one(eltype(T)), A, parent(adjB), zero(eltype(T)), C) +LinearAlgebra.mul!(C::T, A::T, trB::Transpose{<:Any,T}) where {T<:ElementalMatrix} = gemm(NORMAL, TRANSPOSE, one(eltype(T)), A, parent(trB), zero(eltype(T)), C) ## BLAS like multiplication API (i.e. with α and β) -Base.A_mul_B!(α::Number, A::S, B::S, β::Number, C::S) where {S<:ElementalMatrix{T}} where {T} = +LinearAlgebra.mul!(C::S, A::S, B::S, α::Number, β::Number) where {S<:ElementalMatrix{T}} where {T} = gemm(NORMAL, NORMAL, T(α), A, B, T(β), C) -Base.Ac_mul_B!(α::Number, A::S, B::S, β::Number, C::S) where {S<:ElementalMatrix{T}} where {T} = - gemm(ADJOINT, NORMAL, T(α), A, B, T(β), C) -Base.At_mul_B!(α::Number, A::S, B::S, β::Number, C::S) where {S<:ElementalMatrix{T}} where {T} = - gemm(TRANSPOSE, NORMAL, T(α), A, B, T(β), C) -Base.A_mul_Bc!(α::Number, A::S, B::S, β::Number, C::S) where {S<:ElementalMatrix{T}} where {T} = - gemm(NORMAL, ADJOINT, T(α), A, B, T(β), C) -Base.A_mul_Bt!(α::Number, A::S, B::S, β::Number, C::S) where {S<:ElementalMatrix{T}} where {T} = - gemm(NORMAL, TRANSPOSE, T(α), A, B, T(β), C) +LinearAlgebra.mul!(C::S, adjA::Adjoint{<:Any,S}, B::S, α::Number, β::Number) where {S<:ElementalMatrix{T}} where {T} = + gemm(ADJOINT, NORMAL, T(α), parent(adjA), B, T(β), C) +LinearAlgebra.mul!(C::S, trA::Transpose{<:Any,S}, B::S, α::Number, β::Number) where {S<:ElementalMatrix{T}} where {T} = + gemm(TRANSPOSE, NORMAL, T(α), parent(trA), B, T(β), C) +LinearAlgebra.mul!(C::S, A::S, adjB::Adjoint{<:Any,S}, α::Number, β::Number) where {S<:ElementalMatrix{T}} where {T} = + gemm(NORMAL, ADJOINT, T(α), A, parent(adjB), T(β), C) +LinearAlgebra.mul!(C::S, A::S, trB::Transpose{<:Any,S}, α::Number, β::Number) where {S<:ElementalMatrix{T}} where {T} = + gemm(NORMAL, TRANSPOSE, T(α), A, parent(trB), T(β), C) ## Linear solve API -Base.LinAlg.A_ldiv_B!(A::LowerTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = +LinearAlgebra.ldiv!(A::LowerTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = trsm(LEFT, LOWER, NORMAL , NON_UNIT, one(T), A.data, B) -Base.LinAlg.Ac_ldiv_B!(A::LowerTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = - trsm(LEFT, LOWER, ADJOINT , NON_UNIT, one(T), A.data, B) -Base.LinAlg.At_ldiv_B!(A::LowerTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = - trsm(LEFT, LOWER, TRANSPOSE, NON_UNIT, one(T), A.data, B) -Base.LinAlg.A_ldiv_B!(A::UpperTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = +LinearAlgebra.ldiv!(adjA::Adjoint{T,LowerTriangular{T,S}}, B::S) where {T,S<:ElementalMatrix} = + trsm(LEFT, LOWER, ADJOINT , NON_UNIT, one(T), parent(adjA).data, B) +LinearAlgebra.ldiv!(trA::Transpose{T,LowerTriangular{T,S}}, B::S) where {T,S<:ElementalMatrix} = + trsm(LEFT, LOWER, TRANSPOSE, NON_UNIT, one(T), parent(trA).data, B) +LinearAlgebra.ldiv!(A::UpperTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = trsm(LEFT, UPPER, NORMAL , NON_UNIT, one(T), A.data, B) -Base.LinAlg.Ac_ldiv_B!(A::UpperTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = - trsm(LEFT, UPPER, ADJOINT , NON_UNIT, one(T), A.data, B) -Base.LinAlg.At_ldiv_B!(A::UpperTriangular{T,S}, B::S) where {T,S<:ElementalMatrix} = - trsm(LEFT, UPPER, TRANSPOSE, NON_UNIT, one(T), A.data, B) +LinearAlgebra.ldiv!(adjA::Adjoint{T,UpperTriangular{T,S}}, B::S) where {T,S<:ElementalMatrix} = + trsm(LEFT, UPPER, ADJOINT , NON_UNIT, one(T), parent(adjA).data, B) +LinearAlgebra.ldiv!(trA::Transpose{T,UpperTriangular{T,S}}, B::S) where {T,S<:ElementalMatrix} = + trsm(LEFT, UPPER, TRANSPOSE, NON_UNIT, one(T), parent(trA).data, B) -Base.LinAlg.A_rdiv_B!(A::S, B::LowerTriangular{T,S}) where {T,S<:ElementalMatrix} = +LinearAlgebra.rdiv!(A::S, B::LowerTriangular{T,S}) where {T,S<:ElementalMatrix} = trsm(RIGHT, LOWER, NORMAL , NON_UNIT, one(T), B.data, A) -Base.LinAlg.A_rdiv_Bc!(A::S, B::LowerTriangular{T,S}) where {T,S<:ElementalMatrix} = - trsm(RIGHT, LOWER, ADJOINT , NON_UNIT, one(T), B.data, A) -Base.LinAlg.A_rdiv_Bt!(A::S, B::LowerTriangular{T,S}) where {T,S<:ElementalMatrix} = +LinearAlgebra.rdiv!(A::S, adjB::Adjoint{T,LowerTriangular{T,S}}) where {T,S<:ElementalMatrix} = + trsm(RIGHT, LOWER, ADJOINT , NON_UNIT, one(T), parent(adjB).data, A) +LinearAlgebra.rdiv!(A::S, trB::Transpose{T,LowerTriangular{T,S}}) where {T,S<:ElementalMatrix} = trsm(RIGHT, LOWER, TRANSPOSE, NON_UNIT, one(T), B.data, A) -Base.LinAlg.A_rdiv_B!(A::S, B::UpperTriangular{T,S}) where {T,S<:ElementalMatrix} = +LinearAlgebra.rdiv!(A::S, B::UpperTriangular{T,S}) where {T,S<:ElementalMatrix} = trsm(RIGHT, UPPER, NORMAL , NON_UNIT, one(T), B.data, A) -Base.LinAlg.A_rdiv_Bc!(A::S, B::UpperTriangular{T,S}) where {T,S<:ElementalMatrix} = - trsm(RIGHT, UPPER, ADJOINT , NON_UNIT, one(T), B.data, A) -Base.LinAlg.A_rdiv_Bt!(A::S, B::UpperTriangular{T,S}) where {T,S<:ElementalMatrix} = - trsm(RIGHT, UPPER, TRANSPOSE, NON_UNIT, one(T), B.data, A) +LinearAlgebra.rdiv!(A::S, adjB::Adjoint{T,UpperTriangular{T,S}}) where {T,S<:ElementalMatrix} = + trsm(RIGHT, UPPER, ADJOINT , NON_UNIT, one(T), parent(adjB).data, A) +LinearAlgebra.rdiv!(A::S, trB::Transpose{T,UpperTriangular{T,S}}) where {T,S<:ElementalMatrix} = + trsm(RIGHT, UPPER, TRANSPOSE, NON_UNIT, one(T), parent(trB).data, A) # Spectral -Base.LinAlg.svd(A::ElementalMatrix) = svd!(copy(A)) -Base.LinAlg.svd(A::ElementalMatrix, ctrl::SVDCtrl) = svd!(copy(A), ctrl) -Base.LinAlg.svdvals(A::ElementalMatrix, ctrl::SVDCtrl) = svdvals!(copy(A), ctrl) +LinearAlgebra.svd(A::ElementalMatrix) = svd!(copy(A)) +LinearAlgebra.svd(A::ElementalMatrix, ctrl::SVDCtrl) = svd!(copy(A), ctrl) +LinearAlgebra.svdvals(A::ElementalMatrix, ctrl::SVDCtrl) = svdvals!(copy(A), ctrl) # conversions to and from julia arrays -# function copy!{T}(dest::Matrix{T}, src::Base.VecOrMat{T}) +# function copy!(dest::Matrix{T}, src::Base.VecOrMat{T}) where {T} # m, n = size(src, 1), size(src, 2) # resize!(dest, m, n) # Base.unsafe_copy!(pointer(dest), pointer(src), m*n) # return dest # end -# function copy!{T}(dest::Base.Matrix{T}, src::Matrix{T}) +# function copy!(dest::Base.Matrix{T}, src::Matrix{T}) where {T} # m, n = size(dest) # if m != size(src, 1) || n != size(src, 2) # throw(DimensionMisMatch("source and destination must have same shape")) @@ -88,7 +88,7 @@ Base.LinAlg.svdvals(A::ElementalMatrix, ctrl::SVDCtrl) = svdvals!(copy(A), ctrl) # return dest # end -function Base.copy!{T}(dest::DistMatrix{T}, src::Base.VecOrMat) +function Base.copy!(dest::DistMatrix{T}, src::Base.VecOrMat) where {T} m, n = size(src, 1), size(src, 2) zeros!(dest, m, n) if MPI.commRank(comm(dest)) == 0 @@ -102,21 +102,21 @@ function Base.copy!{T}(dest::DistMatrix{T}, src::Base.VecOrMat) return dest end -function Base.convert{T}(::Type{Matrix{T}}, A::Base.VecOrMat{T}) +function Base.convert(::Type{Matrix{T}}, A::Base.VecOrMat{T}) where {T} m, n = size(A, 1), size(A, 2) B = Matrix(T) resize!(B, m, n) Base.unsafe_copy!(pointer(B), pointer(A), m*n) return B end -function Base.convert{T}(::Type{Base.Matrix{T}}, A::Matrix{T}) +function Base.convert(::Type{Base.Matrix{T}}, A::Matrix{T}) where {T} m, n = size(A) B = Base.Matrix{T}(m, n) Base.unsafe_copy!(pointer(B), pointer(A), m*n) return B end -function Base.convert{T}(::Type{DistMatrix{T}}, A::Base.VecOrMat{T}) +function Base.convert(::Type{DistMatrix{T}}, A::Base.VecOrMat{T}) where {T} m, n = size(A, 1), size(A, 2) B = DistMatrix(T) zeros!(B, m, n) @@ -131,7 +131,7 @@ function Base.convert{T}(::Type{DistMatrix{T}}, A::Base.VecOrMat{T}) return B end -function Base.convert{T}(::Type{DistMultiVec{T}}, A::Base.VecOrMat{T}) +function Base.convert(::Type{DistMultiVec{T}}, A::Base.VecOrMat{T}) where {T} m, n = size(A, 1), size(A, 2) B = DistMultiVec(T) zeros!(B, m, n) @@ -146,7 +146,7 @@ function Base.convert{T}(::Type{DistMultiVec{T}}, A::Base.VecOrMat{T}) return B end -function Base.convert{T}(::Type{DistMatrix{T}}, A::DistMultiVec{T}) +function Base.convert(::Type{DistMatrix{T}}, A::DistMultiVec{T}) where {T} m, n = size(A) B = DistMatrix(T) zeros!(B, m, n) @@ -160,20 +160,13 @@ function Base.convert{T}(::Type{DistMatrix{T}}, A::DistMultiVec{T}) return B end -function Base.LinAlg.norm(x::ElementalMatrix) - if size(x, 2) == 1 - return nrm2(x) - else - return twoNorm(x) - end -end - -# Multiplication -# (*){T}(A::DistMatrix{T}, B::Base.VecOrMat{T}) = A*convert(DistMatrix{T}, B) -# (*){T}(A::DistMultiVec{T}, B::Base.VecOrMat{T}) = convert(DistMatrix{T}, A)*convert(DistMatrix{T}, B) -# (*){T}(A::DistSparseMatrix{T}, B::Base.VecOrMat{T}) = A*convert(DistMultiVec{T}, B) -# Ac_mul_B{T}(A::DistMatrix{T}, B::Base.VecOrMat{T}) = Ac_mul_B(A, convert(DistMatrix{T}, B)) -# Ac_mul_B{T}(A::DistMultiVec{T}, B::Base.VecOrMat{T}) = Ac_mul_B(convert(DistMatrix{T}, A), convert(DistMatrix{T}, B)) -# Ac_mul_B{T}(A::DistSparseMatrix{T}, B::Base.VecOrMat{T}) = Ac_mul_B(A, convert(DistMultiVec{T}, B)) +LinearAlgebra.norm(x::ElementalMatrix) = nrm2(x) +# function LinearAlgebra.norm(x::ElementalMatrix) +# if size(x, 2) == 1 +# return nrm2(x) +# else +# return twoNorm(x) +# end +# end -Base.cholfact!(A::Hermitian{<:Any,<:ElementalMatrix}, ::Type{Val{false}}) = Base.LinAlg.Cholesky(cholesky(A.uplo == 'U' ? UPPER : LOWER, A.data), A.uplo) +LinearAlgebra.cholesky!(A::Hermitian{<:Any,<:ElementalMatrix}, ::Type{Val{false}}) = LinearAlgebra.Cholesky(cholesky(A.uplo == 'U' ? UPPER : LOWER, A.data), A.uplo) diff --git a/src/lapack_like/condense.jl b/src/lapack_like/condense.jl index fd4f197..3bd47a4 100644 --- a/src/lapack_like/condense.jl +++ b/src/lapack_like/condense.jl @@ -1,29 +1,29 @@ for (elty, ext) in ((:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) for mattype in ("", "Dist") mat = Symbol(mattype, "Matrix") @eval begin # Hessenberg - function hessenberg!(uplo::UpperOrLower, A::$mat{$elty}, t::$mat{$elty}) + function _hessenberg!(uplo::UpperOrLower, A::$mat{$elty}, t::$mat{$elty}) ElError(ccall(($(string("ElHessenberg", mattype, "_", ext)), libEl), Cuint, - (UpperOrLower, Ptr{Void}, Ptr{Void}), + (UpperOrLower, Ptr{Cvoid}, Ptr{Cvoid}), uplo, A.obj, t.obj)) return A, t end - hessenberg!(A::$mat{$elty}) = hessenberg!(UPPER, A, $mat($elty)) + _hessenberg!(A::$mat{$elty}) = _hessenberg!(UPPER, A, $mat($elty)) end end end -struct ElHessenberg{T,S<:ElementalMatrix} <: Factorization{T} +struct ElHessenberg{T,S<:ElementalMatrix} <: LinearAlgebra.Factorization{T} factors::S τ::S - (::Type{ElHessenberg{T,S}}){T,S<:ElementalMatrix}(factors::ElementalMatrix{T}, τ::ElementalMatrix{T}) = new{T,S}(factors, τ) + ElHessenberg{T,S}(factors::ElementalMatrix{T}, τ::ElementalMatrix{T}) where {T,S<:ElementalMatrix} = new{T,S}(factors, τ) end -ElHessenberg{T}(factors::ElementalMatrix{T}, τ::ElementalMatrix{T}) = ElHessenberg{T,typeof(factors)}(factors, τ) +ElHessenberg(factors::ElementalMatrix{T}, τ::ElementalMatrix{T}) where {T} = ElHessenberg{T,typeof(factors)}(factors, τ) -Base.LinAlg.hessfact!(A::ElementalMatrix) = ElHessenberg(hessenberg!(A)...) +LinearAlgebra.hessenberg!(A::ElementalMatrix) = ElHessenberg(_hessenberg!(A)...) diff --git a/src/lapack_like/euclidean_min.jl b/src/lapack_like/euclidean_min.jl index 181e205..550678a 100644 --- a/src/lapack_like/euclidean_min.jl +++ b/src/lapack_like/euclidean_min.jl @@ -8,7 +8,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function leastSquares!(A::$matA{$elty}, B::$matB{$elty}, X::$matB{$elty}; orientation::Orientation = NORMAL) ElError(ccall(($(string("ElLeastSquares", sym, ext)), libEl), Cuint, - (Cuint, Ptr{Void}, Ptr{Void}, Ptr{Void}), + (Cuint, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), orientation, A.obj, B.obj, X.obj)) return X end @@ -16,13 +16,13 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), end end -function leastSquares{T}(A::DistMatrix{T}, B::DistMatrix{T}; - orientation::Orientation = NORMAL) +function leastSquares(A::DistMatrix{T}, B::DistMatrix{T}; + orientation::Orientation = NORMAL) where {T} X = DistMatrix(T, MC, MR, A.g) return leastSquares!(A, B, X, orientation = orientation) end -function leastSquares{T}(A::DistSparseMatrix{T}, B::DistMultiVec{T}; - orientation::Orientation = NORMAL) +function leastSquares(A::DistSparseMatrix{T}, B::DistMultiVec{T}; + orientation::Orientation = NORMAL) where {T} X = DistMultiVec(T, comm(A)) return leastSquares!(A, B, X, orientation = orientation) end diff --git a/src/lapack_like/factor.jl b/src/lapack_like/factor.jl index 03e4a64..04ab5b4 100644 --- a/src/lapack_like/factor.jl +++ b/src/lapack_like/factor.jl @@ -14,7 +14,7 @@ struct RegSolveCtrl{T<:ElFloatType} time::ElBool end -function RegSolveCtrl{T<:ElFloatType}(::Type{T}; +function RegSolveCtrl(::Type{T}; alg = REG_SOLVE_FGMRES, relTol = eps(T)^0.5, relTolRefine = eps(T)^0.8, @@ -22,7 +22,7 @@ function RegSolveCtrl{T<:ElFloatType}(::Type{T}; maxRefineIts = 2, restart = 4, progress = false, - time = false) + time = false) where {T<:ElFloatType} RegSolveCtrl{T}(RegSolveAlg(alg), T(relTol), @@ -36,15 +36,15 @@ end for (elty, ext) in ((:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) for mattype in ("", "Dist") mat = Symbol(mattype, "Matrix") @eval begin - function cholesky(uplo::UpperOrLower, A::$mat{$elty}) + function _cholesky(uplo::UpperOrLower, A::$mat{$elty}) ElError(ccall(($(string("ElCholesky", mattype, "_", ext)), libEl), Cuint, - (UpperOrLower, Ptr{Void}), + (UpperOrLower, Ptr{Cvoid}), uplo, A.obj)) return A end diff --git a/src/lapack_like/funcs.jl b/src/lapack_like/funcs.jl index c6835ca..166c47f 100644 --- a/src/lapack_like/funcs.jl +++ b/src/lapack_like/funcs.jl @@ -1,13 +1,13 @@ for dtype in ("", "Dist") for (elty, ext) in ((:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) mat = Symbol(dtype, "Matrix") @eval begin function inverse!(A::$mat{$elty}) ElError(ccall(($(string("ElInverse", dtype, "_", ext)), libEl), Cuint, - (Ptr{Void},), + (Ptr{Cvoid},), A.obj,)) return A end diff --git a/src/lapack_like/props.jl b/src/lapack_like/props.jl index 3c917c8..010e53b 100644 --- a/src/lapack_like/props.jl +++ b/src/lapack_like/props.jl @@ -6,8 +6,8 @@ end 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_"), (:SparseMatrix, "Sparse_"), @@ -18,7 +18,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function entrywiseNorm(A::$mat{$elty}, p::Real) rval = Ref{$relty}(0) ElError(ccall(($(string("ElEntrywiseNorm", sym, ext)), libEl), Cuint, - (Ptr{Void}, $relty, Ref{$relty}), + (Ptr{Cvoid}, $relty, Ref{$relty}), A.obj, p, rval)) return rval[] end @@ -26,7 +26,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function infinityNorm(A::$mat{$elty}) rval = Ref{$relty}(0) ElError(ccall(($(string("ElInfinityNorm", sym, ext)), libEl), Cuint, - (Ptr{Void}, Ref{$relty}), + (Ptr{Cvoid}, Ref{$relty}), A.obj, rval)) return rval[] end @@ -34,7 +34,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function maxNorm(A::$mat{$elty}) rval = Ref{$relty}(0) ElError(ccall(($(string("ElMaxNorm", sym, ext)), libEl), Cuint, - (Ptr{Void}, Ref{$relty}), + (Ptr{Cvoid}, Ref{$relty}), A.obj, rval)) return rval[] end @@ -42,7 +42,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function oneNorm(A::$mat{$elty}) rval = Ref{$relty}(0) ElError(ccall(($(string("ElOneNorm", sym, ext)), libEl), Cuint, - (Ptr{Void}, Ref{$relty}), + (Ptr{Cvoid}, Ref{$relty}), A.obj, rval)) return rval[] end @@ -56,7 +56,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function safeHPDDeterminant(uplo::UpperOrLower, A::$mat{$elty}) rval = Ref{SafeProduct{$relty}}() ElError(ccall(($(string("ElSafeHPDDeterminant", sym, ext)), libEl), Cuint, - (UpperOrLower, Ptr{Void}, Ref{SafeProduct{$relty}}), + (UpperOrLower, Ptr{Cvoid}, Ref{SafeProduct{$relty}}), uplo, A.obj, rval)) return rval[] end @@ -64,7 +64,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function twoNorm(A::$mat{$elty}) rval = Ref{$relty}(0) ElError(ccall(($(string("ElTwoNorm", sym, ext)), libEl), Cuint, - (Ptr{Void}, Ref{$relty}), + (Ptr{Cvoid}, Ref{$relty}), A.obj, rval)) return rval[] end @@ -72,7 +72,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), function zeroNorm(A::$mat{$elty}) rval = Ref{ElInt}(0) ElError(ccall(($(string("ElZeroNorm", sym, ext)), libEl), Cuint, - (Ptr{Void}, Ref{ElInt}), + (Ptr{Cvoid}, Ref{ElInt}), A.obj, rval)) return rval[] end @@ -80,9 +80,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), end end -countnz(A::Union{Matrix,DistMatrix}) = Int(zeroNorm(A)) - -function norm(A::ElementalMatrix, p::Real) +function LinearAlgebra.opnorm(A::ElementalMatrix, p::Real = 2) if p == 1 return oneNorm(A) elseif p == 2 diff --git a/src/lapack_like/solve.jl b/src/lapack_like/solve.jl index 4b92422..8fb17a2 100644 --- a/src/lapack_like/solve.jl +++ b/src/lapack_like/solve.jl @@ -2,13 +2,13 @@ for dtype in ("", "Dist") for stype in ("", "Sparse") for (elty, ext) in ((:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) mat = Symbol(dtype, stype, "Matrix") @eval begin function solve!(A::$mat{$elty}, B::$mat{$elty}) ElError(ccall(($(string("ElLinearSolve", dtype, stype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}), + (Ptr{Cvoid}, Ptr{Cvoid}), A.obj, B.obj)) return B end diff --git a/src/lapack_like/spectral.jl b/src/lapack_like/spectral.jl index 70fabb6..87ee75b 100644 --- a/src/lapack_like/spectral.jl +++ b/src/lapack_like/spectral.jl @@ -12,12 +12,13 @@ struct SignCtrl{T<:ElFloatType} scaling::ElSignScaling progress::ElBool end -function SignCtrl{T<:ElFloatType}(::Type{T}; +function SignCtrl(::Type{T}; maxIts = 100, tol = 0, power = 1, scaling = SIGN_SCALE_FROB, - progress::Bool = false) + progress::Bool = false) where {T<:ElFloatType} + SignCtrl{T}(ElInt(maxIts), T(tol), T(power), @@ -35,6 +36,7 @@ function HessQRCtrl( distAED::Bool = false, blockHeight = 32, blockWidth = 32) + HessQRCtrl(ElBool(distAED),ElInt(blockHeight),ElInt(blockWidth)) end @@ -48,7 +50,7 @@ struct SDCCtrl{T<:ElFloatType} progress::ElBool signCtrl::SignCtrl{T} end -function SDCCtrl{T<:ElFloatType}(::Type{T}; +function SDCCtrl(::Type{T}; cutoff = 256, maxInnerIts = 2, maxOuterIts = 10, @@ -56,7 +58,8 @@ function SDCCtrl{T<:ElFloatType}(::Type{T}; spreadFactor = 1e-6, random::Bool = true, progress::Bool = false, - signCtrl = SignCtrl(T)) + signCtrl = SignCtrl(T)) where {T<:ElFloatType} + SDCCtrl{T}(ElInt(cutoff), ElInt(maxInnerIts), ElInt(maxOuterIts), @@ -72,10 +75,11 @@ struct SchurCtrl{T<:ElFloatType} qrCtrl::HessQRCtrl sdcCtrl::SDCCtrl{T} end -function SchurCtrl{T<:ElFloatType}(::Type{T}; +function SchurCtrl(::Type{T}; useSDC::Bool = false, qrCtrl::HessQRCtrl = HessQRCtrl(), - sdcCtrl::SDCCtrl{T} = SDCCtrl(T)) + sdcCtrl::SDCCtrl{T} = SDCCtrl(T)) where {T<:ElFloatType} + SchurCtrl{T}(ElBool(useSDC), qrCtrl, sdcCtrl) @@ -111,6 +115,7 @@ function SnapshotCtrl(realSize=0, imgFormat=PNG, numFormat=ASCII_MATLAB, itCounts::Bool=true) + SnapshotCtrl(Cint(realSize), Cint(imagSize), Cint(imgSaveFreq), @@ -146,7 +151,7 @@ struct PseudospecCtrl{T<:ElFloatType} progress::ElBool snapCtrl::SnapshotCtrl end -function PseudospecCtrl{T<:ElFloatType}(::Type{T}; +function PseudospecCtrl(::Type{T}; norm = PS_TWO_NORM, blockWidth = 10, schur::Bool = true, @@ -160,7 +165,7 @@ function PseudospecCtrl{T<:ElFloatType}(::Type{T}; basisSize = 10, reorthog::Bool = true, progress::Bool = false, - snapCtrl = SnapshotCtrl()) + snapCtrl = SnapshotCtrl()) where {T<:ElFloatType} PseudospecCtrl{T}(ElPseudospecNorm(norm), ElInt(blockWidth), @@ -193,13 +198,13 @@ struct SVDCtrl{T<:ElFloatType} relative::ElBool tol::T end -function SVDCtrl{T<:ElFloatType}(::Type{T}; +function SVDCtrl(::Type{T}; seqQR = false, valChanRatio = 1.2, fullChanRatio = 1.5, thresholded = false, relative = true, - tol = 0.0) + tol = 0.0) where {T<:ElFloatType} SVDCtrl{T}(ElBool(seqQR), Cdouble(valChanRatio), @@ -211,8 +216,8 @@ end for (elty, ext) in ((:Float32, :s), (:Float64, :d), - (:Complex64, :c), - (:Complex128, :z)) + (:ComplexF32, :c), + (:ComplexF64, :z)) for mattype in ("", "Dist") mat = Symbol(mattype, "Matrix") @eval begin @@ -220,7 +225,7 @@ for (elty, ext) in ((:Float32, :s), function eigvalsTridiag(d::$mat{real($elty)}, dSub::$mat{$elty}, sort::SortType = ASCENDING) w = $mat(real($elty)) ElError(ccall(($(string("ElHermitianTridiagEig", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, Ptr{Void}, SortType), + (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, SortType), d.obj, dSub.obj, w.obj, sort)) return w end @@ -229,7 +234,7 @@ for (elty, ext) in ((:Float32, :s), w = $mat(real($elty)) Z = $mat($elty) ElError(ccall(($(string("ElHermitianTridiagEigPair", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}, SortType), + (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, SortType), d.obj, dSub.obj, w.obj, Z.obj, sort)) return w, Z end @@ -237,7 +242,7 @@ for (elty, ext) in ((:Float32, :s), function eigvalsHermitian(uplo::UpperOrLower, A::$mat{$elty}, sort::SortType = ASCENDING) w = $mat(real($elty)) ElError(ccall(($(string("ElHermitianEig", mattype, "_", ext)), libEl), Cuint, - (UpperOrLower, Ptr{Void}, Ptr{Void}, SortType), + (UpperOrLower, Ptr{Cvoid}, Ptr{Cvoid}, SortType), uplo, A.obj, w.obj, sort)) return w end @@ -245,7 +250,7 @@ for (elty, ext) in ((:Float32, :s), function eigvalsHermitian(pencil::Pencil, uplo::UpperOrLower, A::$mat{$elty}, B::$mat{$elty}, sort::SortType = ASCENDING) w = $mat(real($elty)) ElError(ccall(($(string("ElHermitianGenDefEig", mattype, "_", ext)), libEl), Cuint, - (Pencil, UpperOrLower, Ptr{Void}, Ptr{Void}, Ptr{Void}, SortType), + (Pencil, UpperOrLower, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, SortType), pencil, uplo, A.obj, B.obj, w.obj, sort)) return w end @@ -254,7 +259,7 @@ for (elty, ext) in ((:Float32, :s), w = $mat(real($elty)) Z = $mat($elty) ElError(ccall(($(string("ElHermitianEigPair", mattype, "_", ext)), libEl), Cuint, - (UpperOrLower, Ptr{Void}, Ptr{Void}, Ptr{Void}, SortType), + (UpperOrLower, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, SortType), uplo, A.obj, w.obj, Z.obj, sort)) return w, Z end @@ -262,43 +267,43 @@ for (elty, ext) in ((:Float32, :s), function eigvalsGeneral(A::$mat{$elty}, fullTriangle = false) w = $mat(complex($elty)) ElError(ccall(($(string("ElSchur", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, ElBool), + (Ptr{Cvoid}, Ptr{Cvoid}, ElBool), A.obj, w.obj, fullTriangle)) return w end - function svdvals!(A::$mat{$elty}) + function LinearAlgebra.svdvals!(A::$mat{$elty}) s = $mat(real($elty)) ElError(ccall(($(string("ElSingularValues", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}), + (Ptr{Cvoid}, Ptr{Cvoid}), A.obj, s.obj)) return s end - function svdvals!(A::$mat{$elty}, ctrl::SVDCtrl{real($elty)}) + function LinearAlgebra.svdvals!(A::$mat{$elty}, ctrl::SVDCtrl{real($elty)}) s = $mat(real($elty)) ElError(ccall(($(string("ElSingularValuesX", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, SVDCtrl{real($elty)}), + (Ptr{Cvoid}, Ptr{Cvoid}, SVDCtrl{real($elty)}), A.obj, s.obj, ctrl)) return s end - function svd(A::$mat{$elty}) + function LinearAlgebra.svd(A::$mat{$elty}) U = $mat($elty) s = $mat(real($elty)) V = $mat($elty) ElError(ccall(($(string("ElSVD", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}), + (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), A.obj, U.obj, s.obj, V.obj)) return U, s, V end - function svd!(A::$mat{$elty}, ctrl::SVDCtrl{real($elty)}) + function LinearAlgebra.svd!(A::$mat{$elty}, ctrl::SVDCtrl{real($elty)}) U = $mat($elty) s = $mat(real($elty)) V = $mat($elty) ElError(ccall(($(string("ElSVDX", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}, SVDCtrl{real($elty)}), + (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, SVDCtrl{real($elty)}), A.obj, U.obj, s.obj, V.obj, ctrl)) return U, s, V end @@ -307,7 +312,7 @@ for (elty, ext) in ((:Float32, :s), invNormMap = $mat(real($elty)) box = Ref{SpectralBox{real($elty)}}() ElError(ccall(($(string("ElSpectralPortraitX", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, ElInt, ElInt, Ref{SpectralBox{real($elty)}},PseudospecCtrl{real($elty)}), + (Ptr{Cvoid}, Ptr{Cvoid}, ElInt, ElInt, Ref{SpectralBox{real($elty)}},PseudospecCtrl{real($elty)}), A.obj, invNormMap.obj, realSize, imagSize, box, psCtrl)) return invNormMap, box[] end @@ -315,7 +320,7 @@ for (elty, ext) in ((:Float32, :s), function spectralWindow(A::$mat{$elty}, center::Complex{real($elty)}, realWidth::real($elty), imagWidth::real($elty), realSize::ElInt, imagSize::ElInt, psCtrl::PseudospecCtrl{real($elty)}=PseudospecCtrl(real($elty))) invNormMap = $mat(real($elty)) ElError(ccall(($(string("ElSpectralWindowX", mattype, "_", ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, Complex{real($elty)}, real($elty), real($elty), ElInt, ElInt, PseudospecCtrl{real($elty)}), + (Ptr{Cvoid}, Ptr{Cvoid}, Complex{real($elty)}, real($elty), real($elty), ElInt, ElInt, PseudospecCtrl{real($elty)}), A.obj, invNormMap.obj, center, realWidth, imagWidth, realSize, imagSize, psCtrl)) return invNormMap end diff --git a/src/matrices.jl b/src/matrices.jl index 2b53073..c18ba24 100644 --- a/src/matrices.jl +++ b/src/matrices.jl @@ -1,8 +1,8 @@ for (elty, relty, ext) in ((:ElInt, :ElInt, :i), (: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_"), @@ -11,7 +11,7 @@ for (elty, relty, ext) in ((:ElInt, :ElInt, :i), # Bernoulli function bernoulli!(A::$mat{$elty}, m::Integer = size(A, 1), n::Integer = 1, p::Real = 0.5) ElError(ccall(($(string("ElBernoulli", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, Float64), + (Ptr{Cvoid}, ElInt, ElInt, Float64), A.obj, m, n, Float64(p))) return A end @@ -22,7 +22,7 @@ for (elty, relty, ext) in ((:ElInt, :ElInt, :i), function gaussian!(A::$mat{$elty}, m::Integer = size(A, 1), n::Integer = 1, mean::Number = 0, stddev::Number = 1) ElError(ccall(($(string("ElGaussian", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty, $relty), + (Ptr{Cvoid}, ElInt, ElInt, $elty, $relty), A.obj, m, n, mean, stddev)) return A end @@ -33,7 +33,7 @@ for (elty, relty, ext) in ((:ElInt, :ElInt, :i), # Ones function ones!(A::$mat{$elty}, m::Integer = size(A, 1), n::Integer = 1) ElError(ccall(($(string("ElOnes", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, m, n)) return A end @@ -43,7 +43,7 @@ for (elty, relty, ext) in ((:ElInt, :ElInt, :i), function uniform!(A::$mat{$elty}, m::Integer = size(A, 1), n::Integer = 1, center::Number = 0, radius::Real = 1) ElError(ccall(($(string("ElUniform", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty, $relty), + (Ptr{Cvoid}, ElInt, ElInt, $elty, $relty), A.obj, m, n, center, radius)) return A end @@ -53,19 +53,19 @@ for (elty, relty, ext) in ((:ElInt, :ElInt, :i), # Zeros function zeros!(A::$mat{$elty}, m::Integer = size(A, 1), n::Integer = 1) ElError(ccall(($(string("ElZeros", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt), + (Ptr{Cvoid}, ElInt, ElInt), A.obj, m, n)) return A end zeros(::Type{$mat{$elty}}, m::Integer, n::Integer = 1) = zeros!($mat($elty), m, n) end - if elty == :Complex64 || elty == :Complex128 + if elty == :ComplexF32 || elty == :ComplexF64 # Uniform @eval begin function foxLi!(A::$mat{$elty}, n::Integer = size(A, 1), ω::Real = 1.0) ElError(ccall(($(string("ElFoxLi", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, $relty), + (Ptr{Cvoid}, ElInt, $relty), A.obj, n, ω)) return A end @@ -77,8 +77,8 @@ end 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_"), @@ -88,21 +88,21 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), # Helmholtz function helmholtz!(A::$mat{$elty}, nx::Integer; shift::Number = 0) ElError(ccall(($(string("ElHelmholtz1D", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, $elty), + (Ptr{Cvoid}, ElInt, $elty), A.obj, nx, shift)) return A end function helmholtz!(A::$mat{$elty}, nx::Integer, ny::Integer; shift::Number = 0) ElError(ccall(($(string("ElHelmholtz2D", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, $elty), + (Ptr{Cvoid}, ElInt, ElInt, $elty), A.obj, nx, ny, shift)) return A end function helmholtz!(A::$mat{$elty}, nx::Integer, ny::Integer, nz::Integer; shift::Number = 0) ElError(ccall(($(string("ElHelmholtz3D", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt, ElInt, ElInt, $elty), + (Ptr{Cvoid}, ElInt, ElInt, ElInt, $elty), A.obj, nx, ny, nz, shift)) return A end @@ -111,8 +111,8 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s), end end -for (elty, ext) in ((:Complex64, :c), - (:Complex128, :z)) +for (elty, ext) in ((:ComplexF32, :c), + (:ComplexF64, :z)) for (mat, sym) in ((:Matrix, "_"), (:DistMatrix, "Dist_")) @@ -120,7 +120,7 @@ for (elty, ext) in ((:Complex64, :c), # Fourier function fourier!(A::$mat{$elty}, n::Integer) ElError(ccall(($(string("ElFourier", sym, ext)), libEl), Cuint, - (Ptr{Void}, ElInt), + (Ptr{Cvoid}, ElInt), A.obj, n)) return A end diff --git a/src/mpi.jl b/src/mpi.jl index c1032dd..f1adf43 100644 --- a/src/mpi.jl +++ b/src/mpi.jl @@ -1,9 +1,10 @@ module MPI -using Compat -import Compat.String +using Libdl +using Elemental: ElComm, ElElementType, ElInt, libEl -using Elemental: ElComm, ElElementType, ElInt, CommWorld, libEl +const MPIImpl = Ref{Symbol}() +const CommWorld = Ref{Any}() function __init__() # FixMe! The symbol could probably also be missing for other implementations @@ -11,24 +12,33 @@ function __init__() # NOTE! I'm using RTLD_GLOBAL here to avoid the OPEN-MPI error described in # https://www.open-mpi.org/faq/?category=troubleshooting#missing-symbols if Libdl.dlsym_e(Libdl.dlopen(libEl, Libdl.RTLD_GLOBAL), :MPI_Get_library_version) == C_NULL - const global MPIImpl = :MPICH2 + global MPIImpl[] = :MPICH2 else - versionBuffer = Vector{UInt8}(2800) + versionBuffer = Vector{UInt8}(undef, 2800) len = Cint[0] err = ccall((:MPI_Get_library_version, libEl), Cint, (Ptr{UInt8}, Ptr{Cint}), versionBuffer, len) versionString = String(versionBuffer[1:len[1]-1]) - if ismatch(r"Open MPI", versionString) - const global MPIImpl = :OpenMPI - elseif ismatch(r"MPICH", versionString) - const global MPIImpl = :MPICH3 + if occursin(r"Open MPI", versionString) + global MPIImpl[] = :OpenMPI + elseif occursin(r"MPICH", versionString) + global MPIImpl[] = :MPICH3 else error("don't know which MPI implemetation you are using here") end end + + CommWorld[] = CommWorldValue() +end + +# Get MPIWorldComm +function CommWorldValue() + r = Ref{ElComm}(0) + ccall((:ElMPICommWorld, libEl), Cuint, (Ref{ElComm},), r) + return r[] end function MPIType(t::DataType) - if MPIImpl == :OpenMPI + if MPIImpl[] == :OpenMPI if t == Float64 return Libdl.dlsym_e(Libdl.dlopen(libEl), :ompi_mpi_double) elseif t == Cint @@ -38,7 +48,7 @@ function MPIType(t::DataType) else error("data type not defined yet") end - elseif MPIImpl == :MPICH2 || MPIImpl == :MPICH3 + elseif MPIImpl[] == :MPICH2 || MPIImpl[] == :MPICH3 if t == Float64 return Cint(0x4c00080b) elseif t == Cint @@ -54,13 +64,13 @@ function MPIType(t::DataType) end function MPIOp(f::Function) - if MPIImpl == :OpenMPI + if MPIImpl[] == :OpenMPI if f == (+) return Libdl.dlsym_e(Libdl.dlopen(libEl), :ompi_mpi_op_sum) else error("operation not defined yet") end - elseif MPIImpl == :MPICH2 || MPIImpl == :MPICH3 + elseif MPIImpl[] == :MPICH2 || MPIImpl[] == :MPICH3 if f == (+) return Cint(0x58000003) else @@ -80,8 +90,17 @@ function commRank(comm::ElComm) return n[] end +function commSize(comm::ElComm) + n = Ref{Cint}() + err = ccall((:MPI_Comm_size, libEl), Cint, (ElComm, Ref{Cint}), comm, n) + if err != 0 + error("error value was $err") + end + return n[] +end + # FixMe! Should be restricted to support element types -function allreduce{T}(sendbuf::Ref{T}, recvbuf::Ref{T}, count::Integer, op::Function, comm::ElComm = CommWorld) +function allreduce(sendbuf::Ref{T}, recvbuf::Ref{T}, count::Integer, op::Function, comm::ElComm = CommWorld) where {T} err = ccall((:MPI_Allreduce, libEl), Cint, (Ref{T}, Ref{T}, Cint, ElComm, ElComm, ElComm), sendbuf, recvbuf, count, MPIType(T), MPIOp(op), comm) @@ -91,6 +110,6 @@ function allreduce{T}(sendbuf::Ref{T}, recvbuf::Ref{T}, count::Integer, op::Func return recvbuf end -allreduce{T}(value::T, op::Function, comm::ElComm = CommWorld) = ElInt(allreduce(Ref(value), Ref{T}(), 1, op, comm)[]) +allreduce(value::T, op::Function, comm::ElComm = CommWorld) where {T} = ElInt(allreduce(Ref(value), Ref{T}(), 1, op, comm)[]) end # module diff --git a/src/optimization/models.jl b/src/optimization/models.jl index d5e58bf..96b504c 100644 --- a/src/optimization/models.jl +++ b/src/optimization/models.jl @@ -9,14 +9,14 @@ for (elty, ext) in ((:Float32, :s), function lav!(A::$matA{$elty}, b::$matb{$elty}, x::$matb{$elty}) ElError(ccall(($(string("ElLAV", sym, ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, Ptr{Void}), + (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), A.obj, b.obj, x.obj)) return x end function lav!(A::$matA{$elty}, b::$matb{$elty}, x::$matb{$elty}, ctrl::LPAffineCtrl{$elty}) ElError(ccall(($(string("ElLAVX", sym, ext)), libEl), Cuint, - (Ptr{Void}, Ptr{Void}, Ptr{Void}, LPAffineCtrl{$elty}), + (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, LPAffineCtrl{$elty}), A.obj, b.obj, x.obj, ctrl)) return x end @@ -24,20 +24,20 @@ for (elty, ext) in ((:Float32, :s), end end -function lav{T<:Union{Float32,Float64}}(A::Matrix{T}, b::Matrix{T}) +function lav(A::Matrix{T}, b::Matrix{T}) where {T<:Union{Float32,Float64}} x = Matrix(T) return lav!(A, b, x) end -function lav{T<:Union{Float32,Float64}}(A::DistMatrix{T}, b::DistMatrix{T}) +function lav(A::DistMatrix{T}, b::DistMatrix{T}) where {T<:Union{Float32,Float64}} x = DistMatrix(T, MC, MR, A.g) return lav!(A, b, x) end -function lav{T<:Union{Float32,Float64}}(A::DistSparseMatrix{T}, b::DistMultiVec{T}) +function lav(A::DistSparseMatrix{T}, b::DistMultiVec{T}) where {T<:Union{Float32,Float64}} x = DistMultiVec(T, comm(A)) return lav!(A, b, x) end -function lav{T<:Union{Float32,Float64}}(A::DistSparseMatrix{T}, b::DistMultiVec{T}, ctrl::LPAffineCtrl{T}) +function lav(A::DistSparseMatrix{T}, b::DistMultiVec{T}, ctrl::LPAffineCtrl{T}) where {T<:Union{Float32,Float64}} x = DistMultiVec(T, comm(A)) return lav!(A, b, x, ctrl) end diff --git a/src/optimization/solvers.jl b/src/optimization/solvers.jl index 7d2129c..8f34986 100644 --- a/src/optimization/solvers.jl +++ b/src/optimization/solvers.jl @@ -34,7 +34,7 @@ struct MehrotraCtrl{T<:ElFloatType} diagEquilTol::T checkResiduals::ElBool end -function MehrotraCtrl{T<:ElFloatType}(::Type{T}; +function MehrotraCtrl(::Type{T}; primalInit::Bool = false, dualInit::Bool = false, minTol = eps(T)^0.3, @@ -55,7 +55,7 @@ function MehrotraCtrl{T<:ElFloatType}(::Type{T}; ruizEquilTol = eps(T)^(-0.25), ruizMaxIter = 3, diagEquilTol = eps(T)^(-0.15), - checkResiduals = false) + checkResiduals = false) where {T<:ElFloatType} MehrotraCtrl{T}(ElBool(primalInit), ElBool(dualInit), @@ -85,36 +85,36 @@ struct LPAffineCtrl{T<:ElFloatType} mehrotraCtrl::MehrotraCtrl{T} end -function LPAffineCtrl{T<:ElFloatType}(::Type{T}; +function LPAffineCtrl(::Type{T}; approach::Cuint = LP_MEHROTRA, - mehrotraCtrl::MehrotraCtrl = MehrotraCtrl(T)) + mehrotraCtrl::MehrotraCtrl = MehrotraCtrl(T)) where {T<:ElFloatType} LPAffineCtrl{T}(approach, mehrotraCtrl) end for (elty, ext) in ((:Float32, :s), (:Float64, :d)) - @eval begin - function LPAffine( - A::DistSparseMatrix{$elty}, - G::DistSparseMatrix{$elty}, - b::DistMultiVec{$elty}, - c::DistMultiVec{$elty}, - h::DistMultiVec{$elty}, - x::DistMultiVec{$elty}, - y::DistMultiVec{$elty}, - z::DistMultiVec{$elty}, - s::DistMultiVec{$elty}, - ctrl::LPAffineCtrl=SOCPAffineCtrl($elty)) - ElError(ccall(($(string("ElLPAffine_", ext)), libEl), Cuint, - (Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void}, - Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void}, - LPAffineCtrl{$elty}), - A.obj, G.obj, b.obj, c.obj, h.obj, - x.obj, y.obj, z.obj, s.obj, ctrl)) - return nothing + @eval begin + function LPAffine( + A::DistSparseMatrix{$elty}, + G::DistSparseMatrix{$elty}, + b::DistMultiVec{$elty}, + c::DistMultiVec{$elty}, + h::DistMultiVec{$elty}, + x::DistMultiVec{$elty}, + y::DistMultiVec{$elty}, + z::DistMultiVec{$elty}, + s::DistMultiVec{$elty}, + ctrl::LPAffineCtrl=SOCPAffineCtrl($elty)) + ElError(ccall(($(string("ElLPAffine_", ext)), libEl), Cuint, + (Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}, + Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}, + LPAffineCtrl{$elty}), + A.obj, G.obj, b.obj, c.obj, h.obj, + x.obj, y.obj, z.obj, s.obj, ctrl)) + return nothing + end end - end end # Second-Order Cone Programming @@ -129,38 +129,40 @@ struct SOCPAffineCtrl{T<:ElFloatType} approach::Cuint mehrotraCtrl::MehrotraCtrl{T} end -function SOCPAffineCtrl{T<:ElFloatType}(::Type{T}; +function SOCPAffineCtrl(::Type{T}; approach::Cuint = SOCP_MEHROTRA, - mehrotraCtrl::MehrotraCtrl = MehrotraCtrl(T)) + mehrotraCtrl::MehrotraCtrl = MehrotraCtrl(T)) where {T<:ElFloatType} + SOCPAffineCtrl{T}(approach, mehrotraCtrl) end for (elty, ext) in ((:Float32, :s), (:Float64, :d)) - @eval begin - function SOCPAffine( - A::DistSparseMatrix{$elty}, - G::DistSparseMatrix{$elty}, - b::DistMultiVec{$elty}, - c::DistMultiVec{$elty}, - h::DistMultiVec{$elty}, - orders::DistMultiVec{ElInt}, - firstInds::DistMultiVec{ElInt}, - labels::DistMultiVec{ElInt}, - x::DistMultiVec{$elty}, - y::DistMultiVec{$elty}, - z::DistMultiVec{$elty}, - s::DistMultiVec{$elty}, - ctrl::SOCPAffineCtrl=SOCPAffineCtrl($elty)) - ElError(ccall(($(string("ElSOCPAffine_", ext)), libEl), Cuint, - (Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void}, - Ptr{Void},Ptr{Void},Ptr{Void}, - Ptr{Void},Ptr{Void},Ptr{Void},Ptr{Void}, - SOCPAffineCtrl{$elty}), - A.obj, G.obj, b.obj, c.obj, h.obj, - orders.obj, firstInds.obj, labels.obj, - x.obj, y.obj, z.obj, s.obj, ctrl)) - return nothing + @eval begin + function SOCPAffine( + A::DistSparseMatrix{$elty}, + G::DistSparseMatrix{$elty}, + b::DistMultiVec{$elty}, + c::DistMultiVec{$elty}, + h::DistMultiVec{$elty}, + orders::DistMultiVec{ElInt}, + firstInds::DistMultiVec{ElInt}, + labels::DistMultiVec{ElInt}, + x::DistMultiVec{$elty}, + y::DistMultiVec{$elty}, + z::DistMultiVec{$elty}, + s::DistMultiVec{$elty}, + ctrl::SOCPAffineCtrl=SOCPAffineCtrl($elty)) + + ElError(ccall(($(string("ElSOCPAffine_", ext)), libEl), Cuint, + (Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}, + Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}, + Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}, + SOCPAffineCtrl{$elty}), + A.obj, G.obj, b.obj, c.obj, h.obj, + orders.obj, firstInds.obj, labels.obj, + x.obj, y.obj, z.obj, s.obj, ctrl)) + return nothing + end end - end end diff --git a/test/darray.jl b/test/darray.jl index e55adb3..7778a87 100644 --- a/test/darray.jl +++ b/test/darray.jl @@ -1,11 +1,12 @@ -using Base.Test +using Test using Elemental using DistributedArrays +using LinearAlgebra -A = drandn(50,50) -Al = convert(Array, A) -B = drandn(50,10) -Bl = convert(Array, B) +A = drandn(50,50) +Al = Matrix(A) +B = drandn(50,10) +Bl = Matrix(B) @test inv(Al) ≈ inv(A) @test Al\Bl ≈ A\B diff --git a/test/distmatrix.jl b/test/distmatrix.jl index 6c27a83..96833e8 100644 --- a/test/distmatrix.jl +++ b/test/distmatrix.jl @@ -1,4 +1,4 @@ -using Base.Test +using Test using Elemental for T in (Float32, Float64, Complex{Float32}, Complex{Float64}) diff --git a/test/generic.jl b/test/generic.jl index 6bd24e8..3ea8d01 100644 --- a/test/generic.jl +++ b/test/generic.jl @@ -1,4 +1,4 @@ -using Base.Test +using Test using Elemental for T in (Float32, Float64, Complex{Float32}, Complex{Float64}) diff --git a/test/lav.jl b/test/lav.jl index 068bd39..8353087 100644 --- a/test/lav.jl +++ b/test/lav.jl @@ -1,14 +1,13 @@ import Elemental const El = Elemental - -using MPI +using LinearAlgebra: mul! n0 = 50 n1 = 50 testNative = true display = false -worldRank = MPI.Comm_rank(MPI.COMM_WORLD) -worldSize = MPI.Comm_size(MPI.COMM_WORLD) +worldRank = El.MPI.commRank(El.MPI.CommWorld[]) +worldSize = El.MPI.commSize(El.MPI.CommWorld[]) if worldRank == 0 print("worldSize=$worldSize\n") end @@ -101,19 +100,19 @@ ctrl = El.LPAffineCtrl(Float64, elapsedLAV = @elapsed x = El.lav(A, b) elapsedLAV = @elapsed x = El.lav(A, b, ctrl) -if MPI.Comm_rank(MPI.COMM_WORLD) == 0 +if El.MPI.commRank(El.MPI.CommWorld[]) == 0 println("LAV time: $elapsedLAV seconds") end bTwoNorm = El.nrm2(b) bInfNorm = El.maxNorm(b) r = copy(b) -A_mul_B!(-1.0, A, x, 1.0, r) +mul!(r, A, x, -1.0, 1.0) rTwoNorm = El.nrm2(r) rOneNorm = El.entrywiseNorm(r, 1) -if MPI.Comm_rank(MPI.COMM_WORLD) == 0 +if El.MPI.commRank(El.MPI.CommWorld[]) == 0 println("|| b ||_2 = $bTwoNorm") println("|| b ||_oo = $bInfNorm") println("|| A x - b ||_2 = $rTwoNorm") @@ -122,23 +121,23 @@ end elapsedLS = @elapsed xLS = El.leastSquares(A, b) -if MPI.Comm_rank(MPI.COMM_WORLD) == 0 +if El.MPI.commRank(El.MPI.CommWorld[]) == 0 println("LS time: $elapsedLAV seconds") end rLS = copy(b) -A_mul_B!(-1.0, A, xLS, 1., rLS) +mul!(rLS, A, xLS, -1.0, 1.0) if display El.Display( rLS, "A x_{LS} - b" ) end rLSTwoNorm = El.nrm2(rLS) rLSOneNorm = El.entrywiseNorm(rLS, 1) -if MPI.Comm_rank(MPI.COMM_WORLD) == 0 +if El.MPI.commRank(El.MPI.CommWorld[]) == 0 println("|| A x_{LS} - b ||_2 = $rLSTwoNorm") println("|| A x_{LS} - b ||_1 = $rLSOneNorm") end # Require the user to press a button before the figures are closed # commSize = El.mpi.Size( El.mpi.COMM_WORLD() ) -El.Finalize() +# El.Finalize() diff --git a/test/lavdense.jl b/test/lavdense.jl index 9d1d24c..eff197e 100644 --- a/test/lavdense.jl +++ b/test/lavdense.jl @@ -1,12 +1,11 @@ import Elemental const El = Elemental - -using MPI +using LinearAlgebra: mul! m = 500 n = 250 display = true -worldRank = MPI.Comm_rank(MPI.COMM_WORLD) +worldRank = El.MPI.commRank(El.MPI.CommWorld[]) function rectang(height::Integer, width::Integer) A = El.DistMatrix() @@ -28,7 +27,7 @@ El.gaussian!(b, m, 1) # timeLAV = @elapsed x = El.lav(A, b, ctrl) timeLAV = @elapsed x = El.lav(A, b) -if MPI.Comm_rank(MPI.COMM_WORLD) == 0 +if El.MPI.commRank(El.MPI.CommWorld[]) == 0 println("LAV time: $timeLAV seconds") end @@ -39,7 +38,7 @@ bTwoNorm = El.nrm2(b) bInfNorm = El.maxNorm(b) r = copy(b) -A_mul_B!(-1.0, A, x, 1., r) +mul!(r, A, x, -1.0, 1.) # if display # El.Display(r, "r") @@ -64,7 +63,7 @@ end # end rLS = copy(b) -A_mul_B!(-1.0, A, xLS, 1.0, rLS) +mul!(rLS, A, xLS, -1.0, 1.0) # if display: # El.Display(rLS, "A x_{LS} - b") diff --git a/test/matrix.jl b/test/matrix.jl index 8ec0872..b7fea17 100644 --- a/test/matrix.jl +++ b/test/matrix.jl @@ -1,4 +1,4 @@ -using Base.Test +using Test using Elemental for T in (Float32, Float64, Complex{Float32}, Complex{Float64}) diff --git a/test/props.jl b/test/props.jl index 33008b2..183175e 100644 --- a/test/props.jl +++ b/test/props.jl @@ -1,5 +1,6 @@ -using Base.Test +using Test using Elemental +using LinearAlgebra m, n = 10, 10 @@ -8,9 +9,8 @@ for T in (Float32, Float64, Complex{Float32}, Complex{Float64}) A = mat(T) Elemental.gaussian!(A, m, n) - @test norm(A, 1) ≈ norm(T[A[i,j] for i = 1:m, j = 1:n], 1) - @test norm(A) ≈ norm(T[A[i,j] for i = 1:m, j = 1:n]) - @test norm(A, Inf) ≈ norm(T[A[i,j] for i = 1:m, j = 1:n], Inf) - @test countnz(A) ≈ countnz(T[A[i,j] for i = 1:m, j = 1:n]) + @test opnorm(A, 1) ≈ opnorm(T[A[i,j] for i = 1:m, j = 1:n], 1) + @test opnorm(A) ≈ opnorm(T[A[i,j] for i = 1:m, j = 1:n]) + @test opnorm(A, Inf) ≈ opnorm(T[A[i,j] for i = 1:m, j = 1:n], Inf) end end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index b958f25..225dbef 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,21 +1,19 @@ -using Elemental -using Base.Test +using Test function runtests_mpirun() - nprocs = min(4, Sys.CPU_CORES) - exename = joinpath(JULIA_HOME, Base.julia_exename()) + nprocs = min(4, Sys.CPU_THREADS) testdir = dirname(@__FILE__) testfiles = ["lav.jl", "lavdense.jl", "matrix.jl", "distmatrix.jl", "props.jl", "generic.jl", "spectral.jl"] nfail = 0 - print_with_color(:white, "Running Elemental.jl tests\n") + @info "Running Elemental.jl tests" for f in testfiles try - run(`mpirun -np $nprocs $exename $(joinpath(testdir, f))`) - Base.with_output_color(:green,STDOUT) do io + run(`mpirun -np $nprocs $(Base.julia_cmd()) $(joinpath(testdir, f))`) + Base.with_output_color(:green,stdout) do io println(io,"\tSUCCESS: $f") end catch ex - Base.with_output_color(:red,STDERR) do io + Base.with_output_color(:red,stderr) do io println(io,"\tError: $f") showerror(io,ex,backtrace()) end @@ -26,21 +24,23 @@ function runtests_mpirun() end function runtests_repl() - nprocs = min(4, Sys.CPU_CORES) - exename = joinpath(JULIA_HOME, Base.julia_exename()) + nprocs = min(4, Sys.CPU_THREADS) + exename = joinpath(Sys.BINDIR, Base.julia_exename()) testdir = dirname(@__FILE__) testfiles = ["darray.jl"] nfail = 0 - print_with_color(:white, "Running Elemental.jl tests\n") + @info "Running Elemental.jl tests" for f in testfiles try - cmdstr = "using MPI; man = MPIManager(np = $nprocs); addprocs(man); include(\"$(joinpath(testdir, f))\")" + # FixMe! We temporarily run Finalize() explictly on the workers because the atexit hook + # doesn't seem to be correctly triggered on workers as of 31 October 2018. + cmdstr = "using Distributed, MPI; man = MPIManager(np = $nprocs); addprocs(man); include(\"$(joinpath(testdir, f))\"); asyncmap(p -> remotecall_fetch(() -> Elemental.Finalize(), p), workers())" run(`$exename -e $cmdstr`) - Base.with_output_color(:green,STDOUT) do io + Base.with_output_color(:green,stdout) do io println(io,"\tSUCCESS: $f") end catch ex - Base.with_output_color(:red,STDERR) do io + Base.with_output_color(:red,stderr) do io println(io,"\tError: $f") showerror(io,ex,backtrace()) end diff --git a/test/spectral.jl b/test/spectral.jl index 77fd922..6a033ca 100644 --- a/test/spectral.jl +++ b/test/spectral.jl @@ -1,4 +1,6 @@ -using Elemental, Base.Test +using Elemental +using Test +using LinearAlgebra: eigvals @testset "generel eigenvalues (Schur) with eltype: $elty" for elty in (Float32, Float64, Complex{Float32}, Complex{Float64}) n = 10