Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

A strange program behavior I cannot explain

Ibrahim_K_
New Contributor I
650 Views

Dear Friends:

I am about to complete a large mixed language project (C++,Fortran legacy code; I asked silly and not so silly questions before) with lots of bad/risky ingredients like lots of COMMON statement shared by C++. I am now testing the resulting program. It is running bit I have a very strange problem.

In one of the legacy FORTRAN Subroutines I have a local 4x4 matrix. The variable name is SSXY(4,4). I initially included a debug WRITE statement to watch its content. It seemed like all was working. When I deleted the debug statement, the program gives very strange results. When I include a very simple WRITE statement like:

          WRITE(7,7015) SSXY(1,1)
 7015 FORMAT(' ROD: SSXY(1,1) = ',E15.7)

Anywhere. It runs OK. If I put an IF block around it does go back to faulty mode.

I am now going through all the commons shared with C++ code to make sure there is no misalignment. Strange thing is the code is very stable. It never crashes either way.

I am posting this message to ask your wisdom on possible reasons and how I should go about chasing it.

Regards;

I. Konuk

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
650 Views

Problems that appear when you remove (or add) seemingly unrelated statements are usually due to memory corruption issues, such as mismatched arguments or writing past the end of an array. There are many other possibilities. Often the cause of the error is far removed from where it appears.

View solution in original post

0 Kudos
10 Replies
Steve_Lionel
Honored Contributor III
651 Views

Problems that appear when you remove (or add) seemingly unrelated statements are usually due to memory corruption issues, such as mismatched arguments or writing past the end of an array. There are many other possibilities. Often the cause of the error is far removed from where it appears.

0 Kudos
Ibrahim_K_
New Contributor I
650 Views

Steve Lionel (Ret.) (Blackbelt) wrote:

Problems that appear when you remove (or add) seemingly unrelated statements are usually due to memory corruption issues, such as mismatched arguments or writing past the end of an array. There are many other possibilities. Often the cause of the error is far removed from where it appears.

 

Steve:

Thank you very much again. Your advice was indeed very helpful. I am going through all CALLs. I already found one mistyping(!). The subroutine CALL is expecting a matrix. Misspelling means a scalar being passed. Just like you described.

Thank you.

Merry Christmas and happy holidays to all.

I. Konuk

0 Kudos
Steve_Lionel
Honored Contributor III
650 Views

The compiler has a feature, on by default in a Debug Visual Studio configuration, that helps with this. From the command line it is /warn:interfaces and in Visual Studio, Fortran > Diagnostics > Check routine interfaces.

You should also get in the habit of adding IMPLICIT NONE in every program unit - this will help you find misspelled variable names.

0 Kudos
Ibrahim_K_
New Contributor I
650 Views

Steve:

I will do the first one right away. I have plans to do the IMPLICIT in the future as it would be too much work right now to make legacy code type safe. My goal is first to finish the full size prototype. I will try it in the future or I may just code some units (slowly) in C++.

By the way, it seems like the one and only error which I reported earlier was the culprit. Thank you again for all your valuable suggestions.

Happy holidays.

I. Konuk

0 Kudos
Ibrahim_K_
New Contributor I
650 Views

I was wrong! The compiler found a second one. I learned and benefited from this Forum, especially you so much. I owe much gratitude. THANK YOU!

I. Konuk

0 Kudos
kolber__Michael
New Contributor I
650 Views

Steve,

 

I am running vs community edition 2017 with IVF 19 update 5.  I do not have a Fortran menu off of the main menu and under project properties I do not have a diagnostics menu.  I am interested in turning on the interface checking.

 

Michael

0 Kudos
Steve_Lionel
Honored Contributor III
650 Views

Annotation 2019-12-26 123711.png

0 Kudos
kolber__Michael
New Contributor I
650 Views

Steve,

My only option is compile time diagnostics

 

0 Kudos
Steve_Lionel
Honored Contributor III
650 Views

That property page is long - did you scroll it? The screen shot I showed has it scrolled to the end.

Show a screen shot of what you are seeing.

0 Kudos
kolber__Michael
New Contributor I
650 Views

I get the options when I set diagnostics to custom.  So I am good now.

 

Thanks.

0 Kudos
Reply