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

Conversation

samhatfield
Copy link
Collaborator

@samhatfield samhatfield commented Apr 11, 2024

Builds on #78 and resolves #77.

I remove one redundant IF statement (right above there is logic which ensures the condition is always .TRUE..

I also remove the SIZEOF by simply checking the value of the integer used to determine the size of the allocated array, rather than checking how many bytes were actually allocated.

ENDIF

IF( ICLONELEN > 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.

! ZCLONES(IMLOC)%COMMSBUF=>NULL()
ENDIF

IF( ICLONELEN > 0 ) DEALLOCATE(ZCLONES(IMLOC)%COMMSBUF)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

@DJDavies2
Copy link
Contributor

I've tested here and it seems to work for me.

@samhatfield
Copy link
Collaborator Author

@DJDavies2 - could you test the latest commit with NAG Fortran?

@wdeconinck
Copy link
Collaborator

Given we can use STORAGE_SIZE instead of SIZEOF, could we not use the original code with just this change to avoid any surprising side effects?

@samhatfield
Copy link
Collaborator Author

We could do that yes. I'll see what @DJDavies2 gets with NAG then update the PR.

@DJDavies2
Copy link
Contributor

This branch seems to work for me as far as it goes.

@DJDavies2
Copy link
Contributor

I'm down as a reviewer for this but I don't think I have the permissions to do that? I am happy to "approve" this.

Copy link
Collaborator

@wdeconinck wdeconinck left a comment

Choose a reason for hiding this comment

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

OK for me. Nice cleanup

@wdeconinck wdeconinck merged commit 3786b6b into ecmwf-ifs:develop May 6, 2024
11 checks passed
@samhatfield samhatfield deleted the samhatfield/remove_SIZEOF branch June 5, 2024 14:00
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