Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove need for non-standard SIZEOF #89

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/trans/internal/suleg_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
!

MODULE SULEG_MOD
#ifdef __NEC__
#define SIZEOF(x) STORAGE_SIZE(x)/KIND(x)
#endif
CONTAINS
SUBROUTINE SULEG
!DEC$ OPTIMIZE:1
Expand Down Expand Up @@ -874,10 +871,9 @@ SUBROUTINE SULEG
ZCLONEA(IMLOC)%COMMSBUF(1:ICLONELEN) = ZRCVBUTFV(1:ICLONELEN,JSETV)
CALL UNPACK_BUTTERFLY_STRUCT(S%FA(IMLOC)%YBUT_STRUCT_A,ZCLONEA(IMLOC))
ENDIF
IF(ALLOCATED(ZCLONEA(IMLOC)%COMMSBUF) ) THEN
IF( SIZEOF(ZCLONEA(IMLOC)%COMMSBUF) > 0 ) DEALLOCATE(ZCLONEA(IMLOC)%COMMSBUF)
! ZCLONEA(IMLOC)%COMMSBUF=>NULL()
ENDIF

IF( STORAGE_SIZE(ZCLONEA(IMLOC)%COMMSBUF) > 0 ) DEALLOCATE(ZCLONEA(IMLOC)%COMMSBUF)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that ICLONELEN could be unininitialized in case
IF( .NOT.ALLOCATED(ZCLONEA(IMLOC)%COMMSBUF) )THEN (line 868) is not triggered.
Probably the IF(ALLOCATED(ZCLONEA(IMLOC)%COMMSBUF) ) THEN was still correct.
Could it not also be that it needs to stay allocated across iterations? Otherwise why all the guards (line 868).

Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to do this can you just do:

IF( ALLOCATED(ZCLONEA) ) DEALLOCATE(ZCLONEA(IMLOC)%COMMSBUF)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point @wdeconinck - we shouldn't use ICLONELEN.

The first IF has no purpose at all, as far as I can see. I can't see how it's possible for ZCLONEA(IMLOC)%COMMSBUF to not be allocated at line 877.

Instead of checking if ICLONELEN > 0, why don't we check STORAGE_SIZE(ZCLONEA(IMLOC)%COMMSBUF) > 0? STORAGE_SIZE is the same as SIZEOF but returns the bits allocated rather than bytes, and it appears to be part of the Fortran 2008 standard, unlike SIZEOF.

IF( ASSOCIATED(S%FA(IMLOC)%RPNMA) .AND. .NOT. S%LKEEPRPNM ) DEALLOCATE(S%FA(IMLOC)%RPNMA)
IF( ASSOCIATED(S%FA(IMLOC)%RPNMDA) ) DEALLOCATE(S%FA(IMLOC)%RPNMDA)
ENDIF
Expand Down Expand Up @@ -1157,10 +1153,9 @@ SUBROUTINE SULEG
ZCLONES(IMLOC)%COMMSBUF(1:ICLONELEN) = ZRCVBUTFV(1:ICLONELEN,JSETV)
CALL UNPACK_BUTTERFLY_STRUCT( S%FA(IMLOC)%YBUT_STRUCT_S,ZCLONES(IMLOC))
ENDIF
IF( ALLOCATED(ZCLONES(IMLOC)%COMMSBUF) ) THEN
IF( SIZEOF(ZCLONES(IMLOC)%COMMSBUF) > 0 ) DEALLOCATE(ZCLONES(IMLOC)%COMMSBUF)
! ZCLONES(IMLOC)%COMMSBUF=>NULL()
ENDIF

IF( STORAGE_SIZE(ZCLONES(IMLOC)%COMMSBUF) > 0 ) DEALLOCATE(ZCLONES(IMLOC)%COMMSBUF)

IF( ASSOCIATED(S%FA(IMLOC)%RPNMS) .AND. .NOT. S%LKEEPRPNM ) DEALLOCATE(S%FA(IMLOC)%RPNMS)
IF( ASSOCIATED(S%FA(IMLOC)%RPNMDS) ) DEALLOCATE(S%FA(IMLOC)%RPNMDS)
ENDIF
Expand Down
Loading