Skip to content

fix post-loop SIDE/TRANS guard in p?ormrz / p?unmrz#162

Merged
langou merged 1 commit into
Reference-ScaLAPACK:masterfrom
kyungminlee:fix-ormrz-post-loop-guard
May 6, 2026
Merged

fix post-loop SIDE/TRANS guard in p?ormrz / p?unmrz#162
langou merged 1 commit into
Reference-ScaLAPACK:masterfrom
kyungminlee:fix-ormrz-post-loop-guard

Conversation

@kyungminlee
Copy link
Copy Markdown
Contributor

In PCUNMRZ/PDORMRZ/PSORMRZ/PZUNMRZ, the post-loop guard that controls the leading-partial-block PORMR3/PUNMR3 fix-up was a byte-for-byte copy of the pre-loop guard. The same condition gated both blocks, so the post-loop fired together with the pre-loop in the (LEFT,!NOTRAN) / (RIGHT,NOTRAN) directions (over-applying K-1 reflectors to an already transformed C) and never fired in the complementary (LEFT,NOTRAN) / (RIGHT,!NOTRAN) directions (silently skipping the leading partial block of reflectors). All four SIDE/TRANS combinations produced numerically incorrect results.

Replace the post-loop guard with the complement of the pre-loop guard, matching the analogous structure in p?ormrq.f.

In PCUNMRZ/PDORMRZ/PSORMRZ/PZUNMRZ, the post-loop guard that controls
the leading-partial-block PORMR3/PUNMR3 fix-up was a byte-for-byte copy
of the pre-loop guard. The same condition gated both blocks, so the
post-loop fired together with the pre-loop in the (LEFT,!NOTRAN) /
(RIGHT,NOTRAN) directions (over-applying K-1 reflectors to an already
transformed C) and never fired in the complementary (LEFT,NOTRAN) /
(RIGHT,!NOTRAN) directions (silently skipping the leading partial block
of reflectors). All four SIDE/TRANS combinations produced numerically
incorrect results.

Replace the post-loop guard with the complement of the pre-loop guard,
matching the analogous structure in p?ormrq.f.
Comment thread SRC/pcunmrz.f
10 CONTINUE
*
IF( ( LEFT .AND. .NOT.NOTRAN ) .OR.
$ ( .NOT.LEFT .AND. NOTRAN ) ) THEN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these can be replaced with .EQV. for logical equivalence? Simpler?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would look simpler. The pattern seems to have been inherited from LAPACK, and used multiple times within the same subroutine.

scalapack/SRC/pcunmrz.f

Lines 379 to 384 in f7edd05

CALL PB_TOPGET( ICTXT, 'Broadcast', 'Columnwise', COLBTOP )
*
IF( ( LEFT .AND. .NOT.NOTRAN ) .OR.
$ ( .NOT.LEFT .AND. NOTRAN ) ) THEN
I1 = MIN( ICEIL( IA, DESCA( MB_ ) ) * DESCA( MB_ ), IA+K-1 )
$ + 1

@langou langou merged commit f3f3974 into Reference-ScaLAPACK:master May 6, 2026
11 of 12 checks passed
@langou
Copy link
Copy Markdown
Contributor

langou commented May 6, 2026

As pointed @zerothi, we could replace

      IF( ( LEFT .AND. .NOT.NOTRAN ) .OR.
     $    ( .NOT.LEFT .AND. NOTRAN ) ) THEN

with

      IF( LEFT .EQV. .NOT.NOTRAN ) THEN

This is a good comment.

I do not have a strong opinion.

(1) The former might be easier to read (matter of taste), and (2) is what's already in the code and (3) is based on the three more common logical operators .NOT., .AND., .OR. while the .EQV. logical operator is not used anywhere in LAPACK nor ScaLAPACK.

The latter is more concise and elegant (matter of taste).

If someone wants to propose a separate PR, why not.

@zerothi
Copy link
Copy Markdown
Contributor

zerothi commented May 6, 2026

As pointed @zerothi, we could replace

      IF( ( LEFT .AND. .NOT.NOTRAN ) .OR.
     $    ( .NOT.LEFT .AND. NOTRAN ) ) THEN

with

      IF( LEFT .EQV. .NOT.NOTRAN ) THEN

This is a good comment.

I do not have a strong opinion.

(1) The former might be easier to read (matter of taste), and (2) is what's already in the code and (3) is based on the three more common logical operators .NOT., .AND., .OR. while the .EQV. logical operator is not used anywhere in LAPACK nor ScaLAPACK.

The latter is more concise and elegant (matter of taste).

If someone wants to propose a separate PR, why not.

Ok, I can see lots of places in the code that could replace with:
.NEQV. and .EQV..

So if this is ok, I could see if I have the time for this.

@kyungminlee kyungminlee deleted the fix-ormrz-post-loop-guard branch May 8, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants