Bug 147487 - [PATCH] strange behaviour of math/arpack linking with lapack library
Summary: [PATCH] strange behaviour of math/arpack linking with lapack library
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Stefan Walter
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-05 04:40 UTC by Eijiro Shibusawa
Modified: 2010-07-01 21:00 UTC (History)
0 users

See Also:


Attachments
ddd (1.42 KB, text/plain)
2010-06-05 05:32 UTC, Stephen Montgomery-Smith
no flags Details
arpack-patch.txt (1.63 KB, text/plain)
2010-06-05 05:05 UTC, Eijiro Shibusawa
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eijiro Shibusawa 2010-06-05 04:40:05 UTC
When some code is linked with both arpack and lapack library, the arpack routine dsaupd exits with error code -9999, which indicates the routine could not build an Arnoldi factorization.
However the value of iparam[4] indicates all the requested  eigenvalues are successfully converged.
This behaviour seemingly caused by symbol duplication problem described in following website.

http://mathema.tician.de/node/373

After applying the patch provided at the site, I found the code successfully finds all the requested eigen values.

How-To-Repeat: # cd /usr/ports/math/arpack 

# make install WITH_ATLAS=YES

$ gcc44 -v
Using built-in specs.
Target: i386-portbld-freebsd8.0
Configured with: ./../gcc-4.4-20090915/configure --disable-nls --with-system-zlib --with-libiconv-prefix=/usr/local --with-gmp=/usr/local --program-suffix=44 --libdir=/usr/local/lib/gcc44 --libexecdir=/usr/local/libexec/gcc44 --with-gxx-include-dir=/usr/local/lib/gcc44/include/c++/ --disable-rpath --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc44 --build=i386-portbld-freebsd8.0
Thread model: posix
gcc version 4.4.2 20090915 (prerelease) (GCC) 

$ gcc44 arpack.c -oa.out -Wall -I/usr/local/include -L/usr/local/lib -L. -llapack -lcblas -lf77blas -latlas -lm -lgfortran -larpack

$ ./a.out
Error with dsaupd, info = -9999 
Check documentation in dsaupd
3/3 eigen value(s) are successfully converged.

================================ arpack.c =======================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <cblas.h>

int dsaupd_(long *ido, char *bmat, long *n, char *which,
	    long *nev, double *tol, double *resid, long *ncv,
	    double *v, long *ldv, long *iparam, long *ipntr,
	    double *workd, double *workl, long *lworkl,
	    long *info);

int dseupd_(long *rvec, char *howmny, long *select,
	    double *d, double *z, long *ldz,
	    double *sigma, char *bmat, long *n,
	    char *which, long *nev,
	    double *tol, double *resid,
	    long *ncv, double *v, long *ldv,
	    long *iparam, long *ipntr,
	    double *workd, double *workl, long *lworkl, long *info);


