Skip to content

Commit

Permalink
Use lu! for economy mode. No economy argument to lu any more.
Browse files Browse the repository at this point in the history
lu is implemented using lu!
Close #272.
  • Loading branch information
ViralBShah committed Dec 25, 2011
1 parent 2efd6b5 commit 3e7a50d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 43 deletions.
78 changes: 56 additions & 22 deletions external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ OPENBLAS_VER = v0.1alpha2.4
LAPACK_VER = 3.4.0
ARPACK_VER = 96
FFTW_VER = 3.3
SUITESPARSE_VER = 3.7.0
CLP_VER = 1.14.5
UNWIND_VER = 0.99
LIGHTTPD_VER = 1.4.29
Expand Down Expand Up @@ -301,34 +302,38 @@ clean-fftw-double:
distclean-fftw:
rm -rf fftw-$(FFTW_VER).tar.gz fftw-$(FFTW_VER)-{single,double}

## UNWIND ##

LIBUNWIND_TARGET_OBJ = $(EXTROOTLIB)/libunwind.a
LIBUNWIND_TARGET_SOURCE = $(JULIAHOME)/external/libunwind-$(UNWIND_VER)/Makefile

compile-unwind: $(LIBUNWIND_TARGET_SOURCE)
install-unwind: $(LIBUNWIND_TARGET_OBJ)

$(LIBUNWIND_TARGET_OBJ): $(LIBUNWIND_TARGET_SOURCE)
cd libunwind-$(UNWIND_VER) && $(MAKE) && $(MAKE) install
## SUITESPARSE ##

SUITESPARSE_OBJ_TARGET = $(EXTROOTLIB)/libSuiteSparse.$(SHLIB_EXT)
SUITESPARSE_OBJ_SOURCE = SuiteSparse-$(SUITESPARSE_VER)/libSuiteSparse.$(SHLIB_EXT)

libunwind-$(UNWIND_VER).tar.gz:
curl -O http://savannah.spinellicreations.com/libunwind/libunwind-$(UNWIND_VER).tar.gz
compile-SuiteSparse: $(SUITESPARSE_OBJ_SOURCE)
install-SuiteSparse: $(SUITESPARSE_OBJ_TARGET)

open-unwind: libunwind-$(UNWIND_VER).tar.gz
tar xvfz $<
SuiteSparse-$(SUITESPARSE_VER).tar.gz:
curl http://www.cise.ufl.edu/research/sparse/SuiteSparse/SuiteSparse-$(SUITESPARSE_VER).tar.gz > $@
SuiteSparse-patch.tar.gz:
curl http://www.caam.rice.edu/software/SUITESPARSE/SRC/patch.tar.gz > $@
SuiteSparse-$(SUITESPARSE_VER)/Makefile: SuiteSparse-$(SUITESPARSE_VER).tar.gz SuiteSparse-patch.tar.gz
mkdir -p SuiteSparse-$(SUITESPARSE_VER)
for x in $^; do tar -C SuiteSparse-$(SUITESPARSE_VER) --strip-components 1 -zxf $$x; done
perl -i -nle 'print unless /EXTERNAL\s+ETIME/' SuiteSparse-$(SUITESPARSE_VER)/UTIL/second.f
touch $@
$(SUITESPARSE_OBJ_SOURCE): SuiteSparse-$(SUITESPARSE_VER)/Makefile
cd SuiteSparse-$(SUITESPARSE_VER) && \
$(MAKE) lib MAKE=make PLAT= home=`pwd` FC=$(FC) FFLAGS="-O3 -fPIC" && \
ar x libSuiteSparse_.a && \
$(FC) -shared *.o -o libSuiteSparse.$(SHLIB_EXT)
$(SUITESPARSE_OBJ_TARGET): $(SUITESPARSE_OBJ_SOURCE)
mkdir -p $(EXTROOTLIB)
cp $< $@

$(LIBUNWIND_TARGET_SOURCE): open-unwind
cd libunwind-$(UNWIND_VER) && ./configure CFLAGS="-U_FORTIFY_SOURCE -fPIC" --prefix=$(EXTROOT)

clean-unwind:
$(MAKE) -C libunwind-$(UNWIND_VER) clean
rm -rf $(LIBUNWIND_TARGET_OBJ) $(LIBUNWIND_TARGET_SOURCE)

distclean-unwind:
rm -rf libunwind-$(UNWIND_VER).tar.gz libunwind-$(UNWIND_VER)
clean-SuiteSparse:
$(MAKE) -C SuiteSparse-$(SUITESPARSE_VER) home=`pwd`/SuiteSparse-$(SUITESPARSE_VER) clean MAKE=make
rm -f $(SUITESPARSE_OBJ_SOURCE) $(SUITESPARSE_OBJ_TARGET)
distclean-SuiteSparse:
rm -rf SuiteSparse-$(SUITESPARSE_VER).tar.gz SuiteSparse-patch.tar.gz SuiteSparse-$(SUITESPARSE_VER)

## CLP ##

