ports/159129: math/arpack should not be linked with math/lapack

Stephen Montgomery-Smith stephen at FreeBSD.org
Sat Jul 23 04:50:10 UTC 2011


>Number:         159129
>Category:       ports
>Synopsis:       math/arpack should not be linked with math/lapack
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          maintainer-update
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 23 04:50:09 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Stephen Montgomery-Smith
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
>Environment:
System: FreeBSD wilberforce 8.2-STABLE FreeBSD 8.2-STABLE #0: Sat May 28 09:40:58 CDT 2011 stephen at laptop5.gateway.2wire.net:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
math/arpack needs to use lapack version 2 functions for its operation.  However math/lapack is at version 3.  So math/arpack provides its own lapack functions in its source code.

However this can create problems when linking a program with arpack and lapack together.  This is described at http://mathema.tician.de/node/373, and there he provides a patch so that the function "second" is not duplicated in both libraries.

But Pedro F. Giffuni, the original creator of the math/arpack port, pointed out that there still may be problems linking arpack and lapack together, because of the common names used for the version 2 and version 3 lapack functions.

>How-To-Repeat:
See ports/147487.

>Fix:

	

I have added a perl script that mangles the version 2 lapack function names.  This is invoked, along with the patch described at http://mathema.tician.de/node/373, by the MANGLE_LAPACK_NAMES option, which is off by default.

None of this seems to affect any of the other ports that use arpack, and they seem to build equally well whether or not the MANGLE_LAPACK_NAMES option is off or on.

I know I am the maintainer of this port and a committer.  But I am submitting it as a PR, because my solution method is a bit unusual, and I want to give an opportunity for people to comment on my proposed solution.


diff -urN /usr/ports/math/arpack/Makefile arpack/Makefile
--- /usr/ports/math/arpack/Makefile	2011-07-22 15:21:20.000000000 -0500
+++ arpack/Makefile	2011-07-22 19:56:46.000000000 -0500
@@ -7,7 +7,7 @@
 
 PORTNAME=	arpack
 PORTVERSION=	96
-PORTREVISION=	8
+PORTREVISION=	9
 CATEGORIES=	math
 MASTER_SITES=	http://www.caam.rice.edu/software/ARPACK/SRC/
 DISTFILES=	${PORTNAME}${PORTVERSION}.tar.gz patch.tar.gz
@@ -17,15 +17,14 @@
 DIST_SUBDIR=	arpack
 EXTRACT_ONLY=	${PORTNAME}${PORTVERSION}.tar.gz
 
-PATCH_SITES=	http://mathema.tician.de/news.tiker.net/files/
-PATCHFILES=	arpack-arscnd-3.patch.gz
-PATCH_DIST_STRIP=	-p1
-
 MAINTAINER=	stephen at FreeBSD.org
 COMMENT=	Argand Library: large eigenvalue subroutines (serial version)
 
+OPTIONS=	MANGLE_LAPACK_NAMES "Mangle LAPACK names" Off
+
 LDFLAGS+=	-L${LOCALBASE}/lib
 USE_FORTRAN=	yes
+FFLAGS+=	-ffixed-line-length-none
 USE_LDCONFIG=	yes
 WRKSRC =	${WRKDIR}/ARPACK
 
@@ -46,6 +45,13 @@
 
 .include <bsd.port.pre.mk>
 
+.if defined(WITH_MANGLE_LAPACK_NAMES)
+PATCH_SITES=	http://mathema.tician.de/news.tiker.net/files/
+PATCHFILES=	arpack-arscnd-3.patch.gz
+PATCH_DIST_STRIP=	-p1
+USE_PERL5_BUILD=	yes
+.endif
+
 .if exists(${LOCALBASE}/lib/libatlas_r.so)
 WITH_BLAS?=	atlas
 .else
@@ -69,15 +75,25 @@
 post-extract:
 	@${TAR} -C ${WRKDIR} -xzf ${_DISTDIR}/patch.tar.gz
 	@${GZIP_CMD} ${WRKSRC}/DOCUMENTS/ex-*.doc
-
 post-patch:
 	@${REINPLACE_CMD} -E \
 		-e '/^(home|AR|FC|LDFLAGS|MAKE|PLAT|RANLIB|SHELL)[[:space:]]+=/d' \
 		-e '/^ARPACKLIB[[:space:]]+=/s/_\$$\(PLAT\)//' \
 		-e '\|^BLASLIB[[:space:]]+=|s|=.*|= ${LDFLAGS} ${BLAS}|' \
 		-e '/^DIRS[[:space:]]+=/s/\$$\(BLASdir\)//' \
-		-e '\|^FFLAGS[[:space:]]+=|s|=.*|= ${FFLAGS} $${PICFLAG}|' \
+		-e '\|^FFLAGS[[:space:]]+=|s|=.*|= ${FFLAGS} $${PICFLAG} -ffixed-line-length-none|' \
 			${WRKSRC}/ARmake.inc
