Skip to content

Commit

Permalink
[BUG FIX] Make sure iseed is always initialized to values allowed by
Browse files Browse the repository at this point in the history
lapack ?larnv.

This means killing inits variable:
  - Using MPI, inits (shared variable) may be set to false by one proc,
    and prevent other procs to initialize seeds (as inits is shared by
    use of the save fortran keyword).
  - Not using MPI, inits only prevents from re-initializing seeds which
    have already been initialized.

This commit is not-op. From a functional point of view, we are doing
the same thing. From an implementation point of view, we make sure
iseed is always (for all MPI procs) initialized to values allowed
by lapack (if not, lapack crashes).

This problem doesn't occur with sequential code. Changes have been
done in both sequential and MPI code to keep things symmetric.
  • Loading branch information
fghoussen committed Aug 14, 2022
1 parent f36eb6c commit ce2e69a
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 148 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -27,6 +27,7 @@ arpack-ng - 3.9.0
* arpackmm: restart bug fix.
* pyarpack: fix compilation warning, test on macos and latest boost-python (1.79).
* arpackSolver: fix error messages.
* [BUG FIX] Make sure iseed is always initialized to values allowed by lapack ?larnv.

[ Haoyang Liu ]
* CMake: minimum required version changed to 3.0
Expand Down
48 changes: 19 additions & 29 deletions PARPACK/SRC/MPI/pcgetv0.f
Expand Up @@ -176,13 +176,13 @@ subroutine pcgetv0
c | Local Scalars & Arrays |
c %------------------------%
c
logical first, inits, orth
logical first, orth
integer idist, iseed(4), iter, msglvl, jj, myid, igen
Real
& rnorm0
Complex
& cnorm, cnorm2
save first, iseed, inits, iter, msglvl, orth, rnorm0
save first, iseed, iter, msglvl, orth, rnorm0
c
Complex
& cnorm_buf, buf2(1)
Expand All @@ -203,12 +203,6 @@ subroutine pcgetv0
& ccdotc
external ccdotc, pscnorm2, slapy2
c
c %-----------------%
c | Data Statements |
c %-----------------%
c
data inits /.true./
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
Expand All @@ -219,30 +213,26 @@ subroutine pcgetv0
c | random number generator |
c %-----------------------------------%
c
if (inits) then
c
c %-----------------------------------%
c | Generate a seed on each processor |
c | using process id (myid). |
c | Note: the seed must be between 1 |
c | and 4095. iseed(4) must be odd. |
c %-----------------------------------%
c
call MPI_COMM_RANK(comm, myid, ierr)
igen = 1000 + 2*myid + 1
if (igen .gt. 4095) then
write(0,*) 'Error in p_getv0: seed exceeds 4095!'
end if
c
iseed(1) = igen/1000
igen = mod(igen,1000)
iseed(2) = igen/100
igen = mod(igen,100)
iseed(3) = igen/10
iseed(4) = mod(igen,10)
c %-----------------------------------%
c | Generate a seed on each processor |
c | using process id (myid). |
c | Note: the seed must be between 1 |
c | and 4095. iseed(4) must be odd. |
c %-----------------------------------%
c
inits = .false.
call MPI_COMM_RANK(comm, myid, ierr)
igen = 1000 + 2*myid + 1
if (igen .gt. 4095) then
write(0,*) 'Error in p_getv0: seed exceeds 4095!'
end if
c
iseed(1) = igen/1000
igen = mod(igen,1000)
iseed(2) = igen/100
igen = mod(igen,100)
iseed(3) = igen/10
iseed(4) = mod(igen,10)
c
if (ido .eq. 0) then
c
Expand Down
21 changes: 6 additions & 15 deletions PARPACK/SRC/MPI/pdgetv0.f
Expand Up @@ -177,11 +177,11 @@ subroutine pdgetv0
c | Local Scalars & Arrays |
c %------------------------%
c
logical first, inits, orth
logical first, orth
integer idist, iseed(4), iter, msglvl, jj
Double precision
& rnorm0, buf2(1)
save first, iseed, inits, iter, msglvl, orth, rnorm0
save first, iseed, iter, msglvl, orth, rnorm0
c
Double precision
& rnorm_buf
Expand All @@ -206,12 +206,6 @@ subroutine pdgetv0
c
intrinsic abs, sqrt
c
c %-----------------%
c | Data Statements |
c %-----------------%
c
data inits /.true./
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
Expand All @@ -222,13 +216,10 @@ subroutine pdgetv0
c | random number generator |
c %-----------------------------------%
c
if (inits) then
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
inits = .false.
end if
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
c
if (ido .eq. 0) then
c
Expand Down
21 changes: 6 additions & 15 deletions PARPACK/SRC/MPI/psgetv0.f
Expand Up @@ -177,11 +177,11 @@ subroutine psgetv0
c | Local Scalars & Arrays |
c %------------------------%
c
logical first, inits, orth
logical first, orth
integer idist, iseed(4), iter, msglvl, jj
Real
& rnorm0
save first, iseed, inits, iter, msglvl, orth, rnorm0
save first, iseed, iter, msglvl, orth, rnorm0
c
Real
& rnorm_buf
Expand All @@ -206,12 +206,6 @@ subroutine psgetv0
c
intrinsic abs, sqrt
c
c %-----------------%
c | Data Statements |
c %-----------------%
c
data inits /.true./
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
Expand All @@ -222,13 +216,10 @@ subroutine psgetv0
c | random number generator |
c %-----------------------------------%
c
if (inits) then
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
inits = .false.
end if
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
c
if (ido .eq. 0) then
c
Expand Down
48 changes: 19 additions & 29 deletions PARPACK/SRC/MPI/pzgetv0.f
Expand Up @@ -176,13 +176,13 @@ subroutine pzgetv0
c | Local Scalars & Arrays |
c %------------------------%
c
logical first, inits, orth
logical first, orth
integer idist, iseed(4), iter, msglvl, jj, myid, igen
Double precision
& rnorm0
Complex*16
& cnorm, cnorm2
save first, iseed, inits, iter, msglvl, orth, rnorm0
save first, iseed, iter, msglvl, orth, rnorm0
c
Complex*16
& cnorm_buf, buf2(1)
Expand All @@ -203,12 +203,6 @@ subroutine pzgetv0
& zzdotc
external zzdotc , pdznorm2 , dlapy2
c
c %-----------------%
c | Data Statements |
c %-----------------%
c
data inits /.true./
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
Expand All @@ -219,30 +213,26 @@ subroutine pzgetv0
c | random number generator |
c %-----------------------------------%
c
if (inits) then
c
c %-----------------------------------%
c | Generate a seed on each processor |
c | using process id (myid). |
c | Note: the seed must be between 1 |
c | and 4095. iseed(4) must be odd. |
c %-----------------------------------%
c
call MPI_COMM_RANK(comm, myid, ierr)
igen = 1000 + 2*myid + 1
if (igen .gt. 4095) then
write(0,*) 'Error in p_getv0: seed exceeds 4095!'
end if
c
iseed(1) = igen/1000
igen = mod(igen,1000)
iseed(2) = igen/100
igen = mod(igen,100)
iseed(3) = igen/10
iseed(4) = mod(igen,10)
c %-----------------------------------%
c | Generate a seed on each processor |
c | using process id (myid). |
c | Note: the seed must be between 1 |
c | and 4095. iseed(4) must be odd. |
c %-----------------------------------%
c
inits = .false.
call MPI_COMM_RANK(comm, myid, ierr)
igen = 1000 + 2*myid + 1
if (igen .gt. 4095) then
write(0,*) 'Error in p_getv0: seed exceeds 4095!'
end if
c
iseed(1) = igen/1000
igen = mod(igen,1000)
iseed(2) = igen/100
igen = mod(igen,100)
iseed(3) = igen/10
iseed(4) = mod(igen,10)
c
if (ido .eq. 0) then
c
Expand Down
21 changes: 6 additions & 15 deletions SRC/cgetv0.f
Expand Up @@ -156,13 +156,13 @@ subroutine cgetv0
c | Local Scalars & Arrays |
c %------------------------%
c
logical first, inits, orth
logical first, orth
integer idist, iseed(4), iter, msglvl, jj
Real
& rnorm0
Complex
& cnorm
save first, iseed, inits, iter, msglvl, orth, rnorm0
save first, iseed, iter, msglvl, orth, rnorm0
c
c %----------------------%
c | External Subroutines |
Expand All @@ -180,12 +180,6 @@ subroutine cgetv0
& ccdotc
external ccdotc, scnrm2, slapy2
c
c %-----------------%
c | Data Statements |
c %-----------------%
c
data inits /.true./
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
Expand All @@ -196,13 +190,10 @@ subroutine cgetv0
c | random number generator |
c %-----------------------------------%
c
if (inits) then
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
inits = .false.
end if
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
c
if (ido .eq. 0) then
c
Expand Down
21 changes: 6 additions & 15 deletions SRC/dgetv0.f
Expand Up @@ -157,11 +157,11 @@ subroutine dgetv0
c | Local Scalars & Arrays |
c %------------------------%
c
logical first, inits, orth
logical first, orth
integer idist, iseed(4), iter, msglvl, jj
Double precision
& rnorm0
save first, iseed, inits, iter, msglvl, orth, rnorm0
save first, iseed, iter, msglvl, orth, rnorm0
c
c %----------------------%
c | External Subroutines |
Expand All @@ -183,12 +183,6 @@ subroutine dgetv0
c
intrinsic abs, sqrt
c
c %-----------------%
c | Data Statements |
c %-----------------%
c
data inits /.true./
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
Expand All @@ -199,13 +193,10 @@ subroutine dgetv0
c | random number generator |
c %-----------------------------------%
c
if (inits) then
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
inits = .false.
end if
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
c
if (ido .eq. 0) then
c
Expand Down
21 changes: 6 additions & 15 deletions SRC/sgetv0.f
Expand Up @@ -157,11 +157,11 @@ subroutine sgetv0
c | Local Scalars & Arrays |
c %------------------------%
c
logical first, inits, orth
logical first, orth
integer idist, iseed(4), iter, msglvl, jj
Real
& rnorm0
save first, iseed, inits, iter, msglvl, orth, rnorm0
save first, iseed, iter, msglvl, orth, rnorm0
c
c %----------------------%
c | External Subroutines |
Expand All @@ -183,12 +183,6 @@ subroutine sgetv0
c
intrinsic abs, sqrt
c
c %-----------------%
c | Data Statements |
c %-----------------%
c
data inits /.true./
c
c %-----------------------%
c | Executable Statements |
c %-----------------------%
Expand All @@ -199,13 +193,10 @@ subroutine sgetv0
c | random number generator |
c %-----------------------------------%
c
if (inits) then
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
inits = .false.
end if
iseed(1) = 1
iseed(2) = 3
iseed(3) = 5
iseed(4) = 7
c
if (ido .eq. 0) then
c
Expand Down

0 comments on commit ce2e69a

Please sign in to comment.