Expand All @@ -355,6 +360,35 @@ clean-clp:
distclean-clp:
rm -rf Clp-$(CLP_VER).tar.bz2 Clp-$(CLP_VER)

## UNWIND ##

LIBUNWIND_TARGET_OBJ = $(EXTROOTLIB)/libunwind.a
LIBUNWIND_TARGET_SOURCE = $(JULIAHOME)/external/libunwind-$(UNWIND_VER)/Makefile

compile-unwind: $(LIBUNWIND_TARGET_SOURCE)
install-unwind: $(LIBUNWIND_TARGET_OBJ)

$(LIBUNWIND_TARGET_OBJ): $(LIBUNWIND_TARGET_SOURCE)
cd libunwind-$(UNWIND_VER) && $(MAKE) && $(MAKE) install


libunwind-$(UNWIND_VER).tar.gz:
curl -O http://savannah.spinellicreations.com/libunwind/libunwind-$(UNWIND_VER).tar.gz

open-unwind: libunwind-$(UNWIND_VER).tar.gz
tar xvfz $<
touch $@

$(LIBUNWIND_TARGET_SOURCE): open-unwind
cd libunwind-$(UNWIND_VER) && ./configure CFLAGS="-U_FORTIFY_SOURCE -fPIC" --prefix=$(EXTROOT)

clean-unwind:
$(MAKE) -C libunwind-$(UNWIND_VER) clean
rm -rf $(LIBUNWIND_TARGET_OBJ) $(LIBUNWIND_TARGET_SOURCE)

distclean-unwind:
rm -rf libunwind-$(UNWIND_VER).tar.gz libunwind-$(UNWIND_VER)

## GNU LIGHTTPD ##

LIGHTTPD_OBJ_TARGET = $(EXTROOT)/sbin/lighttpd
Expand Down
34 changes: 17 additions & 17 deletions j/linalg_lapack.j
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,34 @@ end
@_jl_lapack_getrf_macro :zgetrf_ Complex128
@_jl_lapack_getrf_macro :cgetrf_ Complex64

lu(A::StridedMatrix) = lu(A, false)
lu{T<:Integer}(x::StridedMatrix{T}) = lu(float64(x))

lu{T<:Integer}(x::StridedMatrix{T}) = lu(float64(x), false)
function lu{T<:Union(Float32,Float64,Complex64,Complex128)}(A::StridedMatrix{T})
(LU, P) = lu!(copy(A))
m, n = size(A)

L = tril(LU, -1) + eye(m,n)
U = m <= n ? triu(LU) : triu(LU)[1:n, :]
return (L, U, P)
end

function lu{T<:Union(Float32,Float64,Complex64,Complex128)}(A::StridedMatrix{T},
economy::Bool)
function lu!{T<:Union(Float32,Float64,Complex64,Complex128)}(A::StridedMatrix{T})
if stride(A,1) != 1; error("lu: matrix columns must have contiguous elements"); end
m, n = size(A)
LU = A
if !economy
LU = copy(A)
end
ipiv = Array(Int32, min(m,n))

info = _jl_lapack_getrf(m, n, LU, stride(LU,2), ipiv)
info = _jl_lapack_getrf(m, n, A, stride(A,2), ipiv)

if info > 0; error("matrix is singular"); end
P = linspace(1, m)
for i=1:min(m,n); t = P[i]; P[i] = P[ipiv[i]]; P[ipiv[i]] = t ; end
for i=1:min(m,n)
t = P[i]
P[i] = P[ipiv[i]]
P[ipiv[i]] = t
end

if info == 0
if economy
return (LU, P)
else
L = tril(LU, -1) + eye(m,n)
U = m <= n ? triu(LU) : triu(LU)[1:n, :]
return (L, U, P)
end
return (A, P)
end
error("error in LU")
end
Expand Down
6 changes: 3 additions & 3 deletions test/bench/hpl_par.j
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function panel_factor(A_KI, col_dep)
@assert col_dep

## Factorize a panel
(A_KI, panel_p) = lu(A_KI, true) # Economy mode
(A_KI, panel_p) = lu!(A_KI) # Economy mode

return (A_KI, panel_p)

Expand Down Expand Up @@ -205,8 +205,8 @@ function panel_factor2(C, i, n)
(I = (C.dist[i]):(C.dist[i+1]-1))
K = I[1]:n
C_KI = C[K,I]
#(C_KI, panel_p) = lu(C_KI, true) #economy mode
panel_p = lu(C_KI, true)[2]
#(C_KI, panel_p) = lu!(C_KI) #economy mode
panel_p = lu!(C_KI)[2]
C[K,I] = C_KI

return panel_p
Expand Down
2 changes: 1 addition & 1 deletion test/bench/hpl_seq.j
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function panel_factor(A, I, col_dep)

## Factorize a panel
K = I[1]:n
(A[K,I], panel_p) = lu(A[K,I], true) # Economy mode
(A[K,I], panel_p) = lu!(A[K,I]) # Economy mode

## Panel permutation
panel_p = K[panel_p]
Expand Down

0 comments on commit 3e7a50d

Please sign in to comment.