+.if defined(WITH_MANGLE_LAPACK_NAMES)
+	@${SETENV} FILESDIR=${FILESDIR} WRKSRC=${WRKSRC} WRKDIR=${WRKDIR} \
+		${PERL} ${SCRIPTDIR}/mangle-lapack-names.pl
+.else
+	@${CP} ${FILESDIR}/arpack.h ${WRKDIR}/
+.endif
+.if defined(WITH_MANGLE_LAPACK_NAMES)
+	@cd ${WRKSRC} && ${PATCH} < ${FILESDIR}/UTIL+arscnd.f-patch
+.else
+	@cd ${WRKSRC} && ${PATCH} < ${FILESDIR}/UTIL+second.f-patch
+.endif
 	@${CP} -R ${WRKSRC} ${WRKSRC}_SHARED
 
 do-build:
@@ -90,7 +106,7 @@
 		${LD} -Bshareable -o libarpack.so.1 -x -soname libarpack.so.1 --whole-archive libarpack.a
 
 do-install:
-	@${INSTALL_DATA} ${FILESDIR}/arpack.h ${PREFIX}/include
+	@${INSTALL_DATA} ${WRKDIR}/arpack.h ${PREFIX}/include
 	@${INSTALL_DATA} ${WRKSRC}/libarpack.a ${PREFIX}/lib
 	@${INSTALL_DATA} ${WRKSRC}_SHARED/libarpack.so.1 ${PREFIX}/lib
 	@${LN} -sf libarpack.so.1 ${PREFIX}/lib/libarpack.so
@@ -108,7 +124,7 @@
 	@cd ${WRKSRC}/EXAMPLES/SIMPLE ; ${SETENV} ${MAKE_ENV} \
 		PICFLAG= home="${WRKSRC}" \
 		${MAKE} ${_MAKE_JOBS} ${MAKE_ARGS} simple ; ${SIMPLETESTS:S|^|./|:S|$| ; |}
-	@cd ${WRKSRC}_SHARED/EXAMPLES/SIMPLE ; ${SETENV} ${MAKE_ENV} \
+	cd ${WRKSRC}_SHARED/EXAMPLES/SIMPLE ; ${SETENV} ${MAKE_ENV} \
 		PICFLAG=${PICFLAG}  home="${WRKSRC}_SHARED" \
 		${MAKE} ${_MAKE_JOBS} ${MAKE_ARGS} simple ; ${SIMPLETESTS:S|^|./|:S|$| ; |}
 
diff -urN /usr/ports/math/arpack/files/UTIL+arscnd.f-patch arpack/files/UTIL+arscnd.f-patch
--- /usr/ports/math/arpack/files/UTIL+arscnd.f-patch	1969-12-31 18:00:00.000000000 -0600
+++ arpack/files/UTIL+arscnd.f-patch	2011-07-22 14:38:20.000000000 -0500
@@ -0,0 +1,10 @@
+--- UTIL/arscnd.f.bak	2011-07-20 19:47:43.000000000 -0400
++++ UTIL/arscnd.f	2011-07-20 19:48:05.000000000 -0400
+@@ -21,7 +21,6 @@
+ *     ..
+ *     .. External Functions ..
+       REAL               ETIME
+-      EXTERNAL           ETIME
+ *     ..
+ *     .. Executable Statements ..
+ *
diff -urN /usr/ports/math/arpack/files/UTIL+second.f-patch arpack/files/UTIL+second.f-patch
--- /usr/ports/math/arpack/files/UTIL+second.f-patch	1969-12-31 18:00:00.000000000 -0600
+++ arpack/files/UTIL+second.f-patch	2011-07-22 14:37:29.000000000 -0500
@@ -0,0 +1,10 @@
+--- UTIL/second.f.bak	2011-07-20 19:47:43.000000000 -0400
++++ UTIL/second.f	2011-07-20 19:48:05.000000000 -0400
+@@ -21,7 +21,6 @@
+ *     ..
+ *     .. External Functions ..
+       REAL               ETIME
+-      EXTERNAL           ETIME
+ *     ..
+ *     .. Executable Statements ..
+ *
diff -urN /usr/ports/math/arpack/files/patch-UTIL+second.f arpack/files/patch-UTIL+second.f
--- /usr/ports/math/arpack/files/patch-UTIL+second.f	2011-07-22 15:21:20.000000000 -0500
+++ arpack/files/patch-UTIL+second.f	1969-12-31 18:00:00.000000000 -0600
@@ -1,10 +0,0 @@
---- UTIL/arscnd.f.bak	2011-07-20 19:47:43.000000000 -0400
-+++ UTIL/arscnd.f	2011-07-20 19:48:05.000000000 -0400
-@@ -21,7 +21,6 @@
- *     ..
- *     .. External Functions ..
-       REAL               ETIME
--      EXTERNAL           ETIME
- *     ..
- *     .. Executable Statements ..
- *
diff -urN /usr/ports/math/arpack/pkg-descr arpack/pkg-descr
--- /usr/ports/math/arpack/pkg-descr	2006-01-14 19:35:37.000000000 -0600
+++ arpack/pkg-descr	2011-07-22 21:59:52.000000000 -0500
@@ -1,24 +1,19 @@
-The package is designed to compute a few eigenvalues and corresponding 
-eigenvectors of a general n by n matrix A. It is most appropriate for large 
-sparse or structured matrices A where structured means that a matrix-vector 
-product w <- Av requires order n rather than the usual order n2 floating point
-operations. This software is based upon an algorithmic variant of the Arnoldi
-process called the Implicitly Restarted Arnoldi Method (IRAM). When the matrix
-A is symmetric it reduces to a variant of the Lanczos process called the 
-Implicitly Restarted Lanczos Method (IRLM). These variants may be viewed as a
-synthesis of the Arnoldi/Lanczos process with the Implicitly Shifted QR
-technique that is suitable for large scale problems. For many standard 
-problems, a matrix factorization is not required. Only the action of the matrix
-on a vector is needed.
-ARPACK software is capable of solving large scale symmetric, nonsymmetric, 
-and generalized eigenproblems from significant application areas. The software
-is designed to compute a few (k) eigenvalues with user specified features 
-such as those of largest real part or largest magnitude. Storage requirements
-are on the order of n*k locations. No auxiliary storage is required. A set 
-of Schur basis vectors for the desired k-dimensional eigen-space is computed
-which is numerically orthogonal to working precision. Numerically accurate 
-eigenvectors are available on request.
+ARPACK software is designed to solve symmetric, nonsymmetric, and generalized
+eigenproblems for sparse matrices.  The software is designed to compute a few
+(k) eigenvalues with user specified features such as those of largest real
+part or largest magnitude. Storage requirements are on the order of n*k
+locations. A set of Schur basis vectors for the desired k-dimensional
+eigen-space is computed which is numerically orthogonal to working precision.
+Numerically accurate eigenvectors are available on request.
 
 WWW:	http://www.caam.rice.edu/software/ARPACK/
 
