- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am using following line of code which always fails, because the compiler is trying to execute TSOURCE although MASK==.FALSE.. This behaviours only occurse when the TSOURCE has some kind of modification. In this case it is SIZE. So he is trying to get the SIZE of LC and then he is checking MASK if TSOURCE or FSOURCE should be used. Is this behaviour intended? Reminds me of the non short circuting behaviour in IF statements.
CLASS(myClass), INTENT(IN) :: this INTEGER, INTENT(IN), OPTIONAL :: LC(:) INTEGER :: nLC nLC = MERGE(SIZE(LC), this%nLoadcases, PRESENT(LC))
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This speculation is typical of compiler optimization levels which permit vectorization of conditional operations. If you don't wish this behavior, you can try compile options such as /fp:strict (look up implied levels of speculation). You may have the option of a novector directive, or placing an explicit IF block. You might think that the equivalent of IF block could actually be an optimization when the mask is invariant, so you could try submitting a request to online service center.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code is non-conforming if LC is ever not present. MERGE is a function - when a function is invoked, all actual argument expressions are evaluated, then the function is executed. If LC is not present, then SIZE(LC) cannot be evaluated.
To control the execution order, use an if statement.
IF (PRESENT(LC)) THEN nLC = SIZE(LC) ELSE nLC = this%nLoadCases END IF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the clarification.
ianh wrote:... when a function is invoked, all actual argument expressions are evaluated, then the function is executed.
Thats what I thought. Still I like to use MERGE in similar situations because of simplicity of a one line statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
nLC = SIZE(LC); IF (PRESENT(LC)) nLC = SIZE(LC)
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:nLC = SIZE(LC); IF (PRESENT(LC)) nLC = SIZE(LC)
Jim Dempsey
Ok right. Like this its possible :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"The programmer doth protest too much, methinks"
Hamlet, by William Shakespeare
IOW you wish to attain a preferable form over function by violating one of the language rules.
"I did it my way"
My Way by Frank Sinatra
Jim Dempsey :)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page