/*********************************************************************************/
/*  wrapper for arpack routine                                                   */
/*********************************************************************************/
long dsaupd_lm_wrap(long n, const double *H, double *Z,
		   double *s, long nev){

  long dbuf_len;
  double *dbuf;
  long ibuf_len;
  long *ibuf;

  /* dsaupd */
  long ido = 0;
  char bmat[2] = "I"; /* standerd eigen problem */
  char which[3] = "LM"; /* Largest Magnitude */
  double tol = 0.0;
  long ldv;
  double *resid, *v, *d;
  double *workd, *workl;
  long ncv, lworkl, info, *iparam, *ipntr;
  /* dsaupd */
  long rvec = 1;
  char howmny[2] = "A";
  long *select, ierr;
  double sigma;

  /* number of the lanczos vector */
  ncv = nev*2;
  if(ncv > n){
    ncv = n;
  }

  ldv = n;
  lworkl = ncv*ncv + 8*ncv;
  dbuf_len = n + n*ncv + 3*n + lworkl + n;
  dbuf = (double *)malloc(dbuf_len*sizeof(double));
  resid = dbuf;
  v = resid + n;
  workd = v + n*ncv;
  workl = workd + 3*n;
  d = workl + lworkl;

  ibuf_len = 11 + 11 + ncv;
  ibuf = (long *)malloc(ibuf_len*sizeof(long));
  iparam = ibuf;
  ipntr = iparam + 11;
  select = ipntr + 11;

  iparam[0] = 1;
  iparam[2] = 3*n; /* max iteration */
  iparam[6] = 1;   /* standerd eigen problem */

  /* initialize */
  info = 0;

  do {
    /* reverse communication */
    dsaupd_(&ido, bmat, &n, which, &nev, &tol, resid,
	    &ncv, v, &ldv, iparam, ipntr,
	    workd, workl, &lworkl, &info);

    if ((ido == 1) || (ido == -1)){
      /* y = H*x */
      cblas_dsymv(CblasColMajor, CblasLower,
		  n, 1.0, H, n,
		  workd+(ipntr[0]-1), 1, 0.0, workd+(ipntr[1]-1), 1);
      /* z = B*x = x */
      if(ido == 1){
	memcpy(workd+(ipntr[2]-1), workd+(ipntr[0]-1), n*sizeof(double));
      }
    }
    else if (ido != 99){
      fprintf(stderr, "Error with (dsaupd_lm_wrap), ido = %ld \n", ido);
      fprintf(stderr, "Check documentation in dsaupd\n\n");
    }

  }while ((ido == 1) ||
	  (ido == -1));

  if (info < 0) {
    fprintf(stderr, "Error with dsaupd, info = %ld \n", info);
    fprintf(stderr, "Check documentation in dsaupd\n");
    if(info == -9999){
      fprintf(stderr, "%ld/%ld eigen value(s) are successfully converged. \n", iparam[4], nev);
    }
    fprintf(stderr, "\n");
    exit(1);
  }
  else {
    dseupd_(&rvec, howmny, select, s, Z, &ldv, &sigma, bmat,
	    &n, which, &nev, &tol, resid, &ncv, v, &ldv,
	    iparam, ipntr, workd, workl, &lworkl, &ierr);
    if (ierr!=0) {
      fprintf(stderr, "Error with dseupd, info = %ld\n", ierr);
      fprintf(stderr, "Check the documentation of dseupd.\n\n");
    } else if (info==1) {
      fprintf(stderr, "Maximum number of iterations reached.\n\n");
    } else if (info==3) {
      fprintf(stderr, "No shifts could be applied during implicit\n");
      fprintf(stderr, "Arnoldi update, try increasing NCV.\n\n");
    }
  }

  free(dbuf);
  free(ibuf);


  return 0;
}

int main(int argc, char *argv[])
{

  int i;
  long nR, rank, buf_len;
  double *R, *Z, *s, *buf;

  nR = 8;
  rank = 3;
  buf_len = nR*nR + rank*nR + rank;
  buf = (double *)malloc(buf_len*sizeof(double));
  R = buf;
  Z = R + nR*nR;
  s = Z + rank*nR;

  /* The Rosser Matrix (8x8, Column Major) */
  R[0] =  611;
  R[1] =  196; R[9]  =  899;
  R[2] = -192; R[10] =  113; R[18] = 899;
  R[3] =  407; R[11] = -192; R[19] = 196; R[27] =  611;
  R[4] =   -8; R[12] =  -71; R[20] =  61; R[28] =    8; R[36] =  411;
  R[5] =  -52; R[13] =  -43; R[21] =  49; R[29] =   44; R[37] = -599; R[45] = 411;
  R[6] =  -49; R[14] =   -8; R[22] =   8; R[30] =   59; R[38] =  208; R[46] = 208;
  R[7] =   29; R[15] =  -44; R[23] =  52; R[31] =  -23; R[39] =  208; R[47] = 208;

  R[54] =   99;
  R[55] = -911; R[63] = 99;

  /* Solve eigen problem of the Rosser matrix using arpack */
  dsaupd_lm_wrap(nR, R, Z, s, rank);

  /* Display eigen values */
  for(i=0; i< rank; i++){
    printf("%lf ", s[i]);
  }
  printf("\n");

  free(buf);

  return 0;
}
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2010-06-05 04:40:12 UTC
Maintainer of math/arpack,