-NOTE: You MUST link with BLAS library or a replacement like ATLAS.
+NOTES
+1. You MUST link with the BLAS library or a replacement like ATLAS.
+2. ARPACK is designed to work with lapack version 2, and it provides its own
+   lapack routines.  If you have to link with lapack version 3 or greater,
+   it is recommended that you switch on the option MANGLE_LAPACK_NAMES.  This
+   does two things.  First it uses a patch described at
+   http://mathema.tician.de/node/373.  Secondly, it mangles all the names of
+   the LAPACK routines provided in ARPACK by preceding each function or
+   subroutine name by "AR_".
diff -urN /usr/ports/math/arpack/scripts/mangle-lapack-names.pl arpack/scripts/mangle-lapack-names.pl
--- /usr/ports/math/arpack/scripts/mangle-lapack-names.pl	1969-12-31 18:00:00.000000000 -0600
+++ arpack/scripts/mangle-lapack-names.pl	2011-07-22 15:08:57.000000000 -0500
@@ -0,0 +1,43 @@
+$WRKSRC = $ENV{"WRKSRC"} || die;
+$WRKDIR = $ENV{"WRKDIR"} || die;
+$FILESDIR = $ENV{"FILESDIR"} || die;
+$|=1;
+
+while (<$WRKSRC/LAPACK/*.f>) {
+  open(FOR,$_);
+  while (<FOR>) {
+    push @functions, $1 if /FUNCTION\s+(\w+)/ || /SUBROUTINE\s+(\w+)/;
+  }
+  close FOR;
+}
+
+print "Mangling LAPACK names.  This may take some time.\n";
+open(LIST,"find $WRKSRC -type f -name \"*.f\" |");
+while ($filename = <LIST>) {
+  print ".";
+  chomp $filename;
+  rename $filename, "$filename.bak";
+  open(IN,"$filename.bak") || die;
+  $contents = join "", <IN>;
+  close IN;
+  foreach (@functions) {
+    $contents =~ s/\b$_\b/AR_$_/gi;
+  }
+  open(OUT,"> $filename") || die;
+  print OUT $contents;
+  close OUT;
+}
+close LIST;
+
+print ".";
+open(IN,"$FILESDIR/arpack.h") || die;
+$contents = join '',<IN>;
+close IN;
+foreach (@functions) {
+  $_ = lc($_);
+  $contents =~ s/\b${_}_\b/ar_${_}_/g;
+}
+open(OUT,"> $WRKDIR/arpack.h") || die;
+print OUT $contents;
+close OUT;
+print "\nDone mangling.\n";
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list