Please note that PR ports/147487 has just been submitted.

If it contains a patch for an upgrade, an enhancement or a bug fix
you agree on, reply to this email stating that you approve the patch
and a committer will take care of it.

The full text of the PR can be found at:
    http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/147487

-- 
Edwin Groothuis via the GNATS Auto Assign Tool
edwin@FreeBSD.org
Comment 2 Edwin Groothuis freebsd_committer freebsd_triage 2010-06-05 04:40:15 UTC
State Changed
From-To: open->feedback

Awaiting maintainers feedback (via the GNATS Auto Assign Tool)
Comment 3 Eijiro Shibusawa 2010-06-05 05:05:04 UTC
Sorry !
I forgot to attach the patch - here it is.

Regards,
Eijiro Shibusawa <ej-sib@ice.uec.ac.jp>
Comment 4 Stephen Montgomery-Smith 2010-06-05 05:32:04 UTC
Dear Eijiro Shibusawa,

Can you tell me which file you used in http://mathema.tician.de/node/373?

I can get arpack-arscnd-2.patch.gz to apply cleanly, but I cannot do the 
same with arpack-arscnd-3.patch.gz.

I have attached a patch to the actual port.  Can you tell me if this works?

Thanks, Stephen
Comment 5 Eijiro Shibusawa 2010-06-05 06:15:24 UTC
Dear Stephen Montgomery-Smith, maintainer of math/arpack, 

For fixing the problem, only arpack-arscnd-2.patch.gz is needed.
I have tested your patch, and I found the library including the patch produced a desired result.
Thank you very much for taking care of the PR.

After sent the PR I just noticed I had forgotten to attach my own patch, and it had been already sent.
However your patch is simpler than it, hence your patch should be merged to the ports tree.

Thanks, Eijiro Shibusawa <ej-sib@ice.uec.ac.jp>
Comment 6 Stephen Montgomery-Smith 2010-06-05 06:15:24 UTC
OK, now that Eijiro has submitted his patch, I can see that his patch 
and the one I proposed are essentially identical.  I do think that mine 
is slightly cleaner, but I don't care which patch ultimately is used. 
PORTREVISION will have to be bumped.

Anyway, I approve the PR.
Comment 7 Eijiro Shibusawa 2010-06-15 15:47:35 UTC
Would someone please commit this PR?

I think that consensus has been reached on this PR.
Prof. Montgomery-Smith, the maintainer of math/arpack, kindly dealt with the problem, and proposed a patch fixing the problem. 
I have confirmed his patch works fine, and I agree that it is cleaner than my own patch.
If the problem is fixed before the ports freeze for 8.1R starts, I would be grateful.

Thanks in advance, Eijiro Shibusawa
Comment 8 Stefan Walter freebsd_committer freebsd_triage 2010-07-01 14:04:38 UTC
Responsible Changed
From-To: freebsd-ports-bugs->stefan

Take.
Comment 9 Stefan Walter freebsd_committer freebsd_triage 2010-07-01 20:53:00 UTC
State Changed
From-To: feedback->closed

Fix committed, thanks!
Comment 10 dfilter service freebsd_committer freebsd_triage 2010-07-01 20:53:06 UTC
stefan      2010-07-01 19:52:49 UTC

  FreeBSD ports repository

  Modified files:
    math/arpack          Makefile distinfo 
  Log:
  Fix a problem with symbol duplication when code is linked with both the arpack
  and lapack libraries.
  
  PR:             147487
  Submitted by:   Eijiro Shibusawa <ej-sib@ice.uec.ac.jp>
  Approved by:    Stephen Montgomery-Smith <stephen@missouri.edu> (maintainer)
  Feature safe:   yes
  
  Revision  Changes    Path
  1.20      +5 -2      ports/math/arpack/Makefile
  1.5       +3 -0      ports/math/arpack/distinfo
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"